STLINK debugging issue in stop mode (STM32U031C8U6)
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:
- enable in the STM32CubeIDE the "Debug in low power modes" option (Debug Configuration, Debugger tab)
- call the HAL_DBGMCU_EnableDBGStopMode() function at the begin of application.
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:
- Enables the TIMOUT function
- Enables the LPTIM1 peripheral
- Enables the Autoreload match interrupt
- Sets the CCR1 compare period to approximately 2 ms: (2 << 5) / 32768
- Sets the ARR autoreload period to approximately 10 ms: (10 << 5) / 32768
At this point, we enter the superloop, which simply:
- Sets the desired period based on the button state. The BSP_LPTIM_SetTimeout() function:
- Does nothing if the requested period is equal to the current one; otherwise,
- Enables the Compare match interrupt if the requested period is 2 ms and disables it if it is 10 ms.
- Start the timer in ONESHOT mode (BSP_LPTIM_Start function()).
- Enter stop mode.
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:
- when the button is pressed, the PROBE pin toggles approximately every 4 ms.
- when the button is released, the PROBE pin never toggles.
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.
