CLionでのesp32開発に必要な環境整備


いろいろハマった(♦)のでメモを残したいと思います。

開発ボードを用意する

  1. USB に差し込んで、/devの下に usbmodemUSBtoUART などの名前が出ているか確認します。
  2. 表示がなければ、ドライバーがインストールされてない可能性があります。SILABSのチップが乗っているかどうか確認します。
  3. SILABSのチップがある場合、Silicon Labs のダウンロードページ から適宜にダウンロードし、インストールします。
  4. 再度USBに差し込んで、/dev/cu.SLAB_USBtoUART があると確認します。

PlatformIO Core をインストールする

必ず homebrew 経由でインストールします。

brew install platformio

PlatformIO 本家のインストール指示に従うと、インストールされるPlatformIO Coreがうまく認識されません♦。

インストールが終わったあと確認します。

$ which platformio
/usr/local/bin/platformio

Platformio プラグインを整備する

  1. CLionの設定画面(+,)を開き、左側から Plugins を選びます。
    スクリーンショット
  2. platformio で検索してインストールします(iniというプラグインが必要です。聞かれたら、合わせてインストールします)。
  3. CLionを再起動します
  4. 再起動した後、再び設定画面を開きます。
  5. 左側から Languages & Frameworks > PlatformIO を選びます。
    スクリーンショット
  6. platformio のインストール場所 /usr/local/bin/platformio を入力します。

プロジェクトを作成しビルドする

  1. メニューから File > New Project を選びます。
  2. 左側から PlatformIO を選びます。
  3. Espressif > Espressif ESP32 Dev Module > espidf を選びます(お持ちのボードに応じて適宜に選んでください)
    スクリーンショット
  4. [Create] を押します。 プロジェクト作成に5分ぐらい時間がかかります。作成終了後 src/main.c が作成されます
  5. platformio.ini を修正します。
    • platform = [email protected] (♦重要。新しい espidf は使えません)
    • upload_port = /dev/cu.SLAB_USBtoUART(Windowsの場合はCOMnnです)

platformio.ini 例

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = [email protected]
board = esp32dev
framework = espidf
src_dir = src
upload_port = /dev/cu.SLAB_USBtoUART

ツールバーの「🔨ビルド」ボタンを押してビルドを開始します。

以上