Skip to main content
dbgarasiya
Senior
February 18, 2020
Solved

can we use debug pins as normal gpio

  • February 18, 2020
  • 2 replies
  • 1440 views

hello

i want to use debug pins as normal gpio pins , is it possible or not?

and if possible then how?

This topic has been closed for replies.
Best answer by Danish1

The short answer is yes you can.

As to how, at the lowest level (see the Reference Manual), those pins are internally routed to debug (rather than GPIO) by the MODE being set to alternate function i.e. the appropriate bits in GPIOx->MODER are 0b10; you'd want those bits to be 00 for digital input, 01 for output (or 11 for analog).

But there are complications.

  1. How do you write your code? Using stm32-Cube? LL wrappers? Some other software wrappers? Tell us what you use and some of us (probably not me) can tell you how to select this for that particular environment.
  2. How do you load your code into your stm32? I use the debug pins - so using them for anything else could cause problems
  3. How do you debug your code? I use the debug pins - see 2

Hope this helps; expand on point 1 and we might be able to help further.

Danish

2 replies

Danish1
Danish1Best answer
Lead III
February 18, 2020

The short answer is yes you can.

As to how, at the lowest level (see the Reference Manual), those pins are internally routed to debug (rather than GPIO) by the MODE being set to alternate function i.e. the appropriate bits in GPIOx->MODER are 0b10; you'd want those bits to be 00 for digital input, 01 for output (or 11 for analog).

But there are complications.

  1. How do you write your code? Using stm32-Cube? LL wrappers? Some other software wrappers? Tell us what you use and some of us (probably not me) can tell you how to select this for that particular environment.
  2. How do you load your code into your stm32? I use the debug pins - so using them for anything else could cause problems
  3. How do you debug your code? I use the debug pins - see 2

Hope this helps; expand on point 1 and we might be able to help further.

Danish

berendi
Principal
February 18, 2020

You can use them as any other GPIO pin, set them to GPIO input or output mode by changing bits 10-13 in GPIOA->MODER, writing to GPIOA->BSRR or GPIOA->ODR, reading from GPIOA->IDR.

Of course the debugging interface is then no longer available to ST-Link.

To flash a new firmware, you can use the internal bootloader (see AN2606), have ST-Link connect under reset (not all ST-Link clones can do that), assert reset when starting the flashing process, or implement your own bootloader.