cancel
Showing results for 
Search instead for 
Did you mean: 

How to allocate variable in Flash to desired address?

msvarc9
Associate
Posted on May 24, 2012 at 10:11

Please, could you help me? with STM32F4xx.

But I think it's general problem with GNU linker.

I'm working on SW for colour graphical display application.

It works fine.

But I need to store some data to Flash after the program start.

I want allocate for this data all 16K Sector 1 in Flash area.

I have tried different ways but unsuccessfully.

My variable is 

const unsigned

short

int

FlashArray[8192].

I have tried this: 

const unsigned short

int

FlashArray[8192] __attribute__ ((at((uint32_t)0x08004000)));

This doesn't work in GNU.

I have tried also this:

const

unsigned

short

int

FlashArray[8192]

__attribute__

((section(

''.flash_data_array''

))); 

+

change in  stm32_flash.ld:

/* Specify the memory areas */

MEMORY

{

FLASH0 (rx) : ORIGIN = 0x08000000, LENGTH = 16K

FLASH1 (rx) : ORIGIN = 0x08004000, LENGTH = 16K

FLASH2 (rx) : ORIGIN = 0x08008000, LENGTH = 992K

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K

MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K

}

/* Define output sections */

SECTIONS

{

/* The startup code goes first into FLASH */

.isr_vector :

{

. = ALIGN(4);

KEEP(*(.isr_vector)) /* Startup code */

. = ALIGN(4);

} >FLASH0

/* My new eeprom area in FLASH */

.flash_data_array :

{

*(.rodata) /* .rodata sections (constants, strings, etc.) */

*(.rodata*) /* .rodata* sections (constants, strings, etc.) */

. = ALIGN(4);

KEEP (*(.init))

KEEP (*(.fini))

. = ALIGN(4);

} >FLASH1

?

/* The program code and other data goes into FLASH */

.text :

{

. = ALIGN(4);

*(.text) /* .text sections (code) */

*(.text*) /* .text* sections (code) */

*(.rodata) /* .rodata sections (constants, strings, etc.) */

*(.rodata*) /* .rodata* sections (constants, strings, etc.) */

*(.glue_7) /* glue arm to thumb code */

*(.glue_7t) /* glue thumb to arm code */

*(.eh_frame)

KEEP (*(.init))

KEEP (*(.fini))

. = ALIGN(4);

_etext = .; /* define a global symbols at end of code */

} >FLASH2

...

But this doesn't work too.

I don't know what's wrong.

I have tried to found out it on internet, but without success.

Here I found out this problem has more people.

Can you help me how to allocate variable array to Sector1 in Flash

and how to prohibit this sector to other flash data?

#linker
31 REPLIES 31
Rahimi.Meysam
Associate II
Posted on September 15, 2015 at 17:17

Hi. I have a question.

How can we set  value and use the value from beta variable?

thank you.

Posted on September 15, 2015 at 20:10

Well you'd write to it like any other FLASH interaction, you'd erase the sector it's in and then write to the memory in question. It's rather slow and invasive, and not like writing data in RAM.

It should read it like any other variable, the linker/compiler knows where it is, and you can access the memory just like any other memory location in RAM, ROM or FLASH

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..