Skip to Content
Hands-On RTOS with Microcontrollers
book

Hands-On RTOS with Microcontrollers

by Brian Amos
May 2020
Intermediate to advanced
496 pages
13h 54m
English
Packt Publishing
Content preview from Hands-On RTOS with Microcontrollers

Keeping an eye on heap space

If your application makes regular use of the FreeRTOS heap, then you should strongly consider using the configUSE_MALLOC_FAILED_HOOK configuration and associated hook, vApplicationMallocFailedHook. This hook is called anytime a call to pvMalloc() fails.

Of course, while you're doing this, you're being a responsible programmer and checking the return value of malloc and handling these error cases anyway... so this hook may be redundant.

The steps for setting this up are the same as in the previous hook:

  1. Add the following in FreeRTOSConfig.h:
#define configUSE_MALLOC_FAILED_HOOK 1
  1. In a *.c file, add the failed malloc hook:
void vApplicationMallocFailedHook( void ){ __disable_irq(); while(1);}

There are also ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On RTOS with Microcontrollers - Second Edition

Hands-On RTOS with Microcontrollers - Second Edition

Jim Yuill, Penn Linder

Publisher Resources

ISBN: 9781838826734Supplemental Content