Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1727,3 +1727,22 @@ jobs:
echo "Neutron backend library not found!"
exit 1
fi

nxp-mcuxpresso-test:
name: nxp-mcuxpresso-test
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
permissions:
id-token: write
contents: read
with:
runner: linux.2xlarge
docker-image: ci-image:executorch-ubuntu-22.04-arm-sdk
submodules: 'recursive'
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
timeout: 90
script: |
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"

./examples/nxp/mcuxpresso/imxrt700/executorch_cifarnet/test_build_from_scratch.sh
139 changes: 139 additions & 0 deletions docs/source/backends/nxp/nxp-mcuxpresso-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Using the MCUXpresso Example

This example demonstrates how to build and run the ExecuTorch CifarNet application for the NXP RT700 platform using the MCUXpresso SDK and the GNU Arm Embedded Toolchain. Before building the project, make sure that all required dependencies are installed and that the necessary environment variables are configured correctly.

> **Tip:** The `test_build_from_scratch.sh` script automates all the steps described in this guide, including downloading the ARM GNU toolchain, preparing the model, and downloading the MCUXpresso SDK using the `west` tool. If you prefer a fully automated setup, you can run it directly instead of following the manual steps below.

All scripts described in this guide are located in the following directory of the ExecuTorch repository:

```text
examples/nxp/mcuxpresso/imxrt700/executorch_cifarnet/
```

## 1. Install the Arm GNU Toolchain

First, download the Arm GCC cross-compilation toolchain that is supported by the RT700 platform:

```text
https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi.tar.xz
```

After extracting the archive, create an environment variable called `ARMGCC_DIR` that points to the root directory of the toolchain installation. The build scripts use this variable to locate the compiler, linker, and other required tools.

Example on Linux:

```bash
export ARMGCC_DIR=/path/to/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi
```

To verify the installation, you can run:

```bash
$ARMGCC_DIR/bin/arm-none-eabi-gcc --version
```

The command should print the installed compiler version.

## 2. Download the MCUXpresso SDK
Comment thread
jirioc marked this conversation as resolved.

Next, download MCUXpresso SDK for the RT700 device family using the west tool:

```bash
pip install west
west init -m https://github.com/nxp-mcuxpresso/mcuxsdk-manifests.git mcuxpresso-sdk
pushd mcuxpresso-sdk
west update_board --set board mimxrt700evk
popd
```

Afterwards, configure the `SdkRootDirPath` environment variable to point to the mcuxsdk directory in the downloaded dir.

Example on Linux:

```bash
export SdkRootDirPath=/path/to/mcuxpresso-sdk/mcuxsdk
```

The build system relies on this variable to locate board support packages, middleware components, startup code, linker scripts, and device-specific libraries.

## 3. Prepare the Model Header File

Before building the application, a compiled model must be provided as a C header file named `model_pte.h` and placed in the current directory. Run the provided helper script to generate it:

```bash
./prepare_model.sh
```

The script performs the following steps:

1. Installs ExecuTorch and its Python dependencies.
2. Installs the `eiq-neutron-sdk` Python package in the version that has been tested with the current ExecuTorch release.
3. Compiles the CifarNet model using the NXP ExecuTorch ahead-of-time (AoT) pipeline and produces a `.pte` model file.
4. Converts the `.pte` file into the `model_pte.h` C header, with the correct memory-section attributes for the RT700 target.

> **Important:** The MCUXpresso SDK package includes a pre-built CifarNet model and a set of Neutron libraries, but this build flow deliberately does **not** use either of them. Instead, `prepare_model.sh` installs the `eiq-neutron-sdk` version that was tested with the current ExecuTorch release, compiles the model from scratch, and the linker later picks up the matching Neutron libraries from that same installation. This keeps the ExecuTorch AoT compiler, the model bytecode, the Neutron driver, the Neutron firmware, and the ExecuTorch runtime all in sync.

Once the script finishes, verify that `model_pte.h` was created in the project directory before proceeding to the build step.

## 4. Build the Application

Once the environment variables have been configured and `model_pte.h` is present in the project directory, set the `NEUTRON_LIB_DIR` variable to the directory that contains the Neutron static libraries shipped with the eiq-neutron-sdk:

