Skip to main content
SWenn.1
Senior III
November 6, 2021
Solved

Counter? Nucleo L476RG

Can someone tell me when I use

uint16_t temp;
	temp = __HAL_TIM_GET_COUNTER(&htim2);

the above why temp doesn't equal the TIM2 CNT register in the debugger? I've also tried

temp = htim2.Instance->CNT;

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
November 6, 2021

This is a normal peripheral register bit.

0693W00000GWgMCQA1.pngMaybe there's some setting to set these bits from inside the debugger, I don't know what debugger are you using.

JW

8 replies

waclawek.jan
Super User
November 6, 2021

> the above why temp doesn't equal the TIM2 CNT register in the debugger?

TIM2 running? temp was read out from TIM2 in a different time than when debugger read out TIM2_CNT register.

JW

TDK
November 6, 2021

Timers continue to run when execution is paused in the debugger by default. You can adjust that behavior in the DBGMCU freeze register settings.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
November 6, 2021

> Timers continue to run when execution is paused in the debugger by default. You can adjust that behavior in the DBGMCU freeze register settings.

Even then, and even if you single-step, executing code which reads out TIMx_CNT may/will happen while the timer is running between steps, whereas the debugger reads it afterwards, so the values may/will differ.

JW

SWenn.1
SWenn.1Author
Senior III
November 6, 2021

being new to this tool suite can you point me to DBGMCU freeze settings location.....Somewhere under Properties- Run/Debug Settings?

waclawek.jan
waclawek.janBest answer
Super User
November 6, 2021

This is a normal peripheral register bit.

0693W00000GWgMCQA1.pngMaybe there's some setting to set these bits from inside the debugger, I don't know what debugger are you using.

JW

SWenn.1
SWenn.1Author
Senior III
November 6, 2021

Oh you are suggesting it is a bit in a register on the target? I thought it was a switch somewhere in the CubeMX IDE...

​

I am using ​a STLINK V3 SET

TDK
November 6, 2021
Yes, it is a bit within a register. Set it during startup of your program.
Note that you may still have a mismatch due to the registers being read at different times, but probably only a couple of counts. Debugging timers using single stepping through code is not ideal.
"If you feel a post has answered your question, please click ""Accept as Solution""."
SWenn.1
SWenn.1Author
Senior III
November 6, 2021

Got it:thumbs_up:...will give it a try...

​

Thanks to all for the help​