022e191c15e7f18318b8b5e7224c66bb6327320b
[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 To run the gdb server, do (you do not need sudo if you have set up
39 permissions correctly):
40 $ make && [sudo] ./gdbserver/st-util 
41
42 There are a few options:
43
44 ./gdbserver/st-util - usage:
45
46   -h, --help        Print this help
47   -vXX, --verbose=XX    specify a specific verbosity level (0..99)
48   -v, --verbose specify generally verbose logging
49   -s X, --stlink_version=X
50             Choose what version of stlink to use, (defaults to 2)
51   -1, --stlinkv1    Force stlink version 1
52   -p 4242, --listen_port=1234
53             Set the gdb server listen port. (default port: 4242)
54
55 Then, in gdb: (remember, you need to run an _ARM_ gdb, not an x86 gdb)
56 (gdb) target remote :4242
57
58 Have fun!
59
60 Resetting the chip from GDB
61 ===========================
62
63 You may reset the chip using GDB if you want. You'll need to use `target
64 extended-remote' command like in this session:
65 (gdb) target extended-remote localhost:4242
66 Remote debugging using localhost:4242
67 0x080007a8 in _startup ()
68 (gdb) kill
69 Kill the program being debugged? (y or n) y
70 (gdb) run
71 Starting program: /home/whitequark/ST/apps/bally/firmware.elf 
72
73 Remember that you can shorten the commands. `tar ext :4242' is good enough
74 for GDB.
75
76 Setting up udev rules
77 =====================
78
79 For convenience, you may install udev rules file, 49-stlinkv*.rules, located
80 in the root of repository. You will need to copy it to /etc/udev/rules.d,
81 and then either reboot or execute
82 $ udevadm control --reload-rules
83
84 Udev will now create a /dev/stlinkv2_XX or /dev/stlinkv1_XX file, with the appropriate permissions.
85 This is currently all the device is for, (only one stlink of each version is supported at 
86 any time presently)
87
88 Running programs from SRAM
89 ==========================
90
91 You can run your firmware directly from SRAM if you want to. Just link
92 it at 0x20000000 and do
93 (gdb) load firmware.elf
94
95 It will be loaded, and pc will be adjusted to point to start of the
96 code, if it is linked correctly (i.e. ELF has correct entry point).
97
98 Writing to flash
99 ================
100
101 The GDB stub ships with a correct memory map, including the flash area.
102 If you would link your executable to 0x08000000 and then do
103 (gdb) load firmware.elf
104 then it would be written to the memory.
105
106
107 FAQ
108 ===
109
110 Q: My breakpoints do not work at all or only work once.
111
112 A: Optimizations can cause severe instruction reordering. For example,
113 if you are doing something like `REG = 0x100;' in a loop, the code may
114 be split into two parts: loading 0x100 into some intermediate register
115 and moving that value to REG. When you set up a breakpoint, GDB will
116 hook to the first instruction, which may be called only once if there are
117 enough unused registers. In my experience, -O3 causes that frequently.
118
119 Q: At some point I use GDB command `next', and it hangs.
120
121 A: Sometimes when you will try to use GDB `next' command to skip a loop,
122 it will use a rather inefficient single-stepping way of doing that.
123 Set up a breakpoint manually in that case and do `continue'.
124
125 Currently known working combinations of programmer and target
126 =============================================================
127
128 STLink v1 (as found on the 32VL Discovery board)
129
130 Known Working Targets:
131 * STM32F100xx (Medium Density VL)
132 * STM32F103 (according to jpa- on ##stm32)
133
134 No information:
135 * everything else!
136
137 STLink v2 (as found on the 32L and F4 Discovery boards)
138 Known Working Targets:
139 * STM32F100xx (Medium Density VL, as on the 32VL Discovery board)
140 * STM32L1xx (STM32L Discovery board)
141 * STM32F407xx (STM32F4 Discovery board)
142
143 Please report any and all known working combinations so I can update this!
144