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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1,100 Views
yongjin2712_cho
Contributor I

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?

Labels (1)
Tags (1)
0 Kudos
Reply
1 Reply

956 Views
Yuri
NXP Employee
NXP Employee

Hello,

  I think, the problem is, that it is not possible to run code and write to the same flash

device. Flash is not usual (SRAM / DRAM) memory in this sense. 


Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply