October 6, 2019

Converting STM32 blue pill board into a stlink-v2 programmer

Filed under: Firmware — mosioX @ 2:12 pm

Couple weeks ago I needed to switch from a high cost ATMEL based ARM-cortex m3 micro-controller (Atmel SAM3X8E) to low cost one (STM32F103), and I found STM32 blue pill board.  During my development process, frankly saying, I love this board due to its simplicity, low cost and small foot print for rapid prototyping.  Also thanks for the YouTube channel GreatScott, there is a very useful comparison video for STM32 Blue Pill and Arduino Mini board. This is also very helpful to get introduction for using the STM32 blue pill board.

On the other hand, I am not a fan of using boot-loader during development cycle.  Especially if I needed to port an RTOS into a new platform where to debug context switching is crucial.  Also using break points is not possible with boot-loader. So I started to use my built-in SWD programmer which comes with STM32 Nucleo-F072RB board.  As you can image this board is a little bit bulky although you can break out its SWD section.  During my search for compact and low cost SWD programmers, I came up with these type of cheap programmers shown below.

Unfortunately these programmers are not only uses counterfeit chips, but also has wrong connection to the reset(RST) pin.  Simply it is impossible to use hardware reset with these programmers. I learnt this defect in a very harsh way, and I had to spend to much time to debug this debug equipment.  In order to utilize hardware reset function, I need to hack this programmer to rewire proper pin connection to the RST pin.

Anyway during my research I have analyzed STM32 Nucleo Board, and its on-board SWD programmer, and I saw it uses stm32f103 as a SWD controller.  This urged me to search how to use stm32f103 blue pill board as a SWD programmer (eventually I am not the smartest guy in the world who thinks if it is possible ;)) then I found these two links link1 and link2.

I made some improvements and created this circuit.  I added target voltage detection, status LEDs, and HW reset lines.  Let’s see the schematics.

and you can see actual prototype as below.  This programmer does not provide power to the target, so you need to provide extra power to the target.  Red wire has been designated to target voltage detection.

 

So far everything seems OK, but as you can imagine there is one important piece is missing.  That piece is the firmware for stm32f103 to enable SWD functionality.  During my search on the net, I could not find official firmware release of STM32 Nucleo board SWD interface firmware.  Then I found a older version of the SWD firmware from an unofficial source.  Please search STLinkV2.J16.S4.  Once you burn this image, you will need to update the image with the latest version.  For detailed instruction can be found at this link.

 

In this article I wanted to share development experience with stm32 programmers.  With this small hack I hope you would be able to create your own low cost st-link v2 compatible SWD programmer.

Any type of feedback are welcome.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress