I am working on ATSAMC21E17 mcu with ASF4 in atmel studio 7.
I write data to the embedded RWW section of internal flash using the following code, it works fine.
uint8_t config_data[64]; uint32_t page_size; uint8_t i,j; /* Init source data */ page_size = _rww_flash_get_page_size(&FLASH_0.dev); /*Write all the 4K RWWEE flash*/ for (j=0;j<64;j++) { for (i = 0; i < page_size; i++) { config_data[i] = j; } /* Write data to RWWEE flash */ if (_rww_flash_write(&FLASH_0.dev, NVMCTRL_RWW_EEPROM_ADDR, config_data, page_size) != ERR_NONE) { while (1) ; /* Trap here when flash write error happen */ } }
I read the flash out into a file. I found the data.
But when I want to read back the data. I got all 0xFF. The code is :
for (i = 0; i < 64; i++) { /* Read data from RWWEE flash */ if (_rww_flash_read(&FLASH_0.dev, NVMCTRL_RWW_EEPROM_ADDR+i*page_size, config_data, page_size) != ERR_NONE) { while (1) ; /* Trap here when flash write error happen */ } }
Most code is copy from the ASF4 example. So what's wrong? Can somebody tell me the reason?
Thanks !