Why the _rww_flash_read() method cann't read out the data in RWW section of ATSAMC21?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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 !

Last Edited: Sun. Jan 31, 2021 - 08:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Haha, I found the reason.

 

I call the _rww_flash_write() , debug the code , and read all flash out into a file, and comment it, and add the _rww_flash_read() to check whether the data is correct, and debug the code again.

What I have done is debug the code twice! Then the debugger program the device twice. In the Device programming tool, I checked the Erase Flash before programming. So what I have wroten to RWW section has been erased at the check debug, I can only read out all 0xFF.