2025-08-06 2:02 AM
Hi all,
I'm having trouble debugging using STLINK when the STM32U031C8U6 microcontroller is in stop mode or running at a low frequency clock
I already tried to:
Issue #1
Attached is a minimal project that reproduces the problem I'm having using the low-power timer peripheral. I'd like to use it to exit stop mode every 2 ms or every 10 ms based on some conditions, which I've simulated here with the state of a push button.
The project works correctly if I use the STLINK debugger to flash the microcontroller and then disconnect it to run in standalone mode.
However, I experience an unexpected behavior when running it in debug mode with STLINK debugger.
The microcontroller runs at a 16 MHz HSI clock and the LPTIM1 peripheral uses an external 32.768 kHz crystal.
Looking at the main() function, you can see that after initialization, it waits for a button press and then sets the two periods mentioned above in LPTIM1.
The BSP_LPTIM_Setup() function performs the following operations:
At this point, we enter the superloop, which simply:
The interrupt callbacks simply reset the counter and toggle the PROBE pin that I use for testing.
The behavior I get in standalone mode is as expected: depending on the state of the button, the micro is woken up every 2 ms by HAL_LPTIM_CompareMatchCallback() or every 10 ms by HAL_LPTIM_AutoReloadMatchCallback().
Instead, the behavior I see in debug is this:
Issue #2
If in the same project I change the ABH Prescaler from /1 to /256 to reduce the HCLK to 62.5 kHz, I have to reduce the STLINK frequency to 1000 kHz to be able to debug, and that's fine.
At this point I experience another unexpected behavior: the execution of the SystemClock_Config() function seems to be continually interrupted by the SysTick_Handler().
If I add a breakpoint anywhere in the main() function after SystemClock_Config() and start debugging, it never gets reached.
If I suspend the execution, I see that I'm still inside the SysTick_Handler().
Thanks in advance,
G.