Skip to content

Commit

Permalink
Added v1.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rundb committed Jun 23, 2024
1 parent 6c64c9c commit e2cf5e4
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"type": "cortex-debug",
"servertype": "jlink",
"serverpath": "/usr/bin/JLinkGDBServerCLExe",
"device": "nRF52832_xxAA",
"device": "nRF52840_xxAA",
"interface": "swd",
"serialNumber": "", // add J-Link serial number if having multiple attached the same time.
"runToMain": false,
"svdFile": "${workspaceRoot}/firmware/sdk/nRF5_SDK_17.1.0_ddde560/modules/nrfx/mdk/nrf52.svd",
"svdFile": "${workspaceRoot}/firmware/sdk/nRF5_SDK_17.1.0_ddde560/modules/nrfx/mdk/nrf52840.svd",
"showDevDebugOutput": "parsed",
}
]
Expand Down
4 changes: 2 additions & 2 deletions firmware/cmake/dictofun.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file contains definitions that are specific for Dictofun target

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNRF_DFU_SETTINGS_VERSION=2 -DCONFIG_NFCT_PINS_AS_GPIOS -DDEBUG")
set(NRF5_BOARD "dictofun_v_1_3")
set(NRF5_SOFTDEVICE_VARIANT "s132")
set(NRF5_BOARD "dictofun_v_1_4")
set(NRF5_SOFTDEVICE_VARIANT "s140")
set(NRF5_LINKER_SCRIPT "${PROJECT_SOURCE_DIR}/src/targets/dictofun/dictofun_linkerscript.ld")
set(NRF5_SDKCONFIG_PATH "${PROJECT_SOURCE_DIR}/src/targets/dictofun/config")
set(FREERTOS_CONFIG_PATH "${PROJECT_SOURCE_DIR}/src/targets/dictofun/config")
Expand Down
5 changes: 4 additions & 1 deletion firmware/cmake/nrf5_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function(nrf5_get_board_target sdk_version board out_target out_define)
set(board_arduinoprimo nrf52832_xxaa BOARD_ARDUINO_PRIMO 15.3.0 16.0.0)
set(board_dictofun_v_1_1 nrf52832_xxaa BOARD_DICTOFUN_1_1 17.1.0 17.1.0)
set(board_dictofun_v_1_3 nrf52832_xxaa BOARD_DICTOFUN_1_3 17.1.0 17.1.0)
set(board_dictofun_v_1_4 nrf52840_xxaa BOARD_DICTOFUN_1_4 17.1.0 17.1.0)

