STM32G4 の開発環境構築 デバック環境
stm32g4 nucleoがdegikeyから届いたのでデバッグ環境を構築。
OPENOCDのビルド
配布されているOPENOCDはSTM32G4とSTLINK-V3がたいおうしていなかったので
github.com の対応版をダウンロードして自分でビルドすることにした。
適当なディレクトリ(自分は~/download内)に移動して
git clone https://github.com/mjbots/openocd.git cd openocd ./bootstrap export CFLAGS="-Wno-error" export CXXFLAGS="-Wno-error" ./configure make -j8 sudo make install
でinstall完了。
export CFLAGS="-Wno-error"と
export CXXFLAGS="-Wno-error"
はglibcのバージョンが新しいとsrc/helper/options.c内で#include <sys/sysctl.h>がdeprecatedのwarningをはいてビルドできなかったのでつけました。
udevの設定
下記のリンク先を参考に
tomoyuki-nakabayashi.github.io
stm32g4 nucleoを接続して
lsusb
してみると
Bus 001 Device 005: ID 0483:374e STMicroelectronics STLINK-V3
と出てきましたので、/etc/udev/rule.d/に60-openocd.cfgを作成して
# STMicroelectronics STLINK-V3 ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374d", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374f", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3753", MODE="660", GROUP="plugdev", TAG+="uaccess"
と記入。
sudo udevadm control --reload-rules
nucleoボードを一度抜き刺しして、パーミッションを確認。
ls -l /dev/bus/usb/001/005 # usb/から先は先程lsusbで確認した番号を入力 crwxrwxrwx+ 1 root root 189, 4 6月 13 15:15 /dev/bus/usb/001/005
パーミッションも設定できたので,これでst-linkを利用可能なはず。
VSCODEの設定
vscodeにプラグイン「Cortex-debug」をインストールする。
launch.jsonの編集
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Cortex Debug", "cwd": "${workspaceRoot}", "executable": "build/(プログラム名).elf", "request": "launch", "type": "cortex-debug", "servertype": "openocd", "configFiles": [ "interface/stlink.cfg", "target/stm32g4x.cfg" ], "preLaunchTask": "build" } ] }
# debug build? DEBUG = 1
にすれば設定は完了。