Align loader to 32-bit boundary
[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 * `pkg-config`
23 * `libusb-1.0` (plus development headers for building, on debian based distros `libusb-1.0.0-dev` package)
24
25 ## For STLINKv1
26
27 The STLINKv1's SCSI emulation is very broken, so the best thing to do
28 is tell your operating system to completely ignore it.
29
30 Options (do one of these before you plug it in)
31
32 * `modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:i`
33 * or 1. `echo "options usb-storage quirks=483:3744:i" >> /etc/modprobe.conf`
34 *    2. `modprobe -r usb-storage && modprobe usb-storage`
35 * or 1. `cp stlink_v1.modprobe.conf /etc/modprobe.d`
36 *    2. `modprobe -r usb-storage && modprobe usb-storage`
37
38 ## For STLINKv2
39
40 You're ready to go :)
41
42 ## Build from sources
43
44 ### Autotools
45
46 This project was converted to Autotools by a well meaning individual. The
47 following steps will build the project for you.
48
49 ```
50 $ ./autogen.sh
51 $ ./configure
52 $ make
53 ```
54
55 ### CMake
56
57 ```
58 $ mkdir build && cd build
59 $ cmake -DCMAKE_BUILD_TYPE=Debug ..
60 $ make
61 ```
62
63 ## Using the gdb server
64
65 To run the gdb server: (you do not need sudo if you have set up
66 permissions correctly)
67
68 ```
69 $ make && [sudo] ./st-util
70
71 There are a few options:
72
73 ./st-util - usage:
74
75   -h, --help            Print this help
76   -vXX, --verbose=XX    Specify a specific verbosity level (0..99)
77   -v, --verbose         Specify generally verbose logging
78   -s X, --stlink_version=X
79                         Choose what version of stlink to use, (defaults to 2)
80   -1, --stlinkv1        Force stlink version 1
81   -p 4242, --listen_port=1234
82                         Set the gdb server listen port. (default port: 4242)
83   -m, --multi
84                         Set gdb server to extended mode.
85                         st-util will continue listening for connections after disconnect.
86   -n, --no-reset
87                         Do not reset board on connection.
88 ```
89
90 The STLINKv2 device to use can be specified in the environment
91 variable STLINK_DEVICE on the format `<USB_BUS>:<USB_ADDR>`.
92
93 Then, in your project directory, someting like this...
94 (remember, you need to run an _ARM_ gdb, not an x86 gdb)
95
96 ```
97 $ arm-none-eabi-gdb fancyblink.elf
98 ...
99 (gdb) tar extended-remote :4242
100 ...
101 (gdb) load
102 Loading section .text, size 0x458 lma 0x8000000
103 Loading section .data, size 0x8 lma 0x8000458
104 Start address 0x80001c1, load size 1120
105 Transfer rate: 1 KB/sec, 560 bytes/write.
106 (gdb)
107 ...
108 (gdb) continue
109 ```
110
111 Have fun!
112
113 ## Resetting the chip from GDB
114
115 You may reset the chip using GDB if you want. You'll need to use `target
116 extended-remote' command like in this session:
117
118 ```
119 (gdb) target extended-remote localhost:4242
120 Remote debugging using localhost:4242
121 0x080007a8 in _startup ()
122 (gdb) kill
123 Kill the program being debugged? (y or n) y
124 (gdb) run
125 Starting program: /home/whitequark/ST/apps/bally/firmware.elf
126 ```
127
128 Remember that you can shorten the commands. `tar ext :4242' is good enough
129 for GDB.
130
131 ## Setting up udev rules
132
133 For convenience, you may install udev rules file, 49-stlinkv*.rules, located
134 in the root of repository. You will need to copy it to /etc/udev/rules.d,
135 and then either reboot or execute
136
137 ```
138 $ udevadm control --reload-rules
139 $ udevadm trigger
140 ```
141
142 Udev will now create a /dev/stlinkv2_XX or /dev/stlinkv1_XX file, with the appropriate permissions.
143 This is currently all the device is for, (only one stlink of each version is supported at 
144 any time presently)
145
146 ## Running programs from SRAM
147
148 You can run your firmware directly from SRAM if you want to. Just link
149 it at 0x20000000 and do
150
151 ```
152 (gdb) load firmware.elf
153 ```
154
155 It will be loaded, and pc will be adjusted to point to start of the
156 code, if it is linked correctly (i.e. ELF has correct entry point).
157
158 ## Writing to flash
159
160 The GDB stub ships with a correct memory map, including the flash area.
161 If you would link your executable to 0x08000000 and then do
162 (gdb) load firmware.elf
163 then it would be written to the memory.
164
165
166 ## FAQ
167
168 Q: My breakpoints do not work at all or only work once.
169
170 A: Optimizations can cause severe instruction reordering. For example,
171 if you are doing something like `REG = 0x100;' in a loop, the code may
172 be split into two parts: loading 0x100 into some intermediate register
173 and moving that value to REG. When you set up a breakpoint, GDB will
174 hook to the first instruction, which may be called only once if there are
175 enough unused registers. In my experience, -O3 causes that frequently.
176
177 Q: At some point I use GDB command `next', and it hangs.
178
179 A: Sometimes when you will try to use GDB `next' command to skip a loop,
180 it will use a rather inefficient single-stepping way of doing that.
181 Set up a breakpoint manually in that case and do `continue'.
182
183 Q: Load command does not work in GDB.
184
185 A: Some people report XML/EXPAT is not enabled by default when compiling
186 GDB. Memory map parsing thus fail. Use --enable-expat.
187
188 ## Currently known working combinations of programmer and target
189
190 STLink v1 (as found on the 32VL Discovery board)
191
192 Known working targets:
193
194 * STM32F100xx (Medium Density VL)
195 * STM32F103 (according to jpa- on ##stm32)
196
197 No information:
198
199 * everything else!
200
201 STLink v2 (as found on the 32L and F4 Discovery boards), known working targets:
202
203 * STM32F030F4P6 (custom board)
204 * STM32F0Discovery (STM32F0 Discovery board)
205 * STM32F100xx (Medium Density VL, as on the 32VL Discovery board)
206 * STM32L1xx (STM32L Discovery board)
207 * STM32F103VC, STM32F107RC, STM32L151RB, STM32F205RE and STM32F405RE on custom boards
208   (https://github.com/UweBonnes/wiki_fuer_alex/layout/usps...)
209 * STM32F103VET6 (HY-STM32 board)
210 * STM32F105RCT6 (DecaWave EVB1000 board)
211 * STM32F303xx (STM32F3 Discovery board)
212 * STM32F407xx (STM32F4 Discovery board)
213 * STM32F429I-DISCO (STM32F4 Discovery board with LCD)
214 * STM32F439VIT6 (discovery board reseated CPU)
215 * STM32L052K8T6 (custom board)
216 * STM32L151CB (custom board)
217 * STM32L152RB (STM32L-Discovery board, custom board)
218 * STM32F051R8T6 (STM320518-EVAL board)
219
220 STLink v2-1 (as found on the Nucleo boards), known working targets:
221
222 * STM32F401xx (STM32 Nucleo-F401RE board) 
223 * STM32F030R8T6 (STM32 Nucleo-F030R8 board)
224 * STM32F072RBT6 (STM32 Nucleo-F072RB board)
225 * STM32F103RB (STM32 Nucleo-F103RB board)
226 * STM32F303RET6 (STM32 Nucleo-F303RE board)
227 * STM32F334R8 (STM32 Nucleo-F334R8 board)
228 * STM32F411RET6 (STM32 Nucleo-F411RE board)
229 * STM32F756NGHx (STMF7 evaluation board)
230 * STM32L053R8 (STM32 Nucleo-L053R8 board)
231
232 Please report any and all known working combinations so I can update this!