This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I advertise and write to flash storage concurrently?

I have a BLE device that listens for a connection - upon opening a connection with a smartphone and switching advertising status to non-connectible - it receives some data, reads the battery, and writes to flash storage - the phone disconnects and depending if the flash operation is finished or not, the device hardfaults. The amount of data I am writing is relatively small (64 bytes). I am using the pstorage interface.

I understand the sd_ interface is supposed to handle these two events gracefully (advertising and flash operations) - in practice I am not seeing that.

What is the preferred best practice for this use case? Wait until the device disconnects before writing? Force a disconnect and then write? Pad writing and connecting methods with flags to detect if the other operation is in progress? Transition to the fstorage interface? (I am using SDK10 as I need dual bank dfu.)

Furthermore - what is the root cause? I understand if the there is a higher priority interrupt during a radio operation the softdevice will fault as it's timer continuity has been violated. This is in part why debugging is extremely frustrating when the soft_device is enabled (read: always).

Is softdevice/flash best practice behavior documented anywhere?

Edit: If I disable flash writes, the device will not hardfault. If I never turn on the radio, the device will not hardfault. If I disable reads from the ADC the likelihood of the device hardfaulting is significantly reduced but still occurs. The faults pretty consistently occur on disconnect.

Related