<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.paparazziuav.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=PeterKorsgaard</id>
	<title>PaparazziUAV - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.paparazziuav.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=PeterKorsgaard"/>
	<link rel="alternate" type="text/html" href="http://wiki.paparazziuav.org/wiki/Special:Contributions/PeterKorsgaard"/>
	<updated>2026-05-07T10:14:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>http://wiki.paparazziuav.org/w/index.php?title=STLink&amp;diff=21237</id>
		<title>STLink</title>
		<link rel="alternate" type="text/html" href="http://wiki.paparazziuav.org/w/index.php?title=STLink&amp;diff=21237"/>
		<updated>2016-06-06T07:09:12Z</updated>

		<summary type="html">&lt;p&gt;PeterKorsgaard: correct stlinkv2 clone programming header info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div style=&amp;quot;float: right; width: 20%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;categorytree style=&amp;quot;float:right; clear:right; margin-left:1ex; border: 1px solid gray; padding: 0.7ex;&amp;quot; mode=pages&amp;gt;Firmware Flashing&amp;lt;/categorytree&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;float: right; width: 60%&amp;quot;&amp;gt;&lt;br /&gt;
[[Image:St-link.jpg|right|450px]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Every STM discovery / eval board comes with a [http://www.st.com/web/catalog/tools/FM146/CL1984/SC724/SS1677/PF251168 ST-Link V2] on board, with one exception; the STM32VL version comes with a ST-Link V1.&lt;br /&gt;
&lt;br /&gt;
==SWD Header==&lt;br /&gt;
&lt;br /&gt;
[[Image:swd_header_discovery_board.png|250px|Pinout with Apogee connector]]&lt;br /&gt;
&lt;br /&gt;
==Install Software==&lt;br /&gt;
&lt;br /&gt;
The ''st-flash'' and ''st-util'' tools are needed, provied by [https://github.com/texane/stlink texane]&lt;br /&gt;
&lt;br /&gt;
Download and compile&lt;br /&gt;
 $ cd /opt&lt;br /&gt;
 $ git clone git://github.com/texane/stlink.git stlink&lt;br /&gt;
 $ cd stlink&lt;br /&gt;
 $ ./autogen.sh&lt;br /&gt;
 $ ./configure&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
Set enviroment variable&lt;br /&gt;
 $ exportline=&amp;quot;PATH=$PATH:/opt/stlink&amp;quot;&lt;br /&gt;
 $ if grep -Fxq &amp;quot;$exportline&amp;quot; ~/.profile; then echo nothing to do ; else echo $exportline &amp;gt;&amp;gt; ~/.profile; fi&lt;br /&gt;
 $ source ~/.profile&lt;br /&gt;
&lt;br /&gt;
Add udev rules &lt;br /&gt;
 $ sudo cp /opt/stlink/49-stlinkv*.rules /etc/udev/rules.d&lt;br /&gt;
 $ sudo udevadm control --reload-rules&lt;br /&gt;
&lt;br /&gt;
ST-LinkV1 requires a bit different treatment, read the [https://github.com/texane/stlink/blob/master/README Readme.txt]&lt;br /&gt;
&lt;br /&gt;
==Airframe.xml setup==&lt;br /&gt;
&lt;br /&gt;
Connect the ST-Link to the MCU.&lt;br /&gt;
If a complete STM32Fx-Discovery board is used, CN3 jumpers need to be set. To program a external MCU, remove CN3 jumpers and connect the external MCU with the SWD header.&lt;br /&gt;
&lt;br /&gt;
To use SWD via STLink as default:&amp;lt;br/&amp;gt;&lt;br /&gt;
Set '''FLASH_MODE=STLINK'''&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Update the ST-Link to blackmagic probe==&lt;br /&gt;
&lt;br /&gt;
The STM32F103 (STLink MCU) can be flashed with the blackmagic's firware.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Two STLinkV2 Method===&lt;br /&gt;
&lt;br /&gt;
Use one STLink to flash another&lt;br /&gt;
&lt;br /&gt;
Hardware Setup:&lt;br /&gt;
One STLinkV2 (connected via USB) is programming the other one. Change the 4 Solder jumpers on the bottom of the target STLinkV2 from &amp;quot;DEFAULT&amp;quot; to &amp;quot;REVERSED&amp;quot;.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Connections between the two STLinks&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;  cellspacing=&amp;quot;0&amp;quot; style=&amp;quot;text-align:center&amp;quot; cellpadding=&amp;quot;6&amp;quot;&lt;br /&gt;
|+'''Connections [Header-Pin]'''&lt;br /&gt;
!''Use''!!''From Programmer''!!''To Target''&lt;br /&gt;
|-&lt;br /&gt;
|5V||P2-5V||P2-5V&lt;br /&gt;
|-&lt;br /&gt;
|SWDIO||CN2-4||CN3-2&lt;br /&gt;
|-&lt;br /&gt;
|SWDCLK||CN2-2||CN3-3&lt;br /&gt;
|-&lt;br /&gt;
|GND||CN2-3||CN3-4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Download and build the Firmware&lt;br /&gt;
 git clone https://github.com/blacksphere/blackmagic&lt;br /&gt;
 cd blackmagic&lt;br /&gt;
 git submodule init&lt;br /&gt;
 git submodule update&lt;br /&gt;
 make&lt;br /&gt;
 cd src&lt;br /&gt;
 make clean&lt;br /&gt;
 make PROBE_HOST=stlink&lt;br /&gt;
&lt;br /&gt;
Remove the readout protection, erase and flash&lt;br /&gt;
 openocd -f interface/stlink-v2.cfg -f target/stm32f1x_stlink.cfg -c &amp;quot;init&amp;quot; -c &amp;quot;halt&amp;quot; -c &amp;quot;stm32f1x unlock 0&amp;quot; -c &amp;quot;shutdown&amp;quot;&lt;br /&gt;
 st-flash erase&lt;br /&gt;
 st-flash --reset write blackmagic.bin 0x8002000&lt;br /&gt;
 st-flash write blackmagic_dfu.bin 0x8000000&lt;br /&gt;
&lt;br /&gt;
====Documentation====&lt;br /&gt;
&lt;br /&gt;
[http://esden.net/2014/12/29/black-magic-discovery Black Magic Discovery from Esden] &amp;lt;-- This also describes how to remove the read out protection. &amp;lt;br/&amp;gt;&lt;br /&gt;
[http://embdev.net/articles/STM_Discovery_as_Black_Magic_Probe embdev.net page]&lt;br /&gt;
&lt;br /&gt;
===BMP Method===&lt;br /&gt;
&lt;br /&gt;
Use a BMP to flash a STLink&lt;br /&gt;
&lt;br /&gt;
Transfer the solder jumpers from &amp;quot;Default&amp;quot; to &amp;quot;Reversed&amp;quot; and build the firmware as descibed above.&amp;lt;br/&amp;gt;&lt;br /&gt;
Connect the BMP to the CN2 header (see Pinout above).&lt;br /&gt;
&lt;br /&gt;
Start gdb, erase the option bytes and flash BMP&lt;br /&gt;
 (gdb) target extended-remote /dev/ttyACM0&lt;br /&gt;
 (gdb) mon swdp_scan&lt;br /&gt;
 (gdb) att 1 &lt;br /&gt;
 (gdb) mon option erase&lt;br /&gt;
 (gdb) load /dir/to/blackmagic&lt;br /&gt;
 (gdb) load /dir/to/blackmagic_dfu&lt;br /&gt;
 (gdb) detach&lt;br /&gt;
&lt;br /&gt;
The option bytes do not cover the Readout Protection (RDP), but the RDP is disabled anyhow...&lt;br /&gt;
&lt;br /&gt;
'''Error at loading a new image after removing RDP'''&lt;br /&gt;
&lt;br /&gt;
 Error erasing flash with vFlashErase packet&lt;br /&gt;
If this occurs powercycle the target (disconnect and reconnect the 3V3 connection), swd scan, attach and try loading the image again. Usually the reset of the RDP requires a flash erase (done by mon option erase) and reset.&lt;br /&gt;
&lt;br /&gt;
Probably this can also be done via gdb.&lt;br /&gt;
&lt;br /&gt;
==Clones==&lt;br /&gt;
&lt;br /&gt;
There are also a lot of different chinese clones out there. Most with an identical MCU as the original STLinkV2, some with an STM32F101.&lt;br /&gt;
&lt;br /&gt;
It seems that each clone has its own programming pinout, so better double check (continuity tester) than to release the magic smoke...&lt;br /&gt;
&lt;br /&gt;
Most (all?) should work with the &amp;quot;stlink&amp;quot; target from Blackmagic Probe, since they probably use the same firmware from the original STLinkV2.&lt;br /&gt;
&lt;br /&gt;
===Red PCB===&lt;br /&gt;
&lt;br /&gt;
Seems to work with the standard stlink BMP image.&lt;br /&gt;
&lt;br /&gt;
[[Image:stlinkv2_clone_red_front.jpg|250px]]&lt;br /&gt;
[[Image:stlinkv2_clone_red_back.jpg|250px]]&lt;br /&gt;
&lt;br /&gt;
* STM32F103C8T6&lt;br /&gt;
&lt;br /&gt;
Programming header (1.27mm, populated on the images) from the Mini USB to the Pin header (right to left on the image), used for programming the onboard MCU.&lt;br /&gt;
&lt;br /&gt;
# SWDIO&lt;br /&gt;
# GND&lt;br /&gt;
# SWDCLK&lt;br /&gt;
# 3V3 &lt;br /&gt;
&lt;br /&gt;
Some Images and details about this hardware can be found at[https://www.mikrocontroller.net/articles/IRMP_auf_STM32_-_Bauanleitung]&lt;br /&gt;
&lt;br /&gt;
===Blue PCB===&lt;br /&gt;
NOT TESTED YET&lt;br /&gt;
[[Image:stlinkv2_clone_blue_front.jpg|250px]]&lt;br /&gt;
[[Image:stlinkv2_clone_blue_back.jpg|250px]]&lt;br /&gt;
&lt;br /&gt;
* STM32F103C8T6&lt;br /&gt;
&lt;br /&gt;
Programming header (2.54mm, unpopulated on the images) from the USB to the Pin header (left to the right on the images), used for programming the onboard MCU.&lt;br /&gt;
&lt;br /&gt;
# GND&lt;br /&gt;
# 5V&lt;br /&gt;
# USART1 RX (PA10)&lt;br /&gt;
# USART1 TX (PA9)&lt;br /&gt;
&lt;br /&gt;
Bootloader header (2.54mm, unpopulated on the images), from the USB to the Pin header (left to the right on the images), used for USART bootloader activation&lt;br /&gt;
&lt;br /&gt;
# 3V3&lt;br /&gt;
# BOOT0 (pin 44)&lt;br /&gt;
&lt;br /&gt;
The 3V3/5V switch selects the input voltage for the onboard MCU.&lt;br /&gt;
&lt;br /&gt;
===Aluminium housing===&lt;br /&gt;
NOT TESTED YET&lt;br /&gt;
[[Image:stlinkv2_clone_aluminium.jpg|250px]]&lt;br /&gt;
[[Image:stlinkv2_clone_aluminium_front.jpg|250px]]&lt;br /&gt;
[[Image:stlinkv2_clone_aluminium_back.jpg|250px]]&lt;br /&gt;
&lt;br /&gt;
* STM32F101C8T6&lt;br /&gt;
&lt;br /&gt;
Programming header (1.27mm, unpopulated on the images) from the USB to the Pin header (left to the right on the images), used for programming the onboard MCU.&lt;br /&gt;
&lt;br /&gt;
# SWDIO (PA13)&lt;br /&gt;
# GND&lt;br /&gt;
# SWDCLK(PA14)&lt;br /&gt;
# VDD, VBAT&lt;br /&gt;
&lt;br /&gt;
To disassemble pull the aluminium housing towards the USB connector.&lt;br /&gt;
&lt;br /&gt;
This has not the same hardware as https://github.com/blacksphere/blackmagic/issues/62 , but the same MCU, seems that this has just an other PCB.&lt;br /&gt;
&lt;br /&gt;
[[Category:Firmware Flashing]] [[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>PeterKorsgaard</name></author>
	</entry>
</feed>