mcpField
Z
zephyr

zephyr

github.com/mohitmishra786開発269481 回インストール18 週間前に更新
リポジトリ

zephyr について

Zephyr アプリケーション開発を支援するエージェント向けガイドで、設定、ビルド、デバッグを行う組み込み開発者を対象とします。west のワークフロー、Kconfig、devicetree、ログ、ホストテスト、GDB によるデバッグを扱います。

主な機能

  1. 01west のワークスペースとビルド手順
  2. 02Kconfig による機能設定
  3. 03devicetree オーバーレイ設定
  4. 04ログサブシステムの設定
  5. 05native_sim によるホストテストと GDB デバッグ

活用シーン

  1. 01Zephyr アプリケーションの作成とビルド
  2. 02ボード機能とハードウェア記述の設定
  3. 03実機なしでのテスト実行
  4. 04Zephyr アプリケーションのデバッグとログ確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill zephyr

インストール後、Claude Code で/zephyrを入力して読み込まれたか確認します。

同梱ファイルreferences/west-manifest.md

詳細

Zephyr RTOS

目的

Zephyr アプリケーションの開発についてエージェントをガイドします。west のビルドワークフロー、ボード設定、Kconfig と devicetree、Zephyr シェルとログ、ホストテスト用の native_sim ターゲット、GDB を使ったデバッグを扱います。

トリガー

  • 「west で Zephyr アプリケーションをビルドするにはどうすればよいですか?」
  • 「Kconfig で Zephyr を設定するにはどうすればよいですか?」
  • 「Zephyr で devicetree オーバーレイを使うにはどうすればよいですか?」
  • 「Zephyr アプリケーションにログを追加するにはどうすればよいですか?」
  • 「テスト用に Zephyr をホストマシン上で実行するにはどうすればよいですか?」
  • 「Zephyr アプリケーションをデバッグするにはどうすればよいですか?」

ワークフロー

1. ワークスペースのセットアップと初回ビルド
# Install west
pip install west

# Initialize workspace from Zephyr manifest
west init ~/zephyrproject
cd ~/zephyrproject
west update                          # fetches Zephyr + all modules

# Install Python dependencies
pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt

# Install Zephyr SDK (toolchains for all targets)
# Download from: https://github.com/zephyrproject-rtos/sdk-ng/releases
export ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk-0.17.0
export ZEPHYR_BASE=~/zephyrproject/zephyr

# Build hello_world for a target board
west build -b nrf52840dk/nrf52840 samples/hello_world

# Flash to hardware
west flash

# Open serial monitor
west espressif monitor  # or: screen /dev/ttyACM0 115200

よく使われるボードターゲット:

ボードターゲット名
nRF52840 DKnrf52840dk/nrf52840
STM32 Nucleo-F446REnucleo_f446re
Raspberry Pi Picorpi_pico/rp2040
ESP32esp32_devkitc_wroom/esp32/procpu
QEMU Cortex-M3qemu_cortex_m3
Native POSIXnative_sim
2. アプリケーションの構成
my_app/
├── CMakeLists.txt
├── prj.conf              # Kconfig fragment
├── app.overlay           # devicetree overlay (optional)
└── src/
    └── main.c
# CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(my_app)
target_sources(app PRIVATE src/main.c)
3. Kconfig — 機能設定
# prj.conf — Kconfig fragment (key=value)
CONFIG_GPIO=y
CONFIG_UART_CONSOLE=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3     # 0=off 1=err 2=warn 3=info 4=debug
CONFIG_PRINTK=y
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=2048
# Interactive Kconfig menu
west build -t menuconfig

# Search for a config option
west build -t guiconfig

# Show all enabled options
west build -t config -- -n | grep "^CONFIG_"
4. Devicetree オーバーレイ
/* app.overlay — board-specific hardware additions */
/ {
    leds {
        compatible = "gpio-leds";
        my_led: led_0 {
            gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
            label = "My LED";
        };
    };
};

/* Override a node property */
&uart0 {
    current-speed = <115200>;
};

/* Disable an existing node */
&spi1 {
    status = "disabled";
};
// Access devicetree nodes in C
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>

#define LED_NODE DT_ALIAS(led0)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);

// Initialize and toggle
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
gpio_pin_toggle_dt(&led);
5. ログサブシステム

prj.conf でのバックエンド設定:

#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(my_module, LOG_LEVEL_DBG);

void my_function(void) {
    LOG_INF("Sensor value: %d", 42);
    LOG_WRN("Low battery: %d%%", battery_pct);
    LOG_ERR("SPI transfer failed: %d", ret);
    LOG_DBG("Debug detail: ptr=%p", ptr);
    LOG_HEXDUMP_DBG(buf, len, "raw buffer");
}
CONFIG_LOG=y
CONFIG_LOG_BACKEND_UART=y        # UART output
CONFIG_LOG_BACKEND_RTT=y         # Segger RTT output
CONFIG_LOG_TIMESTAMP_DEFAULT=y   # add timestamps
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=512
6. native_sim — ホストテスト
# Build for host (no hardware needed)
west build -b native_sim samples/hello_world

# Run directly on host
./build/zephyr/zephyr.exe

# Run with GDB
gdb ./build/zephyr/zephyr.exe
(gdb) run

# Simulated UART appears on a PTY
./build/zephyr/zephyr.exe &
screen $(ls /tmp/zephyr-uart-*)

# native_sim extras
./build/zephyr/zephyr.exe --help
./build/zephyr/zephyr.exe --stop-at=5  # stop after 5 simulated seconds

native_sim は Zephyr を Linux プロセスとして実行します。ほとんどの Zephyr API に対応しており、単体テストや CI に最適です。

7. ハードウェア上でのデバッグ
# West debug (launches OpenOCD + GDB automatically)
west debug

# Or manually with OpenOCD
west build -t run &
arm-zephyr-eabi-gdb build/zephyr/zephyr.elf
(gdb) target remote :3333
(gdb) monitor reset halt
(gdb) load
(gdb) continue

# Zephyr's thread-aware GDB (via OpenOCD RTOS plugin)
(gdb) info threads     # lists Zephyr threads
(gdb) thread 2         # switch to thread

west マニフェストの詳細については、references/west-manifest.md を参照してください。

関連スキル

  • ハードウェアのデバッグの詳細については skills/embedded/openocd-jtag を使用します
  • 代替 RTOS として FreeRTOS を使用する場合は skills/embedded/freertos を使用します
  • メモリ領域の設定については skills/embedded/linker-scripts を使用します
  • GDB セッションの管理については skills/debuggers/gdb を使用します

コメント