vApplicationStackOverflowHook cannot be declared in sketch

Working libraries, libraries being ported and related hardware
Post Reply
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

vApplicationStackOverflowHook cannot be declared in sketch

Post by Phono »

Hi,
for the sake of debugging, I need to check whether a stack overflow would occur in a multitasking sketch. I am using STM32FreeRTOS version 9.0.4.
In the FreeRTOS configuration I activated the option configCHECK_FOR_STACK_OVERFLOW, and I added in my sketch a function as follows:

Code: Select all

extern "C" void vApplicationStackOverflowHook( TaskHandle_t xTask,signed char *pcTaskName );
void vApplicationStackOverflowHook( TaskHandle_t xTask,signed char *pcTaskName )
{
  SERIAL.print("Debordement tache ") ;
  SERIAL.println(pcTaskName[0]) ;
}
But at link time I get a "multiple definition" error.
I had a look at STM32FreeRTOS.c, and I found the following code:

Code: Select all

#if ( configCHECK_FOR_STACK_OVERFLOW >= 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.
  \param[in] pxTask Task handle
  \param[in] pcTaskName Task name
  */
void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) {
  (void) pcTaskName;
  (void) pxTask;
  errorBlink(3);
}
#endif /* configCHECK_FOR_STACK_OVERFLOW >= 1 */
Since the latter has no "weak" attribute, I cannot overload it with my own function.
So,when the option configCHECK_FOR_STACK_OVERFLOW is activated, I have no other choice but rely on the predefined function?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: vApplicationStackOverflowHook cannot be declared in sketch

Post by fpiSTM »

Yes, currently you could not overload it.
For CMSIS OS V2, there is a dummy one defined as weak so the one defined in STM32FreeRTOS.c could not be defined as WEAK.
I guess, it should be possible to define a user one which can be called if it is not NULL.
You can provide a PR for this and we could apply it on both version 9.x and 10.x.
Post Reply

Return to “Libraries & Hardware”