Hi,
we use the NRF52840 as a connectivity chip in a serialized application (based on nRF5-SDK v17.1.0 and SoftDevice S140).
When our main app starts, we would like to reset the SoftDevice (BLE Stack) so we have a known state. The connectivity firmware additionally maintains a USB connection, which should stay available during the reset, if possible. We found that sending the following packet to the connectivity chip does basically what we want (that is, restart the SoftDevice only):
uint8_t reset_command[4] = {0x02, 0x00, SER_PKT_TYPE_GENERIC_CMD, SER_GENERIC_CMD_SOFT_RESET};
This works as intended if there are no active connections or all active connections are idle. However, if a peripheral continuously sends notifications at a high rate, the connectivity firmware crashes during the reset. Here are the steps to reproduce (from the application’s point of view):
- First application run after power-on:
- Open serialization channel
- Send reset command (as defined above)
- Set up BLE (some calls to
sd_ble_cfg_set()and finallysd_ble_enable()) - Scan for a device
- Connect to the device
- Enable notifications
- Process notifications
- Close the application (without closing active BLE connections or disabling notifications; this might also be a crash of the application)
- Second run with the connectivity chip still busy:
- Open serialization channel
- Send reset command
- Set up BLE
- <no response from connectivity chip>
The connectivity chip produces the following log between steps 3.b and 3.c:
<info> app: reset ongoing
<info> app: Dropping BLE event (during reset).
<info> app: Dropping BLE event (during reset).
[10 repetitions removed]
<info> app: Dropping BLE event (during reset).
<error> app: ERROR 12289 [Unknown error code] at ./nrf5-sdk/components/softdevice/common/nrf_sdh_ble.c:315
PC at: 0x000397D9
<error> app: End of error report
The error code is 0x3001 [BLE_ERROR_NOT_ENABLED] and the description says that sd_ble_enable() has not been called. That is obviously correct at this point because the SoftDevice was just disabled and re-enabled. However, it looks like some of the notifications still hang in some queue after the SoftDevice is disabled and are processed once it is enabled again.
Is this a bug or can we change something in our application code to avoid this problem, apart from doing a full chip reset?
Thanks
Thomas