0

I try to define a separate RAM region/section in an IAR linker configuration file (.icf). The section should contain variables that are initialized like this:

#pragma default_variable_attributes = @ "MY_SECTION"

int a = 0;
int b = 666;

#pragma default_variable_attributes =

This is what I tried in the icf file:

define symbol MY_REG_START = PREVIOUS_REGION_END + 1;
define symbol MY_REG_END   = MY_REG_START + SIZE_16K - 1;

define region MY_REGION = mem:[from MY_REG_START to MY_REG_END];

initialize by copy { section MY_SECTION };

place in MY_REGION { section MY_SECTION };

Without the initialize by copy line, everythings works fine. However I am forced to initialize all variables to 0. I want to freely choose the init value which is why I tried to use the copy ROM to RAM initialization.

With the above code I keep getting the warning:

Warning[Be006]: possible conflict for segment/section "MY_SECTION": "test.c"
          variable "b @ "MY_SECTION"" (declared at line 13 of "test.c") is  
an initialized variable 
          variable "a @ "MY_SECTION"" (declared at line 12 of "test.c") is a  
zero-initialized variable (2 more variables like this) 

What is wrong with my configuration?

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
  • Is there any reason why you can't reserve a part of `.data` for this? Otherwise I don't think you can get the "CRT" to do the copy-down for you, you'll have to do it manually. And why does it matter to you if the copy-down takes place before or after `main()` is called? – Lundin Nov 02 '17 at 14:32
  • The memory section must be kept totally separately. Never tried manual initialization; how can I do that? – Silicomancer Nov 02 '17 at 14:37
  • `memcpy(my_ram, my_rom, n);` – Lundin Nov 02 '17 at 14:38
  • I tried it. I changed "by copy" to "manually" in the .icf (and inserted a proper memcpy call). The linker still shows the above warning. – Silicomancer Nov 02 '17 at 15:55
  • What I mean is, there's no need to get fancy with the linker file. Declare one custom RAM segment and one custom flash segment. Copy from flash to RAM with memcpy in runtime. This will also make the code more portable outside IAR. – Lundin Nov 02 '17 at 16:07
  • So you wouldn't use "initialise manually"?. I could create a corresponding ROM segment, that has the same size as my RAM segment, but how can I push the variable initialisation values into the ROM segment? I mean, I can use pragmas to locate the variables, but I do not know a pragma to locate init values. – Silicomancer Nov 02 '17 at 16:15
  • I don't remember how to allocate a variable in a particular segment in IAR, but yeah you just place some `const` variables in the ROM segment and then you copy those variables into RAM. – Lundin Nov 02 '17 at 21:50
  • I think easiest would be to define structure for variables. Define `const struct Vars romVars = { /* init values */ }; struct Vars ramVars;` (with necessary placement pragmas of course) and at the program startup do `ramVars = romVars;`. – user694733 Nov 03 '17 at 12:19

0 Answers0