AnsweredAssumed Answered

How can I write data to variable located in flash memory?

Question asked by YongJin Choi on Jul 15, 2018
Latest reply on Jul 19, 2018 by Yuri Muhin

I use RT1050 EVK with hyperflash

 

Now I'm trying to write data to variable located in flash memory.

 

But I can't do it

 

I defined rw flash section as below

 

MEMORY
{
  /* Define each memory region */
  EXT_FLASH (rx) : ORIGIN = 0x60000000, LENGTH = 0x100000 /* 1M bytes (alias Flash) */
  EXT_FLASH_NVDATA (rwx) : ORIGIN = 0x60100000, LENGTH = 0x80 /* 128 bytes (alias Flash) */
  EXT_FLASH_FONT (rx) : ORIGIN = 0x60100080, LENGTH = 0x80000 /* 512K bytes (alias Flash) */

 

...

 

  __base_EXT_FLASH_NVDATA = 0x60100000  ;
  __top_EXT_FLASH_NVDATA = 0x60100000 + 0x80 ; /* 128 bytes */

 

 .nv_user_data : ALIGN(4)
    {
     KEEP(*(.nv_userdata))
     . = ALIGN(4);
    } > EXT_FLASH_NVDATA

 

And I made a code as below

 

uint32_t test_data __attribute__ ((section (".nv_userdata"))) __attribute__ ((aligned(4))) = 20;

 

void setTestData(unsigned char id)
{
test_data = 30;
}   <- break point

 

After I set break point and run debug with MCUXpresso, I saw that value of memory is changed as below

 

0x60100000 : 0x60100000 <Hexadecimal>
  Address   0 - 3     4 - 7     8 - B     C - F              
  60100000  00464680  00050200  00000000  00000014          <-- before
  60100010  FFFFFFFF  FFFFFFFF  FFFFFFFF  FFFFFFFF

 

0x60100000 : 0x60100000 <Hexadecimal>
  Address   0 - 3     4 - 7     8 - B     C - F              
  60100000  00464680  00050200  00000000  0000001E          <-- after
  60100010  FFFFFFFF  FFFFFFFF  FFFFFFFF  FFFFFFFF

 

However, After board reset, value of it's memory return to 20.

It seems to behave abnormally to acess.

 

And if test_data variable declares uint8_t or uint16_t, value of test_data is not changed.

 

how can I write data to variable located in flash memory?

Outcomes