Mbed-os: NvStore.set hangs on nrf52 if BLE is active

Created on 20 Nov 2018  路  4Comments  路  Source: ARMmbed/mbed-os

Description

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.

Issue request type


[ ] Question
[ ] Enhancement
[x] Bug

CLOSED mirrored bug

All 4 comments

@MarceloSalazar

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drahnr picture drahnr  路  4Comments

pilotak picture pilotak  路  3Comments

rbonghi picture rbonghi  路  3Comments

ghost picture ghost  路  4Comments

toyowata picture toyowata  路  4Comments