Skip to main content
Graduate II
November 20, 2024
Solved

Using SWD pins as GPIO

  • November 20, 2024
  • 3 replies
  • 1537 views

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.
    Best answer by STOne-32

    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

    3 replies

    STOne-32Answer
    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

    Graduate II
    November 23, 2024

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

    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.

    RickoAuthor
    Graduate II
    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.