2
\$\begingroup\$

As in the topic: Can i connect something else to programming pins in STM32 (SWD)? For example a single LED with current limiting resistor connected to SWDIO and SWCLK pins. Will this load affect programming via this interface (SWD)? Should I use a buffer?

\$\endgroup\$
  • 1
    \$\begingroup\$ Yes you can, and yes, it might. Building a buffer for this sort of stuff is often trickier than it seems going in. \$\endgroup\$ – Scott Seidman Jun 19 '17 at 21:35
  • \$\begingroup\$ Pretty much any modern CMOS gate would be suitable as a buffer as far as input considerations are concerned; it's more a question of what can drive the desired LED or whatever. \$\endgroup\$ – Chris Stratton Jun 20 '17 at 6:22
6
\$\begingroup\$

Yes, you can use STM32 SWD pins as GPIO, and yes, you need to think about the impact of doing so on the SWD functionality.

Likely you want anything else driven by those lines to be behind a buffer with a high impedance input, and you want anything that could drive those lines to be behind a specific enable.

But there's also a risk in re-purposing those lines, especially as GPIO output. If you do so, you will not be able to connect an SWD probe to the running system.

With a full capability SWD adapter, you should be able to perform a coordinated "connect under reset" where the CPU core is reset and the SWD connection is used to suspend operation before the program can re-purpose the pins and disable SWD. However, this can be difficult with some setups.

So generally, if you are going to re-purpose the pins, it's best for a program to provide a second or two of delay upon reset before doing so.

You probably also want to make doing so at all dependent on a macro definition, perhaps one passed on the compiler command line. That way, if you decide you want to use a breakpoint debugger, you can build the code with alternate settings that do not re-purpose the SWD pins (maybe something like arm-non-eabi-gcc -DNO_REPURPOSE_SWD), and so leave them operating in SWD mode to permit the debugger to function.

And of course whatever you connect to those pins needs to not problematically mis-operate if it sees SWD traffic rather than the intended signals. So things like motor drives are a very bad idea; but status LEDs, or serial advisory message outputs might be okay.

\$\endgroup\$
  • \$\begingroup\$ Thank you for answer . That's actually an good idea to disable part of code that is using those pins when debugging MCU. Later after development these pins can be used as standard GPIO for less important things. But now i think that it is better to buy MCU that has a little more pins (they are not that expensive) so we don't have to use any buffers etc. \$\endgroup\$ – ByTechLab Jun 20 '17 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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