1 Open source version of the STMicroelectronics Stlink Tools
2 ==========================================================
4 [![Build Status](https://travis-ci.org/texane/stlink.svg?branch=master)](https://travis-ci.org/texane/stlink)
8 First, you have to know there are several boards supported by the software.
9 Those boards use a chip to translate from USB to JTAG commands. The chip is
10 called stlink and there are 2 versions:
12 * STLINKv1, present on STM32VL discovery kits,
13 * STLINKv2, present on STM32L discovery and later kits.
15 Two different transport layers are used:
17 * STLINKv1 uses SCSI passthru commands over USB
18 * STLINKv2 uses raw USB commands.
20 ## Common requirements
22 * Debian based distros (debian, ubuntu)
27 * `cmake` or (`autoconf` && `automake` && `autogen`)
28 * `libusb-1.0` (plus development headers for building, on debian based distros `libusb-1.0.0-dev` package)
29 * (optional) for `stlink-gui` we need libgtk-3-dev
33 The STLINKv1's SCSI emulation is very broken, so the best thing to do
34 is tell your operating system to completely ignore it.
36 Options (do one of these before you plug it in)
38 * `modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:i`
39 * or 1. `echo "options usb-storage quirks=483:3744:i" >> /etc/modprobe.conf`
40 * 2. `modprobe -r usb-storage && modprobe usb-storage`
41 * or 1. `cp stlink_v1.modprobe.conf /etc/modprobe.d`
42 * 2. `modprobe -r usb-storage && modprobe usb-storage`
52 This project was converted to Autotools by a well meaning individual. The
53 following steps will build the project for you.
57 $ ./configure --with-gtk-gui
64 $ mkdir build && cd build
65 $ cmake -DCMAKE_BUILD_TYPE=Debug ..
69 ## Using the gdb server
71 To run the gdb server: (you do not need sudo if you have set up
72 permissions correctly)
75 $ make && [sudo] ./st-util
77 There are a few options:
81 -h, --help Print this help
82 -vXX, --verbose=XX Specify a specific verbosity level (0..99)
83 -v, --verbose Specify generally verbose logging
84 -s X, --stlink_version=X
85 Choose what version of stlink to use, (defaults to 2)
86 -1, --stlinkv1 Force stlink version 1
87 -p 4242, --listen_port=1234
88 Set the gdb server listen port. (default port: 4242)
90 Set gdb server to extended mode.
91 st-util will continue listening for connections after disconnect.
93 Do not reset board on connection.
96 The STLINKv2 device to use can be specified in the environment
97 variable STLINK_DEVICE on the format `<USB_BUS>:<USB_ADDR>`.
99 Then, in your project directory, someting like this...
100 (remember, you need to run an _ARM_ gdb, not an x86 gdb)
103 $ arm-none-eabi-gdb fancyblink.elf
105 (gdb) tar extended-remote :4242
108 Loading section .text, size 0x458 lma 0x8000000
109 Loading section .data, size 0x8 lma 0x8000458
110 Start address 0x80001c1, load size 1120
111 Transfer rate: 1 KB/sec, 560 bytes/write.
119 ## Resetting the chip from GDB
121 You may reset the chip using GDB if you want. You'll need to use `target
122 extended-remote' command like in this session:
125 (gdb) target extended-remote localhost:4242
126 Remote debugging using localhost:4242
127 0x080007a8 in _startup ()
129 Kill the program being debugged? (y or n) y
131 Starting program: /home/whitequark/ST/apps/bally/firmware.elf
134 Remember that you can shorten the commands. `tar ext :4242' is good enough
137 ## Setting up udev rules
139 For convenience, you may install udev rules file, 49-stlinkv*.rules, located
140 in the root of repository. You will need to copy it to /etc/udev/rules.d,
141 and then either reboot or execute
144 $ udevadm control --reload-rules
148 Udev will now create a /dev/stlinkv2_XX or /dev/stlinkv1_XX file, with the appropriate permissions.
149 This is currently all the device is for, (only one stlink of each version is supported at
152 ## Running programs from SRAM
154 You can run your firmware directly from SRAM if you want to. Just link
155 it at 0x20000000 and do
158 (gdb) load firmware.elf
161 It will be loaded, and pc will be adjusted to point to start of the
162 code, if it is linked correctly (i.e. ELF has correct entry point).
166 The GDB stub ships with a correct memory map, including the flash area.
167 If you would link your executable to 0x08000000 and then do
168 (gdb) load firmware.elf
169 then it would be written to the memory.
173 Q: My breakpoints do not work at all or only work once.
175 A: Optimizations can cause severe instruction reordering. For example,
176 if you are doing something like `REG = 0x100;' in a loop, the code may
177 be split into two parts: loading 0x100 into some intermediate register
178 and moving that value to REG. When you set up a breakpoint, GDB will
179 hook to the first instruction, which may be called only once if there are
180 enough unused registers. In my experience, -O3 causes that frequently.
182 Q: At some point I use GDB command `next', and it hangs.
184 A: Sometimes when you will try to use GDB `next' command to skip a loop,
185 it will use a rather inefficient single-stepping way of doing that.
186 Set up a breakpoint manually in that case and do `continue'.
188 Q: Load command does not work in GDB.
190 A: Some people report XML/EXPAT is not enabled by default when compiling
191 GDB. Memory map parsing thus fail. Use --enable-expat.
193 ## Currently known working combinations of programmer and target
195 STLink v1 (as found on the 32VL Discovery board)
197 Known working targets:
199 * STM32F100xx (Medium Density VL)
200 * STM32F103 (according to jpa- on ##stm32)
206 STLink v2 (as found on the 32L and F4 Discovery boards), known working targets:
208 * STM32F030F4P6 (custom board)
209 * STM32F0Discovery (STM32F0 Discovery board)
210 * STM32F100xx (Medium Density VL, as on the 32VL Discovery board)
211 * STM32L1xx (STM32L Discovery board)
212 * STM32F103VC, STM32F107RC, STM32L151RB, STM32F205RE and STM32F405RE on custom boards
213 from [UweBonnes/wiki_fuer_alex](https://github.com/UweBonnes/wiki_fuer_alex/tree/master/layout)
214 * STM32F103VET6 (HY-STM32 board)
215 * STM32F105RCT6 (DecaWave EVB1000 board)
216 * STM32F303xx (STM32F3 Discovery board)
217 * STM32F407xx (STM32F4 Discovery board)
218 * STM32F429I-DISCO (STM32F4 Discovery board with LCD)
219 * STM32F439VIT6 (discovery board reseated CPU)
220 * STM32L052K8T6 (custom board)
221 * STM32L151CB (custom board)
222 * STM32L152RB (STM32L-Discovery board, custom board)
223 * STM32F051R8T6 (STM320518-EVAL board)
225 STLink v2-1 (as found on the Nucleo boards), known working targets:
227 * STM32F401xx (STM32 Nucleo-F401RE board)
228 * STM32F030R8T6 (STM32 Nucleo-F030R8 board)
229 * STM32F072RBT6 (STM32 Nucleo-F072RB board)
230 * STM32F103RB (STM32 Nucleo-F103RB board)
231 * STM32F303RET6 (STM32 Nucleo-F303RE board)
232 * STM32F334R8 (STM32 Nucleo-F334R8 board)
233 * STM32F411RET6 (STM32 Nucleo-F411RE board)
234 * STM32F756NGHx (STMF7 evaluation board)
235 * STM32L053R8 (STM32 Nucleo-L053R8 board)
237 Please report any and all known working combinations so I can update this!
239 ## Contributing and versioning
241 * The semantic versioning scheme is used. Read more at [semver.org](http://semver.org)
242 * When creating a pull request, please open first a issue for discussion of new features
243 * TODO: Enforcement of coding style (linux codestyle + checkpatch)
247 The stlink library and tools are licensed under the [BSD license](LICENSE)