Skip to content

Commit 6a9a6a3

Browse files
authored
Merge pull request #359 from JuergenLeber/add-sd-s340-support
feat: add support for SoftDevice S340
2 parents 4bce0cc + 31c3081 commit 6a9a6a3

File tree

5 files changed

+63
-23
lines changed

5 files changed

+63
-23
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ TAGS
6565

6666
.DS_Store
6767
Makefile.user
68+
69+
# Exclude all SoftDevice S340 files
70+
lib/softdevice/s340*
71+

CMakeLists.txt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,32 +225,29 @@ if (MCU_VARIANT STREQUAL "nrf52")
225225
set(SD_NAME s132)
226226
set(DFU_DEV_REV 0xADAF)
227227
set(DFU_APP_DATA_RESERVED 7*4096)
228-
target_compile_definitions(bootloader PUBLIC
229-
NRF52
230-
NRF52832_XXAA
231-
S132
232-
)
228+
target_compile_definitions(bootloader PUBLIC NRF52 NRF52832_XXAA)
233229
elseif (MCU_VARIANT STREQUAL "nrf52833")
234-
set(SD_NAME s140)
235230
set(DFU_DEV_REV 52833)
236231
set(DFU_APP_DATA_RESERVED 7*4096)
237-
target_compile_definitions(bootloader PUBLIC
238-
NRF52833_XXAA
239-
S140
240-
)
232+
target_compile_definitions(bootloader PUBLIC NRF52833_XXAA)
233+
if (NOT DEFINED SD_NAME)
234+
set(SD_NAME s140)
235+
endif ()
241236
elseif (MCU_VARIANT STREQUAL "nrf52840")
242-
set(SD_NAME s140)
243237
set(DFU_DEV_REV 52840)
244238
# App reserved 40KB (8+32) to match circuitpython for 840
245239
set(DFU_APP_DATA_RESERVED 10*4096)
246-
target_compile_definitions(bootloader PUBLIC
247-
NRF52840_XXAA
248-
S140
249-
)
240+
target_compile_definitions(bootloader PUBLIC NRF52840_XXAA)
241+
if (NOT DEFINED SD_NAME)
242+
set(SD_NAME s140)
243+
endif ()
250244
else ()
251245
message(FATAL_ERROR "MCU_VARIANT ${MCU_VARIANT} is unknown")
252246
endif ()
253247

248+
string(TOUPPER ${SD_NAME} SD_NAME_UPPER)
249+
target_compile_definitions(bootloader PUBLIC ${SD_NAME_UPPER})
250+
254251
set(SD_FILENAME ${SD_NAME}_nrf52_${SD_VERSION})
255252
set(SD_HEX ${SOFTDEVICE_DIR}/${SD_FILENAME}/${SD_FILENAME}_softdevice.hex)
256253

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,32 @@ BIN = _bin/$(BOARD)
104104

105105
# MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840
106106
ifeq ($(MCU_SUB_VARIANT),nrf52)
107+
CFLAGS += -DNRF52 -DNRF52832_XXAA
107108
SD_NAME = s132
108109
DFU_DEV_REV = 0xADAF
109-
CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132
110110
DFU_APP_DATA_RESERVED=7*4096
111111
else ifeq ($(MCU_SUB_VARIANT),nrf52833)
112-
SD_NAME = s140
112+
CFLAGS += -DNRF52833_XXAA
113113
DFU_DEV_REV = 52833
114-
CFLAGS += -DNRF52833_XXAA -DS140
115114
DFU_APP_DATA_RESERVED=7*4096
115+
ifndef SD_NAME
116+
SD_NAME = s140
117+
endif
116118
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
117-
SD_NAME = s140
119+
CFLAGS += -DNRF52840_XXAA
118120
DFU_DEV_REV = 52840
119-
CFLAGS += -DNRF52840_XXAA -DS140
120121
# App reserved 40KB (8+32) to match circuitpython for 840
121122
DFU_APP_DATA_RESERVED=10*4096
123+
ifndef SD_NAME
124+
SD_NAME = s140
125+
endif
122126
else
123127
$(error Sub Variant $(MCU_SUB_VARIANT) is unknown)
124128
endif
125129

130+
SD_NAME_UPPER = $(subst s,S,${SD_NAME})
131+
CFLAGS += -D$(SD_NAME_UPPER)
132+
126133
#------------------------------------------------------------------------------
127134
# SOURCE FILES
128135
#------------------------------------------------------------------------------
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Working with SoftDevice S340
2+
3+
The SoftDevice S340 is closed-source, not publicly available and is only distributed by Garmin Canada Inc.
4+
5+
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:
6+
- Download the SoftDevice S340 v7.0.1 [(here)](https://www.thisisant.com/developer/components/nrf52832#tab_protocol_stacks_tab) and extract its contents
7+
- Under `lib/softdevice` in this repository there is a folder called `s340_nrf52_7.0.1`
8+
- 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.
9+
- Rename the API folder to `s340_nrf52_7.0.1_API`
10+
- Rename the hex file to `s340_nrf52_7.0.1_softdevice.hex`
11+
- 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.
12+
- **VERY IMPORTANT:** You MUST obtain a valid commercial license key BEFORE releasing a product to market that uses the ANT SoftDevice!
13+
14+
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:
15+
```
16+
SD_VERSION = 7.0.1
17+
SD_NAME = s340
18+
```

src/main.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ static void mbr_init_sd(void) {
157157
sd_mbr_command(&com);
158158
}
159159

160+
// Disable the SoftDevice if it is enabled.
161+
static void disable_softdevice(void) {
162+
uint8_t sd_enabled = 0;
163+
sd_softdevice_is_enabled(&sd_enabled);
164+
if (sd_enabled == 1) {
165+
sd_softdevice_disable();
166+
}
167+
}
168+
160169
//--------------------------------------------------------------------+
161170
//
162171
//--------------------------------------------------------------------+
@@ -206,13 +215,14 @@ int main(void) {
206215
if (!_sd_inited) mbr_init_sd();
207216

208217
// Make sure SD is disabled
209-
sd_softdevice_disable();
218+
disable_softdevice();
210219
}
211220

212221
// clear in case we kept DFU_DBL_RESET_APP there
213222
(*dbl_reset_mem) = 0;
214223

215224
// start application
225+
PRINTF("Starting app...\r\n");
216226
bootloader_app_start();
217227
}
218228

@@ -306,7 +316,7 @@ static void check_dfu_mode(void) {
306316
}
307317

308318
if (_ota_dfu) {
309-
sd_softdevice_disable();
319+
disable_softdevice();
310320
} else {
311321
usb_teardown();
312322
}
@@ -326,7 +336,11 @@ static uint32_t ble_stack_init(void) {
326336
.rc_temp_ctiv = 2,
327337
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
328338
};
329-
sd_softdevice_enable(&clock_cfg, app_error_fault_handler);
339+
#ifdef ANT_LICENSE_KEY
340+
sd_softdevice_enable(&clock_cfg, app_error_fault_handler, ANT_LICENSE_KEY);
341+
#else
342+
sd_softdevice_enable(&clock_cfg, app_error_fault_handler);
343+
#endif
330344
sd_nvic_EnableIRQ(SD_EVT_IRQn);
331345

332346
/*------------- Configure BLE params -------------*/

0 commit comments

Comments
 (0)