Home > database >  STM32: is SWD enabled?
STM32: is SWD enabled?

Time:01-13

I use a STM32G431CB, where the SWD-Pins are "dual use" in ym PCB design. If I close two jumpers, both SWD-Pins can be used as GPIO Outputs, which will drive 2 LEDs. During Development, Test & Debug these two jumpers are open and the ST-Link Debugger is connected. This works fine so far.

The question is: is there any #define I could check for with "#ifdef" oder "#ifndef" if the SWD is enabled in the MCU setup or not? I went throuhg all the header files, but could not find a define (or something comparable) which I could use IMHO.

The Plan is to write some pieces of code like this:

#ifndef SWD_ENABLED
 DoSomethingWithTheLED_GPIO();
#endif

The effect should be: as long as I have enabled SWD (at compile time) the functions, that Write the LED GIPOs are ignored. When I disable SWD in the MCU setup, the LEDs should be written.

But I don't know which #SYMBOL I could check on.

CodePudding user response:

DoSomethingWithTheLED_GPIO();

In this function, you will have to configure pins to be used in the modes you need. Those pins are simple configured as debug pins after the boot.

The question is: is there any #define I could check for with "#ifdef" oder "#ifndef" if the SWD is enabled in the MCU setup or not?

No, there are no such defines. But you can easily check if the pin is in "debug" configuration by checking MODER & ARFL(H) registers

CodePudding user response:

Which way do you use to

... disable SWD in the MCU setup, ...

In my projects I use global project #define that is used both to change setup code (set SWD pins to desired mode) and enable/disable the code which uses those pins.

  • Related