Skip to main content
Katzenberger.Michael
Associate III
July 25, 2020
Question

How to detect the selected timer for "Timebase Source" during compile time ?

  • July 25, 2020
  • 6 replies
  • 3378 views

Hi !

I need to overwrite the "normally" weak defined generated function HAL_TIM_PeriodElapsedCallback().

But if a timer other than SysTick is used as Timebase Source (which is recommended when FreeRTOS is used) than STM32CubeMx is generating this function directly in main.c without the weak property.

Therefore I'm looking for a macro or definition which can be used at compile time to know which timer is used ...

 0693W000003BI1pQAG.png

Thanks !

Michael.

This topic has been closed for replies.

6 replies

TDK
July 26, 2020

I don't think that's something that gets put into a #define anywhere.

"If you feel a post has answered your question, please click ""Accept as Solution""."
KnarfB
Super User
July 26, 2020

I think the same. 2 ideas:

  1. In FreeRTOS there are hooks which you can implement. If you set configUSE_TICK_HOOK to 1 and implement vApplicationTickHook, you can do your stuff at every timer tick.
  2. Don't let STM32Cube generate that specific timebase source but init a periodic TIM of your own choice and add your own implementation of HAL_TIM_PeriodElapsedCallback HAL_InitTick HAL_SuspendTick and HAL_ResumeTick, easily copied from the generated stuff.
Pavel A.
July 26, 2020

For this I define "user constants" in Cube projects. They become defines in main.h.

Like #define USE_HAL_TIMER 6

Then in C file:

#if USE_HAL_TIMER == 6

….

#elif USE_HAL_TIMER == 1

...

#endif

> Don't let STM32Cube generate that specific timebase source but init a periodic TIM of your own choice and add your own implementation of HAL_TIM_PeriodElapsedCallback

A good idea for optimization; HAL_TIM_PeriodElapsedCallback is quite heavy. But IMHO you can only hack the TIM interrupt handler in stm32....it.c and let Cube generate initialization and whatever it wants. Linker will discard unused functions.

-- pa

Katzenberger.Michael
Associate III
July 27, 2020

Hi Pavel,

thanks for your feedback.

That's exactly the way I'm doing it currently. My hope was to find a macro to eliminate that error prone step.

prain
Visitor II
July 27, 2020

This setting can be found in .ioc file.​ Use a text editor to inspect the ioc file

Katzenberger.Michael
Associate III
July 27, 2020

That's true but this information must be provided to the gcc compiler somehow - too much effort writing a tool for this ...