There are two common big problems when playing with embedded software. How to get that to the chip and how to debug why nothing is happening.
Many modern chips include a bootloader embedded in the ROM code that can program the firmware to an empty flash. But not always, or maybe the pins used by the bootloader logic are used for something else. Still you need something else for the debugging.
JTAG solves these problems. Or SWD in this case. SWD is a 2-pin electrical alternative JTAG interface with the same JTAG protocol on top. To benefit from that you need SWD support from the target chip and you need a dongle that goes between the chip and you development PC.
The cheapest way to get an SWD dongle is to buy an STM32 F1 discovery (10â‚¬ from Digikey) and replace the ST-Link firmware in it with a modified Versaloon firmware. The downside is that you need Windows and an another Discovery for modifying the first one..
We started with the instructions in http://takenapart.com/?p=82 and here’s how we did it:
- Get the Versaloon firmware modified for STM32.
- Install the ST-Link utility for Windows and the USB driver.
- Make sure you have an F1 Discovery and Fx Discovery (for flashing the target. We tried first with F1 but eventually succeeded with F4.).
- Solder wires to SB6 and SB10. You can try just holding the wires in the vias just below the “A” in “DEFAULT” but the connection may not be sufficient for the programming.
- Connect the SB6 to SWD pin 2 in the F4 Discovery.
- Connect the SB10 to SWD pin 4 in the F4 Discovery.
- Connect the GND and 5V from the F4 to F1.
- Remove CN3 jumpers from both Discovery boards.
- Connect an USB cable from Windows PC to F4 (you should see leds turning on on both Discovery boards).
- Start the ST-Link utility (HELPME: how to do this from Linux?)
- Choose Target -> Connect. This may connect and then disconnect if the connections to SB6 and SB10 pads are bad.
- Choose Target -> Program & Verify to program the firmware obtained in step one to the F1’s ST-Link F103. Disable the Read Out Protection when asked to. If the programming succeeds only partly, the connections to SB6 and SB10 pads are probably bad.
Now you have a Versaloon firmware running in the ST-Link part of the F1 Discovery. If you want to connect the SWD from ST-Link to the F100 on the same discovery, connect CN3 pin 1&4 and 2&3 but if you want to use the ST-Link as an SWD dongle with some other board, make sure to leave CN3 pins open.
Check the next post for using your new SWD dongle with OpenSWD for programming and debugging your STM32 chips.