EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: blueskull on April 15, 2016, 02:51:05 am

Title: [Solved] STM32 debugging if SWD is used as GPIO
Post by: blueskull on April 15, 2016, 02:51:05 am
I'm designing a custom PCB incorporating an STM32F070. I do not have to do this, but I am just curious if I released PA13 and PA14 from SWD controller, how do I program the chip?
Can the chip be programmed under reset conditions? Or do I have to pull BOOT0 up to force my user program from being executed?
Title: Re: STM32 debugging if SWD is used as GPIO
Post by: ade on April 15, 2016, 03:18:08 am
Yes hence a typical SWD connector will have a reset line in addition to clock and data (plus power and ground).  Or you can use an alternative bootloader (e.g., via UART).
Title: Re: STM32 debugging if SWD is used as GPIO
Post by: ade on April 15, 2016, 03:36:06 am
Yes those five... reset is optional but useful for the scenario you've described.

SWO is the other common pin, useful for real-time tracing (via Serial Wire Viewer) if your IDE supports it and you can spare the pin.  E.g., the IDE variable "watch" function works over SWO... you can also stream your own data using SWO I believe.
Title: Re: STM32 debugging if SWD is used as GPIO
Post by: ade on April 15, 2016, 05:56:18 am
Ah, I believe you're right.  Coincidentally I just got a whole bunch of STM32F070s delivered to me (box still unopened), TSSOP-20 package... maybe I'll make a ghetto board this weekend to get more familiar with this part.
Title: Re: STM32 debugging if SWD is used as GPIO
Post by: Brutte on April 15, 2016, 08:23:08 am
SWO is the other common pin, useful for real-time tracing
Tinies do not have SWO.
Also target voltage is not really necessary if the target is powered from some external supply. The nRESET line is not needed if you have a reset button on-board as you can connect to a uC that is kept under reset. Alternatively you can insert a delay at power-up so that the SWD pins are in their default state for a fraction of a second - this is enough for a debugger to overtake control and halt the core before it executes the GPIO reconfiguration.
Title: Re: [Solved] STM32 debugging if SWD is used as GPIO
Post by: Jeroen3 on April 15, 2016, 08:41:55 am
I think some programmers even use the target voltage for their output buffers to perform level shifting.
Title: Re: STM32 debugging if SWD is used as GPIO
Post by: Brutte on April 15, 2016, 08:49:01 am
I will include test pads on PCB for BOOT0 and nRST.
The BOOT0 is only for pointing the uC on where to start from when it has no debugger connected. When the debugger is connected then you can keep the uC under reset as long as you want to and start from where you want to, not necessarily from where boot pins indicate.
Title: Re: [Solved] STM32 debugging if SWD is used as GPIO
Post by: bingo600 on April 15, 2016, 01:44:56 pm
I have used a design where there was a 500ms boot delay , before switching (disabling) the jtag-pins, and reuse them for io.

Then there was no issue "activating jtag" before it got disabled.

/Bingo
Title: Re: [Solved] STM32 debugging if SWD is used as GPIO
Post by: ade on April 15, 2016, 02:52:40 pm
It's a matter of convenience I think.  By having NRST, programming can happen anytime without needing to first plug/unplug power or manually pressing the reset button and get the timing right.  When you're coding + debugging + flashing all day long, every day, each additional step gets really annoying.

For a production board the answer might be different...
Title: Re: [Solved] STM32 debugging if SWD is used as GPIO
Post by: mikerj on April 15, 2016, 03:36:24 pm
I had this problem on a product using an STM32F103.  Switching the SWD pins into GPIO via the firmware disconnected the debugger, so I had to make the firmware check if a debugger was attached before changing the pin functions.  I don't know if this is required with the STM32F070 however.
Title: Re: [Solved] STM32 debugging if SWD is used as GPIO
Post by: Brutte on April 15, 2016, 05:35:55 pm
For a production board the answer might be different...
Definitely, I would not do a development on TSSOP-20.