Storing a few parameter bytes in flash

I need to store just and handful of bytes in flash, some config data. Looking around the forum I've seen recommendation to read and write from/to by using the nvs functionality, but that looks massively overcomplicated at first glance. I don't need or want a filesystem. On an STM32 it's really simple and easy to put aside a sector and program data within it, without needing a file system you can do all that with just a handful of lines of code. Is it not possible to do the same with this chip?

Am using that VSC Zephyr setup and taken the central uart project to do my UART stuff after a lot of hand holding. Now I just want to save a few bytes of data at a particular point and then read that data at boot. Just six bytes.

How do I do this without the over complication of a file system please?

  • Hi, thanks, finally came back to this project after giving up on it and this provides the answer I need. Wasted a lot of time on the first, incorrect one.

    Many thanks for that.

  • I have a question about this. Having seemingly got to just about being ready to give this to a customer for beta testing, it's more often than not crashing when I call:

    nrfx_nvmc_page_erase
    DuckDuckGoing about I have seen some
    suggestions that you cannot use nrfx_nvmc_page_erase when
    you're using the soft device.

    Is that true? I can't really see how you could use any
    Nordic product without using soft device, so it seems unlikely
    but maybe I'm missing something. Maybe I don't understand
    properly what the soft device is.

    I'm using an nrf52840 with Zephyr as the OS, based on nrf Connect SDK2.0 and
    using BLE with the 52840 acting as a central device.

    So, can I actually *not* use nrfx_nvmc_page_erase()
    in this scenario?

    If that is the case, I need to reask my question
    from half a year ago:

    How do I store six bytes of data in internal flash please? The
    advice given by Kenneth seemed perfect, but now I have other
    aspects of the system going and I try to erae a sector it's all going wrong.

    If Kenneth's method *is* suitable for my setup, any idea
    why it might by crashing in
    nrfx_nvmc_page_erase() please?
  • Hello,

    You can't use the direct nvmc while actively advertising or in a connection no. So to workaround this there are two solutions:

    1. Disconnect BLE for a short period of time to store the data.

    2. Use timeslot to request a short period of time where you can use nvmc directly:
    https://docs.nordicsemi.com/bundle/ncs-2.0.0/page/nrfxlib/mpsl/doc/timeslot.html 

    If you are interested in timeslot there is an old example here (this allow running a different radio protocol (ESB) in the timeslot, in your case you want to do the flash write instead), it may possible still be of use: https://github.com/too1/ncs-esb-ble-mpsl-demo 

    If you want to erase you need a 100ms window.

    Kenneth

Related