cancel
Showing results for 
Search instead for 
Did you mean: 

can we use debug pins as normal gpio

dbgarasiya
Senior II

hello

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

and if possible then how?

1 ACCEPTED SOLUTION

Accepted Solutions
Danish1
Lead II

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

View solution in original post

2 REPLIES 2
Danish1
Lead II

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

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.