背景:STM32C0をOpenOCD+RaspberryPi(GPIO)でデバッグできるようにする(ST-Linkどっかにいったので)
課題:RPi用のDebianに入っているOpenOCDではSTM32C0をサポートしていない(正確にはconfigファイルが無い)
取り組み:Gitからソースを落としてきてビルドして最新版OpenOCDを入れる
結果:なんとかデバッグできる状態にはなった
詳細:
STM32C0は新しいマイコンなので、Ubuntuの標準パッケージで配布されるOpenOCDにはConfig等が入っていない。一方、Gitの最新版にはConfigが入っている。ということで、Configを自作せず、すなおに最新版をビルドしてそれを使うことにする
手順はよく知られた方法なので、、以下で進める。
sudo apt-get install -y git gcc g++ autoconf automake libtool pkg-config make \ libusb-1.0-0-dev libhidapi-dev libgpiod-dev libftdi1-dev
git clone https://github.com/openocd-org/openocd.git cd openocd git submodule update --init --recursive # add ./bootstrap ./configure make
お約束で怒られる
configure: error: jimtcl is required but not found via pkg-config and system includes
openocdに移動して、追加のsubmoduleを取ってくる?必要があるらしかった(上記手順は修正済み)
この方法でも、jimtclの問題が解消しない。ねむいさんブログにもコンパイルエラーが
述べられていて、以下で回避できると書かれていた。
git config --global http.sslVerify false
が、これでも依然としてエラーが出る(エラー箇所が移った可能性もあり)
しっかり調べて対応が必要なようだ。一旦中断
Gitのページでも、以下が必要ですよとは言われてるので・・
You'll also need: - make - libtool - pkg-config >= 0.23 or pkgconf - libjim >= 0.79
libjim関連のソースが必要なようで、ソースをパッケージでインストールした。
apt-get install libjim-dev
この一連の対応でconfigureは通過して、makeも通った。
./configure ./make sudo make install
/usr/local/binに入ったopenocdと/usr/bin/のopenocdを比較。バージョンは大きく変わらないのだが。。
$ /usr/local/bin/openocd --version Open On-Chip Debugger 0.12.0+dev-02000-g6a3abda0b (2025-05-22-13:57) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html $ /usr/bin/openocd --version Open On-Chip Debugger 0.12.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html
configをいろいろ試したがエラーが取れず、どうもドライバ用ライブラリ(bcm2835gpio)が足りないと判断
bcm2835gpioを同梱できるようにconfigureをやり直して、make -> make install
./configure --enable-bcm2835gpio
テスト用のconfigとして以下を作成
source [find interface/raspberrypi-native.cfg ] transport select swd source [find target/stm32c0x.cfg] reset_config srst_only
OpenOCDを起動、3333でListen状態
$ /usr/local/bin/openocd -f try2.cfg Open On-Chip Debugger 0.12.0+dev-02000-g6a3abda0b (2025-05-22-15:10) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Warn : TMS/SWDIO moved to GPIO 8 (pin 24). Check the wiring please! 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 2000 kHz Info : SWD DPIDR 0x0bc11477 Info : [stm32c0x.cpu] Cortex-M0+ r0p1 processor detected Info : [stm32c0x.cpu] target has 4 breakpoints, 2 watchpoints Info : [stm32c0x.cpu] Examination succeed Info : [stm32c0x.cpu] starting gdb server on 3333 Info : Listening on port 3333 for gdb connections
gdbを起動、target remote localhost:3333でOpenOCDと接続、レジスタを表示してみる
PCが0x1fff0cceとはどこを走っているのだろうか。。
(gdb) target remote localhost:3333 Remote debugging using localhost:3333 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x1fff0cce in ?? () (gdb) info registers r0 0x10000000 268435456 r1 0xe5e5e5e5 -437918235 r2 0x80c8 32968 r3 0x66000000 1711276032 r4 0x20000360 536871776 r5 0x40005400 1073763328 r6 0xffffffff -1 r7 0xffffffff -1 r8 0xffffffff -1 r9 0xffffffff -1 r10 0xffffffff -1 r11 0xffffffff -1 r12 0xffffffff -1 sp 0x20000d80 0x20000d80 lr 0x1fff0cc1 536808641 pc 0x1fff0cce 0x1fff0cce xpsr 0x1000000 16777216 msp 0x20000d80 0x20000d80 psp 0xfffffffc 0xfffffffc primask 0x1 1 basepri 0x0 0 faultmask 0x0 0 control 0x0 0 (gdb)
gdb と接続できた時のOpenOCDのログ
Info : accepting 'gdb' connection on tcp/3333 Info : device idcode = 0x10016443 (STM32C01xx - Rev Z : 0x1001) Info : RDP level 0 (0xAA) Info : flash size = 16 KiB Info : flash mode : single-bank Info : device idcode = 0x10016443 (STM32C01xx - Rev Z : 0x1001) Info : RDP level 0 (0xAA) Info : OTP size is 1024 bytes, base address is 0x1fff7000 undefined debug reason 8 (UNDEFINED) - target needs reset Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
0番地付近をダンプ
(gdb) x /4xw 0x0 0x0: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
何も焼いていないFlashだから0xFFなのか。。?
とりあえず、GDB+OpenOCD+RaspberryPi(SWD)でSTM32C0をデバッグできるようにはなった