Skip to main content
Fnx_QT
Associate II
November 3, 2022
Solved

multiple definition of `SysTick_Handler'

  • November 3, 2022
  • 2 replies
  • 6480 views

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

This topic has been closed for replies.
Best answer by EXUE.2

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).

2 replies

Pavel A.
Super User
November 3, 2022

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.

Fnx_QT
Fnx_QTAuthor
Associate II
November 4, 2022

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
EXUE.2Best answer
ST Employee
November 4, 2022

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).

Fnx_QT
Fnx_QTAuthor
Associate II
November 4, 2022

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 ?

EXUE.2
ST Employee
November 7, 2022

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.