Hello, I use Keil µvision 3.60 I need to store some variables from different files.c in the same memory area in order. I saw there are link directives such ORDER, SECTIONS, GROUPS, but it seems these directives work for all variables or constants from the same file. My problem is my variables are defined in different files and I don't know to specify to store such variable from such file.c in the same defined memory area and the other in the default memory area. I need to specify when I define my variables the allocated memory where are stored. Is possible with Keil Compiler? How can I make this operation? Thanks.
Have a look at this to determine placement of certain data: http://www.keil.com/support/man/docs/c166/c166_le_memtypes.htm
Or put all data in a single module/section and use this to put the section at a certain location: http://www.keil.com/support/man/docs/l166/l166_sections.htm
Or have a look at this to define your own memory class and use the linker file to place it at the required location: http://www.keil.com/support/man/docs/c166/c166_renameclass.htm
Or tell us what you're trying to accomplish and maybe there's a different way to solve it altogether.
-- Joost
I can't use just one file to define declare my variables. The purpose of this operation is to define variables of differents types to use in calibration. In fact in my soft I want to copy a memory area from ROM to RAM and use these data to calibrate a system. At the end of my tests, I save these data in ROM (in flash). It is for this reason, I want the same ROM memory map than the RAM memory map (same order for the variable).
On an old project using microchip compiler for this method, I used the following Macro:
#if ( __CCP__ == STD_ENABLED ) /* @Comment : Macro that allow definiton of calibration data */ #define DEF_CALIB( Type , Name , Value ) \ Type __attribute__((__section__(".calibrationRAM"))) Name##Cal ; \ const Type Name##CalMem __attribute__((__section__(".calibrationROM,r"))) = Value #else /* @Comment : Macro that allow definiton of calibration data */ #define DEF_CALIB( Type , Name , Value ) \ const Type Name##Cal __attribute__((__section__(".calibrationROM,r"))) = Value
A ROM memory and RAM memory sections are defined to store the calibrations data; they are the same map.
If I'm in CCP mode, I define for the same data a variable and a constant and when I've finished I copy my RAM memory in ROM memory. And when I'not in CCP mode, I used just constant for my datas. For this reason, I need the same RAM memory map than the ROM memory map. I want just to used the same method with the C166 Keil Compiler.
I know if I declare my variables int he same file it is good but the architecture of my project doesn't permit this thing. I can use table or structure, but is not very easy to use in the code.
With the previous described method, it is transparent for the user. But it seems the Keil compiler is limited for the memory allocation.
(please use the b, i and pre HTML tags to format text/code)
In fact in my soft I want to copy a memory area from ROM to RAM and use these data to calibrate a system. At the end of my tests, I save these data in ROM (in flash). It is for this reason, I want the same ROM memory map than the RAM memory map (same order for the variable).
I think you're going at this in completely wrong way. What you should do is
1) define a struct type that holds all those calibration variables. 2) define one object of that type in ROM, the other in RAM.
Now you can just copy the ROM variable to RAM by struct assignment.
I did not want to use a sturcture because my soft is made by two software teams, and we have to define this structure in a common file and by experience I prefere to share least data (avoid the problem). with my method on another compiler, I had just to copy a memory area, without to know any definition.
Now I have only the choice to use a structure or to define every variable in the same file using the directive ORDER. It is not very good for the architecture of my soft.
It is regrettable that the compiler is limited.
Thank you for your answer.
Complaining that the compiler is limited is most definitely the wrong way to go. It is your imagination that is the limiting factor in this case. It is the poor carpenter who blames his tools...
Anyway. Create one struct in one header file (maintained by one team). Create another struct in another header file for the other team.
Either let the two teams have a pointer each, to a raw block of data, or have a union with the two structs.
If team A only works with code relating to struct A, it doesn't matter to them what happens with struct B. They either uses a_ptr->field or union.a_data.field to access their data.
Of course, mapping two structs above each other can also be done by the linker, but the disadvantage compared to a union is that it isn't visible in the code that you have shared variable space and have to take care when calling functions.
with my method on another compiler, I had just to copy a memory area, without to know any definition.
But the developers still had to know that they had to put the relevant variables into that memory area. That's no better than putting them in a centrally maintained struct datatype.
It's not C166 that is limited here. It's your code's portability that is limited by relying on extensions in some other compiler. Lack of extension is not a limitation.