2017-12-13 08:32 AM - edited 2024-06-10 07:36 AM
Posted on December 13, 2017 at 17:32
In Cortex-M3, M4, etc, we can just check the DEBUGEN bit in DHCSR (the Debug Halting Control and Status Register)
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/CEGCJAHJ.html
But in Cortex-M0, that register is not accessible to the user code.
:(
So - is there any other way on an STM32L0 to detect when the debugger is connected?
#stm32l0 #debug
Solved! Go to Solution.
2017-12-13 01:06 PM
While I would not dare to question Clive One ...
SWDIO has a pullup on the STM32L0 side. The IDLE state of SWDIO is a logic 0. So one could simply read back SDWIO (in a loop with multiple samples). If there is a 0 detected, then a debugger is driving the line.
N.b. that this should detect the presence of a debugger, not necessarily whether it's active. So after detecting presence, one could use the __BKPT() idea to check whether it's active ....
2023-12-05 11:01 AM
Coming back to this, on an STM32F0, the RCC_APB2ENR_DBGMCUEN bit is set only when a debug session is active.
(not set when no debugger is connected, and also not set when a debugger is physically connected, but no debug session is active)
At least that's the case with STM32CubeIDE v1.13.0 and an ST-Link/V2 ...
2024-06-10 07:29 AM
For STM32H743 this worked for me
if(READ_BIT(DBGMCU->CR, DBGMCU_CR_DBG_CKD1EN))
{
// This Code here is only entered when Debugging is active
}
2024-06-10 07:38 AM
@ChrisAtWork wrote:For STM32H743
But that's not a Cortex-M0.
The point is that higher Cortex-Mx give access to DBGMCU status bits - I know that (see OP) - but that's not available on M0.