infineon4engi@twitter infineon4engineers infineon@linkedin infineon@youtube
twitter Facebook Linkedin Youtube

+ Reply to Thread
Results 1 to 4 of 4

Thread: Problem with storage of large const array

  1. #1
    New Member New Member fraenky is on a distinguished road
    Join Date
    Mar 2015
    Posts
    18
    Points
    135.9375

    Problem with storage of large const array

    Hi,

    I want to store a large constant array on an XMC4200.
    e.g.
    Code:
    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:
    Code:
    '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

  2. #2
    Beginner Beginner
    Infineon Employee
    Infineon Employee
    DRubeša will become famous soon enough
    Join Date
    Jul 2016
    Location
    München
    Posts
    196
    Points
    447.8125
    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:
    Code:
     .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
    The views expressed here are my personal opinions, have not been reviewed or authorized by Infineon and do not necessarily represent the views of Infineon.

  3. #3
    New Member New Member fraenky is on a distinguished road
    Join Date
    Mar 2015
    Posts
    18
    Points
    135.9375
    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 .
    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

  4. #4
    New Member New Member Halbenandy is on a distinguished road
    Join Date
    Nov 2016
    Posts
    2
    Points
    45
    Quote Originally Posted by DRubeša View Post
    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:
    Code:
     .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:
    Code:
     
    .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:
    Code:
     .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.

+ Reply to Thread

Tags for this Thread

Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.