This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Example code for using Non volatile memory

I want to store a block of data in nRF51x22. I tried the following:

void HalStoreNVMBlock(uint32_t size, uint8_t* pBuf) { nrf_nvmc_page_erase(NRF_UICR_BASE); nrf_nvmc_write_bytes(NRF_UICR_BASE, pBuf, size); }

but after this code was executed the first time, I could not reprogram the device from Keil. I had to erase all using nRFgo Studio. Is there a code example for doing this?

Parents
  • Hi Ole Thanks’ very much for your quick answer. Basically I only need to store 8 bytes, so using a full flash page for that seems like overkill. I have tried reading out the first 1024 bytes of UICR (address 0x10001000 - 0x10001400) and they are all 0xff. I then tried writing 0x55 to offset 0x80 (Reserved for customer) and it worked fine. I can’t see the application start address (BOOTLOADERADDR from nrf51.h) as it seems to be 0xffffffff. If I could see the data I’m not allowed to erase, I could save it before erasing, and then write it back after the erase. Is that possible?

    Thanks,

    Klaus Karkov

Reply
  • Hi Ole Thanks’ very much for your quick answer. Basically I only need to store 8 bytes, so using a full flash page for that seems like overkill. I have tried reading out the first 1024 bytes of UICR (address 0x10001000 - 0x10001400) and they are all 0xff. I then tried writing 0x55 to offset 0x80 (Reserved for customer) and it worked fine. I can’t see the application start address (BOOTLOADERADDR from nrf51.h) as it seems to be 0xffffffff. If I could see the data I’m not allowed to erase, I could save it before erasing, and then write it back after the erase. Is that possible?

    Thanks,

    Klaus Karkov

Children
  • If you just need to store 8 bytes, you should be able to just write them to the correct part of UICR without erasing anything first. This can also be done with nrfjprog or similar, during production.

    When reading UICR, you should see that CLENR0 register at offset 0 (full address 0x10001000) is 0x14000 and that the FWID register at offset 0x10 also have a non-0xFF value, if you have programmed the S110 softdevice.

    I would strongly recommend you to not do an erase of UICR during run-time in your application, since this could potentially give you a bricked device if an external reset/power-loss happens just after erasing. If you need to change the value, I'd recommend you to either just cycle through UICR, and stop when it's full, or just use a regular flash page, even though the size needed is small.

Related