chakokuのブログ(rev4)

テック・コミック・ごくまれにチャリ

STEVAL-DRONE01とST-LINK V2を接続

STEVAL-DRONE01を組み立てたので、gdbデバッグできるか、ST-LINK V2経由で接続してみた。
以下の通り、openOCDを立ち上げて、gdbを起動してポート3333で接続、STM32F401のレジスタダンプ、メモリダンプは行えた。

STEVAL-Drone01とST-Link V2を接続
OpenOCDの起動

$ ./bin-x64/openocd.exe  -f scripts/interface/stlink-v2.cfg  -f scripts/target/stm32f4x.cfg
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override u
se 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results mi
ght differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v29 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.170428
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection on tcp/3333
Info : device id = 0x00016423
Info : flash size = 256kbytes
undefined debug reason 7 - target needs reset
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08012e78 msp: 0x20005368

gdbを起動、レジスタダンプ、メモリダンプを実行

$ /usr/local/GNUToolsARMEmbedded/4.8_2013q4/bin/arm-none-eabi-gdb.exe
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20131129-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=i586-mingw32 --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

(gdb) target extended-remote : 3333
Remote debugging using : 3333
0x00000000 in ?? ()

(gdb) mon reset halt
Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08012e78 msp: 0x20005368

(gdb) i r
r0             0x0      0
r1             0x0      0
r2             0x0      0
r3             0x0      0
r4             0x0      0
r5             0x0      0
r6             0x0      0
r7             0x0      0
r8             0x0      0
r9             0x0      0
r10            0x0      0
r11            0x0      0
r12            0x0      0
sp             0x0      0x0
lr             0x0      0
pc             0x0      0x0
xPSR           0x0      0

(gdb) cont
Continuing.

Program received signal SIGINT, Interrupt.
0x08004f78 in ?? ()
(gdb) i r
r0             0x3e8    1000
r1             0x3e8    1000
r2             0x2000   8192
r3             0x2000   8192
r4             0x0      0
r5             0x4      4
r6             0x0      0
r7             0x0      0
r8             0x0      0
r9             0x0      0
r10            0x0      0
r11            0x0      0
r12            0x0      0
sp             0x20005308       0x20005308
lr             0x8004f79        134238073
pc             0x8004f78        0x8004f78
xPSR           0x81000000       -2130706432
(gdb) x/32wx 0
0x0:    0x20005368      0x08012e79      0x08012f31      0x08012f35
0x10:   0x08012f39      0x08012f3d      0x08012f41      0x00000000
0x20:   0x00000000      0x00000000      0x00000000      0x08012f45
0x30:   0x08012f49      0x00000000      0x08012f4d      0x08012689
0x40:   0x08012f51      0x08012f55      0x08012f59      0x08012f5d
0x50:   0x08012f61      0x08012f65      0x08012f69      0x08012f6d
0x60:   0x08012f71      0x08012f75      0x080126e9      0x08012f79
0x70:   0x08012f7d      0x08012f81      0x08012f85      0x08012f89
(gdb)

Flashには何か書き込まれていて走っているようだが、、どうせ使いこなせないし。。別にいらん。

■補足
当初、USBケーブルからSTM32の基板に電源を供給して、ST-LINKはGNDと信号線だけを繋いでいたけど、その状態だと正常に通信が確立できなかった。USBケーブルをはずして、ST-LINKの3.3VとGNDを接続すると通信が正常化した。なぜだろうか。。回路図まだ詳しく見ていないので原因は分からず。

■ご参考URL
STM32F401の仕様書類
https://www.st.com/ja/microcontrollers-microprocessors/stm32f401cc.html