cancel
Showing results for 
Search instead for 
Did you mean: 

How to sense JTAG/SWD connected?

MSipo
Senior II

How could I in code sense that something is connected to the JTAG/SWD connector?

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Practically, like this on Cortex M7:

bool is_debugger_enabled()
{
  // NOTE: After disconnecting debugger, do power cycle because
  // software reset does not seem to clear DHCSR.C_DEBUGEN!
  // DHCSR and debugger behavior are described in ARM v7-M Architecture Reference Manual
  return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk); // bit 0: DHCSR.C_DEBUGEN
}
 

View solution in original post

1 REPLY 1
Pavel A.
Evangelist III

Practically, like this on Cortex M7:

bool is_debugger_enabled()
{
  // NOTE: After disconnecting debugger, do power cycle because
  // software reset does not seem to clear DHCSR.C_DEBUGEN!
  // DHCSR and debugger behavior are described in ARM v7-M Architecture Reference Manual
  return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk); // bit 0: DHCSR.C_DEBUGEN
}