Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


How calculate heap, stack for PIC32MX

Posted by ulmus on January 6, 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 :) 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... :( 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 :)

RE: How calculate heap, stack for PIC32MX

Posted by Richard on January 7, 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()).


RE: How calculate heap, stack for PIC32MX

Posted by ulmus on January 8, 2012
Thanx a lot! As always support here is the greatest!

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner