Claude codeを使ってZephyr RTOSのデバイスツリーを書かせてみました。
ラズパイPico2WのGPIOという簡単な内容を対応しています。
実際にテストした内容・プロンプト含めて紹介します。
Claude codeでZephyr(RTOS)のデバイスツリーを書かせてみた
Claude codeを使ってZephyr RTOSのデバイスツリーを書かせてみました。
ラズパイPico2WのGPIOという簡単な内容を対応しています。最終的にはLチカさせています。
実際にテストした内容・プロンプト含めて紹介します。
テストした動画は下記です。
既に一度テスト済の内容
既に、Zephyr+ラズパイpico2WをLチカさせるのは下記で実施済です。

その際はラズパイPico2のデバイスツリーを一部修正して対応しました。
ZephyrRTOSでは、ハードウェアの構成をデバイスツリー(Device Tree)で定義します。
Claude codeを活用することで、楽に新規作成できるようになるかと試してみました。
Claude codeとは
今回はClaude Pro版を使っています。
Claude.aiさんにClaude codeを説明させると、こんな感じの説明です。
同類のボード設定(デバイスツリー)を横展開するときも楽になるかと思い、やってみました。
1 2 3 4 5 |
Claude codeは、Anthropic社が提供するAI支援のコマンドラインツールです。 開発者がコーディング作業をClaude AIに直接委託できる画期的なツールで、現在リサーチプレビューとして提供されています。 特に組み込み開発では、デバイスツリーの記述が複雑になりがちですが、Claude codeを使うことで効率的に生成できます。 |
今回の開発環境
- ターゲットボード: Raspberry Pi Pico2W
- OS: Windows 11
- 開発環境: VS Code + Zephyr SDK
- Claude code: Pro版
- West: Zephyr公式ビルドツール
もし同様に実施したい場合は、Zephyrのインストールガイドに従うだけで作れます。
参考までに筆者がインストールした際の動画です。
Claude codeでのDevice Tree生成
Claude Codeの詳しい使い方は色んな人が紹介しているので詳細は省略します。
さらっと動画ベースで紹介します。
WSLを起動して、Claude codeを立ち上げ中
Claude codeへのプロンプトを作ります。下記形で作ってもらいました。
1 2 3 4 5 6 7 8 9 |
これはZephyrのプロジェクトです。 現在ラズパイPico2Wはサポートされていません。 \claude-zephyrproject\zephyr\boards\raspberrypi\rpi_pico2 但し、一つ前のラズパイPicoWはサポートされています。 \claude-zephyrproject\zephyr\boards\raspberrypi\rpi_pico ハードウェア構成は同じですので、ラズパイPicoW2のデバイスツリーをラズパイPicoWのように修正してください。 .dtsだけではなく.yamlやdeconfigのファイルも対応してください |
Claude code コード作成中…
Zephyr(RTOS)+ラズパイPico2Wのデバイスツリーを作成中です
おおよそ、いい感じに作れていそうです。GPIO周辺も調整してもらいます。
1 2 3 4 5 |
現在、samples/basic/blinkyは下記デバイスツリーを参照してGPIO25をON/OFFしようとしています。 ただしラズパイPico2WではGPIO25WはCYW43439の通信用に使われているためblinkしません \zephyr\boards\raspberrypi\common\rpi_pico-led.dtsi GPIO14からLチカさせるようにしてください |
今回は仮環境なのでコマンドプロンプトでビルドします
Claude Codeにビルド時のエラー箇所を伝えて(貼り付けて)、修正中…。
勝手にガンガン修正されていきます。
修正終えて、ビルドも通るようになりました。
Pico2WでLチカさせます。Pico2Wにプログラム書き込み中…。
Lチカ+シリアルメッセージも確認しました。
Claude codeが作成・修正したデバイスツリーなど
最後に、Claude codeが作成・修正したデバイスツリーなどを貼り付けておきます。
本当に必要な所を修正したな、という感想です。(褒めています)
●修正・追記した箇所
zephyr\boards\raspberrypi\rpi_pico2\board.yml
1 2 3 4 5 6 7 8 9 |
board: name: rpi_pico2 full_name: Raspberry Pi Pico 2 vendor: raspberrypi socs: - name: rp2350a variants: - name: m33_w cpucluster: m33 |
zephyr\boards\raspberrypi\rpi_pico2\Kconfig.rpi_pico2
1 2 3 4 5 6 |
# Copyright (c) 2024 Andrew Featherstone # SPDX-License-Identifier: Apache-2.0 config BOARD_RPI_PICO2 select SOC_RP2350A_M33 if BOARD_RPI_PICO2_RP2350A_M33 select SOC_RP2350A_M33 if BOARD_RPI_PICO2_RP2350A_M33_M33_W |
●新規作成した箇所
zephyr\boards\raspberrypi\rpi_pico2\rpi_pico2_rp2350a_m33_m33_w_defconfig
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# This configuration is orthogonal to whether the Cortex-M33 or Hazard3 cores # are in use, but Zephyr does not support providing a qualifier-agnostic # _defconfig file. CONFIG_BUILD_OUTPUT_HEX=y CONFIG_BUILD_OUTPUT_UF2=y CONFIG_CLOCK_CONTROL=y CONFIG_CONSOLE=y CONFIG_GPIO=y CONFIG_RESET=y CONFIG_SERIAL=y CONFIG_UART_CONSOLE=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_USE_DT_CODE_PARTITION=y # Default networking configuration CONFIG_CYW43439=y |
zephyr\boards\raspberrypi\rpi_pico2\rpi_pico2_rp2350a_m33_m33_w.dts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
/* * Copyright (c) 2024 Andrew Featherstone * Copyright (c) 2023 Dave Rensberger - Beechwoods Software * Copyright (c) 2024 Steve Boylan <stephen.boylan@beechwoods.com> * * SPDX-License-Identifier: Apache-2.0 */ /dts-v1/; /* The build system assumes that there's a cpucluster-specific file. * * This file provides composition of the device tree: * 1. The common features of the SoC * 2. Core-specific configuration. * 3. Board-specific configuration with WiFi support. */ #include <raspberrypi/rpi_pico/rp2350a.dtsi> #include <raspberrypi/rpi_pico/m33.dtsi> /* there's nothing specific to the Cortex-M33 cores vs the (not yet * implemented) Hazard3 cores. */ #include "rpi_pico2.dtsi" &pinctrl { pio0_spi0_default: pio0_spi0_default { /* gpio 25 is used for chip select, not assigned to the PIO */ group1 { pinmux = <PIO0_P29>; }; }; airoc_wifi_default: airoc_wifi_default { /* Control of GPIO24 is done through the WiFi driver */ group1 { pinmux = <PIO0_P24>; input-enable; }; }; airoc_wifi_host_wake: airoc_wifi_host_wake { /* Assign GPIO24 to SIO (GPIO) for use as an interrupt source */ group1 { /* Lacking a specific SIO pin definition, use the RP2040_PINMUX macro */ pinmux = <RP2XXX_PINMUX(24, RP2_PINCTRL_GPIO_FUNC_SIO)>; input-enable; }; }; }; &pio0 { status = "okay"; pio0_spi0: pio0_spi0 { compatible = "raspberrypi,pico-spi-pio"; clocks = < &clocks RPI_PICO_CLKID_CLK_SYS >; #address-cells = <1>; #size-cells = <0>; cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>; clk-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; sio-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>; pinctrl-0 = <&pio0_spi0_default>; pinctrl-names = "default"; status = "okay"; airoc-wifi@0 { compatible = "infineon,airoc-wifi"; reg = < 0 >; wifi-reg-on-gpios = < &gpio0 23 GPIO_ACTIVE_HIGH >; bus-select-gpios = < &gpio0 24 GPIO_ACTIVE_HIGH >; wifi-host-wake-gpios = < &gpio0 24 GPIO_ACTIVE_HIGH >; spi-max-frequency = < 10000000 >; spi-half-duplex; spi-data-irq-shared; pinctrl-0 = <&airoc_wifi_default>; pinctrl-1 = <&airoc_wifi_host_wake>; pinctrl-names = "default", "host_wake"; status = "okay"; }; }; }; /* Override LED configuration for Pico 2W - use GPIO14 instead of GPIO25 * since GPIO25 is used for CYW43439 WiFi communication */ &led0 { gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>; }; |
zephyr\boards\raspberrypi\rpi_pico2\rpi_pico2_rp2350a_m33_m33_w.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
identifier: rpi_pico2/rp2350a/m33/m33_w name: Raspberry Pi Pico 2 W (Cortex-M33) type: mcu arch: arm flash: 4096 ram: 520 toolchain: - zephyr - gnuarmemb supported: - adc - clock - counter - dma - gpio - hwinfo - i2c - pwm - spi - uart - usbd - watchdog |
まとめ
Claude codeを使ってZephyr RTOSのデバイスツリーを書かせてみました。
ラズパイPico2WのGPIOという簡単な内容を対応しています。
実際にテストした内容・プロンプト含めて紹介しました。
コメント