とりあえずgdbを入れる
sudo apt-get install gdb-multiarch
OpenOCDもパッケージであるらしい
sudo apt-get install openocd
RPiのポートとマイコンを接続する。接続Pinは以下らしい
SWCLK RPi 22pin (GP25) SWDIO RPi 18pin (GP24) GND RPi 20pin
ボード(乗っているマイコン次第)のconfigを指定してopenocdを起動する
openocd -f /usr/share/openocd/scripts/board/stm32l0discovery.cfg
STM32C011J4M7用のconfigは上記フォルダには無さそうなので、どこかから探してくるか自力で書き換える必要あり
interface/raspberrypi2-native.cfgには以下となっているのだが
# Each of the SWD lines need a gpio number set: swclk swdio # Header pin numbers: 23 22 adapter gpio swclk -chip 0 11 adapter gpio swdio -chip 0 25
GPIO11 → 物理ピン23 GPIO25 → 物理ピン22
configに従い、SWDのCLOCKは物理ピン23、SWDのDIOは物理ピン22を使用
適当なボードを選ぶとエラーになるので、最低限の設定をtmp.cfgに入れて以下で起動
$ openocd -f interface/raspberrypi-native.cfg -f /tmp/tmp.cfg Open On-Chip Debugger 0.12.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html swd Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Warn : An adapter speed is not selected in the init scripts. OpenOCD will try to run the adapter at the low speed (100 kHz) Warn : To remove this warnings and achieve reasonable communication speed with the target, set "adapter speed" or "jtag_rclk" in the init scripts. Info : BCM2835 GPIO JTAG/SWD bitbang driver Info : clock speed 100 kHz Warn : gdb services need one or more targets defined
4444で待つとOpenOCDは言っているようだ
Listenポートを確認。確かに4444で待っている
sumi@raspberrypi:~ $ netstat -na|grep -i listen tcp 0 0 127.0.0.1:4444 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6666 0.0.0.0:* LISTEN
gdbを立ち上げて4444で接続する。。エラーになる
$ gdb (gdb) target remote localhost:4444 Remote debugging using localhost:4444 Remote replied unexpectedly to 'vMustReplyEmpty': vMustReplyEmpty
OpenOCD側のエラーは以下
Info : accepting 'telnet' connection on tcp/4444 Error: error during read: Connection reset by peer Info : dropped 'telnet' connection
考えられるのはTargetの属性を全く設定していないからと思われる(configファイル最低限なので)
file: /tmp/tmp.cfg
transport select swd
configを修正
file: /tmp/st_nucleo_f4.cfg
source [find interface/raspberrypi2-native.cfg ] transport select swd source [find target/stm32f4x.cfg] reset_config srst_only
$ openocd -f /tmp/st_nucleo_f4.cfg Open On-Chip Debugger 0.12.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html srst_only separate srst_nogate srst_open_drain connect_deassert_srst Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : BCM2835 GPIO JTAG/SWD bitbang driver Info : clock speed 2008 kHz Info : SWD DPIDR 0x0bc11477 Info : [stm32f4x.cpu] Cortex-M0+ r0p1 processor detected Info : [stm32f4x.cpu] target has 4 breakpoints, 2 watchpoints Info : starting gdb server for stm32f4x.cpu on 3333 Info : Listening on port 3333 for gdb connections Info : accepting 'gdb' connection on tcp/3333 [stm32f4x.cpu] halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x1fff0cd4 msp: 0x20000d80 Info : device id = 0x00000000 Warn : Cannot identify target as a STM32 family. Error: auto_probe failed Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'. Error: attempted 'gdb' connection rejected
sumi@raspberrypi:~ $ gdb (gdb) target remote localhost:3333 Remote debugging using localhost:3333 Remote connection closed
多分メモリマップがstm32f4x.cfgと一致していないためおかしくなっていると思われる
STM32 Memory Map - Stm32World Wiki
ねむいさんのぶろぐ | STM32C0を使ってみる4 -8PinのSTM32C0を使いこなせ!-
pio-stm32c0/packages/xpack-openocd-0.12.0-3-win32-x64/openocd/scripts/target/stm32c0x.cfg at 3a7285a905dba5378f7cd90ea1e8981ed1182ce3 · maxgerhardt/pio-stm32c0 · GitHub
ねむいさんのぶろぐ | Project Examples and Misc Files