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

Where is the peer manager data stored?

Hello, I can't find where in flash the peer manager data is stored. I'm currently working on DFU support and as part of that I want to define the memory area that should be preserved when doing updates (I want to store some custom data along with the peer manager stuff).

When looking at the memory map infocenter.nordicsemi.com/.../bootloader_memory_nrf52.svg I suspect that the peer manager data may be part of "Application data", but I can't find information about this anywhere.

Can you either explain this, or point me in the right direction? I'd like to know where peer manager stores its data, and how much data it stores (per connection etc). Also, if it's not in the "Application data" area, how is it handled when doing a DFU?

Thanks, Jacob

  • Hello Jacob

    The peer manager uses the Flash Data Storage (FDS) module, which in turn uses the Flash Storage (fstorage) module, which again employs the Softdevice,’s API for storing data in flash.

    The FDS registers with fstorage using the highest priority available, meaning its data will be placed at the highest address in flash, underneath the region reserved for the bootloader (if a bootloader is present). By default the FDS reserves 3 pages of flash (defined in sdk_config.h, minimum is 2), where 1 page is used for garbage handling, the rest is used for storage. The location of the stored data within the reserved memory is based on a first come first serve principal, so data location is not sorted based on user. The size of the data from the peer manager varies with what data it needs to store.

    If you use FDS to store your custom data it will be stored in the same reserved flash area where the peer manager data is stored.

    For more information please see the following pages on Nordic Infocenter

    Peer Manager: infocenter.nordicsemi.com/.../lib_peer_manager.html

    Flash Data Storage: infocenter.nordicsemi.com/.../lib_fds.html

    Flash Storage: infocenter.nordicsemi.com/.../lib_fstorage.html

    Best regards

    Jørn Frøysa

  • Thanks for your answer.

    FDS looks good. However, it feels dangerous that the peer manager data size may vary over time. The custom data may not be lost under any circumstances - is FDS the right module to use for that kind of data?

    Let's say I know the custom data occupies X bytes - how can I be sure the peer manager data will never grow and overwrite this?

  • Yes, you can use fds to write to flash even when using Peer Manager. You don't need to take any precautions, fds will handle everything so that your data and Peer Manager data will not overwrite each other. You can write anything to flash, update it, read it back, delete it and whatnot.

  • There is a configuration option in DFU to preserve fds data during updates. I think it's called DFU_APP_DATA_RESERVED in nrf_dfu_types.h. You should set it to the number of pages used by FDS.

  • Stored data does not grow in its original location. When a record is updated, a new record with the new data size is written. The new record will be localized in the next available area of the virtual flash data page. After the new record is written, the old record is marked for deletion. The old record will not actually be erased until garbage collection is performed.

    If there is not enough room to store the new data, a FDS_ERR_NO_SPACE_IN_FLASH error will occur. This error is usually used to trigger the garbage collection procedure, to free up room before a new attempt is made to store the data.

    This way the data cannot grow into previously stored data.

Related