こんにちは、あろっちです。
今回は、PlatformIO IDE(VS Code + PlatformIO)で、Raspberry Pi Pico/RP2040ボード(earlephilhower版)のプロジェクトを新規作成する手順を記述したメモ日記です。
PlatformIO IDE
本記事は、以下のページを参考にしています。
記事の内容につきましては、PlatformIO IDEの基本知識がある前提としています。
新規プロジェクトの作成
Raspberry Pi Pico/RP2040ボード(earlephilhower版)は、PlatformIOにはまだ統合されていないそうです。
そのため、現状、新規プロジェクトを作成するには、2つの手順を踏む必要があるようです。
STEP 1
PlatformIO IDEからデフォルトのRaspberry Pi Picoプロジェクトを新規作成する
すると、プロジェクト内に以下のような内容のplatform.iniが作成されます。
platform.ini
[env:pico]
platform = raspberrypi
board = pico
framework = arduino
このプロジェクトのボードは、Arduino Mbed OS RP2040ボードです。
STEP 2
platform.iniを書き換える
platform.iniを書き換えることで、Raspberry Pi Pico/RP2040ボード(earlephilhower版)用のプロジェクトになります。
Raspberry Pi Pico/RP2040ボード(earlephilhower版)用のplatform.iniを例示します。
Windows版 PlatformIO IDEの例です。
[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
; note that download link for toolchain is specific for OS. see https://github.com/earlephilhower/pico-quick-toolchain/releases.
platform_packages =
maxgerhardt/framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git
maxgerhardt/toolchain-pico@https://github.com/earlephilhower/pico-quick-toolchain/releases/download/1.3.1-a/x86_64-w64-mingw32.arm-none-eabi-7855b0c.210706.zip
Mac(Intel CPU向け)版 PlatformIO IDEの例です。
[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
; note that download link for toolchain is specific for OS. see https://github.com/earlephilhower/pico-quick-toolchain/releases.
platform_packages =
maxgerhardt/framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git
maxgerhardt/toolchain-pico@https://github.com/earlephilhower/pico-quick-toolchain/releases/download/1.3.3-a/x86_64-apple-darwin14.arm-none-eabi-ed6d983.220212.tar.gz
ボードの設定について
Arduino IDEにあるような以下の項目が設定できます。
フラッシュサイズ
board_build.filesystem_size
ファイルシステムに割り当てるサイズを指定することができます。
設定値には、”b”, “k”, “m” (bytes/kilobytes/megabytes) と浮動小数点数を含むことができます。
Arduino IDEのようにプルダウンによる選択式ではないので、Arduino IDEよりも自由度が高いのが特徴とのことです。
例:
; in reference to a board = pico config (2MB flash)
; Flash Size: 2MB (Sketch: 1MB, FS:1MB)
board_build.filesystem_size = 1m
; Flash Size: 2MB (No FS)
board_build.filesystem_size = 0m
; Flash Size: 2MB (Sketch: 0.5MB, FS:1.5MB)
board_build.filesystem_size = 1.5m
CPUクロック
board_build.f_cpu
CPUクロックを指定できます。
RP2040は、最大133MHzです。(これ以上はオーバークロック扱いになります。)
例:
; 133MHz
board_build.f_cpu = 133000000L
デバッグポート
build_flags
デバッグポートを指定できます。
例:
; Debug Port: Serial
build_flags = -DDEBUG_RP2040_PORT=Serial
; Debug Port: Serial 1
build_flags = -DDEBUG_RP2040_PORT=Serial1
; Debug Port: Serial 2
build_flags = -DDEBUG_RP2040_PORT=Serial2
デバッグレベル
build_flags
デバッグレベルは、この項目に以下の例のように指定できます。
複数パラメータを指定したい場合は、半角スペースか改行のいずれかで区切ります。
例:
; Debug level: Core
build_flags = -DDEBUG_RP2040_CORE
; Debug level: SPI
build_flags = -DDEBUG_RP2040_SPI
; Debug level: Wire
build_flags = -DDEBUG_RP2040_WIRE
; Debug level: All
build_flags = -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE
; Debug level: NDEBUG
build_flags = -DNDEBUG
; example: Debug port on serial 2 and all debug output
build_flags = -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE -DDEBUG_RP2040_PORT=Serial2
; equivalent to above
build_flags =
-DDEBUG_RP2040_WIRE
-DDEBUG_RP2040_SPI
-DDEBUG_RP2040_CORE
-DDEBUG_RP2040_PORT=Serial2
USBスタック
build_flags
デフォルト(未指定)の場合、Pico SDKが使用されます。
なお、特別な「USBなし」設定も、PIO_FRAMEWORK_ARDUINO_NO_USBでサポートされています。
例:
; Adafruit TinyUSB
build_flags = -DUSE_TINYUSB
; No USB stack
build_flags = -DPIO_FRAMEWORK_ARDUINO_NO_USB
定義名の前の-Dについて
build_flagsの例を見ていただくと、パラメータ(定義名)の先頭に必ず-Dがついていることがお分かりかと思います。
先頭の-Dってなに? そもそも必要なの? っていうところですが、
-Dというのは、Javaで動作するプログラムに、通知したい任意のパラメータ(つまり、-D以降の文字列=定義名)を知らせるためのオプションで、
ArduinoではビルドにJavaを使っている関係で定義名(例えば、PIO_FRAMEWORK_ARDUINO_NO_USB)の前に必ず-Dが必要という訳なのです。
まとめ
platform.ini設定後は、ビルドに必要なボードやライブラリは自動的にダウンロードされ、通常のPlatformIOのプロジェクトと同様に開発することができます。
コメント