Skip to main content
n2wx
Senior
April 8, 2020
Question

STM32H7 - How to tell if debugger is attached?

  • April 8, 2020
  • 2 replies
  • 3398 views

So I was handed code that breaks when debugging, but to fix the breakage breaks a power control on the board. Rev A only has this problem but Rev A is what I'm stuck with . Nice, right?

So I need a way to tell at run time whether the debugger is attached.

Does anyone have any idea how to accomplish this without changing the hardware?

This topic has been closed for replies.

2 replies

berendi
Principal
April 8, 2020

Read GPIOA->IDR a few times, if bits 13/14 are changing, then there is most probably a debugger doing its stuff. Even EXTI interrupts should work on it while a pin is in AF mode.

n2wx
n2wxAuthor
Senior
April 8, 2020

This sounds kind of contingent. How many reads do you think are needed for 99% (or some extremely reliable) confidence?

berendi
Principal
April 8, 2020

I would be extremely confident if I got 10 EXTI events within 1 ms on the SWCLK pin.

Tesla DeLorean
Guru
April 8, 2020

DBGMCU_IDC reads zero in Keil

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
n2wx
n2wxAuthor
Senior
April 8, 2020

I was wondering why this sounded familiar. Our old friend for checking the chips release level! Unfortunately I'm in TrueStudio and I'm in an enforced timeout due to an overtemperature but when it comes back I'm going to see if I can persuade it to expose its J-Link-attached status. In a more perfect world I wouldn't have to ask you folks for workarounds for stupid problems like the one im facing.

Pavel A.
April 9, 2020

Have your debug start script write a magic value to some memory address at startup.

Then you'll know if the debugger is present.

This is simpler than poking around, though adds dependency on debugger script.

-- pa