Maximum static array size

Discussions and support about ChibiOS/RT, the free embedded RTOS.
User avatar
Skadi
Posts: 60
Joined: Fri Apr 17, 2015 5:10 pm
Has thanked: 4 times
Been thanked: 3 times

Maximum static array size

Postby Skadi » Tue Aug 07, 2018 7:26 pm

Hi,

I'm running ChibiOS on a STM32F429VI which has 2048 kB Flash and 256 kB RAM. What I'm trying to do, is to allocate a static array like

Code: Select all

static uint16_t Buffer[X] = {0};

I curious what's the maximum static array size can be. For an array size up to X = 64800, compiling works fine. For a larger array e.g. X = 64900 i get following error:

rules.ld:359 cannot move location counter backwards (from 200300a0 to 20030000)
collect2.exe: error: ld returned 1 exit status


According to the address shown above, the static array is allocated from the SRAM, corresponding to the Reference Manual RM0090 (section 2.3.1 page 68). As I'm allocating an uint_16t array, the array should have a size of 2 x 64900 = 129.8 kB, which shouldn't be too large for the RAM.

To be hornest, I don't kow which part of my program is stored in the Flash and which in the RAM. I assume, the main part is stored in the Flash, as it is non-volatile.

Further, I'm using ChibiStudio and for me it's not clear how large my code is, as I only get the following lines when compiling is finished

text data bss dec hex filename
60732 456 196604 257792 3ef00 build/TEST.elf


Is it the size of the .hex file (in the build folder)?


Perhaps someone can clarify things for me :) .

BR Skadi

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Maximum static array size

Postby Giovanni » Wed Aug 08, 2018 6:48 am

Hi,

Details are in the .dmp and .map files, look there.

Try removing the initializer to the array declaration, that may cause have a copy of the array in flash.

Giovanni

User avatar
Skadi
Posts: 60
Joined: Fri Apr 17, 2015 5:10 pm
Has thanked: 4 times
Been thanked: 3 times

Re: Maximum static array size

Postby Skadi » Wed Aug 08, 2018 1:04 pm

Hi Giovanni,

I had a look at the .map file, where I found the following Memory Configuration:

Name Origin Length Attributes
flash 0x08000000 0x00200000
ram0 0x20000000 0x00030000
ram1 0x20000000 0x0001c000
ram2 0x2001c000 0x00004000
ram3 0x20020000 0x00010000
ram4 0x10000000 0x00010000
ram5 0x40024000 0x00001000
ram6 0x00000000 0x00000000
ram7 0x00000000 0x00000000
*default* 0x00000000 0xffffffff


So it looks like, allocating a static array will exceeds the RAM3 space/length.

Sorry but I do not understand the following suggestion :? .
Giovanni wrote:Try removing the initializer to the array declaration, that may cause have a copy of the array in flash.


BR Skadi

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Maximum static array size

Postby Giovanni » Wed Aug 08, 2018 1:53 pm

Try removing this:

static uint16_t Buffer[X] = {0};

It could force the compiler to allocate the array in the DATA segment instead of BSS.

Giovanni

User avatar
Skadi
Posts: 60
Joined: Fri Apr 17, 2015 5:10 pm
Has thanked: 4 times
Been thanked: 3 times

Re: Maximum static array size

Postby Skadi » Thu Aug 09, 2018 4:54 pm

Hi Giovanni,

I followed your suggestion, but I get the same error massage.

BR

apmorton
Posts: 36
Joined: Fri Sep 29, 2017 10:26 am
Been thanked: 16 times

Re: Maximum static array size

Postby apmorton » Wed Aug 15, 2018 7:08 pm

chances are you are simply out of memory and aren't aware of it.
Remove the large array and recompile - then look at the line that looks like below:

Code: Select all

text   data   bss   dec   hex   filename
60732   456   196604   257792   3ef00   build/TEST.elf

If you add up the bss and data columns that will tell you roughly how much memory you are using.

Your device doesn't actually have 256k of continuous RAM - ST is not so up front about this.

The chip has 3 SRAM banks that are laid out sequentially.
SRAM1 = 112k
SRAM2 = 16k
SRAM3 = 64k

for a total of 192k of sequential memory.

The remaining 64k of memory is the CCM SRAM - which is at address 0x10000000 and has some limitations that make it not suitable for "general purpose" ram. It can only be accessed by the CPU itself - the DMA controller and other peripherals cannot access it. Because of this, if you want to use it, you need to explicitly put your variables there since only you (the human writing the code) know whether or not it is safe to do so.

The way you do that is dependent on your compiler.


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 6 guests