cancel
Showing results for 
Search instead for 
Did you mean: 

How to set SWD pins as GPIO pins in STM32H743ZI ?

PREDATOR
Associate II

Want to use SWD pins as GPIO pins.

6 REPLIES 6
berendi
Principal

Set bits 26-29 in GPIOA->MODER to the required mode (input/output).

E.g. to set PA13 as input and PA14 as output:

GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODE13|GPIO_MODER_MODE14))
    | GPIO_MODER_MODE14_0;

ST-Link debugging will of course not work afterwards. You'd need a way to connect under reset, activate the internal bootloader, or have a user bootloader to change the firmware.

PREDATOR
Associate II

I want to toggle from SWD to GPIO or GPIO to SWD in run time whenever i wanted to,so please tell me how to reverse swd pins from GPIO to SWD.

You can put it back to alternate mode, as described in the description of the GPIO MODER register in the reference manual, or just examine the original contents of bits 26 to 29, and put them back.

Of course if you change pullup/pulldown or speed settings, you have to restore them as well.

PREDATOR
Associate II

please give me a code to just change swd to gpio and code to reverse it.

Sure. If you pay us $$$. We're just volunteers here...

No seriously, you'll be much better off if you put in the effort and try to understand the Reference Manual for your stm32. Then you'll be able to answer this and many other questions yourself without having to wait for us to respond. And anyway, sometimes we make mistakes; unless *you* understand what you're doing, you won't be able to debug what's going wrong and work out how to fix it - without going back to us, whereupon we'll ask you to try various things...

And anyway, you haven't told us which programming language you're using (we assume C / C++, but we don't know). Without knowing that, we can't get the syntax right for you.

Also you should tell us which development environment you're using. I suspect that many debuggers and integrated-debugging-environments won't like to be disconnected / reconnected on-the-fly. My one has a menu item to attempt to reconnect the debugging interface, but doing so often results in the processor being reset.

PREDATOR
Associate II

I'm using SW4STM32 and CUBEMX for generation and development of codes , Actually i want to disable j-tag to protect the data in flash from intruders , but don't want to enable read out protection level 2 , i want to program flash only via inbuilt bootloader ,i already heard that read out protection level 1 can easily be hacked.