cancel
Showing results for 
Search instead for 
Did you mean: 

Out of memory?

hitsumen
Associate II
Posted on May 13, 2012 at 18:30

Good day,

I was playing with ST32F103RET6 MCU.

I looked in datasheet, my MCU has 64Kb of SRAM, so I could easily create array with 20 kbytes. But I cannot.

I use IAR compiler, What can be wrong. I can create only 1800byte array.

unsigned char my_array[1800];

If I create something like my_array[3000]. My MCU going to reset..

Thank you.

#ram #linker-error
14 REPLIES 14
Posted on May 13, 2012 at 22:18

Sounds like you need to select the correct CPU target in your GUI, or within your linker script or scatter file. You don't however specify the tool chain, so it's hard to say specifically. Either way the software needs to know the settings which are appropriate for the hardware you are using.

If these are local allocations, you will need to assure that your stack is sufficiently large.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
harinath
Associate III
Posted on May 14, 2012 at 04:38

Hi Clive1,

I have similar problem. I use IAR embedded workbench IDE v6.30, FreeRTOS, ST LINK on windows 7.

I use Olimex STM32-P103 board which has STM32F103RBT6 micro. I'm trying to adapt ST firmware provided for

http://www.st.com/internet/evalboard/product/250367.jsp

board. I get the following linker error:

Error[Lp011]: section placement failed: unable to allocate space for sections/blocks with a total estimated minimum size of 0x583c bytes in <[0x20000000-0x20004fff]>  (total uncommitted space 0x5000). 

The microcontroller RAM adress is 0x20000000-0x20004fff.

I don't know whats the problem. If I'm facing RAM shortage problem, how to solve this problem without using any external RAM.

Thank you

hitsumen
Associate II
Posted on May 14, 2012 at 08:57

Hi,

I choosed the correct CPU, Il give you the message from debugger:

The stack pointer for stack 'CSTACK' (currently 0x1FFFF4D8) is outside the stack range (0x200000B0 to 0x200008B0)

for harinath:

if you use freertos, then try to change this file FreeRTOSConfig.h

and this line: Its total allocated ram.  good luck 🙂

#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 55 * 1024 ) )

Posted on May 14, 2012 at 19:23

I don't know whats the problem. If I'm facing RAM shortage problem, how to solve this problem without using any external RAM.

The simple answer is to use less of the memory you have.

The more complicated answer is to go through the .MAP, or equivalent, file and figure out what static allocations you are doing which are hogging resources. Identify where the memory is going, and why.

Can you make certain data ''static const'' so that it stays in ROM?

Can you fold a number of buffers, or other allocations, so they share the same memory footprint? This can help if there are no interdependencies, you'll have to examine/understand those.

Consider dynamic allocation methods, can you for instance have a pool of different fixed size blocks? A PC allocator probably won't work well due to fragmentation issues.

Do you understand your call trees well enough to be able to allocated local storage on a larger stack? You need to have a clear idea of the potential stack depth rather than just experimenting and arbitrarily increasing the size.

Use a smaller ring buffer, instead of allocating ten ~1500 byte ethernet buffers, for example. The implementation is more complex, but will use less memory.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on May 14, 2012 at 19:28

The stack pointer for stack 'CSTACK' (currently 0x1FFFF4D8) is outside the stack range (0x200000B0 to 0x200008B0)

 

Well that sounds like you have a 2048 byte stack, to which you're stuffing 5080 bytes.

For local/auto variables you need to define a stack big enough to meet your needs.

If you want if to use non-stack RAM, use the static keyword, or define if globally.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
hitsumen
Associate II
Posted on May 15, 2012 at 07:04

Thank you, yes, I tried to change Cstack settings and it worked, till something like 20kbs, then I put static keyword before my array, and it worked, but weird thing is that I need to use some delay before operations if I do not want to have some wrong data like delay_us(2);

So now I can put my resized array of 38400 bytes to memory (160x120x2(16bytes)).

hitsumen
Associate II
Posted on May 15, 2012 at 07:13

''Can you make certain data ''static const'' so that it stays in ROM?''

About static const, yes I could some, but the program itself has no so much data, so I do not think that it could make any difference.

''Consider dynamic allocation methods, can you for instance have a pool of different fixed size blocks? A PC allocator probably won't work well due to fragmentation issues.''

I thinked about that, but do not like dynamic allocations, sometimes you do not know what could happen if somewhere memory is not free'd correctly.

Actually everything is nice with static array. You see I have the camera I want to read the image. Original size is 320x240 and 16bit so 320x240x2=153600bytes image. So its not possible to put the image to memory. I thought I will do some resizing. With your help I could but 1/4 of image to memory so its ok, for now its nice, I could do some image processing.

Later on, If I want to have full image I need external memory. 

Have you worked with external memory? Can you give me some advice, which one to buy, I need some fast one, not much something like 400kbytes to store 1-2 images.

Thank you,

//Nikolaj 

hitsumen
Associate II
Posted on May 17, 2012 at 11:34

clive1

I initialized my array like this. Sometimes it works, sometimes it is not.

static unsigned char image_array[160][120][2];

I mean when I do some image editing my array going to be distorted.. Maybe you know why? In some cases delay_us() function helps, but in some do not, I will post some code here which is not working..

for(int k = 0; k < 117; k++){

for(int j = 0; j < 157; j++){

          if((image_array[j][k][1] == 0x7F) && (image_array[j][k][0] == 0xFF)){

             if(image_array[j+2][k][0] == 0xFF){

             image_array[j+1][k][0]=0xFF;

             image_array[j+1][k][1]=0x7F;

             }

             if(image_array[j][k+2][0] == 0xFF){

             image_array[j][k+1][0]=0xFF;

             image_array[j][k+1][1]=0x7F;

             }}

    }}

And here is the image:

1. Good

0690X00000602PMQAY.bmp

2. Bad

0690X00000602PRQAY.bmp

Can you tell me what can be wrong here?? And like I said in some cases I put delay and it works..

alok472
Associate II
Posted on May 18, 2012 at 03:54

''And like I said in some cases I put delay and it works..''

It' not clear where you put the delay ? When taking data from flash and putting in RAM, there should not be any need for delay. Is your CPU configuration correct ?

for image processing, are you trying to change some colour ?