1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FRDM-MCXA153(その4:Zephyr)アンドZephyrその1

1
Posted at

Zephyrに触れる

NXPのFRDM-MCXA153にて、RTOSであるZephyrを動かすことにした。Mac環境での実現(構築)に多少ハマったので、その時の備忘録。macOS環境で実施、適宜、AIさん利用。今後、Zephyrにトライ予定なので、同時にシリーズ1回目とした。

サイト情報

本家下記サイトに沿って進める。

環境構築

つまづき1はMac環境をUpdateして解消

brewはインストール済みなので、各種ツールインストール。

$ brew install cmake ninja gperf python3 python-tk ccache qemu dtc libmagic wget openocd
$ (echo; echo 'export PATH="'$(brew --prefix)'/opt/python/libexec/bin:$PATH"') >> ~/.zprofile
source ~/.zprofile

ここはOKだったが、最初にハマったのが、Macにてpythonの仮想環境を作るところ。

% python3 -m venv ~/zephyrproject/.venv

Error: Command '['/Users/nameXYZ/zephyrproject/.venv/bin/python3.14', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

AIさんに聞いてトライしたところ、macOSをUpdate及びXcodeのCLI(Command Line Tool)をUpdateにすることにより、上記問題はクリア。

% python3 -m venv ~/zephyrproject/.venv
% source ~/zephyrproject/.venv/bin/activate
(.venv) nameXYZ@hostName ~ %

続く

上記サイトに従って進める。

(.venv) nameXYZ@hostName ~ % pip install west
<略>

Successfully installed PyYAML-6.0.3 colorama-0.4.6 docopt-0.6.2 packaging-26.2 pykwalify-1.8.0 python-dateutil-2.9.0.post0 ruamel.yaml-0.19.1 six-1.17.0 west-1.5.0

(.venv) nameXYZ@hostName ~ % west init ~/zephyrproject
<略>

=== Initialized. Now run "west update" inside /Users/nameXYZ/zephyrproject.

(.venv) nameXYZ@hostName ~ % cd ~/zephyrproject
(.venv) nameXYZ@hostName zephyrproject % west update
<略>

(.venv) nameXYZ@hostName zephyrproject % west zephyr-export
<略>

ZephyrUnittest (/Users/nameXYZ/zephyrproject/zephyr/share/zephyrunittest-package/cmake)
has been added to the user package registry in:
~/.cmake/packages/ZephyrUnittest

(.venv) nameXYZ@hostName zephyrproject % west packages pip --install
<略>

xmltodict-1.0.4 yamllint-1.38.0 zipp-3.23.1

(.venv) nameXYZ@hostName zephyrproject % cd ~/zephyrproject/zephyr
(.venv) nameXYZ@hostName zephyr % west sdk install
<略>

All done.

サンプルプログラム実行

つまづき2&書き込み成功まで

「Hello World」を表示するサンプルプログラムを試す。まずは、Build実行。下記「samples/hello_world」がプロジェクト名のようなもの。

(.venv) nameXYZ@hostName zephyr % west build -b frdm_mcxa153 samples/hello_world
<略>

[157/157] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       17600 B       128 KB     13.43%
             RAM:        3928 B        24 KB     15.98%
        IDT_LIST:           0 B        32 KB      0.00%
Generating files from /Users/nameXYZ/zephyrproject/zephyr/build/zephyr/zephyr.elf for board: frdm_mcxa153/mcxa153

Buildは成功。順番が前後したが、ソースコードは下記。

#include <stdio.h>

int main(void)
{
	printf("Hello World! %s\n", CONFIG_BOARD_TARGET);

	return 0;
}

次に、ボード(FRDM-MCXA153)に書き込み。

(.venv) nameXYZ@hostName zephyr % west flash -r jlink
<略>

FATAL ERROR: command exited with status 1: /Applications/SEGGER/JLink_V844/JLinkExe -nogui 1 -if swd -speed auto -device MCXA153 -CommanderScript /var/folders/2j/jgw8jvys6bl19bfyg1cy0v080000gn/T/tmpwdq0dchdjlink/runner.jlink -nogui 1

エラーが出る。AI曰く、Segger J-Linkがボードを認識しているか確認する。

(.venv) nameXYZ@hostName zephyr % /Applications/SEGGER/JLink_V844/JLinkExe -device MCXA153 -if SWD -speed 4000
SEGGER J-Link Commander V8.44 (Compiled Jun 18 2025 12:19:16)
DLL version V8.44, compiled Jun 18 2025 12:18:28

Connecting to J-Link via USB...FAILED: Cannot connect to J-Link.
J-Link>

(.venv) nameXYZ@hostName zephyr % west flash -r linkserver
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner linkserver
RUNNER - gdb_port = 3333, semih port = 8888
FATAL ERROR: required program LinkServer not found; install it or add its location to PATH

認識していない様子。NXP純正のLinkServerを使えと言われる。インストール&PATH追加。

(.venv) nameXYZ@hostName zephyr % brew install --cask linkserver
(.venv) nameXYZ@hostName zephyr % export PATH=$PATH:/Applications/LinkServer_25.6.131

再度書き込み実施。

(.venv) nameXYZ@hostName zephyr % west flash -r linkserver
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner linkserver
RUNNER - gdb_port = 3333, semih port = 8888
-- runners.linkserver: LinkServer: /Applications/LinkServer_25.6.131/LinkServer, version v25.6.131
INFO: Exact match for MCXA153:FRDM-MCXA153 found
INFO: Selected device MCXA153:FRDM-MCXA153
INFO: Getting available probes
INFO: Selecting probe by index
INFO: Selected probe #1 SZ3X55WUG2CLX (MCU-LINK FRDM-MCXA153 (r0E7) CMSIS-DAP V3.128)
INFO: MCU-Link firmware update `check`: Probe ([SZ3X55WUG2CLX] [MCU-LINK FRDM-MCXA153 (r0E7) CMSIS-DAP V3.128]) is running a firmware version which is older than the included firmware version [3.160]
INFO: Selected device matches probe's target identification info

