How calculate heap, stack for PIC32MX

ulmus71 wrote on Friday, January 06, 2012:

Hi! i have running already my firmware on pic32mx with FreeRTOS, it has 2 serials(printer, usb), 2 I2C(flash, rtc) and 2 SPI (a/c converter) 3 PWMs (calibration, sound) and of course graphics LCD RA8835 with PMP :slight_smile: Wow! FreeRtos works great! I had it working first as a modules without freertos and now i solve this puzzle with your rtos (semaphores and mutexes are great!)
But… memory… :frowning: can you give me simple tips for calculating heap and maybe stacks? i have tasks created on start of app and never deleted (i am programming measurement device firmware).
I know a little, but info from you, i mean from source :)  are best:)
thanx in advance :slight_smile:

rtel wrote on Saturday, January 07, 2012:

While it is possible to calculate worst case stack usage, likewise heap usage, I take a more pragmatic approach and use experimentation.  It is made easier by the fact that, on the PIC32 (and other CPUs), the FreeRTOS port uses a separate stack for interrupts - so interrupt nesting does not need to be taken into consideration on the task stack.

If a stack is too small, then the stack overflow hook will catch it, and you know to increase it.

If a stack is larger than necessary, then you can resize it using the information obtained from its high water mark.

With regards to the FreeRTOS heap, if you are allocating everything up front then just inspect the FreeRTOS heap to see how much is left, and you can reduce its size accordingly.  If you are using heap_1.c or heap_2.c there is even a function provided to query how much is left (xPortGetFreeHeapSize()).


ulmus71 wrote on Sunday, January 08, 2012:

Thanx a lot! As always support here is the greatest!