cancel
Showing results for 
Search instead for 
Did you mean: 

How to mix CubeIDE code with register code for timers

HABIJ.1
Associate III

Hello,

I'm developping a software where some timers are totally configured through STM32CubeIDE and others totally configured through registers. I'm getting errors concerning the register configured timers. Here is an example :

../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:649:31: error: expected identifier or '(' before 'TIM_TypeDef'

I'm wondering if STM32CubeIDE code and register code is possible! Can someone help me?

Regards,

1 ACCEPTED SOLUTION

Accepted Solutions
HABIJ.1
Associate III

I finally succeeded updating the timer period through TIMx->ARR. The problem was a variable type incompatibility!

View solution in original post

7 REPLIES 7
TDK
Guru

There's no issue using registers alongside HAL. Technically, the file you're pointing to isn't even HAL, but a CMSIS header.

Your error might be caused by an errant define for one of the timer registers. Did you #define OR somewhere?

If you feel a post has answered your question, please click "Accept as Solution".
HABIJ.1
Associate III

Thank you for your reply. Well, I haven't defined anything in any file.

I tried different means to overcome the problem but always in the main.c file

First I tried to update the autoreload register with the instruction (from the MX_TIM2_INIT function):

htim3.Init.Period = rand();

and rand() is a function returning an random integer between 800 and 1800, but it didn't work because the autoreload register remained with the first value generated by rand() and didn't consider the following values generated by rand()

After I tried to initialize the timer with CubeIDE but updating the autoreload register with

TIM3->ARR = rand();

The solution seemed to work for a moment (like 30 sec) but then for an unknown reason the autoreload register diverged and contained the value 65536 whereas the rand() function returns values ranging from 800 to 1800. To overcome the problem I enabled the autoreload preload register, but it changed nothing

At last, I tried to totally configure the timer using registers alongside other timers using HAL. And it is at that moment that encountered errors like :

../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:649:31: error: expected identifier or '(' before 'TIM_TypeDef'

I verified and the definition of TIM3 in the stm32f103xb.h is the same as the one in the stm32f10x.h for the register configuration (with Keil for example) :

#define TIM3               ((TIM_TypeDef *)TIM3_BASE);

But I noticed that TIM3_BASE memory map is different in the two files. In stm32f103xb.h, it is

 #define TIM3_BASE            (APB1PERIPH_BASE + 0x00000400UL);

whereas in stm32f10x.h, it is

#define TIM3_BASE             (APB1PERIPH_BASE + 0x0400)

I wonder if those different memory maps may be the problem

Regards,

TDK
Guru

Are you including stm32f10x.h and stm32f103xb.h in the same project? That's not going to work if they both try to define TIM_TypeDef.

If you feel a post has answered your question, please click "Accept as Solution".
HABIJ.1
Associate III

No, I haven't included both in the same project. There is only the stm32f103xb.h file in my CubeIDE project. I only opened stm32f10x.h using Keil to inspect if the errors were caused by differences of definition of TIM3 in stm32f103xb.h and stm32f10x.h files .

The "stm32f103xb.h" file is unlikely to contain gross errors which prevent it from compiling, unless it's been modified. The issue probably lies elsewhere..
The definitions you've listed for TIM3_BASE are equivalent.
If you feel a post has answered your question, please click "Accept as Solution".

Well as you said earlier, maybe it is not possible mixing HAL and registers.

Thanks anyway for your help

HABIJ.1
Associate III

I finally succeeded updating the timer period through TIMx->ARR. The problem was a variable type incompatibility!