cancel
Showing results for 
Search instead for 
Did you mean: 

Counter? Nucleo L476RG

SWenn.1
Senior III

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;

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

8 REPLIES 8

> 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
Guru

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".

> 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

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

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
Senior III

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

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
Senior III

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

Thanks to all for the help​