Skip to main content
Senior
November 20, 2024
Solved

Using SWD pins as GPIO

Hi,

at the moment on the STM32U5G9 we have the SWD pins (SWDIO and SWCLK) set to DEBUG, but we would like to also use them as GPIO after programming.

 

How do we switch them to GPIO at runtime?

 

Thank you

 

This topic has been closed for replies.
STOne-32
STOne-32Best answer
ST Technical Moderator
November 23, 2024

Dear @Ricko ,

 

You can by software anytime at your application change the GPIOA_MODER to either Input or Output as below

IMG_0511.jpeg

 

IMG_0510.jpeg

then  also  to remove or keep the internal pull-up/down resistors .  Routing these signals also is important at PCB  as they share with Debug connector or test points .

hope it helps you,

STOne-32

4 replies

STOne-32
STOne-32Best answer
ST Technical Moderator
November 23, 2024

Dear @Ricko ,

 

You can by software anytime at your application change the GPIOA_MODER to either Input or Output as below

IMG_0511.jpeg

 

IMG_0510.jpeg

then  also  to remove or keep the internal pull-up/down resistors .  Routing these signals also is important at PCB  as they share with Debug connector or test points .

hope it helps you,

STOne-32

MM..1
Super User
November 23, 2024

You can use normal init as for any other pins, but on moment init is executed, debuger lost connection.

Andrew Neil
Super User
November 23, 2024

@Ricko wrote:

we would like to also use them as GPIO after programming.


I would strongly advise against doing that!

as @MM..1 said, that means you will have no debug access.

If you must, then be sure to include access to NRST in your debug connector - otherwise you won't even be able to connect for programming.

Also, put in a time delay after startup before you re-purpose the pins - to give a chance to connect.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
RickoAuthor
Senior
November 23, 2024

Thank you all ! :)

Good point about the NRST. I do have it connected already because I thought you always need it for programming.