Dear sir/madame
Hopefully someone at this forum can bring a clarifying light to me.
I am struggling with storing a variable in flash (nRF 52840 and SDK 17.0.2).
If I define the variable to be stored as static then I can store and read, but if it not defined as static, I am able to store, but data read is different.
Here is the code with static variable
void storeTestADDR1(){
static uint32_t myData = 0xAA;
// uint32_t myData = 0xCC;;
ret_code_t rc;
rc = nrf_fstorage_write(&fstorage, FLASH_ADDR1, &myData, sizeof(myData), NULL);
APP_ERROR_CHECK(rc);
}
Gives this printout when reading content at ADDR1 location:
[00:00:00.514,831] <info> app: Stored data at flash ADDR1 is: AA
Here is the code with non-static variable
void storeTestADDR1(){
//static uint32_t myData = 0xAA;
uint32_t myData = 0xCC;
ret_code_t rc;
rc = nrf_fstorage_write(&fstorage, FLASH_ADDR1, &myData, sizeof(myData), NULL);
APP_ERROR_CHECK(rc);
}
Gives this printout when reading content at ADDR1 location:
[00:00:00.616,088] <info> app: Stored data at flash ADDR1 is: 293ED
Here is the code for reading:
void read_data_from_flash_addr1(){
uint32_t* p = (uint32_t *)FLASH_ADDR1;
NRF_LOG_INFO("Stored data at flash ADDR1 is: %x", p[0]);
}
Kind regards
Svein