Topic : RIDE7, GCC : no simple way to order vars in RAM

Forum : ARM

Original Post
Post Information Post
November 18, 2010 - 6:27pm
Guest

Hi all,

I have almost 1200 vars in my project, for STM32.
I want to have them ordered, so that I will be able to read them through a MODBUS protocol (via CAN, UART, etc).
Example, as done in my previous lives :
global.c
#pragma segment memory=zzzz
volatile u8 var1;
volatile u8 var2;
volatile u8 var3;

so that i would find in .map file, something like that :
0x20000000 var1
0x20000001 var2
0x20000002 var3
In that way, I can sort my vars, make sections, add some without distroying all the mapping, etc

The only way I found with RIDE/GCC is to declare a segment in a .ld file :
----------file.ld------------------------------
...
.ram_data :
{
_bb_ram_data = . ;
. = ALIGN(0x100);
_b_ram_data = . ;
_e_ram_data = _bb_ram_data + SIZEOF (.ram_data); /* pirouette inélégante, mais que ca qui compile ok */
} >RAM
...
----end file.ld----------------------------

I define some vars in a global.c

volatile u8 BYTE_AD_25 __attribute__ ((section (".ram_data")));
volatile u8 BYTE_AD_26 __attribute__ ((section (".ram_data")));
volatile u8 BYTE_AD_27 __attribute__ ((section (".ram_data")));

declared in a global.h file

Then, i need to erase vars at start (because Gcc will not) :

----erase fct----------------------------
extern u32 _b_ram_data; //declaration des extern definis dans le fichier .ld
extern u32 _e_ram_data;

u8p_RAM = (u8 *)((u32)(&_b_ram_data));
for (u16_j=0;u16_j<(((u32)&_e_ram_data) - ((u32)&_b_ram_data));u16_j++)
{
*u8p_RAM++ = 0;
}
----end erase fct----------------------------

And i found that in .map file :
.ram_data 0x20000c00 0x50 C:\...\global.o
0x20000c03 BYTE_AD_27
0x20000c01 BYTE_AD_25
0x20000c02 BYTE_AD_26
That's OK, but I want to be sure that's the only way before adding "__attribute__ ((section (".ram_data")));" to my thousand of variables ! ! ! !
I spent many hours on that issue, and this is not 'elegant' at all. Please help if anybody knows...

Hoping I am clear enough !

Replies
Post Information Post
+1
0
-1
November 19, 2010 - 9:22am
Raisonance Support Team

Hi Otis,

That may work, but it is quite a cumbersome solution!

I would rather write a simple script that takes the linker map file as input and outputs a list of variables with their address and size. This would be fed into your live RAM reader, so you would have direct access to your variables without modifying your sources.

I hope this helps,

+1
0
-1
November 19, 2010 - 10:29am
Guest

You can order them by putting them into a struct, or array if they are all of the same type.

Another way is writing read/write functions that use 'iterators' like it is done in the c++ STL.

+1
0
-1
November 19, 2010 - 10:45am
Guest

Thanks Bruno,

Understood your suggestion.
I agree this is easy to sort the map file and get actual list.
But in that way, if I add some vars at the end of my global.c file, I will have no guaranty to keep existing vars in the same order

I would have prefered a way to have independent sections in which all vars stay ordered.

something like :

> Somewhere, in compiler/linker :
sect_1 = 0x20000000
sect_2 = 0x20000100
sect_3 = 0x20002000

>somewhere in code :
#pragma section 'sect_1'
var1
var2
var3

#pragma section 'sect_2'
var10
var20
var30
<<