st-info: Add support for OpenOCD hla_serial printing
[fw/stlink] / README
1 STMicroelectronics Stlink Tools
2 ===============================
3
4 [![Build Status](https://travis-ci.org/texane/stlink.svg?branch=travis)](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 . libusb-1.0  (You probably already have this, but you'll need the
23 development version to compile)
24 . pkg-config
25
26 ## For STLINKv1
27
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.
30
31 Options (do one of these before you plug it in)
32
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
38
39 ## For STLINKv2
40
41 You're ready to go :)
42
43 ## Build from sources
44
45 ### Autotools
46
47 This project was converted to Autotools by a well meaning individual. The
48 following steps will build the project for you.
49
50 ```
51 $ ./autogen.sh
52 $ ./configure
53 $ make
54 ```
55
56 ### CMake
57
58 ```
59 $ mkdir build && cd build
60 $ cmake -DCMAKE_BUILD_TYPE=Debug ..
61 $ make
62 ```
63
64 ## Using the gdb server
65
66 To run the gdb server: (you do not need sudo if you have set up
67 permissions correctly)
68
69 ```
70 $ make && [sudo] ./st-util
71
72 There are a few options:
73
74 ./st-util - usage:
75
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)
84   -m, --multi
85                         Set gdb server to extended mode.
86                         st-util will continue listening for connections after disconnect.
87   -n, --no-reset
88                         Do not reset board on connection.
89 ```
90
91 The STLINKv2 device to use can be specified in the environment
92 variable STLINK_DEVICE on the format `<USB_BUS>:<USB_ADDR>`.
93
94 Then, in your project directory, someting like this...
95 (remember, you need to run an _ARM_ gdb, not an x86 gdb)
96
97 ```
98 $ arm-none-eabi-gdb fancyblink.elf
99 ...
100 (gdb) tar extended-remote :4242
101 ...
102 (gdb) load
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.
107 (gdb)
108 ...
109 (gdb) continue
110 ```
111
112 Have fun!
113
114 ## Resetting the chip from GDB
115
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:
118
119 ```
120 (gdb) target extended-remote localhost:4242
121 Remote debugging using localhost:4242
122 0x080007a8 in _startup ()
123 (gdb) kill
124 Kill the program being debugged? (y or n) y
125 (gdb) run
126 Starting program: /home/whitequark/ST/apps/bally/firmware.elf
127 ```
128
129 Remember that you can shorten the commands. `tar ext :4242' is good enough
130 for GDB.
131
132 ## Setting up udev rules
133
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
137
138 ```
139 $ udevadm control --reload-rules
140 $ udevadm trigger
141 ```
142
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 
145 any time presently)
146
147 ## Running programs from SRAM
148
149 You can run your firmware directly from SRAM if you want to. Just link
150 it at 0x20000000 and do
151
152 ```
153 (gdb) load firmware.elf
154 ```
155
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).
158
159 ## Writing to flash
160
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.
165
166
167 ## FAQ
168
169 Q: My breakpoints do not work at all or only work once.
170
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.
177
178 Q: At some point I use GDB command `next', and it hangs.
179
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'.
183
184 Q: Load command does not work in GDB.
185
186 A: Some people report XML/EXPAT is not enabled by default when compiling
187 GDB. Memory map parsing thus fail. Use --enable-expat.
188
189 ## Currently known working combinations of programmer and target
190
191 STLink v1 (as found on the 32VL Discovery board)
192
193 Known working targets:
194
195 * STM32F100xx (Medium Density VL)
196 * STM32F103 (according to jpa- on ##stm32)
197
198 No information:
199
200 * everything else!
201
202 STLink v2 (as found on the 32L and F4 Discovery boards), known working targets:
203
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)
220
221 STLink v2-1 (as found on the Nucleo boards), known working targets:
222
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)
232
233 Please report any and all known working combinations so I can update this!