Merge branch 'master' of git://github.com/texane/stlink
[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
67 Then, in your project directory, someting like this...
68 (remember, you need to run an _ARM_ gdb, not an x86 gdb)
69
70 $ arm-none-eabi-gdb fancyblink.elf
71 ...
72 (gdb) tar extended-remote :4242
73 ...
74 (gdb) load
75 Loading section .text, size 0x458 lma 0x8000000
76 Loading section .data, size 0x8 lma 0x8000458
77 Start address 0x80001c1, load size 1120
78 Transfer rate: 1 KB/sec, 560 bytes/write.
79 (gdb)
80 ...
81 (gdb) continue
82
83 Have fun!
84
85 Resetting the chip from GDB
86 ===========================
87
88 You may reset the chip using GDB if you want. You'll need to use `target
89 extended-remote' command like in this session:
90 (gdb) target extended-remote localhost:4242
91 Remote debugging using localhost:4242
92 0x080007a8 in _startup ()
93 (gdb) kill
94 Kill the program being debugged? (y or n) y
95 (gdb) run
96 Starting program: /home/whitequark/ST/apps/bally/firmware.elf 
97
98 Remember that you can shorten the commands. `tar ext :4242' is good enough
99 for GDB.
100
101 Setting up udev rules
102 =====================
103
104 For convenience, you may install udev rules file, 49-stlinkv*.rules, located
105 in the root of repository. You will need to copy it to /etc/udev/rules.d,
106 and then either reboot or execute
107 $ udevadm control --reload-rules
108
109 Udev will now create a /dev/stlinkv2_XX or /dev/stlinkv1_XX file, with the appropriate permissions.
110 This is currently all the device is for, (only one stlink of each version is supported at 
111 any time presently)
112
113 Running programs from SRAM
114 ==========================
115
116 You can run your firmware directly from SRAM if you want to. Just link
117 it at 0x20000000 and do
118 (gdb) load firmware.elf
119
120 It will be loaded, and pc will be adjusted to point to start of the
121 code, if it is linked correctly (i.e. ELF has correct entry point).
122
123 Writing to flash
124 ================
125
126 The GDB stub ships with a correct memory map, including the flash area.
127 If you would link your executable to 0x08000000 and then do
128 (gdb) load firmware.elf
129 then it would be written to the memory.
130
131
132 FAQ
133 ===
134
135 Q: My breakpoints do not work at all or only work once.
136
137 A: Optimizations can cause severe instruction reordering. For example,
138 if you are doing something like `REG = 0x100;' in a loop, the code may
139 be split into two parts: loading 0x100 into some intermediate register
140 and moving that value to REG. When you set up a breakpoint, GDB will
141 hook to the first instruction, which may be called only once if there are
142 enough unused registers. In my experience, -O3 causes that frequently.
143
144 Q: At some point I use GDB command `next', and it hangs.
145
146 A: Sometimes when you will try to use GDB `next' command to skip a loop,
147 it will use a rather inefficient single-stepping way of doing that.
148 Set up a breakpoint manually in that case and do `continue'.
149
150 Currently known working combinations of programmer and target
151 =============================================================
152
153 STLink v1 (as found on the 32VL Discovery board)
154
155 Known Working Targets:
156 * STM32F100xx (Medium Density VL)
157 * STM32F103 (according to jpa- on ##stm32)
158
159 No information:
160 * everything else!
161
162 STLink v2 (as found on the 32L and F4 Discovery boards)
163 Known Working Targets:
164 * STM32F100xx (Medium Density VL, as on the 32VL Discovery board)
165 * STM32L1xx (STM32L Discovery board)
166 * STM32F107RC, STM32L151RB, STM32F205RE and  STM32F405RE  on a custom boards 
167   (https://github.com/UweBonnes/wiki_fuer_alex/layout/usps...)
168 * STM32F407xx (STM32F4 Discovery board)
169
170 Please report any and all known working combinations so I can update this!
171