1
\$\begingroup\$

We have STM32G0 in one of our projects. We have limited pins on the PCB connector. We need to use 2 connector pins as I2C and SWD same time, to do that we think of connecting the one connector pin to two STM32 pins(SWDIO, I2CSDA for example). We want to use SWD while programming and after the programming, we want to use I2C as the normal state.

Is it possible to program STM32 with SWD and SWCLK without using RST pin and set SWD pins high z state after programming?

  1. We are wondering if we can use SWDIO and SWCLK pins as GPIO(High z) after programming?
  2. Can we re-program with SWD after setting high z?
  3. Do we have to use RST pin while programming with SWD?
  4. Do we have to use the RST pin while re-programming STM32 with high z SWD pins?
\$\endgroup\$
1
  • 1
    \$\begingroup\$ As an embedded developer - only do this as absolute last resort. It's a major pain to debug a device which reprograms the SWD pins. At least when it comes to development units. \$\endgroup\$
    – jaskij
    Commented Aug 22, 2022 at 19:50

2 Answers 2

1
\$\begingroup\$

We are wondering if we can use SWDIO and SWCLK pins as GPIO(High z) after programming?

Yes.

The Reference manual describes how to disable the SWD port and configure the pins for GPIO usage.

See 29.3.2 on page 967:
enter image description here

And 6.3.2 on page 175: enter image description here

Can we re-program with SWD after setting high z?

Yes.

There is actually not much magic happening here. You just need to know that on reset (SYSRESETn/PORESETn) the SWD function is automatically assigned. This ensures that the MCU can be reprogrammed at a later point. And during init you can configure these pins for alternate functions, which will disable the debugging funcion.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Regarding your last last paragraph - if you program the MCU once, it will have reconfigured the pins. So you need a reset (I forgot whether POR or SYS) to actually reset the pins to SWD mode. If they are not in SWD mode you can not start programming. \$\endgroup\$
    – jaskij
    Commented Aug 22, 2022 at 19:49
  • \$\begingroup\$ Both POR and SYSRST sets the pins to SWD mode. The NRST pin is used to issue a SYSRST. \$\endgroup\$
    – Velvet
    Commented Aug 22, 2022 at 19:54
  • 1
    \$\begingroup\$ True, and in cases like this NRST is held during programming. My point is that your last paragraph reads more like the reset is not needed - which is untrue. \$\endgroup\$
    – jaskij
    Commented Aug 22, 2022 at 19:56
  • \$\begingroup\$ Thanks for your input. I'll clarify that paragraph. \$\endgroup\$
    – Velvet
    Commented Aug 22, 2022 at 19:58
  • 1
    \$\begingroup\$ "Do we have to use RST pin while programming with SWD? Yes. The debugger uses the NRST pin to issue a SYSRESET." That is not true, if your SWD pins are not configured as a different function (i.e. not programmed chip), the programmer can usually reset the device with a software reset and program the device without using the NRST pin. It often helps having NRST connected, as it's more reliable, but it's not needed. \$\endgroup\$
    – Arsenal
    Commented Aug 23, 2022 at 13:10
0
\$\begingroup\$

This is found in the datasheets and manuals.

After reset the certain pins default to SWD/JTAG to allow a debug probe access to the micro.

At an appropriate time or based on a decision the SWD/JTAG pins can be configured to operate as GPIO. (Not always true).

Read the datasheet/manual

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.