cancel
Showing results for 
Search instead for 
Did you mean: 

multiple definition of `SysTick_Handler'

Fnx_QT
Associate III

Hello,

I created a new project in STM32CubeIDE for my STM32MP157A by using STM32CubeMX. In it I enabled UART and FreeRTOS on CMSIS-RTOSv2 and that's all. I use the auto generated code.

Then I wanted to use TraceAlyzer on top of FreeRTOS however, upon including

#include "trcRecorder.h"

In the FreeRTOSConfig.h I got a strange error:

/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c:154: multiple definition of `SysTick_Handler'; ./Core/Src/stm32mp1xx_it.o: 
 
./CM4/Core/Src/stm32mp1xx_it.c:160: first defined here

The SysTick_Handler is defined in both files, here are the implementations if it may help:

in cmsis_os2.c :

/*
  SysTick handler implementation that also clears overflow flag.
*/
void SysTick_Handler (void) {
  /* Clear overflow flag */
  SysTick->CTRL;
 
  if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
    /* Call tick handler */
    xPortSysTickHandler();
  }
}
#endif /* SysTick */

In stm32mp1xx_it.c :

/**
  * @brief This function handles System tick timer.
  */
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */
 
  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
  if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
  {
#endif /* INCLUDE_xTaskGetSchedulerState */
  xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
  }
#endif /* INCLUDE_xTaskGetSchedulerState */
  /* USER CODE BEGIN SysTick_IRQn 1 */
 
  /* USER CODE END SysTick_IRQn 1 */
}

Which one is the correct implementation? Do I lack a configuration in STM32CubeMX ?

It's strange that the error arise when I include the trcRecorder.h file.

Thank you for your help.

Best regards

1 ACCEPTED SOLUTION

Accepted Solutions
EXUE.2
ST Employee

the SysTick_Handler() is the interrupt handler of the system tick, it is set to trigger per 1ms as default when configure system clock, and it it have not any reference to timer.

if there have double definition of SysTick_Handler(), you should merge these functions to one function based your requirement(only keep the operations which you need to do in system tick handler).

View solution in original post

6 REPLIES 6
Pavel A.
Evangelist III

I don't have MP1 (yet) but normally the systick is owned either by a RTOS or by ST HAL.

(it is possible to do something different, but those who do that don't ask such questions 😉

When Cube generates a project with RTOS, and the HAL timer is the systick, it prompts to select a different timer for the HAL.

Ok, so I think I made a mistake because I did not define a timer in Cube. But I know that when I tried to define the timer as systick Cube prompted me to select another one. I though why bother if it works without me stting anything.

Maybe the problem is because I did not set a timer.

In the meantime to resolve the problem I commented out the implementation in stm32mp1xx_it.c and just added HAL_IncTick() call in the cmsis_os2.c and it seems to work.

EXUE.2
ST Employee

the SysTick_Handler() is the interrupt handler of the system tick, it is set to trigger per 1ms as default when configure system clock, and it it have not any reference to timer.

if there have double definition of SysTick_Handler(), you should merge these functions to one function based your requirement(only keep the operations which you need to do in system tick handler).

Thank you, yes that's what I did finally. Do you think that the fact I did not set a timer in CubeMX may create a problem ?

I don't think there has a problem if you don't set a timer, because the system tick is count from system clock, and is independent of timer.

Wrong. FreeRTOS sets the SysTick to the lowest priority. Many HAL functions, which are supposed to be called from interrupts, are infested with delays and timeouts based on HAL tick. Because of this, the HAL tick interrupt must be set to a higher priority than other interrupts, from which HAL functions are called. Not only a blocking code in interrupts is a stupid design, but it's interrupt priority requirements also conflict with FreeRTOS SysTick requirements.

Edited by moderation team to adhere to community guidelines.