一度成功すれば、その後は、「west flash」のみで十分のようだ。

実行

screenコマンドで、ボードにアクセスする。シリアルデバイス名(/dev/tty.usbmodemなにがし)は適宜確認。

(.venv) nameXYZ@hostName zephyr % screen /dev/tty.usbmodemSZ3X44WUG2WWW3 115200

*** Booting Zephyr OS build v4.4.0-1647-g29d97bdaf61b ***
Hello World! frdm_mcxa153/mcxa153

成功。

ついでに別ボード(M5Stack)をトライ

Build&書き込み

初代M5Stack(ESP32搭載)で同じ内容を実施する。まずは、ボード名を調べる。

(.venv) nameXYZ@Obidos zephyr % west boards | wc -l
    1027

相当数あり、ESP32でも多数見つかる。トライ&エラー及びAIさんに聞いたところ、「esp32_devkitc/esp32/procpu」と指定するとのこと。

(.venv) nameXYZ@hostName zephyr % west build -p -b esp32_devkitc/esp32/procpu samples/hello_world

すでに一度Buildしたのであれば、「-p」オプションが必要(「build」ディレクトリ以下をクリアするらしい)。書き込み実施。

(.venv) nameXYZ@hostName zephyr % west flash
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner esp32
-- runners.esp32: reset after flashing requested
-- runners.esp32: Flashing esp32 chip on None (921600bps)
esptool v5.2.0
Connected to ESP32 on /dev/cu.usbserial-0x7Dyy52:
Chip type:          ESP32-D0WDQ6 (revision v1.0)
Features:           Wi-Fi, BT, Dual Core + LP Core, 240MHz, Vref calibration in eFuse, Coding Scheme None
Crystal frequency:  40MHz
MAC:                84:0d:8e:25:c3:40

Stub flasher running.
Changing baud rate to 921600...
Changed.

Configuring flash size...
Flash will be erased from 0x00001000 to 0x0002ffff...
Wrote 192512 bytes at 0x00001000 in 3.1 seconds (502.7 kbit/s).
Hash of data verified.

Hard resetting via RTS pin...

自動的に組み込まれた「esptool」で書き込みを行っている。なお、シリアルデバイスは、「/dev/cu.usbserial-なにがし」となるようだ。

実行(トライ&エラー)

(.venv) undeux3@Obidos zephyr % screen /dev/tty.usbserial-017D1D52 115200

I (soc_init): ESP Simple boot
I (soc_init): compile time May  3 2026 09:09:53
W (soc_init): Unicore bootloader
I (soc_init): chip revision: v1.0
E (soc_init): You are using ESP32 chip revision (1) that is unsupported. While it may work, it could cause unexpected behavior or issues.
E (soc_init): Proceeding with this ESP32 chip revision is not recommended unless you fully understand the potential risk and limitations.
E (soc_init): If you choose to continue, please enable 'CONFIG_ESP32_USE_UNSUPPORTED_REVISION=y' in your project configuration.

「Hello World」が表示されず。よく見ると「CONFIG_ESP32_USE_UNSUPPORTED_REVISION=y」が必要とのこと。そこで、「prj.conf」にて、それを記述。

zephyr/samples/hello_world/prj.conf
CONFIG_ESP32_USE_UNSUPPORTED_REVISION=y

再度build&書き込み実施。

(.venv) nameXYZ@Obidos zephyr % west build -p -b esp32_devkitc/esp32/procpu samples/hello_world
(.venv) nameXYZ@Obidos zephyr % west flash

再実行。

(.venv) nameXYZ@Obidos zephyr % screen /dev/tty.usbserial-0x7WWD52 115200

I (soc_init): ESP Simple boot
I (soc_init): compile time May  3 2026 09:14:40
W (soc_init): Unicore bootloader
I (soc_init): chip revision: v1.0
E (soc_init): You are using ESP32 chip revision (1) that is unsupported. While it may work, it could cause unexpected behavior or issues.
E (soc_init): Proceeding with this ESP32 chip revision is not recommended unless you fully understand the potential risk and limitations.
I (flash_init): SPI Speed      : 40MHz
I (flash_init): SPI Mode       : DIO
I (flash_init): SPI Flash Size : 4MB
I (boot): DRAM  : lma=00001020h vma=3ffb0000h size=01a80h (  6784)
I (boot): IRAM  : lma=00002aa8h vma=40080000h size=07c80h ( 31872)
I (boot): RTC_DATA      : lma=0000a730h vma=50000000h size=00028h (    40)
I (boot): IROM  : lma=00010000h vma=400d0000h size=03134h ( 12596)
I (boot): DROM  : lma=00020000h vma=3f400000h size=10000h ( 65536)
I (boot): libc heap size 180 kB.
I (spi_flash): detected chip: gd
I (spi_flash): flash io: dio
*** Booting Zephyr OS build v4.4.0-1647-g29d97bdaf61b ***
Hello World! esp32_devkitc/esp32/procpu

「Hello World」が表示された。

参考

複数ボードを扱うには、「-d」オプション(オブジェクト生成場所)がおすすめ。

% west build -d build_nxp -b frdm_mcxa153 samples/hello_world
% west flash -d build_nxp

最初がBuild、次が書き込みである。

% west build -d build_m5stack -b esp32_devkitc/esp32/procpu samples/hello_world
% west flash -d build_m5stack

こちらも同様。

EOF

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?