Merge pull request #359 from JuergenLeber/add-sd-s340-support

feat: add support for SoftDevice S340
This commit is contained in:
Ha Thach 2025-06-30 17:54:31 +07:00 committed by GitHub
commit 6a9a6a3e6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 63 additions and 23 deletions

4
.gitignore vendored
View file

@ -65,3 +65,7 @@ TAGS
.DS_Store
Makefile.user
# Exclude all SoftDevice S340 files
lib/softdevice/s340*

View file

@ -225,32 +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(SD_NAME s140)
set(DFU_DEV_REV 52833)
set(DFU_APP_DATA_RESERVED 7*4096)
target_compile_definitions(bootloader PUBLIC
NRF52833_XXAA
S140
)
target_compile_definitions(bootloader PUBLIC NRF52833_XXAA)
if (NOT DEFINED SD_NAME)
set(SD_NAME 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
)
target_compile_definitions(bootloader PUBLIC NRF52840_XXAA)
if (NOT DEFINED SD_NAME)
set(SD_NAME 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)

View file

@ -104,25 +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)
SD_NAME = s140
CFLAGS += -DNRF52833_XXAA
DFU_DEV_REV = 52833
CFLAGS += -DNRF52833_XXAA -DS140
DFU_APP_DATA_RESERVED=7*4096
ifndef SD_NAME
SD_NAME = s140
endif
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
SD_NAME = s140
CFLAGS += -DNRF52840_XXAA
DFU_DEV_REV = 52840
CFLAGS += -DNRF52840_XXAA -DS140
# 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
#------------------------------------------------------------------------------

View file

@ -0,0 +1,18 @@
## 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 and place SoftDevice S340 v7.0.1 files here. 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
```

View file

@ -157,6 +157,15 @@ static void mbr_init_sd(void) {
sd_mbr_command(&com);
}
// 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) {
sd_softdevice_disable();
}
}
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
@ -206,13 +215,14 @@ int main(void) {
if (!_sd_inited) mbr_init_sd();
// Make sure SD is disabled
sd_softdevice_disable();
disable_softdevice();
}
// 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 +316,7 @@ static void check_dfu_mode(void) {
}
if (_ota_dfu) {
sd_softdevice_disable();
disable_softdevice();
} else {
usb_teardown();
}
@ -326,7 +336,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);
#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);
/*------------- Configure BLE params -------------*/