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

Flash write with SDK 4.4.2 + S110 5.2.1

Hello everyone,

I have inherited a project from my coworker. It uses NRF51822 QFAAH0, SDK 4.4.2 and S110 5.2.1. My device is scheduled to: advertise, collect the data from a sensor.

Now I would like to store sensor data in flash then transfer them via BLE if there is a connection. As I have searched in this forum: fstorage, pstorage are preferred (to avoid conflicts between flash writing and BLE communcation). However, due to some reasons, I still have to use SDK 4.4.2 and S110 5.2.1 instead of other SDKs and Softdevices which support fstorage and pstorage functions.

My question is:

  1. In my case (SDK 4.4.2 and S110 5.2.1), how can I store data in flash?
  2. Could someone explain the use of flash_word/page_write function? I saw it is used in ble_bondmngr.c but I can't find and document about it. This may be a solution for me. If yes,
  3. Can I define a fixed area in my flash for storing data? BLE may use some spaces in flash for storing its own bonding and attribute information. And I don't want them to be stored in my data area.

Thank you for spending time.

Best regards.

  • SDK 4.4.2 and S110 5.2.1 is really old. QFAAH0 is a revision 3 chip, see this, and is not even compatible with these, see this. Why not use the latest SDK and SoftDevice?

  • Thank you for your reply. What is the risk of using incompatible SDK and SD for chip revision? I'm sorry for this question since I'm really new for Nordic chip.

    One more question is: Can I upgrade the SoftDevice and Bootloader over the air? Some boards are now fixed in the machine so I can't plug it out to upgrade SD and botloader. It's the reason why I have to use current SDK and SD.

  • It is hard to say. If revisions and SDK/SD are incompatible it means that we haven't tested them together. It doesn't have to be a problem, but it could be. The bootloader in SDK 4.4.2 only supports application update. SDK 6.1.0 and later supports update of SD/BL/APP. Do the fixed boards have chips with the same revision?

  • Now my fixed boards are incompatible with SDK and SD version. They are NRF51822 QFAAH0, and using SDK 4.4.2 and SD110 5.2.1. Until now I didn't find any big problem. Maybe my application is not so complicated so they are still working fine. There are some small problems such as some SD functions didn't work (maybe). At that time I just suspected that my code was not perfect.

    Back to my question, instead of using latest SDK/SD, can I still use flash_word/page_write functions (as in flashwrite_example folder in SDK 4.4.2 folder)? This example wrote data to flash without considering the BT communication. Therefore, in my case, do I need to disable the SD before writing and then enable it again after writing or just wait until the BT communication is disconnected? BT communication also write some data in flash so how can I manage that data area? I don't want it to be stored in my data area.

  • You cannot use pstorage or fstorage, these are accessing flash through the SoftDevice, with functions like sd_flash_write() and sd_flash_page_erase(). These do not exist in SD 110 5.2.1.

    With SD 110 5.2.1 the application has to access Non-Volatile Memory Controller registers directly, which doesn't have to be a problem, but writing to flash will halt the CPU for a given period of time (depending on how much data you write). When it is finished, the flash is written, the CPU will return (just like a normal function call). BLE connections have strict timing, so if the CPU is halted when the stack requires the CPU it will cause problems. A flash page erase takes 22 ms.

    The simplest/safest way to do this is to not use the radio when you write/erase flash, so stop advertising, write/erase flash then start advertising again, and never write/erase flash while in a connection.

    You can use the Flash Manager library. You can find it's documentation in SDK documentation. Modules->nRF51822->Libraries->Bluetooth Libraries->Flash Manager. If you have specific questions regarding the library I think you should add a new question and explain more about what is unclear.

    You have to have control over which flash pages are used by SoftDevice, application, and bond manager, and which that are available. QFAAH0 has 256 flash pages, the SD 110 5.2.1 uses 0-79. You application is in 80-x, while the bond manager typically reserves 253-255. So you should be free to use any page between x and 253.

Related