Skip to content

Commit 6cf5a74

Browse files
committed
nRF52840: Add process.env.SOFTDEVICE for detecting which softdevice version is installed
1 parent 7f39a77 commit 6cf5a74

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
nRF52: Fix gatt.setRSSIHandler on the first active connection
1515
Added i2cRead/WriteReg for simplified internal I2C code
1616
Bangle.js2: Support for new Bangles with MMC36X0 magnetometer (Bangle.dbg() now shows info)
17+
nRF52840: Add process.env.SOFTDEVICE for detecting which softdevice version is installed
1718

1819
2v27 : nRF5x: Ensure Bluetooth notifications work correctly when two separate connections use the same handle for their characteristics
1920
nRF5x: Remove handlers from our handlers array when a device is disconnected

src/jswrap_process.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Returns an Object containing various pre-defined variables.
122122
* `APP_RAM_BASE` - On nRF5x boards, this is the RAM required by the Softdevice
123123
*if it doesn't exactly match what was allocated*. You can use this to update
124124
`LD_APP_RAM_BASE` in the `BOARD.py` file
125+
* `SOFTDEVICE` - (on nRF52840) the version of Bluetooth Softdevice that is installed on
126+
the device, usually `"6.0.0"` or `"6.1.1"`
125127
126128
For example, to get a list of built-in modules, you can use
127129
`process.env.MODULES.split(',')`
@@ -160,6 +162,17 @@ JsVar *jswrap_process_env() {
160162
if (app_ram_base)
161163
jsvObjectSetChildAndUnLock(obj, "APP_RAM_BASE", jsvNewFromInteger((JsVarInt)app_ram_base));
162164
#endif
165+
#ifdef NRF52840
166+
// Do a CRC of the 32 bytes from offset 256 (in the softdevice area), eg E.CRC32(E.memoryArea(256,32))
167+
const char *softdevice = "unknown";
168+
JsVar *sdArea = jswrap_espruino_memoryArea(256,32);
169+
uint32_t crc = (uint32_t)jsvGetIntegerAndUnLock(jswrap_espruino_CRC32(sdArea));
170+
jsvUnLock(sdArea);
171+
// compare with known values
172+
if (crc == 3039104175) softdevice = "6.0.0";
173+
if (crc == 2754746215) softdevice = "6.1.1";
174+
jsvObjectSetChildAndUnLock(obj, "SOFTDEVICE", jsvNewFromString(softdevice));
175+
#endif
163176
#endif
164177
return obj;
165178
}

0 commit comments

Comments
 (0)