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

Using pstorage for Large Circular Buffer

I am planning to record some information in the flash of the nRF51822. This will occupy a large circular buffer (quite a few kb), and new data (in chunks of around a dozen bytes) will eventually overwrite old (when the buffer is full).

Since I am using firmware with the pstorage module, how should I use pstorage in this implementation?

Should I use several application handles for the one buffer and make each of them 1024 bytes so that I can erase a single page when circling round rather than the whole buffer, or is there a simpler way?

Would it be safe to just call sd_flash_page_erase and sd_flash_write directly from my code? (I assume these functions wait for a gap in radio transmission and only return after completion)

  • Hi Paul,

    In case you are writing fixed amount of data each time to the buffer, lets say 32 bytes and you need the circular buffer size to be 4k, you can request 128 blocks of size 32 when registering with PStorage.

    If your data is variable length, then you probably need 1 block of 4k and writing at whatever offset you like. Do note that you will have to increase limit for maximum block size in your pstorage_platform.h file.

    You are free to use sd_flash_page_erase and sd_flash_write yourself, do remember but you will have to manage the limitation of issuing only one flash operation at a time and ensuring that you are not exceeding one page a time when you do a write or erase. PStorage masks these limiations from teh module by managing a queue and maintaining logic to continue in case flash or erase exceeds one page at a time.

    Hope this helps!

    Regards, Krishna

Related