cancel
Showing results for 
Search instead for 
Did you mean: 

GCC and memory regions

ccowdery9
Associate III
Posted on November 04, 2009 at 10:56

GCC and memory regions

3 REPLIES 3
ccowdery9
Associate III
Posted on May 17, 2011 at 13:28

I would like to declare a large array in internal flash, in a separate part of Flash to my main code.

Relevant part of linker script:

Code:

MEMORY

{

/* These for STM32T6U6, 32K Flash, 10K RAM */

CODE (rx) : ORIGIN = 0x08000000, LENGTH = 0x00006000

FAT_AREA (r) : ORIGIN = 0x08006000, LENGTH = 0x00002000

DATA (rw) : ORIGIN = 0x20000000, LENGTH = 0x00002800

}

/* Section Definitions */

SECTIONS

{

/* Fixed area in flash to hold internal filesystem

.fat :

{

*(.fat)

} >FAT_AREA

/* first section is .text which is used for code */

.text :

{

......

Relevant C code

Code:

u8 fat_memory_region __attribute__ ((section (''fat''))) = 0;

int main(void)

{

... init stuff ...

uart_putint((int)&fat_memory_region); //Dump address of variable

...

I expect to get 0x08006000 output, yet I get 0x200005cc. This tells me that my variable is being put in RAM along with the rest, i.e. my direction to place it in FAT_AREA is being ignored somewhere.

Anybody know where the problem is?

Tools are GCC (Anglia IDEaliST)

Thanks,

Chris.

paulsmitton9
Associate II
Posted on May 17, 2011 at 13:28

two things,

firstly that declaration probably wants to be const and volatile:

const vu8 __attribute__((section(''.myflashsection''))) SomeArray[2048];

(which sounds strange at first, but makes sense when you look at their definitions)

secondly, your special section of flash should be inside code, not after it (and within the .text section of code).

so in your .ld file, go down to SECTIONS { .text { and immediately after CREATE_OBJECT_SYMBOLS put in:

KEEP(*(.myflashsection))

. = ALIGN(4096);

this should give you 4k of .myflashsection (or 8k, 12k, 16k etc if you leak over by a byte or more), although it will be the first 4k of flash, and your code will be after it. if you find out how to put your code before and your special section after, then please post the results in this thread.

There's a page on the web somewhere with more info on .ld, keep, align, etc.

Paul.

[ This message was edited by: paul.smitton on 30-10-2009 09:23 ]

ccowdery9
Associate III
Posted on May 17, 2011 at 13:28

Thanks for your comments. There's a subtle difference between what you suggest and what I'm trying to do. And that is that your suggestion allocates an area 'in-line' with the code. I want it to be a separate area.

I have fixed it, and it was a stuuuuuuupid mistake.

Check out the comment '/* Fixed area in flash to hold internal filesystem

'

Observe the missing closing */

If I put that in, it works just as I expect!!!

DOH! :(

Chris.

P.S. Final syntax is:

Linker:

Code:

MEMORY

{

/* These for STM32T6U6, 32K Flash, 10K RAM */

CODE (rx) : ORIGIN = 0x08000000, LENGTH = 0x00006000

FAT_AREA (r) : ORIGIN = 0x08006000, LENGTH = 0x00002000

DATA (rw) : ORIGIN = 0x20000000, LENGTH = 0x00002800

}

/* Section Definitions */

SECTIONS

{

/* Fixed area in flash to hold internal filesystem */

.fat :

{

*(.fat)

} >FAT_AREA

/* first section is .text which is used for code */

...

and source:

Code:

u8 fat_memory_region[512] __attribute__ ((section (''.fat''))) = {0};