Using zephyr or nrfxlib to manipulate flash area

Hello

In pm_static.yml I defined a flash partition, intended to save some NV-flags for the application, which should survive OTA/DFU updates.

The project uses BLE for OTA/DFU and for application communication.

To erase / write I used the zephyr routines from flash.h (i.e. flash_write(), flash_erase(), ...) and everything seems to work OK in the lab with the development kit.

On the other hand, the SoftDevice-API encourages to use this routines to avoid problems with BLE (see developer.nordicsemi.com/.../api.html

But there is no sample code for the SD-solution, neither searching the web for, e.g., the function sdc_soc_flash_page_erase_async().

What is the recommended solution? Can the approach from the Zepyhr example project "soc_flash_nrf" be safely used with BLE...?

In case the SoftDevice - approach is the recommended solution, can you please point to an example of its proper using?

Best Regards

Gerardo

  • Hi Gerardo,

    You cannot access the flash directly via (nrfx or otherwise) when using the SoftDevice Controller. You can use higher level Zephyr APIs (like NVS), or use the sdc_soc_flash* functions if you want to have full control yourself but. You may also want to consider storing your data in Settings subsystem.

    Note that if you only have a limited set of data  you need to store, and they never change, then putting the data in the UICR might be the simplest (that is special flash that is never touched during DFU).

    Einar

  • Hi Einar,


    Since the amount of information to be stored is big (long time loggging information), the overhead caused by NVS, LittleFS or other systems would be too space consuming, since the device has to have also DFU/FOTA capability (which in turn almost halves the application space size...). That's why I would prefer to write the flash on a 32-bit word basis.

    As far as I understood, with the nrf Connect SDK 2.2.x, when using BLE, a sort of SoftDevice emulation is used.
    Can I therefore safely use the Zephyr flash API (Flash — Zephyr Project Documentation)?

    Best Regards

    Gerardo

  • Hi,

    I see. You can use the Zephyr flash APIs as well, as demonstrated by the soc_flash_nrf sampel you referred to. If you combine this sample with a BT sample where MPSL is enabled step through you will see you end up in flash_sync_mpsl.c with the default configuration, which is CONFIG_SOC_FLASH_NRF_RADIO_SYNC_MPSL enabled. You can see an example of that here: peripheral_hr_with_flash_write.zip.

    If you always use MPSL and don't need to support a situation without it, it does perhaps make more sense to use the sdc_soc_flash API, though. This is very simple, with two functions (one for writing and one for page erase), and you provide a callback function which handles one of two results (timeout or success).

  • Hi Einar

    Many thanks!
    Can you please provide me a link to some example using the sdc_soc_flash API?

    What file should I include in my project to gain access to the sdc_soc_flash API - elements? What CONFIG_xx's should be set in my proj.conf for that?

    Btw.: I can not find an actual page with an explanation of CONFIG_SOC_FLASH_NRF_RADIO_SYNC_MPSL , just older zephyr versions 1.x

    Best Regards

    Gerardo

  • Hi,

    Gera64 said:
    Can you please provide me a link to some example using the sdc_soc_flash API?

    You can see the MPSL API documentation. You don't need any specific config as long as MPSL is enbled (which is is if you are using the SoftDevice Controller, which is the default Bluetooth controller in the nRF Connect SDK. The only thing you need to do is include sdc_soc.h in the file where you use it.

    Gera64 said:
    Btw.: I can not find an actual page with an explanation of CONFIG_SOC_FLASH_NRF_RADIO_SYNC_MPSL , just older zephyr versions 1.x

    You don't need to think about CONFIG_SOC_FLASH_NRF_RADIO_SYNC_MPSL as it will be enabled by default when you use MPSL. You can search in the code if you are interested to see how it is used (and if you look at the generated .config you should see it is enable din your projects that use the MPSL).

Related