Page MenuHomePhabricator

Debugowanie za pomocą openocd+gdb+stlinkv2
Updated 1,925 Days AgoPublic

Version 1 of 6: You are viewing an older version of this document, as it appeared on Jan 11 2019, 12:00 PM.
Debugowanie za pomocą openocd+gdb+stlinkv2

Zakładając, że używasz makefile z działu cmsis_gcc. Zakładam także, że dysponujesz STLinkv2 (albo jego podróbką (ebay, ebay, ebay!), ew. łatwo zrobić taki dongle samemu, w środku siedzi nic innego jak STM32F101CBT6)

  • Podpinasz dongle do komputera, łączysz do procka GND, SWCLK, SWDIO, ew. VCC jak nie zasilasz go osobno z zasilacza
  • Z użytkownika "root" albo innego, który ma możliwość bezpośredniego pisania po urządzeniach usb odpalasz debugserver, winno to wyglądać jakoś tak.
  • <code># make debugserver

openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x_stlink.cfg
Open On-Chip Debugger 0.7.0 (2013-08-04-09:35)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v20 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : Target voltage: 3.198419
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
</code> I zostawiasz go w tle... Jakbyś restartował serwer (bo czasami się coś spieprzy) to jakby coś nie chodziło odłącz i podłącz dongla do komputera na nowo..

  • W innej konsoli (już jako normalny użytkownik) odpal gdb
  • <code>$ make debug

(echo "target remote localhost:3333"; cat) | arm-none-eabi-gdb main.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140228-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from stm32/projekty/blink/main.elf...done.
(gdb) Remote debugging using localhost:3333
0x00000000 in ?? ()</code> GDB podłączy się do openocd i możesz zacząć wydawać komendy.

  • Na początek dobrze jest zresetować procek i od razu zatrzymać wykonywanie kodu
  • <code>(gdb) monitor reset halt

target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800010c msp: 0x20005000
(gdb)</code>

  • Za pomocą "load" możemy wgrać kod na procka
  • <code>(gdb) load

Loading section .isr_vector, size 0x10c lma 0x8000000
Loading section .text, size 0x2d4 lma 0x800010c
Loading section .data, size 0x4 lma 0x80004cd
Start address 0x800010c, load size 996
Transfer rate: 7 KB/sec, 332 bytes/write.
(gdb) </code>

  • No i teraz już możemy używać gdb dalej jak przy debugowaniu normalnego programu na komputerze :)
  • <code>(gdb) info br

No breakpoints or watchpoints.
(gdb) br main.c:30
Breakpoint 1 at 0x800039c: file src/main.c, line 30.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at src/main.c:30
30 GPIO_SetBits(GPIOA, GPIO_Pin_1);
(gdb)
Continuing.

Breakpoint 1, main () at src/main.c:30
30 GPIO_SetBits(GPIOA, GPIO_Pin_1);
(gdb)
Continuing.

Breakpoint 1, main () at src/main.c:30
30 GPIO_SetBits(GPIOA, GPIO_Pin_1);
(gdb)
Continuing.

Breakpoint 1, main () at src/main.c:30
30 GPIO_SetBits(GPIOA, GPIO_Pin_1);
(gdb) bt
#0 main () at src/main.c:30
(gdb) delete 1
(gdb) br delay_ms
Breakpoint 2 at 0x800039a: delay_ms. (2 locations)
(gdb) c
Continuing.

Breakpoint 2, main () at src/main.c:33
33 delay_ms(100);
(gdb) </code>

Last Author
jkramarz
Last Edited
Jan 11 2019, 12:00 PM

Event Timeline

jkramarz edited the content of this document. (Show Details)
jkramarz edited the content of this document. (Show Details)
jkramarz edited the content of this document. (Show Details)
jkramarz edited the content of this document. (Show Details)