Problem with storage of large const array

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User9897
Level 2
Level 2
Hi,

I want to store a large constant array on an XMC4200.
e.g.
const uint32_t d[20000] = {...};

20000 * 4 Byte = 80000 Byte. The flash memory of the XMC4200 ist 256k so there should be enough space. But I get the following error:

'Invoking: ARM-GCC C Linker'
c:/davev4/dave-4.1.2/eclipse/arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: TestProject.elf section `.data' will not fit in region `SRAM_combined'
"C:\DAVEv4\DAVE-4.1.2\eclipse\ARM-GCC-49/bin/arm-none-eabi-gcc" -T"../linker_script.ld" -nostartfiles -Xlinker --gc-sections -specs=nano.specs -specs=nosys.specs -Wl,-Map,TestProject.map -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mcpu=cortex-m4 -mthumb -g -gdwarf-2 -o "TestProject.elf" "@objects.rsp" -lm
c:/davev4/dave-4.1.2/eclipse/arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: address 0x20010318 of TestProject.elf section `USB_RAM' is not within region `SRAM_combined'
c:/davev4/dave-4.1.2/eclipse/arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: address 0x20010318 of TestProject.elf section `USB_RAM' is not within region `SRAM_combined'
c:/davev4/dave-4.1.2/eclipse/arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: address 0x20010318 of TestProject.elf section `USB_RAM' is not within region `SRAM_combined'
c:/davev4/dave-4.1.2/eclipse/arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: region SRAM_combined overflowed no_init section
c:/davev4/dave-4.1.2/eclipse/arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: region `SRAM_combined' overflowed by -32 bytes
makefile:51: recipe for target 'TestProject.elf' failed

I thought “const” variables end up in flash memory. Why is this not the case?

Best regards
Frank
0 Likes
3 Replies
DRubeša
Employee
Employee
First solution authored First like received
Hi Frank,

me and my colleague tried with multiple ways to get the same error message as you got, but in our case your variable was always correctly placed in .rodata part meaning Flash memory. Only once we removed the "const" keyword from the array declaration we got the same message as you. Is it possible that there is some other such a big array in your code that is not defined as constant? Also, can you try to change the size of the array...try to put it to 1, and then try to build project.

If the build is still not successful then there is apparently some other issue in your code then mentioned array.
If the build is successful then check the .map file (you can find it under your project files in "Debug" folder). Search for your array (I advise you to change the name of array to something more "searchable"...something like "test_array") and see where the linker will place the array in memory.

For example, in my case .map file for "test_array" looks like this:
 .rodata.test_array
0x00000000 0x13880 ./main.o


as you can see, the size of array is 0x13880 (80000 bytes) and the array is located in .rodata (.text ==> Flash memory).

Best regards,
Deni
0 Likes
User9897
Level 2
Level 2
Thank you for your effort and the proof that it works as intended.

Meanwhile I found the problem. It was a stupid mistake of my own :mad:.
In my test I put a "volatile" in front of it in order not to get optimized out since I dind't have real code accessing the array yet. Too bad "volatile" worked as it should ... Without volatile and a bit of real code it worked.

Best regards
Frank
0 Likes
Not applicable
DRubeša wrote:
Hi Frank,

me and my colleague tried with multiple ways to get the same error message as you got, but in our case your variable was always correctly placed in .rodata part meaning Flash memory. Only once we removed the "const" keyword from the array declaration we got the same message as you. Is it possible that there is some other such a big array in your code that is not defined as constant? Also, can you try to change the size of the array...try to put it to 1, and then try to build project.

If the build is still not successful then there is apparently some other issue in your code then mentioned array.
If the build is successful then check the .map file (you can find it under your project files in "Debug" folder). Search for your array (I advise you to change the name of array to something more "searchable"...something like "test_array") and see where the linker will place the array in memory.

For example, in my case .map file for "test_array" looks like this:
 .rodata.test_array
0x00000000 0x13880 ./main.o


as you can see, the size of array is 0x13880 (80000 bytes) and the array is located in .rodata (.text ==> Flash memory).

Best regards,
Deni


But it seems that the array in your example is not linked at all since the address of the array is 0x00000000 and therefore the array appears most likely inside the "Discarded input sections" area of the map file.

I added a const array called "ConstMemArray" without meaningful source code and the result is like in your example:
 
.rodata.ConstMemArray
0x00000000 0x20 ./main.o


But if I add meaningful code to the project, which uses the array, then the map file looks as follows:

.rodata.ConstMemArray
0x0802c260 0x20 ./main.o
0x0802c260 ConstMemArray


So I think important is also to check that the array gets a real Flash address assigned.
0 Likes