From d05df76c1ab0664c4bf7ef8318d80baac164186c Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 25 Jul 2024 17:11:13 +0200 Subject: [PATCH] feat: provide default functions only if requested configUSE_MALLOC_FAILED_HOOK and configCHECK_FOR_STACK_OVERFLOW allow to define specific function to call when a malloc failed or a stack overflow occured. Respectively, vApplicationIdleHook and vApplicationStackOverflowHook. Previous implementation provide them unconditionally preventing users to define their own implementation. Now extra config is required to have the default implementation: /* Set to 1 to use default blink hook if configUSE_MALLOC_FAILED_HOOK is 1 */ #ifndef configUSE_MALLOC_FAILED_HOOK_BLINK #define configUSE_MALLOC_FAILED_HOOK_BLINK 0 #endif /* Set to 1 to used default blink if configCHECK_FOR_STACK_OVERFLOW is 1 or 2 */ #ifndef configCHECK_FOR_STACK_OVERFLOW_BLINK #define configCHECK_FOR_STACK_OVERFLOW_BLINK 0 #endif Fixes #69. Signed-off-by: Frederic Pillon --- src/FreeRTOSConfig_Default.h | 13 +++++++++++-- src/STM32FreeRTOS.c | 18 +++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/FreeRTOSConfig_Default.h b/src/FreeRTOSConfig_Default.h index c0e71ce..0805fdf 100644 --- a/src/FreeRTOSConfig_Default.h +++ b/src/FreeRTOSConfig_Default.h @@ -46,7 +46,16 @@ * -1 for heap_useNewlib_ST.c * Default -1 see heap.c */ -/*#define configMEMMANG_HEAP_NB 3*/ +/* #define configMEMMANG_HEAP_NB 3 */ + +/* Set to 1 to use default blink hook if configUSE_MALLOC_FAILED_HOOK is 1 */ +#ifndef configUSE_MALLOC_FAILED_HOOK_BLINK + #define configUSE_MALLOC_FAILED_HOOK_BLINK 0 +#endif +/* Set to 1 to used default blink if configCHECK_FOR_STACK_OVERFLOW is 1 or 2 */ +#ifndef configCHECK_FOR_STACK_OVERFLOW_BLINK + #define configCHECK_FOR_STACK_OVERFLOW_BLINK 0 +#endif /* configUSE_CMSIS_RTOS_V2 has to be defined and set to 1 to use CMSIS-RTOSv2 */ /*#define configUSE_CMSIS_RTOS_V2 1*/ @@ -218,7 +227,7 @@ header file. */ /* * IMPORTANT: * SysTick_Handler() from stm32duino core is calling weak osSystickHandler(). - * Both CMSIS-RTOSv2 and CMSIS-RTOS override osSystickHandler() + * Both CMSIS-RTOSv2 and CMSIS-RTOS override osSystickHandler() * which is calling xPortSysTickHandler(), defined in respective CortexM-x port */ /* #define xPortSysTickHandler SysTick_Handler */ diff --git a/src/STM32FreeRTOS.c b/src/STM32FreeRTOS.c index dbd85e8..d20fdfa 100644 --- a/src/STM32FreeRTOS.c +++ b/src/STM32FreeRTOS.c @@ -50,13 +50,12 @@ void assertBlink() { errorBlink(1); } //------------------------------------------------------------------------------ -#if ( configUSE_MALLOC_FAILED_HOOK == 1 ) +#if ( ( configUSE_MALLOC_FAILED_HOOK == 1 ) && ( configUSE_MALLOC_FAILED_HOOK_BLINK == 1 ) ) /** vApplicationMallocFailedHook() - Blink two short pulses if malloc fails. - - will only be called if - configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook - function that will get called if a call to pvPortMalloc() fails. + Blink two short pulses if malloc fails. Itwill only be called if + configUSE_MALLOC_FAILED_HOOK is set to 1 and + configUSE_MALLOC_FAILED_HOOK_BLINK defined in FreeRTOSConfig.h. + It is a hook function that will get called if a call to pvPortMalloc() fails. pvPortMalloc() is called internally by the kernel whenever a task, queue, timer or semaphore is created. It is also called by various parts of the demo application. If heap_1.c or heap_2.c are used, then the size of the @@ -87,11 +86,12 @@ void __attribute__((weak)) vApplicationIdleHook( void ) { #endif /* configUSE_IDLE_HOOK == 1 */ /*-----------------------------------------------------------*/ -#if ( configCHECK_FOR_STACK_OVERFLOW >= 1 ) +#if ( ( configCHECK_FOR_STACK_OVERFLOW >= 1 ) && ( configCHECK_FOR_STACK_OVERFLOW_BLINK == 1 ) ) /** Blink three short pulses if stack overflow is detected. Run time stack overflow checking is performed if - configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook - function is called if a stack overflow is detected. + configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2 and + configCHECK_FOR_STACK_OVERFLOW_BLINK is defined. + This hook function is called if a stack overflow is detected. \param[in] pxTask Task handle \param[in] pcTaskName Task name */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy