1 STMicroelectronics Stlink Tools
2 ===============================
4 [![Build Status](https://travis-ci.org/xor-gate/stlink.svg?branch=travis)](https://travis-ci.org/xor-gate/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 . libusb-1.0 (You probably already have this, but you'll need the
23 development version to compile)
28 The STLINKv1's SCSI emulation is very broken, so the best thing to do
29 is tell your operating system to completely ignore it.
31 Options (do one of these before you plug it in)
33 * `modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:i`
34 * or *)1. add "options usb-storage quirks=483:3744:i" to /etc/modprobe.conf
35 * *)2. modprobe -r usb-storage && modprobe usb-storage
36 * or *)1. cp stlink_v1.modprobe.conf /etc/modprobe.d
37 * *)2. modprobe -r usb-storage && modprobe usb-storage
47 This project was converted to Autotools by a well meaning individual. The
48 following steps will build the project for you.
59 $ mkdir build && cd build
64 ## Using the gdb server
66 To run the gdb server: (you do not need sudo if you have set up
67 permissions correctly)
70 $ make && [sudo] ./st-util
72 There are a few options:
76 -h, --help Print this help
77 -vXX, --verbose=XX Specify a specific verbosity level (0..99)
78 -v, --verbose Specify generally verbose logging
79 -s X, --stlink_version=X
80 Choose what version of stlink to use, (defaults to 2)
81 -1, --stlinkv1 Force stlink version 1
82 -p 4242, --listen_port=1234
83 Set the gdb server listen port. (default port: 4242)
85 Set gdb server to extended mode.
86 st-util will continue listening for connections after disconnect.
88 Do not reset board on connection.
91 The STLINKv2 device to use can be specified in the environment
92 variable STLINK_DEVICE on the format `<USB_BUS>:<USB_ADDR>`.
94 Then, in your project directory, someting like this...
95 (remember, you need to run an _ARM_ gdb, not an x86 gdb)
98 $ arm-none-eabi-gdb fancyblink.elf
100 (gdb) tar extended-remote :4242
103 Loading section .text, size 0x458 lma 0x8000000
104 Loading section .data, size 0x8 lma 0x8000458
105 Start address 0x80001c1, load size 1120
106 Transfer rate: 1 KB/sec, 560 bytes/write.
114 ## Resetting the chip from GDB
116 You may reset the chip using GDB if you want. You'll need to use `target
117 extended-remote' command like in this session:
120 (gdb) target extended-remote localhost:4242
121 Remote debugging using localhost:4242
122 0x080007a8 in _startup ()
124 Kill the program being debugged? (y or n) y
126 Starting program: /home/whitequark/ST/apps/bally/firmware.elf
129 Remember that you can shorten the commands. `tar ext :4242' is good enough
132 ## Setting up udev rules
134 For convenience, you may install udev rules file, 49-stlinkv*.rules, located
135 in the root of repository. You will need to copy it to /etc/udev/rules.d,
136 and then either reboot or execute
139 $ udevadm control --reload-rules
143 Udev will now create a /dev/stlinkv2_XX or /dev/stlinkv1_XX file, with the appropriate permissions.
144 This is currently all the device is for, (only one stlink of each version is supported at
147 ## Running programs from SRAM
149 You can run your firmware directly from SRAM if you want to. Just link
150 it at 0x20000000 and do
153 (gdb) load firmware.elf
156 It will be loaded, and pc will be adjusted to point to start of the
157 code, if it is linked correctly (i.e. ELF has correct entry point).
161 The GDB stub ships with a correct memory map, including the flash area.
162 If you would link your executable to 0x08000000 and then do
163 (gdb) load firmware.elf
164 then it would be written to the memory.
169 Q: My breakpoints do not work at all or only work once.
171 A: Optimizations can cause severe instruction reordering. For example,
172 if you are doing something like `REG = 0x100;' in a loop, the code may
173 be split into two parts: loading 0x100 into some intermediate register
174 and moving that value to REG. When you set up a breakpoint, GDB will
175 hook to the first instruction, which may be called only once if there are
176 enough unused registers. In my experience, -O3 causes that frequently.
178 Q: At some point I use GDB command `next', and it hangs.
180 A: Sometimes when you will try to use GDB `next' command to skip a loop,
181 it will use a rather inefficient single-stepping way of doing that.
182 Set up a breakpoint manually in that case and do `continue'.
184 Q: Load command does not work in GDB.
186 A: Some people report XML/EXPAT is not enabled by default when compiling
187 GDB. Memory map parsing thus fail. Use --enable-expat.
189 ## Currently known working combinations of programmer and target
191 STLink v1 (as found on the 32VL Discovery board)
193 Known working targets:
195 * STM32F100xx (Medium Density VL)
196 * STM32F103 (according to jpa- on ##stm32)
202 STLink v2 (as found on the 32L and F4 Discovery boards), known working targets:
204 * STM32F030F4P6 (custom board)
205 * STM32F0Discovery (STM32F0 Discovery board)
206 * STM32F100xx (Medium Density VL, as on the 32VL Discovery board)
207 * STM32L1xx (STM32L Discovery board)
208 * STM32F103VC, STM32F107RC, STM32L151RB, STM32F205RE and STM32F405RE on custom boards
209 (https://github.com/UweBonnes/wiki_fuer_alex/layout/usps...)
210 * STM32F103VET6 (HY-STM32 board)
211 * STM32F105RCT6 (DecaWave EVB1000 board)
212 * STM32F303xx (STM32F3 Discovery board)
213 * STM32F407xx (STM32F4 Discovery board)
214 * STM32F429I-DISCO (STM32F4 Discovery board with LCD)
215 * STM32F439VIT6 (discovery board reseated CPU)
216 * STM32L052K8T6 (custom board)
217 * STM32L151CB (custom board)
218 * STM32L152RB (STM32L-Discovery board, custom board)
219 * STM32F051R8T6 (STM320518-EVAL board)
221 STLink v2-1 (as found on the Nucleo boards), known working targets:
223 * STM32F401xx (STM32 Nucleo-F401RE board)
224 * STM32F030R8T6 (STM32 Nucleo-F030R8 board)
225 * STM32F072RBT6 (STM32 Nucleo-F072RB board)
226 * STM32F103RB (STM32 Nucleo-F103RB board)
227 * STM32F303RET6 (STM32 Nucleo-F303RE board)
228 * STM32F334R8 (STM32 Nucleo-F334R8 board)
229 * STM32F411RET6 (STM32 Nucleo-F411RE board)
230 * STM32F756NGHx (STMF7 evaluation board)
231 * STM32L053R8 (STM32 Nucleo-L053R8 board)
233 Please report any and all known working combinations so I can update this!