Showing results for 
Search instead for 
Did you mean: 

Reuse SWD Pins on STM32F0


I would like to place a user button on PA13 (SWDIO) and PA14 (SWCLK) pins. Reading through the datasheet I find:

  • PA13 (SWDIO) has an alternate function as IR_OUT
  • PA14 (SWCLK) has an alternate function of USART1_TX or USART2_TX
  • Both pins are listed as FT (5V tolerant I/O)
  • Both pins have Note 7 which says:
    • After reset, these pins are configured as SWDIO and SWCLK alternate functions, and the internal pull-up on SWDIO pin and internal pull-down on SWCLK pin are activated.

I’m thinking that this means that we can use both of these pins for the user interface. I also read in this document that you can regain SWD mode on reconfigured SWD pins if you connect during reset which makes sense to me. We'll want to be able to program our board via SWD so will we be able to do that if our program redefines these pins to GPIO inputs?

I’m thinking that if I use these pins for user input I may need to connect the button to GND (when pushed) for the SWDIO pin but connect the button on SWCLK to Vcc (when pushed) since that will have an internal pull-down on it.

Has anyone successfully done this?




If one pulls BOOT0 High, your code won't run at reset, and the pins will operate normally.

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

The internal pulldown in SWCLK is controlled from the respective GPIO_PUPDR register, so that can be redefined at runtime, too. In other words, you can have both pushbuttons connected to ground.

Using BOOT0 is one option, but you can also simply connect NRST to SWD interface (i.e. have 4 wires, SWDIO, SWCLK, GND and NRST) and then use the "connect under reset" option of the debugging/programming software when debugging/programming.

For debugging it's abit of a pain, as for debugging sessions you need to remove the GPIO functionality and have some replacement for them (I pester the HW guy to connect only rarely used buttons or, better, LEDs, to these two pins).



So I do have BOOT0 available. I'm actually designing a board that will test my production board and was planning on using BOOT0 to make the production board run the bootloader and then program the production board over UART. If I'm understanding you correctly when BOOT0 is high on boot up this also puts PA13/PA14 pins into SWD mode?

So it sounds like it's really a concern for debugging sessions since I also already do have NRST available and have used the "connect under reset" with the STM32 ST-LINK Utility. I was thinking of using these pins for the user interface on the tester to move through a menu on an I2C LCD so maybe this won't be a real issue if we do like you say and only implement the buttons after everything else is known to be working.