AnsweredAssumed Answered

How to enable a timer using cube hal?

Question asked by Joe on Nov 26, 2015
Latest reply on Jan 1, 2016 by h.sven
Working with:
       
  • Stm32F401C-Disco
  •    
  • STM32Cube_FW_F4_V1.9.0
  •    
  • CubeMX 4.11.0
  •    
  • SW4STM32
In my project, I need to setup a timer (e.g. TIM3) directly in hand written code.
I struggled around on the question, what is the official way to do that using cube hal api.

I find things like:
__TIM3_CLK_ENABLE();
well, it works, but 3 things bother me here (yep, most might cosmetics, but because of my company guidelines the code must be as clean as possible):
       
  • The macro is located in stm32_hal_legacy.h. As I'm working on a fresh new project, I don't want to use legacy stuff.
  •    
  • The double underscore prefix of the macro sounds like private stuff rather than api for application code, isn't it?
  •    
  • Using SW4STM32 with -Wall -Wextra in C++ source give warnings: "conversion to void will not access object of type 'volatile uint32_t {aka volatile long unsigned int}'"
I'd checked generated code when configuring the timer using CubeMX and find out that the code generator also uses this legacy call `__TIM3_CLK_ENABLE()`.

Regarding the gcc warning, I find out the problem is located to the UNUSED macro in stm32f4xx_hal_def.h:
#define UNUSED(x) ((void)(x))
The problem became solved when I just remove two brackets like:
#define UNUSED(x) ((void)x)
It seems that this is more portable than the current macro.

So could you please:
       
  • State out how to enable the timer using cube hal (without legacy macros and hopefully without underscore prefixing).
  •    
  • Change the `#define UNUSED` in stm32f4xx_hal_def.h

Thanks in advance,
    Joe

Outcomes