Memory allocation issues with the LPC1788

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Memory allocation issues with the LPC1788

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tagc on Fri Aug 31 01:16:19 MST 2012
I'm fairly new to programming microcontrollers; I've been working with the LPC1788 for a couple of weeks now.

One problem I've been having recently is that I'm running out of memory much sooner than I expect to. I've tested how much memory seems to be available by testing how large a block of contiguous memory I can malloc, and the result is 972 bytes. Allocation is done starting at address 0x10000000 (the start of the on-chip SRAM that should be around 64kB on this board).

The program I'm working on at the moment is meant to act as a simple debugger that utilises the LCD and allows messages to be printed to it. I have one string that will constantly be "added to" by new messages, and then the whole message will be printed on the LCD. When the message's length down the screen goes past the vertical boundary, it will delete the oldest messages (the ones nearer the top) until it fits. However, I can only add about 7 additional messages before it refuses to allocate more memory. If needed, the main.c for the project is hosted at http://pastebin.com/bwUdpnD3

Earlier I also started work on a project that uses the threadX RTOS to create and execute several threads. When I tried including use of the LCD in that program, I found memory to be very limited there aswell. The LCD seems to store all pixel data starting from the SDRAM base address, but I'm not sure if that's the same thing as the SRAM I'm using.

What I need is a way to allocate memory enough to allow several threads to function or large strings to be stored, while being able to utilise the LCD. One possibility might be to use buffers or other areas of memory, but I'm not quite sure how to do that. Any help would be appreciated.


tl;dr: Quickly running out of allocatable memory on SRAM when trying to print out large strings on the LCD.
Labels (1)
0 Kudos
2 Replies

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by John Sinclair on Wed Sep 05 01:15:30 MST 2012
Hi Tagc,

malloc uses heap. So you have increase your heap size in the startup file. But attention, in the embedded world malloc is a taboo, because the Controller doesn't have a MMU (memory management unit). So your heap will defragmented after a lot of malloc and free calls with different sizes. Better (saver) is to use static memory like a array.
Best regards

John
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave on Fri Aug 31 22:47:41 MST 2012
...
0 Kudos