Skip to main content
Katzenberger.Michael
Associate III
January 18, 2017
Question

How to check at runtime if a debugger is connected ?

Posted on January 18, 2017 at 19:24

Hi all !

I would like to know if there is a possibility to check at runtime if a debugger is connected to the STM32.

I have to distinguish between two use cases in software:

  • application connected to a debugger via 4 pin header (SWD and power 3.3V / GND)  -> no battery protection needed
  • appliction is running in normal operation state with connected battery - battery protection (to greater than 3.3V) needed

Any help/hints are appreciated - thanks !

Best regards,

Michael.

#check-debugger-connected-programmatically
    This topic has been closed for replies.

    7 replies

    waclawek.jan
    Super User
    January 18, 2017
    Posted on January 18, 2017 at 19:34

     
    Tesla DeLorean
    Guru
    January 18, 2017
    Posted on January 18, 2017 at 19:46

    I have this for my SWV trace, suggest you look at ITM and SCB registers (not Cortex-M0)

    if (*SCB_DHCSR & 1) // Debugger Enabled

    http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/CEGCJAHJ.html

     

    //****************************************************************************

    static int Debug_ITMDebug = 0;

    //****************************************************************************

    void Debug_ITMDebugEnable(void)

    {

    volatile unsigned int *ITM_TER = (volatile unsigned int *)0xE0000E00;

    volatile unsigned int *ITM_TCR = (volatile unsigned int *)0xE0000E80;

    volatile unsigned int *SCB_DHCSR = (volatile unsigned int *)0xE000EDF0;

    volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC;

    *((u32 *)0xE0042004) |= 0x27;

    printf('%08X %08X %08X %08X\n', *ITM_TCR, *ITM_TER

    , *SCB_DEMCR, *SCB_DHCSR

    );

    if ((*SCB_DHCSR & 1) && (*ITM_TER & 1)) // Enabled?

    Debug_ITMDebug = 1;

    }

    //****************************************************************************

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Katzenberger.Michael
    Associate III
    January 18, 2017
    Posted on January 18, 2017 at 21:10

    Thanks for pointing me into the right direction !

    I have this for my SWV trace, suggest you look at ITM and SCB registers

    (not Cortex-M0)

    Unfortunately the target processor is a STM32F072 (Cortex M0) and the detection is not working.

    The ARM documentation for Cortex M0 lists the DHCSR register:

    http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/CEGCJAHJ.html

     

    but there is no detailed description about the bit definitions or the address of the register ...

    Also the CMSIS register header file shows a lack of the CoreDebug_BASE register

    0690X000006064wQAA.png

    Is this feature simply not available for a M0 device ???

    Tesla DeLorean
    Guru
    January 18, 2017
    Posted on January 18, 2017 at 21:33

    >>

    Is this feature simply not available for a M0 device ???

    They dropped a lot of functionality out, which I've always felt is a step backward, which is why I don't have much time for the M0.

    Look at the DBGMCU registers, and the clocks in the AHB/APB enabled at ResetHandler... because the debugger has likely tweaked things to suit its needs.

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