```bash
export NEUTRON_LIB_DIR=/path/to/eiq_neutron_sdk/libs
```

The build script expects the following libraries to exist in that directory:

- `libNeutronDriver.a`
- `libNeutronFirmware.a`

Then build the project by executing the provided script:

```bash
./build_example.sh
```

The script validates all required inputs, configures CMake, compiles the source code, links the application, and generates the executable image:

```text
flash_release/executorch_cifarnet.elf
```

If the build completes successfully, the ELF file will be available and ready for programming onto the target board.

## 5. Flash the Application

The generated application can be programmed onto the RT700 device using SEGGER J-Link tools.

### Linux

```bash
echo "loadfile flash_release/executorch_cifarnet.elf" | \
/opt/SEGGER/JLink_V796k/JLinkExe \
-IF SWD \
-speed auto \
-Device MIMXRT798S_M33_0
```

Before flashing, ensure that:
Comment thread
jirioc marked this conversation as resolved.

- The board is powered on.
- The JLink debugger probe is flashed on device, if not see [documentation](https://mcuxpresso.nxp.com/mcuxsdk/latest/html/boards/RT/mimxrt700evk/gettingStartedXplorer/topics/program_lpc-link2_with_segger_j-link.html) how to flash it.
- The J-Link debugger is connected to the target.
- The SWD interface is available and correctly wired.
- No other debugging application is currently using the J-Link connection.

The programming process typically takes only a few seconds. Once the image has been loaded successfully, the application can be started directly from flash memory.

## 6. Running the Example

After the firmware is programmed, reset the board and open a serial terminal connected to the device's debug UART interface. The application will initialize the hardware, load the embedded CifarNet model, and begin performing image inference.

During execution, inference results and diagnostic messages are printed to the terminal. The included demonstration image contains a cat, and the model is expected to classify the image accordingly.

A successful run produces output similar to the following:

![example](terminal.png "Example")

This example serves as a basic validation that the ExecuTorch runtime, model integration, SDK configuration, and hardware platform are all functioning correctly. It can also be used as a starting point for evaluating custom neural network models and experimenting with on-device machine learning workloads on the RT700 platform.
5 changes: 5 additions & 0 deletions docs/source/backends/nxp/nxp-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ For more finegrained tutorial, visit [this manual page](https://mcuxpresso.nxp.c
For guideline how to update the eIQ Neutron Runtime on MCUXpresso SDK, follow the instructions from the eIQ Neutron SDK package `docs/NeutronSDKUserGuide.md` available
here https://www.nxp.com/design/design-center/software/eiq-ai-development-environment/eiq-toolkit-for-end-to-end-model-development-and-deployment:EIQ-TOOLKIT.

## Using the MCUXpresso Example

[This page](nxp-mcuxpresso-example.md) demonstrates how to build and run the ExecuTorch CIFARNet example from MCUXpresso SDK.


## Reference

**→{doc}`nxp-partitioner` — Partitioner options.**
Expand Down
Binary file added docs/source/backends/nxp/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 144 additions & 0 deletions examples/nxp/mcuxpresso/imxrt700/executorch_cifarnet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright 2026 NXP
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.24)

set(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
set(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)

# CURRENT DIRECTORY
set(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE})

# Skip link step during compiler check (bare-metal cross-compilation).
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

project(executorch_cifarnet)

enable_language(ASM)

set(MCUX_SDK_PROJECT_NAME executorch_cifarnet.elf)

set(EXECUTORCH_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)

# CPU and FPU flags required for Cortex-M33 with single-precision FPU.
set(CPU_FLAGS "-mcpu=cortex-m33 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16")
set(CPU_DEFINES
"-DCPU_MIMXRT798SGFOA_cm33_core0 -DCPU_MIMXRT798SGFOB_cm33_core0 \
-DMIMXRT798S_cm33_core0_SERIES -DMCUXPRESSO_SDK \
-D__STARTUP_INITIALIZE_NONCACHEDATA -D__STARTUP_CLEAR_BSS \
-DDSP_IMAGE_COPY_TO_RAM=1 -DBOOT_HEADER_ENABLE=1 \
-DEIQ_EXAMPLE_HSRUN_CLOCK -DMCUX_META_BUILD \
-DPRINTF_ADVANCED_ENABLE=1 -DPRINTF_FLOAT_ENABLE=1 -DNO_HEAP_USAGE=1 \
-DSDK_DEBUGCONSOLE=1 -DSDK_I2C_BASED_COMPONENT_USED=1"
)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} ${CPU_FLAGS} ${CPU_DEFINES} -fno-common -ffunction-sections -fdata-sections -fno-builtin -mapcs -std=gnu99"
)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${CPU_FLAGS} ${CPU_DEFINES} -fno-common -ffunction-sections -fdata-sections -fno-builtin -mapcs -fno-rtti -fno-exceptions"
)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CPU_FLAGS} ${CPU_DEFINES}")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} ${CPU_FLAGS} -fno-common -ffunction-sections -fdata-sections -fno-builtin -mapcs -Wl,--gc-sections -Wl,-static -specs=nano.specs -specs=nosys.specs -T\"${SdkRootDirPath}/examples/_boards/mimxrt700evk/eiq_examples/executorch_cifarnet/cm33_core0/gcc/MIMXRT798Sxxxx_cm33_core0_flash.ld\" -static"
)

