Safe Memory Optimization for Beginners?

Hi,

It has been a few years since I last used FreeRTOS, and even then I was still learning it. I am now working with a custom PCB based on an STM32C051G6U6 (12 KB RAM, 32 KB Flash).

After generating FreeRTOS with CubeMX default settings and using heap_4, the firmware reports only about 3.4 KB of free RAM and 14.6 KB of free Flash remaining.

The application itself is relatively simple, but I would like to run at least three tasks. Since I am still a beginner with FreeRTOS configuration, I would like to focus only on safe and low-risk optimizations.

Which FreeRTOS configuration options can a newbie confidently adjust to reduce RAM/Flash usage without risking subtle stability issues or breaking core functionality? Are there commonly accepted “safe to disable” features for small-memory MCUs?

Any guidance or best-practice recommendations would be greatly appreciated.

Thank you.

You can look at the map file to see where the RAM is going. This will help in deciding where to focus. You can use static allocation only to keep everything fixed at compile time.

1 Like

First you should make sure that you are understanding the statement of “3.4kB free RAM“ correctly. If this is the compiler output, this already includes the memory reserved by heap_4 because of configTOTAL_HEAP_SIZE set via FreeRTOSConfig.h. So you are probably fine, since the memory for your tasks is already reserved. Considering Flash, FreeRTOSConfig.h is also your next stop. In general every feature is safe to remove if you don’t need it. But which feature you need is completely up to your application.
Also if you do not plan to free memory anywhere, using heap_1 will save flash (and a bit of ram) and is less hassle to use compared to the fully static allocation.