Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


FreeRTOS Heap / Stack / Memory Management

Hi there,

I am working on a custom board with the STM32F107VCT processor. I am using FreeRTOS & lwIP

I am using tinyxml2 library and reading / writing to an EEPROM and running into strange corruption issues and crashes. I suspect I may be running out of memory. I am fairly new embedded electornics and FreeRTOS so am unsure where I should be looking.

I create a few threads like so:

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 512);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

osThreadDef(RfTask, StartRfTask, osPriorityNormal, 0, 700);
RfTaskHandle = osThreadCreate(osThread(RfTask), NULL);

osThreadDef(DiscoveryTask, StartDiscoveryTask, osPriorityNormal, 0, 256);
DisoveryTaskHandle = osThreadCreate(osThread(DiscoveryTask), NULL);

Here are some of my defines related to heap / stack

FreeRTOS.h
define configTOTAL_HEAP_SIZE ((size_t)1024*24)

Flash.id

_estack = 0x20010000; /* end of RAM */

_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x200; /* required amount of stack */

I am not really following in my mind exactly what heap / stack theory is, and how it relates to the figures in flash.id and FreeRTOS.h

Could someone offer me an explanation please of how this all works, and any methods to check amount of ram available for the tasks etc?

I can share my code on gitlab if required

Thank you so much

There are few information to detect the reason of your bug but here a little explanation of what stack and heap memories are:
stack memory is used by cpu to store all the local array or pointers needed to manage the returning of function calls (think of an interrupt that is served so the cpu must store the right memory address to recall when its routine terminate). when you use an rtos usually define a priori the amount of memory reserved for each task. if you don’t need an rtos the stack memory is all the free ram memory you leave in your program.

heap memory is a kind of reserved memory to manage the dynamic memory access. When you have memory space problem you can decide to use the amount of needed memory in sharing way calling a malloc() or calloc(). In such a way you request to get it for a short time and then release that amount calling free().
The size of that memory is always defined,

Hope could help!