Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: gnuarm question

2006-02-11 by Guillermo Prandi

If you use 'const', they will stay in flash, rest assured.

This is my compile command for 'console.c' (not using thumb, just 
ARM):

gcc -c -mcpu=arm7tdmi -I. -gdwarf-2 -DREENTRANT_SYSCALLS_PROVIDED
-DROM_RUN -DGCC_ARM7 -I ./include -O2 -Wall -Wcast-align
-Wimplicit -Wwrite-strings -Wpointer-arith -Wswitch -Wreturn-type
-Wunused -Wshadow -Wa,-adhlns=lib/console.lst
-fmerge-constants -IARG -IARG/include -MD -MP
-MF .dep/console.o.d -Wstrict-prototypes -Wmissing-declarations
-Wmissing-prototypes -std=gnu99 lib/console.c -o lib/console.o

And this is the linker command for the 'project' executable:

gcc -mcpu=arm7tdmi -I. -gdwarf-2 -DREENTRANT_SYSCALLS_PROVIDED
-DROM_RUN -DGCC_ARM7 -I ./include -O2 -Wall -Wcast-align
-Wimplicit -Wwrite-strings -Wpointer-arith -Wswitch
-Wreturn-type -Wunused -Wshadow -Wa,-adhlns=build/crt0.lst
-fmerge-constants -MD -MP -MF .dep/project.elf.d
build/crt0.o lib/console.o --output project.elf -nostartfiles
-Wl,-Map=project.map,--cref  -lc  -lm -lc -lgcc
-Tbuild/LPC2138-ROM.ld

The -Map=project.map option will output the map file. The --cref 
addition will output the final assembler listing (.lss). I don't 
recall which of these linker options will give you the project.sym 
file. In this file (.sym) you will be able to see whether your 
variable will reside in flash or in RAM: flash addresses are below 
0x00080000, whilst RAM addresses will be between 0x4000000 and 
0x40007fff. Also, a letter before the symbol name will give you the 
name of the section where they will be placed (t=.text, d=.data, 
b=.bss). For example, these are tables that will reside in flash 
(.text):

0001ca4c t hex
0001ca60 t leds.1409
0001ca78 t badptr.1408
0001ca88 t SectorsByCPU
0001caa0 t LPC2138sectors
0001cbf0 t cOffPat
0001cbfc t LED_Bits

These are tables that will be copied to RAM at system startup (.data):

40000014 d sGPSMaxWait
40000018 d sGPSMinSats
4000001c d sGPSMinData
40000020 d sGPSOffDuty
40000024 d sGPSOnDuty

Finally, these are variables that will be zero-filled and reside in 
RAM from start (.bss):

40001e00 b sNextAction
40001e04 b sMainShutDown
40001e08 b sMainThreadHandle


The t, d, and b flags come also in uppercase flavor, although I don't 
know what is the difference between t and T, d and D or b and B.

All this is provided you start from 'standard' crt0.asm and .ld 
scripts, like those from the WinARM or FreeRTOS examples for gcc.

Guille

--- In lpc2000@yahoogroups.com, G B <microsys@...> wrote:
>
> That's the ticket!
> 
> How can you tell the compiler to put the string in flash?
> 
> Glen
> 
> 
> Guillermo Prandi wrote:
> > Hi, Sean. From tests I did with GCC 4.0.1, I came into the 
conclusion 
> > that:
> > 
> > char* test1 = "TEST1"; <--- doesn't get copied to RAM
> > char  test2[] = {'T','E','S','T','2'}; <--- does get copied to 
RAM.
> > 
> > i.e., omiting the const modifier is not enough to make strings be 
> > copied to RAM. Strings declared with double quotes are considered 
> > const whether we say so or not. There are options to explore 
besides 
> > this. For instance, you can specify the section where you want 
your 
> > variable placed (.text, .data, etc.); I did no tests with that.
> > 
> > Guille
> >
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.