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