cancel
Showing results for 
Search instead for 
Did you mean: 

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

Katzenberger.Michael
Associate III

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.

6 REPLIES 6
TDK
Guru

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
Principal III

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.
Evangelist III

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

prain
Senior III

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

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.

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