add_executable(
${MCUX_SDK_PROJECT_NAME}
${SdkRootDirPath}/examples/_boards/mimxrt700evk/flash_config/flash_config.c
${SdkRootDirPath}/examples/_boards/mimxrt700evk/eiq_examples/executorch_cifarnet/cm33_core0/hardware_init.c
${SdkRootDirPath}/examples/_boards/mimxrt700evk/eiq_examples/executorch_cifarnet/cm33_core0/pin_mux.c
${SdkRootDirPath}/examples/_boards/mimxrt700evk/board.c
${SdkRootDirPath}/examples/_boards/mimxrt700evk/pmic_support.c
${SdkRootDirPath}/examples/_boards/mimxrt700evk/common/clock/cm33_core0/clock_config.c
${SdkRootDirPath}/examples/eiq_examples/executorch_cifarnet/main.cpp
${SdkRootDirPath}/examples/eiq_examples/executorch_cifarnet/RegisterKernels.cpp
${SdkRootDirPath}/examples/eiq_examples/common/timer.c
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/startup_MIMXRT798S_cm33_core0.c
${EXECUTORCH_ROOT_DIR}/backends/nxp/runtime/NeutronBackend.cpp
${SdkRootDirPath}/middleware/tfm/tf-m/platform/ext/common/syscalls_stub.c
# Device-level drivers (clock, power, reset, system init).
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/drivers/fsl_clock.c
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/drivers/fsl_power.c
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/drivers/fsl_reset.c
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/system_MIMXRT798S_cm33_core0.c
# Common ARM driver (provides SDK_DelayAtLeastUs).
${SdkRootDirPath}/drivers/common/fsl_common_arm.c
# Peripheral drivers.
${SdkRootDirPath}/drivers/cache/xcache/fsl_cache.c
${SdkRootDirPath}/drivers/lpflexcomm/fsl_lpflexcomm.c
${SdkRootDirPath}/drivers/lpflexcomm/lpi2c/fsl_lpi2c.c
${SdkRootDirPath}/drivers/lpflexcomm/lpuart/fsl_lpuart.c
${SdkRootDirPath}/drivers/gpio/fsl_gpio.c
${SdkRootDirPath}/drivers/glikey/fsl_glikey.c
# UART HAL adapter (provides HAL_UartInit etc.).
${SdkRootDirPath}/components/uart/fsl_adapter_lpuart.c
# PMIC driver.
${SdkRootDirPath}/components/pmic/pca9422/fsl_pca9422.c
# Debug console (provides DbgConsole_Init/Printf).
${SdkRootDirPath}/components/debug_console_lite/fsl_debug_console.c
)

