Error: multiple definition of `SysTick_Handler' compiling truestudio IDE

563 Views Asked by At

Please wish to request for help. Trying to use STM32F1 syst_tick interrupt. I am using Atollic truestudio 9.3.0.

I have c++ file (tasks.cpp), i declared the interrupts handler in this file and hoping it will overide the default handler since default was has attribute .weak in the startup file.

But funny as it seems, when i compile, i get error: "multiple definition of `SysTick_Handler" this is how i declared it.

extern "C"void SysTick_Handler(void)
{
  timeElapsed++;
}

Other interrupts handlers for TIM1, 2,3 ,4 were declared in that same file and they working Ok but syst_tick is NOT. The question, why?

2

There are 2 best solutions below

0
0___________ On

SysTick_Handler is defined in STM files. If you use HAL do not define it yourself. If you want to get the counter value simply use HAL function HAL_GetTick(); and if you want to tun some of your code in the handler define the callback function. The definition is located in the ..._it.c file in your project.

1
avong On

For the issue I earlier posted, what later worked for me was to edit the default file stm32103f10xx_it.c.

On the sysTick handler, I added:

void __attribute__((weak))SysTick_Handler( )
{
}

Now, anywhere in my C++ project, I can implement the SysTick handler this way:

extern "C" { 
    void SysTick_Handler( )
    { 
    
    } 
};

This now will surely override the default handler at compile time.

Notes:

  1. This issue is common to only default interrupt handler.
  2. I only tested in TrueStudio IDE; I am not sure the behavior in CUBE IDE.