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