Removed comment about STM32F4 limitations
[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 It means that if you are using a STM32VL board, you have to install and load
15 SCSI related software. First, load the sg kernel module:
16 # modprobe sg
17
18 Then, you need to install the package libsgutils2-dev. On Ubuntu:
19 # sudo apt-get install libsgutils2-dev
20
21 LIBUSB is required for both cases.
22
23 To run the gdb server, do (you do not need sudo if you have set up
24 permissions correctly):
25 $ make -C build && sudo ./build/st-util [/dev/sgX]
26
27 Currently, the GDB server listening port is hardcoded to 4242:
28
29 Then, in gdb:
30 (gdb) target remote :4242
31
32 Have fun!
33
34 Resetting the chip from GDB
35 ===========================
36
37 You may reset the chip using GDB if you want. You'll need to use `target
38 extended-remote' command like in this session:
39 (gdb) target extended-remote localhost:4242
40 Remote debugging using localhost:4242
41 0x080007a8 in _startup ()
42 (gdb) kill
43 Kill the program being debugged? (y or n) y
44 (gdb) run
45 Starting program: /home/whitequark/ST/apps/bally/firmware.elf 
46
47 Remember that you can shorten the commands. `tar ext :4242' is good enough
48 for GDB.
49
50 Setting up udev rules
51 =====================
52
53 For convenience, you may install udev rules file, 10-stlink.rules, located
54 in the root of repository. You will need to copy it to /etc/udev/rules.d,
55 and then either reboot or execute
56 $ udevadm control --reload-rules
57
58 Udev will now create a /dev/stlink file, which will point at appropriate
59 /dev/sgX device. Good to not accidentally start debugging your flash drive.
60
61 Running programs from SRAM
62 ==========================
63
64 You can run your firmware directly from SRAM if you want to. Just link
65 it at 0x20000000 and do
66 (gdb) load firmware.elf
67
68 It will be loaded, and pc will be adjusted to point to start of the
69 code, if it is linked correctly (i.e. ELF has correct entry point).
70
71 Writing to flash
72 ================
73
74 The GDB stub ships with a correct memory map, including the flash area.
75 If you would link your executable to 0x08000000 and then do
76 (gdb) load firmware.elf
77 then it would be written to the memory.
78
79
80 FAQ
81 ===
82
83 Q: My breakpoints do not work at all or only work once.
84
85 A: Optimizations can cause severe instruction reordering. For example,
86 if you are doing something like `REG = 0x100;' in a loop, the code may
87 be split into two parts: loading 0x100 into some intermediate register
88 and moving that value to REG. When you set up a breakpoint, GDB will
89 hook to the first instruction, which may be called only once if there are
90 enough unused registers. In my experience, -O3 causes that frequently.
91
92 Q: At some point I use GDB command `next', and it hangs.
93
94 A: Sometimes when you will try to use GDB `next' command to skip a loop,
95 it will use a rather inefficient single-stepping way of doing that.
96 Set up a breakpoint manually in that case and do `continue'.