diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 68b4f7f..55086fc 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/\/$//' | jq -R -s -c 'split("\n")[:-1]') + MATRIX_JSON=$(ls -d */ | sed 's/\/$//' | grep -vE '_s340$' | jq -R -s -c 'split("\n")[:-1]') echo "matrix=$MATRIX_JSON" echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT diff --git a/.gitignore b/.gitignore index 1c244fc..e7b13c9 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,7 @@ TAGS .DS_Store Makefile.user + +# Exclude all SoftDevice S340 files +lib/softdevice/s340* + diff --git a/CMakeLists.txt b/CMakeLists.txt index 567a815..6d21fa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,22 +227,37 @@ if (MCU_VARIANT STREQUAL "nrf52") S132 ) elseif (MCU_VARIANT STREQUAL "nrf52833") - set(SD_NAME s140) set(DFU_DEV_REV 52833) set(DFU_APP_DATA_RESERVED 7*4096) - target_compile_definitions(bootloader PUBLIC - NRF52833_XXAA - S140 - ) + if (SD_NAME STREQUAL "s340") + target_compile_definitions(bootloader PUBLIC + NRF52833_XXAA + S340 + ) + else () + set(SD_NAME s140) + target_compile_definitions(bootloader PUBLIC + NRF52833_XXAA + S140 + ) + endif () elseif (MCU_VARIANT STREQUAL "nrf52840") - set(SD_NAME s140) set(DFU_DEV_REV 52840) # App reserved 40KB (8+32) to match circuitpython for 840 set(DFU_APP_DATA_RESERVED 10*4096) - target_compile_definitions(bootloader PUBLIC - NRF52840_XXAA - S140 - ) + if (SD_NAME STREQUAL "s340") + target_compile_definitions(bootloader PUBLIC + NRF52840_XXAA + S340 + ) + else () + set(SD_NAME s140) + target_compile_definitions(bootloader PUBLIC + NRF52840_XXAA + S140 + ) + endif () + else () message(FATAL_ERROR "MCU_VARIANT ${MCU_VARIANT} is unknown") endif () diff --git a/Makefile b/Makefile index f345826..22ad007 100644 --- a/Makefile +++ b/Makefile @@ -109,14 +109,22 @@ ifeq ($(MCU_SUB_VARIANT),nrf52) CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132 DFU_APP_DATA_RESERVED=7*4096 else ifeq ($(MCU_SUB_VARIANT),nrf52833) - SD_NAME = s140 + ifeq ($(SD_NAME),s340) + CFLAGS += -DNRF52833_XXAA -DS340 + else + SD_NAME = s140 + CFLAGS += -DNRF52833_XXAA -DS140 + endif DFU_DEV_REV = 52833 - CFLAGS += -DNRF52833_XXAA -DS140 DFU_APP_DATA_RESERVED=7*4096 else ifeq ($(MCU_SUB_VARIANT),nrf52840) - SD_NAME = s140 + ifeq ($(SD_NAME),s340) + CFLAGS += -DNRF52840_XXAA -DS340 + else + SD_NAME = s140 + CFLAGS += -DNRF52840_XXAA -DS140 + endif DFU_DEV_REV = 52840 - CFLAGS += -DNRF52840_XXAA -DS140 # App reserved 40KB (8+32) to match circuitpython for 840 DFU_APP_DATA_RESERVED=10*4096 else diff --git a/README.md b/README.md index b4e3cdb..ce2ab06 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,25 @@ Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056 Makefile:90: *** BOARD not defined. Stop ``` +#### Working with SoftDevice S340: +The SoftDevice S340 is closed-source, not publicly available and is only distributed by Garmin Canada Inc. + +In order to be able to download the required ANT+ capable SoftDevice, you need to register an 'ANT+ Adopter' account at [thisisant.com](https://www.thisisant.com/register/). After around one business day you will receive access to the resources there. Then do the following steps: +- Download the SoftDevice S340 v7.0.1 [(here)](https://www.thisisant.com/developer/components/nrf52832#tab_protocol_stacks_tab) and extract its contents +- Under `lib/softdevice` in this repository there is a folder called `s340_nrf52_7.0.1` + - Copy the API folder `ANT_s340_nrf52_7.0.1.API`, the license agreement `License_Agreement_ANT_Softdevice_rev3_3.pdf` and the hex file `ANT_s340_nrf52_7.0.1.hex` from the extracted contents to it. + - Rename the API folder to `s340_nrf52_7.0.1_API` + - Rename the hex file to `s340_nrf52_7.0.1_softdevice.hex` + - Modify `lib/softdevice/s340_nrf52_7.0.1_API/include/nrf_sdm.h` on line 191 and remove the two slashes at the beginning of `//#define...` to use the *evaluation key* for the ANT SoftDevice. + - **VERY IMPORTANT:** You MUST obtain a valid commercial license key BEFORE releasing a product to market that uses the ANT SoftDevice! + +To add or modify a board with an ANT+ capable SoftDevice S340 the `SD_VERSION` and `SD_NAME` parameters in the corresponding `board.mk` file have to be set: +``` +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. + ### Flash To flash the bootloader (without softdevice/mbr) using JLink: diff --git a/lib/softdevice/s340_nrf52_7.0.1/readme.txt b/lib/softdevice/s340_nrf52_7.0.1/readme.txt new file mode 100644 index 0000000..3cde0e6 --- /dev/null +++ b/lib/softdevice/s340_nrf52_7.0.1/readme.txt @@ -0,0 +1 @@ +Place SoftDevice S340 v7.0.1 files here \ No newline at end of file diff --git a/src/main.c b/src/main.c index 92ad020..b48e1cb 100644 --- a/src/main.c +++ b/src/main.c @@ -157,6 +157,14 @@ static void mbr_init_sd(void) { sd_mbr_command(&com); } +// Helper function to check if SoftDevice is already enabled. +// Especially SoftDevice S340 locks up when calling sd_softdevice_disable() and it's not enabled. +static bool is_sd_enabled(void) { + uint8_t sd_enabled = 0; + sd_softdevice_is_enabled(&sd_enabled); + return (sd_enabled == 1); +} + //--------------------------------------------------------------------+ // //--------------------------------------------------------------------+ @@ -206,13 +214,16 @@ int main(void) { if (!_sd_inited) mbr_init_sd(); // Make sure SD is disabled - sd_softdevice_disable(); + if (is_sd_enabled()) { + sd_softdevice_disable(); + } } // clear in case we kept DFU_DBL_RESET_APP there (*dbl_reset_mem) = 0; // start application + PRINTF("Starting app...\r\n"); bootloader_app_start(); } @@ -306,7 +317,9 @@ static void check_dfu_mode(void) { } if (_ota_dfu) { - sd_softdevice_disable(); + if (is_sd_enabled()) { + sd_softdevice_disable(); + } } else { usb_teardown(); } @@ -326,7 +339,11 @@ static uint32_t ble_stack_init(void) { .rc_temp_ctiv = 2, .accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM }; - sd_softdevice_enable(&clock_cfg, app_error_fault_handler); + #ifndef ANT_LICENSE_KEY + sd_softdevice_enable(&clock_cfg, app_error_fault_handler); + #else + sd_softdevice_enable(&clock_cfg, app_error_fault_handler, ANT_LICENSE_KEY); + #endif sd_nvic_EnableIRQ(SD_EVT_IRQn); /*------------- Configure BLE params -------------*/