0

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?

avong
  • 21
  • 4
  • Do you use a framework like STM32Cube (HAL) or FreeRTOS? Maybe the framework uses SysTick timer itself. I'm not familiar with HAL, but if I remember correctly, it has an option to choose its base timer, which is by default SysTick. – Tagli Jan 29 '22 at 11:33
  • i dont use any of those you mentioned (STM32Cube (HAL) or FreeRTOS). i use atollic truestudio 9.3.0. i just discovered, mere wrapping like this extern "C" SysTick_Handler(void); does not help in my case. i found, i had to edit the stm32f1xx_it.c file like this. void __attribute__((weak))SysTick_Handler(void); this one is OK, no compile error and interrupt firing – avong Jan 29 '22 at 13:05
  • BTW, you can add answers to your own questions. Doing so may be helpful to other people. – Tagli Jan 29 '22 at 14:27

2 Answers2

1

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.
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
avong
  • 21
  • 4
0

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.

0___________
  • 60,014
  • 4
  • 34
  • 74