Skip to main content
Marc1
Associate III
October 21, 2026
Question

STM32L052 random register reset

Hi there,

I’m using STM32L052 for PWM generation with TIM2.

TIM2->CR1 is initialized once at start of the program and never touched again during runtime:

TIM2->CR1 = 0x00000081;

Even though, in some random cases TIM2->CR1 switches back to 0. How can that happen? How can TIM2->CR1 accidentally switch back to 0? Is there a known issue? I really don’t know how to debug such an error. TIM2->CR1 is the only register that changes randomly.

Thanks in advance for your help!

 

3 replies

TDK
October 21, 2026

CR1 does not spontaneously change back to 0. If the clock is disabled, it may be read back as 0. Or if the chip is reset, it will have its reset value.

Instrument your code to find out where/when it gets changed. It’s possible a bad pointer or a stack overflow is causing the issue. Unfortunately, hardware watchpoints do not work on registers.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Marc1
Marc1Author
Associate III
October 21, 2026

Hi TDK,

Thank you for your response.

> If the clock is disabled, it may be read back as 0.
Clock is still running: APB1ENR = 0x98800001

> Or if the chip is reset, it will have its reset value.
Chip reset would also reset all other registers.

> It’s possible a bad pointer or a stack overflow is causing the issue.
This was my first thought and I’m still searching.

TIM2->CR1 is at address 0X4000 0000 and there is no register or RAM below.
Address range 0X2000 2000 - 0X3FFF FFFF is marked as “reserved”.

gbm
Super User
October 21, 2026

Check all the occurrences of TIM2 symbol in your code. I suspect some incorrect register assignment or DMA transfer setup.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice