From 31c3081668c0ffe0215c125b88d3cb5c2447050e Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Jun 2025 17:32:49 +0700 Subject: [PATCH] update makefile/cmake for softdevice macro. Remove the _s340 filter in ci --- .github/workflows/githubci.yml | 2 +- CMakeLists.txt | 34 ++++++----------------- Makefile | 25 ++++++++--------- lib/softdevice/s340_nrf52_7.0.1/readme.md | 3 +- src/main.c | 15 +++++----- 5 files changed, 29 insertions(+), 50 deletions(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 55086fc..68b4f7f 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -21,7 +21,7 @@ jobs: id: set-matrix working-directory: src/boards run: | - MATRIX_JSON=$(ls -d */ | sed 's/\/$//' | grep -vE '_s340$' | jq -R -s -c 'split("\n")[:-1]') + MATRIX_JSON=$(ls -d */ | sed 's/\/$//' | jq -R -s -c 'split("\n")[:-1]') echo "matrix=$MATRIX_JSON" echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT diff --git a/CMakeLists.txt b/CMakeLists.txt index e66a274..7133135 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,47 +225,29 @@ if (MCU_VARIANT STREQUAL "nrf52") set(SD_NAME s132) set(DFU_DEV_REV 0xADAF) set(DFU_APP_DATA_RESERVED 7*4096) - target_compile_definitions(bootloader PUBLIC - NRF52 - NRF52832_XXAA - S132 - ) + target_compile_definitions(bootloader PUBLIC NRF52 NRF52832_XXAA) elseif (MCU_VARIANT STREQUAL "nrf52833") set(DFU_DEV_REV 52833) set(DFU_APP_DATA_RESERVED 7*4096) - if (SD_NAME STREQUAL "s340") - target_compile_definitions(bootloader PUBLIC - NRF52833_XXAA - S340 - ) - else () + target_compile_definitions(bootloader PUBLIC NRF52833_XXAA) + if (NOT DEFINED SD_NAME) set(SD_NAME s140) - target_compile_definitions(bootloader PUBLIC - NRF52833_XXAA - S140 - ) endif () elseif (MCU_VARIANT STREQUAL "nrf52840") set(DFU_DEV_REV 52840) # App reserved 40KB (8+32) to match circuitpython for 840 set(DFU_APP_DATA_RESERVED 10*4096) - if (SD_NAME STREQUAL "s340") - target_compile_definitions(bootloader PUBLIC - NRF52840_XXAA - S340 - ) - else () + target_compile_definitions(bootloader PUBLIC NRF52840_XXAA) + if (NOT DEFINED SD_NAME) set(SD_NAME s140) - target_compile_definitions(bootloader PUBLIC - NRF52840_XXAA - S140 - ) endif () - else () message(FATAL_ERROR "MCU_VARIANT ${MCU_VARIANT} is unknown") endif () +string(TOUPPER ${SD_NAME} SD_NAME_UPPER) +target_compile_definitions(bootloader PUBLIC ${SD_NAME_UPPER}) + set(SD_FILENAME ${SD_NAME}_nrf52_${SD_VERSION}) set(SD_HEX ${SOFTDEVICE_DIR}/${SD_FILENAME}/${SD_FILENAME}_softdevice.hex) diff --git a/Makefile b/Makefile index 22ad007..bea75cf 100644 --- a/Makefile +++ b/Makefile @@ -104,33 +104,32 @@ BIN = _bin/$(BOARD) # MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840 ifeq ($(MCU_SUB_VARIANT),nrf52) + CFLAGS += -DNRF52 -DNRF52832_XXAA SD_NAME = s132 DFU_DEV_REV = 0xADAF - CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132 DFU_APP_DATA_RESERVED=7*4096 else ifeq ($(MCU_SUB_VARIANT),nrf52833) - ifeq ($(SD_NAME),s340) - CFLAGS += -DNRF52833_XXAA -DS340 - else - SD_NAME = s140 - CFLAGS += -DNRF52833_XXAA -DS140 - endif + CFLAGS += -DNRF52833_XXAA DFU_DEV_REV = 52833 DFU_APP_DATA_RESERVED=7*4096 + ifndef SD_NAME + SD_NAME = s140 + endif else ifeq ($(MCU_SUB_VARIANT),nrf52840) - ifeq ($(SD_NAME),s340) - CFLAGS += -DNRF52840_XXAA -DS340 - else - SD_NAME = s140 - CFLAGS += -DNRF52840_XXAA -DS140 - endif + CFLAGS += -DNRF52840_XXAA DFU_DEV_REV = 52840 # App reserved 40KB (8+32) to match circuitpython for 840 DFU_APP_DATA_RESERVED=10*4096 + ifndef SD_NAME + SD_NAME = s140 + endif else $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) endif +SD_NAME_UPPER = $(subst s,S,${SD_NAME}) +CFLAGS += -D$(SD_NAME_UPPER) + #------------------------------------------------------------------------------ # SOURCE FILES #------------------------------------------------------------------------------ diff --git a/lib/softdevice/s340_nrf52_7.0.1/readme.md b/lib/softdevice/s340_nrf52_7.0.1/readme.md index 55b790b..c408bbd 100644 --- a/lib/softdevice/s340_nrf52_7.0.1/readme.md +++ b/lib/softdevice/s340_nrf52_7.0.1/readme.md @@ -15,5 +15,4 @@ To add or modify a board with an ANT+ capable SoftDevice S340 the `SD_VERSION` a ``` SD_VERSION = 7.0.1 SD_NAME = s340 -``` -**Important:** When adding a new board you must add the suffix `_s340` to the folder name to exclude it from automatic builds. \ No newline at end of file +``` \ No newline at end of file diff --git a/src/main.c b/src/main.c index cd9de87..a4c0a70 100644 --- a/src/main.c +++ b/src/main.c @@ -157,9 +157,8 @@ static void mbr_init_sd(void) { sd_mbr_command(&com); } -// Helper function to disable the SoftDevice with upfront check if it is enabled. -// Especially SoftDevice S340 locks up when calling sd_softdevice_disable() and it's not enabled. -static void sd_disable(void) { +// Disable the SoftDevice if it is enabled. +static void disable_softdevice(void) { uint8_t sd_enabled = 0; sd_softdevice_is_enabled(&sd_enabled); if (sd_enabled == 1) { @@ -216,7 +215,7 @@ int main(void) { if (!_sd_inited) mbr_init_sd(); // Make sure SD is disabled - sd_disable(); + disable_softdevice(); } // clear in case we kept DFU_DBL_RESET_APP there @@ -317,7 +316,7 @@ static void check_dfu_mode(void) { } if (_ota_dfu) { - sd_disable(); + disable_softdevice(); } else { usb_teardown(); } @@ -337,10 +336,10 @@ static uint32_t ble_stack_init(void) { .rc_temp_ctiv = 2, .accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM }; - #ifndef ANT_LICENSE_KEY - sd_softdevice_enable(&clock_cfg, app_error_fault_handler); - #else + #ifdef ANT_LICENSE_KEY sd_softdevice_enable(&clock_cfg, app_error_fault_handler, ANT_LICENSE_KEY); + #else + sd_softdevice_enable(&clock_cfg, app_error_fault_handler); #endif sd_nvic_EnableIRQ(SD_EVT_IRQn);