target_include_directories(
${MCUX_SDK_PROJECT_NAME}
PRIVATE
${MODEL_DIR}
${SdkRootDirPath}/arch/arm/CMSIS/Core/Include
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/cm33_core0
${SdkRootDirPath}/devices/RT/RT700/MIMXRT798S/drivers
${SdkRootDirPath}/devices/RT/RT700/periph
${SdkRootDirPath}/drivers/common
${SdkRootDirPath}/components/pmic/pca9422
${SdkRootDirPath}/components/uart
${SdkRootDirPath}/components/debug_console_lite
${SdkRootDirPath}/examples/_boards/mimxrt700evk
${SdkRootDirPath}/examples/_boards/mimxrt700evk/flash_config
${SdkRootDirPath}/examples/_boards/mimxrt700evk/eiq_examples/executorch_cifarnet/cm33_core0
${SdkRootDirPath}/examples/_boards/mimxrt700evk/common/clock/cm33_core0
${SdkRootDirPath}/examples/eiq_examples/executorch_cifarnet
${SdkRootDirPath}/examples/eiq_examples/common
${SdkRootDirPath}/examples/_boards/mimxrt700evk/eiq_examples/executorch_cifarnet/npu
${SdkRootDirPath}/drivers/cache/xcache
${SdkRootDirPath}/drivers/gpio
${SdkRootDirPath}/drivers/lpflexcomm
${SdkRootDirPath}/drivers/lpflexcomm/lpuart
${SdkRootDirPath}/drivers/lpflexcomm/lpi2c
${SdkRootDirPath}/drivers/xspi
${SdkRootDirPath}/drivers/reset
${SdkRootDirPath}/drivers/clock
${SdkRootDirPath}/drivers/glikey
${SdkRootDirPath}/drivers/mu1
${SdkRootDirPath}/drivers/power
${SdkRootDirPath}/drivers/iopctl
${SdkRootDirPath}/components/str
)

set(EXECUTORCH_BUILD_PYBIND OFF)
set(EXECUTORCH_BUILD_TESTS OFF)
set(EXECUTORCH_BUILD_DEVTOOLS OFF)
set(EXECUTORCH_BUILD_EXECUTOR_RUNNER OFF)
set(EXECUTORCH_BUILD_CPUINFO OFF)
set(EXECUTORCH_BUILD_PTHREADPOOL OFF)
set(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON)
set(EXECUTORCH_BUILD_PORTABLE_OPS ON)
set(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
add_subdirectory(${EXECUTORCH_ROOT_DIR} EXCLUDE_FROM_ALL executorch)

target_link_libraries(
${MCUX_SDK_PROJECT_NAME}
PRIVATE -Wl,--start-group
executorch
executorch_core
extension_runner_util
quantized_kernels
portable_kernels
${NEUTRON_LIB_DIR}/libNeutronDriver.a
${NEUTRON_LIB_DIR}/libNeutronFirmware.a
-Wl,--end-group
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# Copyright 2026 NXP
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

if [ -z ${ARMGCC_DIR+x} ]; then
echo "ARMGCC_DIR needs to be set in the environment!"
exit 1;
fi

if [ -z ${SdkRootDirPath+x} ]; then
echo "SdkRootDirPath needs to be set in the environment!"
exit 1;
fi

if [ ! -f model_pte.h ]; then
echo "Cannot find model_pte.h!"
exit 1;
fi

if [ -z ${NEUTRON_LIB_DIR+x} ]; then
echo "NEUTRON_LIB_DIR needs to be set in the environment!"
exit 1;
fi

if [ ! -f ${NEUTRON_LIB_DIR}/libNeutronDriver.a ]; then
echo "Neutron driver not found in ${NEUTRON_LIB_DIR}!"
exit 1;
fi

if [ ! -f ${NEUTRON_LIB_DIR}/libNeutronFirmware.a ]; then
echo "Neutron firmware not found in ${NEUTRON_LIB_DIR}!"
exit 1;
fi

rm -rf cmake-out && mkdir -p cmake-out

cmake -DSdkRootDirPath=${SdkRootDirPath} \
-DCMAKE_TOOLCHAIN_FILE=${SdkRootDirPath}/cmake/toolchain/armgcc.cmake \
-DMODEL_DIR=$(pwd) \
-DNEUTRON_LIB_DIR=${NEUTRON_LIB_DIR} \
-DCMAKE_BUILD_TYPE=flash_release \
-G "Unix Makefiles" \
-B cmake-out \
"$(dirname "$0")"

make -C cmake-out -j$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu) + 1 )) executorch_cifarnet.elf
Loading
Loading