使用 Zephyr RTOS 在 NXP FRDM-MCXN236 開發板上進行嵌入式開發實作

文章簡介

本文將說明如何在 Linux 主機上,於價格實惠且功能強大的 NXP FRDM-MCXN236 開發板上執行 Zephyr RTOS。透過實際範例,包含 Hello World、LED 閃爍 (Blinky) 以及執行緒同步 (Synchronization) 範例,快速驗證 Zephyr RTOS 在 FRDM-MCXN236 平台上的開發流程。

NXP FRDM-MCXN236 開發板簡介

NXP FRDM-MCXN236 開發板 搭載 32-bit Arm Cortex-M33 微控制器,適用於工業與消費級物聯網(IoT)應用。

FRDM-MCXN236 開發板方塊圖如下:

安裝 NXP LinkServer

完成 Zephyr 開發環境安裝後(安裝方式可參考前述 Zephyr Linux 安裝文章),接著需從 NXP 官方網站下載並安裝 LinkServer:

LinkServer 將用於後續燒錄(Flash)流程。

安裝完成後,可透過以下指令確認版本:

DigiKey_Coffee_Cup: /usr/local/LinkServer/LinkServer --version
ls (uutils coreutils) 0.8.0

驗證開發板連線

使用隨附 USB 線將開發板透過 J10 USB 埠連接至主機後,執行:

DigiKey_Coffee_Cup: /zephyrproject/zephyr$ LinkServer probes
  #  Description                                    Serial         Device    Board         Capabilities
---  ---------------------------------------------  -------------  --------  ------------  ----------------
  1  MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146  NTHJHYIGWSDV5  MCXN236   FRDM-MCXN236  DEBUG, VCOM, SIO

修改 Hello World 範例

編輯 samples/hello_world/src/main.c

修改內容如下:

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>

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

        return 0;
}


建置 Hello World

於 Python Virtual Environment 中執行,及建置完成後可看到:

(venv) DigiKey_Coffee_Cup: /zephyrproject/zephyr/ west build -b frdm_mcxn236 samples/hello_world

...
...

 v4.4.0-8487-g17939cff6553
[168/168] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       27504 B         1 MB      2.62%
             RAM:        4328 B       192 KB      2.20%
           SRAM1:           0 B        96 KB      0.00%
        IDT_LIST:           0 B        32 KB      0.00%

燒錄 Hello World

開啟新的終端機並啟動 minicom。

接著執行,及輸出內容如下:

(venv) DigiKey_Coffee_Cup: /zephyrproject/zephyr$ west flash
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner linkserver
RUNNER - gdb_port = 3333, semih port = 8888
LinkServer: /usr/local/LinkServer/LinkServer, version v26.6.137
INFO: Exact match for MCXN236:FRDM-MCXN236 found
INFO: Selected device MCXN236:FRDM-MCXN236
INFO: Selected probe #1 NTHJHYIGWSDV5 (MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146)
INFO: MCU-Link firmware update `check`: Probe ([NTHJHYIGWSDV5] [MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146]) is running a firmware version which is older than the included firmware version [3.172]
INFO: Selected device matches probe's target identification info

minicom 顯示:

Welcome to minicom 2.10

OPTIONS: I18n 
Port /dev/ttyACM0, 08:34:37 [U]

Press CTRL-A Z for help on special keys
                                                        
*** Booting Zephyr OS build v4.4.0-8487-g17939cff6553 ***
DigiKey_Coffee_Cup Hello World! frdm_mcxn236/mcxn236                  
                                                       

建置與執行 Blinky 範例

建置 LED 範例:

(venv) DigiKey_Coffee_Cup: west build -b frdm_mcxn236 samples/basic/blinky
...
...

[168/168] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       27580 B         1 MB      2.63%
             RAM:        4328 B       192 KB      2.20%
           SRAM1:           0 B        96 KB      0.00%
        IDT_LIST:           0 B        32 KB      0.00%

編譯完成後執行:

(venv) DigiKey_Coffee_Cup: west flash
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner linkserver
RUNNER - gdb_port = 3333, semih port = 8888
LinkServer: /usr/local/LinkServer/LinkServer, version v26.6.137
INFO: Exact match for MCXN236:FRDM-MCXN236 found
INFO: Selected device MCXN236:FRDM-MCXN236
INFO: Selected probe #1 NTHJHYIGWSDV5 (MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146)
INFO: MCU-Link firmware update `check`: Probe ([NTHJHYIGWSDV5] [MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146]) is running a firmware version which is older than the included firmware version [3.172]
INFO: Selected device matches probe's target identification info

minicom 顯示:

*** Booting Zephyr OS build v4.4.0-8487-g17939cff6553 ***
LED state: OFF
LED state: ON
LED state: OFF
LED state: ON
LED state: OFF
LED state: ON
LED state: OFF
LED state: ON

...
...


以下影片顯示 NXP FRDM-MCXN236 開發板 RGB LED 的 Zephyr Blinky 範例執行情況。

建置與執行 Synchronization 範例

建置 Synchronization 範例, 及建置完成後:

(venv) DigiKey_Coffee_Cup: zephyrproject/zephyr$ west build -b frdm_mcxn236 samples/synchronization

...
...
...

[168/168] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       28472 B         1 MB      2.72%
             RAM:        6824 B       192 KB      3.47%
           SRAM1:           0 B        96 KB      0.00%
        IDT_LIST:           0 B        32 KB      0.00%

保持 minicom 開啟並執行:


/zephyrproject/zephyr$ west flash
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner linkserver
RUNNER - gdb_port = 3333, semih port = 8888
LinkServer: /usr/local/LinkServer/LinkServer, version v26.6.137
INFO: Exact match for MCXN236:FRDM-MCXN236 found
INFO: Selected device MCXN236:FRDM-MCXN236
INFO: Selected probe #1 NTHJHYIGWSDV5 (MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146)
INFO: MCU-Link firmware update `check`: Probe ([NTHJHYIGWSDV5] [MCU-LINK FRDM-MCXN236 (r0E7) CMSIS-DAP V3.146]) is running a firmware version which is older than the included firmware version [3.172]
INFO: Selected device matches probe's target identification info

minicom 將顯示:

*** Booting Zephyr OS build v4.4.0-8487-g17939cff6553 ***                                                                                         
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_b: Hello World from cpu 0 on frdm_mcxn236!                                                                                                                                             
thread_a: Hello World from cpu 0 on frdm_mcxn236!    
...
...

此結果顯示 Zephyr Kernel 的排程、通訊與計時機制正常運作。

FRDM-MCXN236 開發板功能

FRDM-MCXN236 是基於 MCX N236 元件設計的低成本開發與評估平台,搭載 Winbond 64 Mbit 外部序列式快閃記憶體。

板載功能包括:

  • High-Speed USB
  • Accelerometer Sensor
  • CAN PHY
  • Audio Codec (DNP)
  • DMIC Sensor
  • RGB LED
  • Push Buttons
  • MCU-Link Debug Probe

此外,開發板亦支援:

以及相容的相機模組與 LCD 模組。

image

image

結語

本文示範如何在 Linux 主機上使用 Zephyr RTOS,並於 NXP FRDM-MCXN236 開發板上執行 Hello World、Blinky 與 Synchronization 範例。

FRDM-MCXN236 是一款精巧且可擴充的開發平台,可用於 MCX N23X MCU 的快速原型開發與評估,並已於 DigiKey 提供相關產品資訊。