Update README
[fw/stlink] / README
1 Open source version of the STMicroelectronics Stlink Tools
2 ==========================================================
3
4 [![Build Status](https://travis-ci.org/texane/stlink.svg?branch=master)](https://travis-ci.org/texane/stlink)
5
6 ## HOWTO
7
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:
11
12 * STLINKv1, present on STM32VL discovery kits,
13 * STLINKv2, present on STM32L discovery and later kits.
14
15 Two different transport layers are used:
16
17 * STLINKv1 uses SCSI passthru commands over USB
18 * STLINKv2 uses raw USB commands.
19
20 ## Common requirements
21
22 * Debian based distros (debian, ubuntu)
23   * `build-essential`
24
25 * `pkg-config`
26 * `intltool`
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
30
31 ## For STLINKv1
32
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.
35
36 Options (do one of these before you plug it in)
37
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`
43
44 ## For STLINKv2
45
46 You're ready to go :)
47
48 ## Build from sources
49
50 ### Autotools
51
52 This project was converted to Autotools by a well meaning individual. The
53 following steps will build the project for you.
54
55 ```
56 $ ./autogen.sh
57 $ ./configure --with-gtk-gui
58 $ make
59 ```
60
61 ### CMake
62
63 ```
64 $ mkdir build && cd build
65 $ cmake -DCMAKE_BUILD_TYPE=Debug ..
66 $ make
67 ```
68
69 ## Using the gdb server
70
71 To run the gdb server: (you do not need sudo if you have set up
72 permissions correctly)
73
74 ```
75 $ make && [sudo] ./st-util
76
77 There are a few options:
78
79 ./st-util - usage:
80
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)
89   -m, --multi
90                         Set gdb server to extended mode.
91                         st-util will continue listening for connections after disconnect.
92   -n, --no-reset
93                         Do not reset board on connection.
94 ```
95
96 The STLINKv2 device to use can be specified in the environment
97 variable STLINK_DEVICE on the format `<USB_BUS>:<USB_ADDR>`.
98
99 Then, in your project directory, someting like this...
100 (remember, you need to run an _ARM_ gdb, not an x86 gdb)
101
102 ```
103 $ arm-none-eabi-gdb fancyblink.elf
104 ...
105 (gdb) tar extended-remote :4242
106 ...
107 (gdb) load
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.
112 (gdb)
113 ...
114 (gdb) continue
115 ```
116
117 Have fun!
118
119 ## Resetting the chip from GDB
120
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:
123
124 ```
125 (gdb) target extended-remote localhost:4242
126 Remote debugging using localhost:4242
127 0x080007a8 in _startup ()
128 (gdb) kill
129 Kill the program being debugged? (y or n) y
130 (gdb) run
131 Starting program: /home/whitequark/ST/apps/bally/firmware.elf
132 ```
133
134 Remember that you can shorten the commands. `tar ext :4242' is good enough
135 for GDB.
136
137 ## Setting up udev rules
138
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
142
143 ```
144 $ udevadm control --reload-rules
145 $ udevadm trigger
146 ```
147
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 
150 any time presently)
151
152 ## Running programs from SRAM
153
154 You can run your firmware directly from SRAM if you want to. Just link
155 it at 0x20000000 and do
156
157 ```
158 (gdb) load firmware.elf
159 ```
160
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).
163
164 ## Writing to flash
165
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.
170
171 ## FAQ
172
173 Q: My breakpoints do not work at all or only work once.
174
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.
181
182 Q: At some point I use GDB command `next', and it hangs.
183
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'.
187
188 Q: Load command does not work in GDB.
189
190 A: Some people report XML/EXPAT is not enabled by default when compiling
191 GDB. Memory map parsing thus fail. Use --enable-expat.
192
193 ## Currently known working combinations of programmer and target
194
195 STLink v1 (as found on the 32VL Discovery board)
196
197 Known working targets:
198
199 * STM32F100xx (Medium Density VL)
200 * STM32F103 (according to jpa- on ##stm32)
201
202 No information:
203
204 * everything else!
205
206 STLink v2 (as found on the 32L and F4 Discovery boards), known working targets:
207
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)
224
225 STLink v2-1 (as found on the Nucleo boards), known working targets:
226
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)
236
237 Please report any and all known working combinations so I can update this!
238
239 ## Known bugs
240
241 ### Sometimes flashing only works after a mass erase
242
243 There is seen a problem sometimes where a flash loader run error occurs and is resolved after mass-erase
244 of the flash:
245
246 ```
247 2015-12-09T22:01:57 INFO src/stlink-common.c: Successfully loaded flash loader in sram
248 2015-12-09T22:02:18 ERROR src/stlink-common.c: flash loader run error
249 2015-12-09T22:02:18 ERROR src/stlink-common.c: run_flash_loader(0x8000000) failed! == -1
250 ```
251
252 Issue(s): [#356](https://github.com/texane/stlink/issues/356)
253
254 ## Contributing and versioning
255
256 * The semantic versioning scheme is used. Read more at [semver.org](http://semver.org)
257 * When creating a pull request, please open first a issue for discussion of new features
258 * TODO: Enforcement of coding style (linux codestyle + checkpatch)
259
260 ## License
261
262 The stlink library and tools are licensed under the [BSD license](LICENSE)