TARGET=UBLOX_EVK_NINA_B1 (nrf52)
TOOLCHAIN=GCC_ARM
nvstore.set hangs if BLE/softdevice is active. Looking at the source, it appears that 'system' activity can prevent iap from working correctly and there is a retry mechanism in the flash write code so this is not completely unexpected. However, it would be desirable if some more meaningful error was returned - it took me a while to figure out that ble was the culprit. The solution is to ensure that ble.shutdown has been called...
BLE &ble = BLE::Instance();
ble.onEventsToProcess(scheduleBleEventsProcessing);
ble.init(bleInitComplete);
eventQueue.dispatch(1000);
ble.shutdown(); //<--- Without the shutdown, nvstore.set will either take many seconds to complete
// or hang indefinitely.
[ ] Question
[ ] Enhancement
[x] Bug
@MarceloSalazar
Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-186
Hi NeilMacMullen,
Because mbed-os is using NRF_SDH_DISPATCH_MODEL_POLLING to handle SoftDevice events, so you have to call eventQueue.dispatch(to) after NvStore.set, that will call nrf_sdh_evts_poll() and release the queue allocated.
The reason why ble.shutdown() woking is that when SoftDevice is disabled, the events are processed immediately, no SoftDevice events waits for processing.
The code snippet is for your reference.
for (;;) {
eventQueue.dispatch(1000);
if (i++ < 50) {
rc = nvstore.set(key, sizeof(value), &value);
printf("Set key %d to value %ld. \r\n", key, value);
print_return_code(rc, NVSTORE_SUCCESS);
}
}
@desmond-blue Thanks Desmond - much appreciated!