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

Able to write only one time in NVMC

Hi ,

Here is my code used to write in to non volatile memory.

#include "nrf.h" //#include "uicr_config.h" #include <stdint.h> #include <stdbool.h> #include "nrf_nvmc.h"

int main(void) {

			uint32_t     address   =  0x10001088;
			uint32_t     value       =  0x13345652;
			uint32_t     b            =   0;
			nrf_nvmc_write_word(address,	value);

			b = *(uint32_t *)address;
			
			//nrf_nvmc_write_word(address+12,	b);
			while (true)
			{
						/* Do nothing */
			}

}

But for first time i able to see the data whatever i have written in memory.

But if i change the value, i cant see the changed data. it remains as old data.

means i am not able to write one more time.

i check by reset the device also , but not able to write.

but if increase address value to 4 more bytes, i am able to write data in new address.

Kindly suggest me, where i am wrong.

Regards Balaji

  • When erasing flash, all bits are set back to 1, and when then writing, the needed bits are set to 0. To set a bit back to 1, you must erase the address again.

    This means that it isn't possible to write to bytes successively to flash, if the change needs to set bits back to one. In other words, you can first write 0b10101111 to an address, and then 0b10100101, but you can't write 0b1010000 and then write 0xb10100101.

  • Hi Ole,

    I tried by erasing also but not yet worked.

    Here is my code :

    #include "nrf.h" //#include "uicr_config.h" #include <stdint.h> #include <stdbool.h> #include "nrf_nvmc.h"

    int main(void) {

    			uint32_t address = 0x1000108C;
    			uint32_t value   = 0x13345653;
    			uint32_t b=0;
    			
    			nrf_nvmc_page_erase(address);
    			nrf_nvmc_write_word(address,	value);
    
    			b = *(uint32_t *)address;
    			
    			//nrf_nvmc_write_word(address+12,	b);
    			while (true)
    			{
    						/* Do nothing */
    			}
    

    }

    Regards Balaji

  • You can erase only a full page at a time, as is explained in the nRF51 Reference Manual, and quite clearly shown in the function name, so this code will obviously not work.

  • Hi Ole,

    Here i done changes in code. but not yet worked.

    Kindly confirm where i am wrong.

    uint32_t address = 0x10001080; uint32_t value = 0x13345621; uint32_t b=0;

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {

    } // Erase the page NRF_NVMC->ERASEUICR=1; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { } NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { }

    nrf_nvmc_write_word(address, value); while (true) { /* Do nothing */ }

    }

    Regards Balaji

  • Hi Ole,

    In my case soft device is enabled.

    So i cant able to erase UICR .

    Now i think , i want to use ble_flash* functions to read ,write and erase in to nvm.

    But i dont know in which page i can write my configuration.

    how to know falsh page number.

    Kindly suggest me.

    Regards Balaji

Related