Hi,
I have a device built on NRF52840. I use Softdevice S340 since I use both BLE and ANT+. I'm on SDK 17.0.2.
My problem is - I want to save the currect state of my device to flash, just before it goes dead after power is turned off. The construction of my device allows it to work for couple of seconds after it is powered off. I noticed that if I initiate the save action from a connected BLE device it works: I cut the power, then I click save in the mobile app connected to my device and I can see in the log, that the save worked just fine.
However If I do it from my code (I have a mechanism that can detect if the power was cut off) the nrf_fstorage_write function keeps waiting and never executes. I guess it's waiting for the SoftDevice, since it's priority is higher by definition?
The power off detection mechanism is based on an interrupt detecting the external power supply phase going trhough "0" . I get an tnterrupt every 10ms (for 50Hz installations). So I created a timer that expires after 15 ms. I reset this timer in the event handler of the "0 detection". When the timer expires I know it's been no more that 15 ms since the power was cut off. I tested this mechanism and it works reliably.
My questions and ideas:
1. Can I make the 15ms timer with same or higher priority as the SoftDevice? My experiments / reading showed that this is sadly impossible
2. Can I somehow turn off / block / stop the Softdevice just before my nrf_fstorage_write (in the 15ms timer handler)? I don't care about waiting events, ongoing stuff, queues, anything. The power was cut off - I need to save! - sadly I was also unable to do so using different methods.
3. Can I wite to Flash using some other methos that would not interfere with the SD? I tried unloading the fstorage and saving using other methods, but mostly I just get 'SOFTDEVICE: INVALID MEMORY ACCESS'
4. Can I somehow trigger the BLE Characteristic that is used by the mobile app, but do it locally? Ideally without my device being connected to itself via Bluetooth.
5. Or maybe there is some other method to be used to call a function from the context of the SoftDevice, i.e. with its priority?
Please consider, that when the power off event comes the device is more often that not connected to a mobile app, and possibly other BLE devices, connected to one or more ANT+ devices and/or scanning for ANT+/BLE devices to connect to. In other words - the SoftDevice is busy!
Please advice
Thanks & regards!