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

Using nrf52840 Flash block as EEPROM

Hi,

What is the best approach to use a block of flash in nrf52840 as EEPROM. Are there any pre-existing library support for the same?

Also which is the best flash operation that I should use for this particular feature?

nrf provides multiple APIs like nrf_fstorage, nrf_fds, nrf_nvmc_write_bytes...

Thanks.

Parents
  • Hi,

    What exactly do you mean by using as EEPROM? Using in to persistently store application data, or something more specific? Which approach and library to use depends on the use case, but in most cases the FDS library is a good option. It allows you to write arbitrary size records (within a page size less overhead), and has basic wear leveling etc. It is used by key SDK modules such as the peer manger. The fstorage library is a lower level library which provides basic functions to write and erase flash in a generic way that works both with and without a SoftDevice, and is used by the peer manger, though it can also be used directly.

    As a side note, the reason the SoftDevice is relevant here is that while a SoftDevice is used, flash write and erase operations must be done using SoftDevice APIs, and that is handled by the fstorage library (and thus also FDS). You can also use SoftDevice flash API-s directly, or nrf_nvmc API's if not using a SoftDevice and you want simple low level write and erase support.

  • Hi,

    Thanks. I was able to use FDS library which fulfills my requirements. But I see one problem.

    I am writing a record with key 0x1001 with 1 byte of data and update it periodically and read back.

    I start from value 0x00 and update till 0xF6 by incrementing 0x06 at a time and again back from 0.

    It works fine till 0xF0 When I write 0xF6 the update call returns success, but the next read returns CRC CHECK ERROR.

    I see the flash stats and it is as below

    INF:total pages: 3
    total records: 81
    valid records: 2
    dirty records: 79
    largest contig: 1022
    freeable words: 355 (1420 bytes)

    Could you please help me why and when this CRC error could possibly come?

  • I have problems explaining that. Can you reproduce this with a piece of code that I can run on a DK so that I can test on my side? Of second best upload the code so that I can see exactly how you are doing this?

  • Hey, Thanks for your reply.

    Did some exploring in the nordic forum and found the reason for that. now I wait in the same function after write call until I get a write/update event in the callback. That seems to solve the problem.

    Thanks to this post.

Reply Children
No Data
Related