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

A nice place to keep a small amount of state data

Hello Nordic users and employees,

I'm having a small dilemma. The device I'm building runs on the nRF51822 and needs to store a small number of bytes off to the side and some will occasionally be modified. However, flash is very precious in my application, I have a file system that needs as much space as possible.

The bytes must be off to the side and not a part of the file system because they must be read and written by both my main application and a small bootloader and the latter does not have or need the ability to use the file system. This is in the interest of saving space.

I'm considering using the user-reserved parts of the UICR region of memory to save my data, which consists of state and factory production parameters (date of manufacture, etc.). The factory parameters will not change in normal use.

The state data will occasionally change to signal that the bootloader should perform a device firmware update (DFU) on the next restart. Once the DFU is complete, the bootloader must clear the flag and launch the application normally.

I'm a little concerned using the UICR region for this because if it were somehow corrupted the BOOTLOADERADDR field would be unset and my device would become bricked.

Given that background, my question essentially is: Is there a safe way to use UICR for storing a small amount of modifiable data, without putting the BOOTLOADERADDR and other configuration registers at risk, or is there another place to tuck some nonvolitile data out of the way of main flash?

Regards, Cody

Parents
  • Hi

    I do not think it is possible to use the UICR to store application data that occasionally needs to be updated. You can write once to the "user reserved data" region of the UICR (addresses 0x10001080 - 0x100010FC), but in order to write again, you need to erase the whole UICR. As described in the nRF51 Reference Manual, chapter for NVMC, when erasing UICR, you also delete the whole code area, i.e. application and bootloader.

    The only retained register is the GPREGRET, which can store one byte. In fact this register is used by the latest bootloader in nRF51 SDK v6.1.0. The latest heart rate example in SDK 6.1.0 includes a bootloader service that you can write to in order to enable bootloader mode from a central device, which is convenient for devices that do not have a button to enable the bootloader mode. The application will write 0xB1 (if I remember correctly) to the GPREGRET register and then restart the device. The bootloader check for value 0xB1 when it starts up and goes into bootloader mode if the value is there.

    Update 22.10.2014 So I guess the conclusion is that the only place to store nonvolatile storage is the 256kB of flash. Have you already utilized all the flash, so there is no space left for these few bytes? Have you compressed the bootloader and your application, in order to consume less flash space?

Reply
  • Hi

    I do not think it is possible to use the UICR to store application data that occasionally needs to be updated. You can write once to the "user reserved data" region of the UICR (addresses 0x10001080 - 0x100010FC), but in order to write again, you need to erase the whole UICR. As described in the nRF51 Reference Manual, chapter for NVMC, when erasing UICR, you also delete the whole code area, i.e. application and bootloader.

    The only retained register is the GPREGRET, which can store one byte. In fact this register is used by the latest bootloader in nRF51 SDK v6.1.0. The latest heart rate example in SDK 6.1.0 includes a bootloader service that you can write to in order to enable bootloader mode from a central device, which is convenient for devices that do not have a button to enable the bootloader mode. The application will write 0xB1 (if I remember correctly) to the GPREGRET register and then restart the device. The bootloader check for value 0xB1 when it starts up and goes into bootloader mode if the value is there.

    Update 22.10.2014 So I guess the conclusion is that the only place to store nonvolatile storage is the 256kB of flash. Have you already utilized all the flash, so there is no space left for these few bytes? Have you compressed the bootloader and your application, in order to consume less flash space?

Children
No Data
Related