Memory management is important in a multi-threaded environment, as threads (or tasks) can quickly consume all of the allocated memory, causing bizarre effects such as overwritten memory locations or random processor resets.
The solution to the challenge in the video can be found here: https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-4-memory-management/6d4dfcaa1ff84f57a2098da8e6401d9c
In this video, we look at various ways to allocate memory to a task and how to monitor memory usage in FreeRTOS.
Most C programs rely on 3 different types of memory. Static memory is set aside prior to program execution and used for things like static variables, constants, and global variables. Stack is allowed to grow dynamically and consists of local variables declared at the function level. Finally, heap may also grow dynamically and must be specifically allocated and deallocated by the programmer (e.g. using the malloc() and free() functions, respectively).
Whenever we create a new task in FreeRTOS, we must assign it a set amount of stack memory to use out of the global, available heap. Note that each task also requires another section of heap for the Task Control Block (TCB), which stores various attributes about the task, such as its state and priority.
We demonstrate ways to monitor the stack in each thread as well as the total amount of heap available to the system. We also show what happens when you overrun the stack or heap!
Product Links:
https://www.digikey.com/en/products/detail/adafruit-industries-llc/3405/7244967
Related Videos:
Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? - https://youtu.be/F321087yYy4
Introduction to RTOS Part 2 - Getting Started with FreeRTOS - https://youtu.be/JIr7Xm_riRs
Introduction to RTOS Part 3 - Task Scheduling - https://youtu.be/95yUbClyf3E
Introduction to RTOS Part 4 - Memory Management - https://youtu.be/Qske3yZRW5I
Introduction to RTOS Part 5 - Queue - https://youtu.be/pHJ3lxOoWeI
Introduction to RTOS Part 6 - Mutex - https://youtu.be/I55auRpbiTs
Introduction to RTOS Part 7 - https://youtu.be/5JcMtbA9QEE
Introduction to RTOS Part 8 - https://youtu.be/b1f1Iex0Tso
Introduction to RTOS Part 9 - https://youtu.be/qsflCf6ahXU
Introduction to RTOS Part 10 - https://youtu.be/hRsWi4HIENc
Introduction to RTOS Part 11 - https://youtu.be/C2xKhxROmhA
Introduction to RTOS Part 12 - https://youtu.be/LPSHUcH5aQc
Related Project Links:
https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-4-memory-management/6d4dfcaa1ff84f57a2098da8e6401d9c
Related Articles:
https://www.digikey.com/en/maker/videos/shawn-hymel/getting-started-with-stm32-and-nucleo-part-3-how-to-run-multiple-threads-with-cmsis-rtos-interface
Learn more:
Maker.io - https://www.digikey.com/en/maker
Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/
And follow us on Twitter https://twitter.com/digikey