3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

esp32で少し快適なシリアルデバッグ

Posted at

快適なシリアルデバッグがしたい!

備忘として置いておきます

対象環境

  • esp32
  • vscode
    • platformio

結論

設定ファイル(抜粋)

platform.ini
; PlatformIO Project Configuration File

[env]
platform = espressif32
framework = arduino
build_flags = 
    -DCORE_DEBUG_LEVEL=4
    ; 0:None, 1:Error, 2:WARN, 3:Info, 4:Debug, 5:Verbose
    -DCONFIG_ARDUHAL_LOG_COLORS=1
monitor_raw = yes

ソースコード

main.cpp
#include <Arduino.h>

void setup(){
    // serial connect
    Serial.begin(115200);
    while (!Serial);
    Serial.println();   // 変な位置で始まる可能性を消すために改行
    log_v("Verbose");   // その他
    log_d("Debug");     // デバッグ
    log_i("Info");      // 情報
    log_w("Warn");      // 警告
    log_e("Error");     // エラー
}

// 内容が無いよう!(激うまギャグ)
void loop(){
    delay(1);
}

従来のシリアルデバッグ

  • ひたすら文字が流れていくだけ
  • デバッグのために出力を増やす
    • どこが重要かわからなくなる
    • 最後に消す必要性

これらを解決するために...

ログ出力マクロ+色付きシリアルデバッグ

  • ログ出力マクロ
    • ファイル名・関数名がわかる
      • いちいち自分で入力しなくていい
    • 設定に応じて自動で出力無効化
      • デバッグが終わった後もログ出力用のコードを消す必要なし
      • 設定を変更するだけで出力されなくなる
      • タグをつけて重要度を一括で管理することも可能
  • 色付きシリアルデバッグ
    • 重要な部分を目立つ色で出力

image.png

嬉しさポイント

  • esp32の標準なのでどの機種でも使える
  • 処理時刻や関数名を一緒にログとして吐き出してくれる
  • CORE_DEBUG_LEVELを変更すればプリコンパイルで処理を無効化してくれる
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?