if(NOT board_${board})
message(FATAL_ERROR "Unsupported nRF board: ${board}")
Expand Down Expand Up @@ -135,7 +136,7 @@ function(nrf5_get_target_flags sdk_version target out_target out_target_short ou
set(target_nrf52832_xxaa nrf52832 NRF52832_XXAA 15.3.0 17.1.0)
set(target_nrf52832_xxab nrf52832 NRF52832_XXAB 15.3.0 16.0.0)
set(target_nrf52833_xxaa nrf52833 NRF52833_XXAA 16.0.0 16.0.0)
set(target_nrf52840_xxaa nrf52840 NRF52840_XXAA 15.3.0 16.0.0)
set(target_nrf52840_xxaa nrf52840 NRF52840_XXAA 15.3.0 17.1.0)

if(NOT target_${target})
message(FATAL_ERROR "Unsupported nRF target: ${target}")
Expand Down Expand Up @@ -264,6 +265,7 @@ function(nrf5_get_softdevice_data sdk_path sdk_version target sd_variant out_sd_
set(supports_16.0.0_s340 nrf52840)

set(supports_17.1.0_s132 nrf52832)
set(supports_17.1.0_s140 nrf52811 nrf52820 nrf52833 nrf52840)

list(FIND supports_${sdk_version}_${sd_variant} ${target_group} sd_target_supported)
if (sd_target_supported EQUAL -1)
Expand Down Expand Up @@ -301,6 +303,7 @@ function(nrf5_get_softdevice_data sdk_path sdk_version target sd_variant out_sd_
set(softdevice_16.0.0_s340 6.1.1 YES YES)

set(softdevice_17.1.0_s132 7.2.0 YES NO)
set(softdevice_17.1.0_s140 7.2.0 YES NO)

list(GET softdevice_${sdk_version}_${sd_variant} ${sd_key_version} sd_version)
list(GET softdevice_${sdk_version}_${sd_variant} ${sd_key_use_ble} sd_use_ble)
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/targets/boards/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "dictofun_1_1.h"
#elif defined(BOARD_DICTOFUN_1_3)
#include "dictofun_1_3.h"
#elif defined(BOARD_DICTOFUN_1_4)
#include "dictofun_1_4.h"
#else
#error "Board is not defined"
#endif
Expand Down
50 changes: 50 additions & 0 deletions firmware/src/targets/boards/dictofun_1_4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "nrf_gpio.h"

#define BSP_BUTTON_0 NRF_GPIO_PIN_MAP(1,13)
#define LED_1 NRF_GPIO_PIN_MAP(0,24) // BLUE
#define LED_2 NRF_GPIO_PIN_MAP(1,0) // GREEN
#define LED_3 NRF_GPIO_PIN_MAP(0,22) // RED

#define BUTTON_PULL NRF_GPIO_PIN_PULLUP

#define LEDS_NUMBER 3
#define BUTTONS_NUMBER 1

#define LEDS_LIST { LED_1, LED_2, LED_3 }
#define BUTTONS_LIST { BSP_BUTTON_0 }

#define LEDS_ACTIVE_STATE 0
#define LED_ON 0
#define LED_OFF 1

#define LEDS_INV_MASK LEDS_MASK

#define BUTTONS_ACTIVE_STATE 1

#define BUTTON_PIN NRF_GPIO_PIN_MAP(1,13)

#define BOARD_NAME "dictofun_v1.4"

#define SPI_FLASH_MISO_PIN NRF_GPIO_PIN_MAP(1,4)
#define SPI_FLASH_WP_PIN NRF_GPIO_PIN_MAP(0,9)
#define SPI_FLASH_CS_PIN NRF_GPIO_PIN_MAP(1,6)
#define SPI_FLASH_MOSI_PIN NRF_GPIO_PIN_MAP(1,2)
#define SPI_FLASH_SCK_PIN NRF_GPIO_PIN_MAP(1,7)
#define SPI_FLASH_RST_PIN NRF_GPIO_PIN_MAP(0,25)

#define CONFIG_IO_PDM_CLK NRF_GPIO_PIN_MAP(0,15)
#define CONFIG_IO_PDM_DATA NRF_GPIO_PIN_MAP(0, 17)

#define UART_TX_PIN_NUMBER (6)
#define UART_RX_PIN_NUMBER (4)

#define I2C_CLK_PIN_NUMBER NRF_GPIO_PIN_MAP(1,9)
#define I2C_DATA_PIN_NUMBER NRF_GPIO_PIN_MAP(0,12)
#define RTC_INT_N_PIN NRF_GPIO_PIN_MAP(0,8)
#define I2C_MODULE_IDX 1

#define LDO_LATCH_D_PIN NRF_GPIO_PIN_MAP(0,2)
#define LDO_LATCH_CLK_PIN NRF_GPIO_PIN_MAP(1,15)

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
PROJECT_NAME := secure_bootloader_ble_s132_pca10040_debug
TARGETS := nrf52832_xxaa_s132
PROJECT_NAME := secure_bootloader_ble_s140_pca10056_debug
TARGETS := nrf52840_xxaa_s140
OUTPUT_DIRECTORY := _build

SDK_ROOT := ../../../../../sdk/nRF5_SDK_17.1.0_ddde560
PROJ_DIR := ../..

$(OUTPUT_DIRECTORY)/nrf52832_xxaa_s132.out: \
$(OUTPUT_DIRECTORY)/nrf52840_xxaa_s140.out: \
LINKER_SCRIPT := secure_bootloader_gcc_nrf52.ld

# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \
Expand Down Expand Up @@ -97,7 +97,7 @@ SRC_FILES += \
# Include folders common to all targets
INC_FOLDERS += \
$(SDK_ROOT)/components/libraries/crypto/backend/micro_ecc \
$(SDK_ROOT)/components/softdevice/s132/headers \
$(SDK_ROOT)/components/softdevice/s140/headers \
$(SDK_ROOT)/components/libraries/memobj \
$(SDK_ROOT)/components/libraries/sha256 \
$(SDK_ROOT)/components/libraries/crc32 \
Expand All @@ -112,7 +112,7 @@ INC_FOLDERS += \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310_bl \
$(SDK_ROOT)/components/softdevice/s132/headers/nrf52 \
$(SDK_ROOT)/components/softdevice/s140/headers/nrf52 \
$(SDK_ROOT)/components/libraries/log/src \
$(SDK_ROOT)/components/libraries/bootloader/dfu \
$(SDK_ROOT)/components/ble/common \
Expand Down Expand Up @@ -162,19 +162,17 @@ OPT = -Os -g3
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -DBOARD_DICTOFUN_1_3
CFLAGS += -DBOARD_DICTOFUN_1_4
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DDEBUG_NRF
CFLAGS += -DDEBUG
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DNRF52
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DNRF52_PAN_74
CFLAGS += -DNRF52840_XXAA
CFLAGS += -DNRF_DFU_DEBUG_VERSION
CFLAGS += -DNRF_DFU_SETTINGS_VERSION=2
CFLAGS += -DNRF_DFU_SVCI_ENABLED
CFLAGS += -DNRF_SD_BLE_API_VERSION=7
CFLAGS += -DS132
CFLAGS += -DS140
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DSVC_INTERFACE_CALL_AS_NORMAL_FUNCTION
CFLAGS += -DuECC_ENABLE_VLI_API=0
Expand All @@ -198,18 +196,16 @@ ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
ASMFLAGS += -DBOARD_DICTOFUN_1_3
ASMFLAGS += -DBOARD_DICTOFUN_1_4
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DDEBUG_NRF
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DNRF52
ASMFLAGS += -DNRF52832_XXAA
ASMFLAGS += -DNRF52_PAN_74
ASMFLAGS += -DNRF52840_XXAA
ASMFLAGS += -DNRF_DFU_DEBUG_VERSION
ASMFLAGS += -DNRF_DFU_SETTINGS_VERSION=2
ASMFLAGS += -DNRF_DFU_SVCI_ENABLED
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=7
ASMFLAGS += -DS132
ASMFLAGS += -DS140
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DSVC_INTERFACE_CALL_AS_NORMAL_FUNCTION
ASMFLAGS += -DuECC_ENABLE_VLI_API=0
Expand All @@ -228,8 +224,8 @@ LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs

nrf52832_xxaa_s132: CFLAGS += -D__HEAP_SIZE=0
nrf52832_xxaa_s132: ASMFLAGS += -D__HEAP_SIZE=0
nrf52840_xxaa_s140: CFLAGS += -D__HEAP_SIZE=0
nrf52840_xxaa_s140: ASMFLAGS += -D__HEAP_SIZE=0

# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
Expand All @@ -239,12 +235,12 @@ LIB_FILES += -lc -lnosys -lm
.PHONY: default help

# Default target - first one defined
default: nrf52832_xxaa_s132
default: nrf52840_xxaa_s140

# Print all targets that can be built
help:
@echo following targets are available:
@echo nrf52832_xxaa_s132
@echo nrf52840_xxaa_s140
@echo flash_softdevice
@echo sdk_config - starting external tool for editing sdk_config.h
@echo flash - flashing binary
Expand All @@ -260,14 +256,14 @@ $(foreach target, $(TARGETS), $(call define_target, $(target)))

# Flash the program
flash: default
@echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa_s132.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa_s132.hex --sectorerase
@echo Flashing: $(OUTPUT_DIRECTORY)/nrf52840_xxaa_s140.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52840_xxaa_s140.hex --sectorerase
nrfjprog -f nrf52 --reset

# Flash softdevice
flash_softdevice:
@echo Flashing: s132_nrf52_7.2.0_softdevice.hex
nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_7.2.0_softdevice.hex --sectorerase
@echo Flashing: s140_nrf52_7.2.0_softdevice.hex
nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex --sectorerase
nrfjprog -f nrf52 --reset

erase:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@
#endif
// <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin
#ifndef NRF_LOG_BACKEND_UART_TX_PIN
#define NRF_LOG_BACKEND_UART_TX_PIN 11
#define NRF_LOG_BACKEND_UART_TX_PIN 4
#endif

#ifndef NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE
Expand Down Expand Up @@ -1854,7 +1854,7 @@
// <4=> Debug

#ifndef NRF_LOG_DEFAULT_LEVEL
#define NRF_LOG_DEFAULT_LEVEL 3
#define NRF_LOG_DEFAULT_LEVEL 4
#endif

// <q> NRF_LOG_DEFERRED - Enable deffered logger.
Expand Down
8 changes: 7 additions & 1 deletion firmware/src/targets/dictofun/app_error_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,11 @@ void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
NRF_BREAKPOINT_COND;
// On assert, the system can only recover with a reset.

nrf_gpio_pin_clear(LDO_EN_PIN);
//nrf_gpio_pin_clear(LDO_EN_PIN);
nrf_gpio_pin_clear(LDO_LATCH_D_PIN);
nrf_gpio_pin_set(LDO_LATCH_CLK_PIN);
for (volatile int i = 0; i < 100000; ++i);
nrf_gpio_pin_clear(LDO_LATCH_CLK_PIN);
for (volatile int i = 0; i < 100000; ++i);
nrf_gpio_pin_set(LDO_LATCH_CLK_PIN);
}
4 changes: 2 additions & 2 deletions firmware/src/targets/dictofun/config/sdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7725,7 +7725,7 @@
#endif
// <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin
#ifndef NRF_LOG_BACKEND_UART_TX_PIN
#define NRF_LOG_BACKEND_UART_TX_PIN 11
#define NRF_LOG_BACKEND_UART_TX_PIN 6
#endif

// <o> NRF_LOG_BACKEND_UART_BAUDRATE - Default Baudrate
Expand Down Expand Up @@ -7838,7 +7838,7 @@
// <4=> Debug

#ifndef NRF_LOG_DEFAULT_LEVEL
#define NRF_LOG_DEFAULT_LEVEL 3
#define NRF_LOG_DEFAULT_LEVEL 4
#endif

// <q> NRF_LOG_DEFERRED - Enable deffered logger.
Expand Down
6 changes: 3 additions & 3 deletions firmware/src/targets/dictofun/dictofun_linkerscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ GROUP(-lgcc -lc -lnosys)

MEMORY
{
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x4B000 /* leaving space for bootloader */
RAM (rwx) : ORIGIN = 0x20002C70, LENGTH = 0xD380
NOINIT(rwx) : ORIGIN = 0x2000FFE0, LENGTH = 0x20
FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xd9000 /*52840: 27000-d9000*/
RAM (rwx) : ORIGIN = 0x20005978, LENGTH = 0x3a668 /* 0x40000 total */
NOINIT(rwx) : ORIGIN = 0x2003FFE0, LENGTH = 0x20
}

SECTIONS
Expand Down
15 changes: 11 additions & 4 deletions firmware/src/targets/dictofun/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,23 @@ battery::Context battery_context;

void latch_ldo_enable()
{
nrf_gpio_cfg_output(LDO_EN_PIN);
nrf_gpio_cfg_output(LDO_LATCH_D_PIN);
nrf_gpio_cfg_output(LDO_LATCH_CLK_PIN);
nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLDOWN);
nrf_gpio_pin_set(LDO_EN_PIN);
nrf_gpio_pin_set(LDO_LATCH_D_PIN);

nrf_gpio_cfg(LDO_EN_PIN,
nrf_gpio_cfg(LDO_LATCH_D_PIN,
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_PULLDOWN,
NRF_GPIO_PIN_H0S1,
NRF_GPIO_PIN_NOSENSE);

nrf_gpio_pin_set(LDO_LATCH_CLK_PIN);
for (volatile int i = 0; i < 100000; ++i);
nrf_gpio_pin_clear(LDO_LATCH_CLK_PIN);
for (volatile int i = 0; i < 100000; ++i);
nrf_gpio_pin_set(LDO_LATCH_CLK_PIN);
}

int main()
Expand Down Expand Up @@ -269,7 +276,7 @@ int main()
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}

// Timers' initialization
// // Timers' initialization
record_timer_handle = xTimerCreateStatic(
"AUDIO", 1, pdFALSE, nullptr, systemstate::record_end_callback, &record_timer_buffer);
if(nullptr == record_timer_handle)
Expand Down
3 changes: 2 additions & 1 deletion firmware/src/targets/dictofun/tasks/battery/task_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#include "adc.h"
#include "battery.h"
#include "nrf_log.h"
#include <nrfx_saadc.h>

#include "FreeRTOS.h"
#include "task.h"

namespace battery
{

static constexpr adc::AdcIf::AnalogInputId battery_pin_id{2};
static constexpr adc::AdcIf::AnalogInputId battery_pin_id{NRF_SAADC_INPUT_AIN5};
static constexpr float battery_conversion_factor{2.0};
static const adc::NrfAdc::Config nrf_adc_config{1, {battery_pin_id, 0, 0, 0}};

Expand Down
6 changes: 3 additions & 3 deletions firmware/src/targets/dictofun/tasks/led/task_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

namespace led
{
constexpr uint16_t RED_LED_PIN = LED_3;
constexpr uint16_t BLUE_LED_PIN = LED_1;
constexpr uint16_t GREEN_LED_PIN = LED_2;
constexpr uint16_t RED_LED_PIN = LED_2;
constexpr uint16_t BLUE_LED_PIN = LED_3;
constexpr uint16_t GREEN_LED_PIN = LED_1;
constexpr uint16_t UNCONNECTED_PIN = 30;

constexpr uint32_t task_led_queue_wait_time{10};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include "nrf_log.h"
#include "nrf_log_ctrl.h"

#include "boards.h"

namespace systemstate
{

static constexpr uint8_t power_flipflop_clk{26};
static constexpr uint8_t power_flipflop_d{27};
static constexpr uint8_t power_flipflop_clk{LDO_LATCH_CLK_PIN};
static constexpr uint8_t power_flipflop_d{LDO_LATCH_D_PIN};

void configure_power_latch()
{
Expand Down
Binary file added pcb/out/v1.4.52840/schematic/dictofun.pdf
Binary file not shown.

0 comments on commit e2cf5e4

Please sign in to comment.