Closed19

embedded rustでprobe-rsとdefmtを設定する

chamachama
probe-rs chip list

でチップリストを見ることができる

chamachama
runner = 'probe-rs run --chip STM32G431C6Tx'

単純にこれだけ追加するとcargo run -rで以下のエラーが出る

Error: The flashing procedure failed for 'target\thumbv7em-none-eabihf\release\imu-fsr-stm32g4'.   

Caused by:
    Failed to configure a stack for the flash algorithm.
chamachama

cargo add defmt
して
"-C", "link-arg=-Tdefmt.x",を追加したが状況は変わらず

chamachama

probe-rsをgithubリポジトリからクローンしてきて、stack_size: 32768の行を削除した
cargo install --path probe-rs --features cliでローカルのコードからインストールした。

chamachama

yamlを書き換えなくても--chip-description-path <chip description file path>で実行時に直接指定することは可能らしい

chamachama

こちらは修正対応いただきcloseされているので今後は問題なくデフォルト設定で書き込めると思われます

chamachama

続いてdefmtの設定

Cargo.tomlの依存関係に以下を追加

defmt = "0.3"
chamachama

mainで

use defmt_rtt as _;

を追加して
適当な場所から

defmt::error!("hello from defmt");

すると表示を確認できた

chamachama

VS Codeでのデバッガー設定
手順をちゃんと読んで設定すれば動いた
https://probe.rs/docs/tools/debugger/


{
    "version": "0.2.0",
    "configurations": [
        {
            "preLaunchTask": "${defaultBuildTask}",
            "type": "probe-rs-debug",
            "request": "launch",
            "name": "probe_rs Executable Test",
            "flashingConfig": {
                "flashingEnabled": true,
            },
            //!MODIFY
            "chip": "STM32G431C6Tx",
            "coreConfigs": [
                {
                //!MODIFY
                "programBinary": "${workspaceRoot}\\target\\thumbv7em-none-eabihf\\release\\プロジェクト名",
                "coreIndex": 0,
                "rttEnabled": true
                }
            ],
            "env": {
                //!MODIFY: Remove or use any of the supported DEFMT_LOG options.
                "DEFMT_LOG": "info"
            }
        },
// 省略

chamachama

.cargo/config.toml

// 省略
[env]
DEFMT_LOG = "info"
chamachama

tasks.json

// ... <snip> ...
  "options": {
    "env": {
      //!MODIFY: Remove or use any of the supported DEFMT_LOG options.
      "DEFMT_LOG": "info"
    }
  },
  "tasks": [
// ... <snip> ...
このスクラップは1ヶ月前にクローズされました