Minimal useful heap size w/LPC2103

ktownsend wrote on Tuesday, October 06, 2009:

I’ve been trying to squeeze FreeRTOS onto an LPC2103 (8KB SRam and 32KB Flash) and am able to get it working with the following config setting:

configTOTAL_HEAP_SIZE = 4 * 1024

Which I think should be enough for the kind of basic tasks I’m doing (reading an LM75, etc.), but I don’t have enough experience with FreeRTOS to say for sure.  I also adjusted the size of the heap/stack for the LPC2103 to try to claw back a bit of memory.  I was wondering if anyone would be able to guess (from their experience) if the following settings are likely to cause a problem with FreeRTOS or if I should be adjusting them up or down:

- Heap Size: 1024 Bytes
- Abort Mode Stack: 4 Bytes
- FIQ Stack: 32 Bytes
- IRQ Stack: 256 Bytes
- Supervisor Stack: 256 Bytes
- Undefined Stack: 4 Bytes
- User/System Stack: 0 Bytes
- .

Since FreeRTOS runs in supervisor mode I’m assuming I don’t really need the User/System stack space, but I’m not completely sure.

In any case, with the settings above FreeRTOS at least runs and uses:

- **19,732 Bytes Flash** (12.7KB Free)
- **5,868 SRAM** (2.2 KB Free)

If anyone can suggest something to improve on this or let me know if I’m doing something dangerous, I’d certainly be glad to hear it now rather than 3 months down the road. :slight_smile:

rtel wrote on Tuesday, October 06, 2009:

FreeRTOS V6.0.0 is now in SVN (although not yet released), if you look at heap_1.c and heap_2.c you will see a new function that allows you to query the amount of heap space remaining.  Using that and uxTaskGetStackHighWaterMark() you can tune your memory usage.

Also worth setting confgCHECK_FOR_STACK_OVERFLOW to 2 to provide some run time stack checking too.

Not exactly what you were asking, but hopefully helpful none the less.