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