Page 1 of 1

Correct syntax to directly read/write a timer register?

Posted: Mon Apr 26, 2021 4:43 am
by AndrewBCN
Hello,
I apologize for the basic question, but I have a doubt about the correct syntax to directly read / write a timer register.
Should I use, for example:

Code: Select all

TIMER2_BASE->PSC = 0x0000; // disable prescaler
or

Code: Select all

TIM2->PSC = 0x0000; // disable prescaler
Or are they equivalent? And if so, which one is recommended (I would prefer the second form, which is shorter)?

And also, do I need to include a specific .h file to directly access the timer registers? I am using STM32 Core release 2.0.0 and a STM32F411CE "Black Pill" board.

Re: Correct syntax to directly read/write a timer register?

Posted: Mon Apr 26, 2021 7:43 am
by fpiSTM
You can use both of them.

TIM2 is simply an alias to the TIM2_BASE (not TIMER2_BASE) defined by the CMSIS device drivers definitons.
You don't need any specific include file.

https://github.com/stm32duino/Arduino_C ... 1xe.h#L658
https://github.com/stm32duino/Arduino_C ... 1xe.h#L751

Re: Correct syntax to directly read/write a timer register?

Posted: Mon Apr 26, 2021 8:46 am
by AndrewBCN
Perfect, thank you very much!