Correct syntax to directly read/write a timer register?

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
AndrewBCN
Posts: 105
Joined: Sun Apr 25, 2021 3:50 pm
Answers: 1
Location: Strasbourg, France

Correct syntax to directly read/write a timer register?

Post 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.
by fpiSTM » Mon Apr 26, 2021 7:43 am
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
Go to full post
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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
AndrewBCN
Posts: 105
Joined: Sun Apr 25, 2021 3:50 pm
Answers: 1
Location: Strasbourg, France

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

Post by AndrewBCN »

Perfect, thank you very much!
Post Reply

Return to “General discussion”