I am trying to store data to the UICR using SDK16, mesh SDK 4.2.0 and the nRF52840 chip.
I want to write to the UICR once on runtime and never again. To avoid messing with the softdevice, I am trying to write to the UICR before calling ble_stack_init() and after __LOG_INIT to get logs working.
This is the code:
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} uint32_t * consumer0 = (uint32_t *) 0x10001080; *consumer0 = 0x00000005; NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%d\n", *consumer0); NVIC_SystemReset();
So we put the NVMC in Write enable, wait for it to be ready, write to consumer0, put it in Read enable, wait for it to be ready and reset the device. I can see 5 logged to Segger console.
Then I comment what I don't need:
//NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; //while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} uint32_t * consumer0 = (uint32_t *) 0x10001080; //*consumer0 = 0x00000005; //NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; //while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%d\n", *consumer0); //NVIC_SystemReset();
And I see -1 logged to Segger console, meaning the flash still has the 0xFFFF on that position. I can confirm it on Segger Memory explorer that 10001080 is never filled with the data I wanted. Am I doing something wrong?