LoginSignup
0
3

More than 3 years have passed since last update.

VSCodeのArduino拡張からstm32duinoをデバッグする

Last updated at Posted at 2020-07-04
  • 2021/2/10 Arduino拡張の更新に合わせて内容を更新しました。

VisualStudioCodeのArduino拡張ではデバッガを設定することができます。
これらを適切に設定してVisualStudioCodeからNucleoF030R8をデバッグするまでの作業手順(備忘録)です。

環境

Windows 10 バージョン 1903
パスを読み替えれば、他のOSでも同じ手順で動きそう
Nucleo-F030R8
たまたま手元にあったボード、デバッガ付きなのでUSBケーブでPCとつなぐだけ

必要なソフト

インストールするソフトは以下です。()内はchocolateyのパッケージ名です。

私はArduino IDE,VisualStudioCode,OpenOCDをchocolateyでインストールしました。

(Administrator)
choco install arduino vscode openocd

STM32 CoresとVisual Studio Code extension for Arduinoはそれぞれのインストール方法に従ってインストールしました。インストール方法は割愛します。
また、ST-LINK serverはSTMicroelectronicsのページからインストーラをダウンロードしてきました。

設定

VisualStudioCodeでArduinoプロジェクトを作成します。
F1を押して"Arduino: Examples"を選択し、"Build-in Examples" => "01.Basics" => "Blink"を選択。

プロジェクトが開いたら、ボードを選択しておきます。再びF1を押して"Arduino: Board Config"を選択。
以下の通りに選択します。デバッグしたい時は最適化オプション(Optimize)でDebug (-g) を詮索することを忘れないでください。

項目名 設定値
Selected Board: Nucleo-64 (STM32 Cores)
Board Part Number: Nucleo F030R8
Upload Method: Mass Storage
U(S)ART support: Enabled (generic 'Serial')
USB support (if available): None
USB speed (if available): Low/Full Speed
Optimize: Debug (-g)
C Runtime Library: Newlib Nano (default)

動作確認

ここまで完了すれば、NucleoF030R8にファームウェアを書き込むことができます。
書き込みは以下のいずれかで実行します。

  • 右上の下矢印がついたアイコンをクリック
  • F1 => "Arduino: Upload"を選択
  • Ctrl + Alt + u を押す

基板上の緑色のLEDが1秒間隔で点滅します。

デバッガの設定

ここまででは「デバッグを実行」しても以下のようなエラーメッセージが表示されます。
デバッガを設定する必要があります。

vscode_errormessage
Cannot find the OpenOCD from the launch.json debugServerPath property.
Please input the right path of OpenOCD

「メニュー」=> 「デバッグ」=>「構成の追加」を選択してください。.vscodeの下にlunch.jsonが作成されます。
以下の項目を編集してください、ほかの項目は変更なしで良いです。

項目 元の値 設定後の値
miDebuggerPath (空) arm-none-eabi-gdb.exeまでのフルパス
debugServerPath (空) C:/ProgramData/chocolatey/bin/openocd.exe
debugServerArgs (空) -s \"C:\ProgramData\chocolatey\lib\openocd\tools\OpenOCD-20190828-0.10.0\share\openocd\scripts\" -f \"board\st_nucleo_f0.cfg\" -f \"interface\st-link.cfg\"

バージョンが違う場合は、適宜修正してください。

OpenOCD終了タスクの追加

(2021/2/10更新 ST-Linkを使うように設定すれば不要です)

編集時点では、デバッグの終了時にOpenOCDが終了されないため、次にデバッグを実行した時にエラーになります。
tasks.jsonにOpenOCDを終了するタスクを追加し、lunch.jsonに以下の項目を追加してください。

tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "shutdown gdb",
            "type": "shell",
            "command": "/full/path/of/folder/which/contains/arm-none-eabi-gdb.exe",
            "args": [
                "-ex", "'target remote localhost:3333'",
                "-ex", "'monitor shutdown'",
                "-ex", "'quit'"
            ],
        }
    ]
}
項目 元の値 設定後の値
postDebugTask (空) "shutdown dgb"

その後、デバッグ実行のタスクを変更します。
これで終了時に、確認のメッセージに応答する必要はありますが、デバッグサーバを落とすようになります。

参考にしたサイト

How to debug
https://github.com/stm32duino/wiki/wiki/How-to-debug

ryochack.blog
https://ryochack.hatenablog.com/entry/2018/02/12/231755

21 GDB and OpenOCD
http://openocd.org/doc/html/GDB-and-OpenOCD.html

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3