Thursday, June 5, 2025

Exploring Edge AI with NXP's FRDM-MCXN947

I recently attended NXP technology day in Auckland, where the latest innovations from NXP were showcased - including their microcontrollers, i.MX microprocessors, and other advanced semiconductor technologies. NXP, a leading Dutch semiconductor company, designs and manufactures a wide array of products for automotive, industrial, and IoT applications. Among their latest developments is the MCX series of microcontrollers, which unifies the legacy Philips and Kinetis families into a new, modern MCU architecture.

What particularly caught my attention was the MCXN947 from the MCX N series. This device delivers high performance and low power consumption, while integrating a neural processing unit (NPU) to enable on-device AI processing. As computing increasingly moves to the edge, it's exciting to see compact, energy-efficient hardware like this supporting real-time AI workloads. NXP also hosted a hands-on machine learning session with the MCXN947, which inspired me to explore its potential as an edge AI platform.


Hardware Requirements

  • FRDM-MCXN947 - A development board for MCX N94/N54 MCUs. It features headers for I/O access, serial interfaces, onboard flash memory, and an integrated MCU-Link debugger. Additional resources such as expansion board support and software examples are also available.
  • Accel 4 Click by Mikroe - A three-axis acceleration sensor add-on board from Mikroe, featuring the FXLS8974CF accelerometer with selectable ranges (±2g to ±16g) and support for SPI/I2C communication.


MCXN947 development board equipped with the Accel 4 Click add-on board.
Figure 1. FRDM-MCXN947 with Accel 4 Click attached.


Software Setup

Import the SDK by dragging the ZIP into the "Installed SDKs" section of MCUXpresso IDE.

Building a Classification Project


1. Launch Time Series Studio (TSS)

Open eIQ Toolkit and click on "TIME SERIES" to launch Time Series Studio (TSS). Keep the eIQ Portal open in the background to prevent errors. You will see some example applications on the TSS home screen. Choose the 'Classification' tab, under the "Fan State Monitoring Application", click "More" to explore instructions and overview.


Figure 2. Fan State Monitoring in TSS.



2. Download Sample Dataset

Click the Dataset button in Fan State Monitoring to download the sample data. Extract it from:
C:\Users\[username]\AppData\Roaming\time_series_studio\sample_dataset 

3. Create the Project

Click "Classification" on the left panel, and, in the project tab, click "Create New Project".


Figure 3. Creating a new classification project in TSS.


Use default project name or enter a custom project name. Use FRDM-MCXN947 as the target board. Set the number of channels to 3 (3-axis accelerometer). Use 4 classes for training data (on, off, clog, and friction). We can leave default values for max RAM and max Flash as the library will be typically small and we don't need to limit them. Finally, click "Confirm and Create" button.


Figure 4. Setting up classification project in TSS.



4. Train and Validate

Now, select "Dataset" tab at the top, then click '+' sign for the first class to import training data. Navigate to the training data set we just extracted and select one of the CSV files. Make sure that the delimiter is 'Space'. After that, you can edit the Class name also.


Figure 5. Loading dataset.


Repeat for other 3 classes. You should see even distribution in the sample chart.


Figure 6. After loading all four classes.


Go to training tab at the top, click "Start New Training", and turn on "Quick Search" to reduce the search time and use the default ratio for train/validation before clicking "Start". After training, review RAM, flash usage, and the confusion matrix.


Figure 7. Training result.


We now can validate the model using test dataset. Select "Emulation" tab, select a model e.g. '37 RForest' and click new emulation. On the pop up window, click select and use respective test dataset file for it. And then click "start".


Figure 8. Emulation of test data.


Analyze the accuracy and download the report if you want.


Figure 9. Emulation report.



Deploying the Model

Choose "Deployment" tab at the top, select the model and toolchain. To generate a complete MCUXpresso IDE project, set "Library/Project" to "Project". Click "Generate" to get the project as a ZIP file.


Figure 10. Generating the full MCUXpresso IDE project.



Importing and Running the Project in MCUXpresso IDE

Open MCUXpresso IDE and select a workspace. Close welcome screen panel. Ensure that you have MCXN947 SDK installed. In the Quickstart Panel, click 'Import project(s) from file system...', and choose the generated zip file in the pop up window. Click 'Next', and 'Finish'.


Figure 11. Importing the project into MCUXpresso IDE.


You can just click OK if you got pop up warning for SDK version. In the project tab, right click on the project and select 'rename' to rename the project as illustrated in the following figure.


Figure 12. Renaming the project.


You can now build the project, by clicking 'Build' in the Quickstart panel.


Figure 13. Building the project.


Connect the board via USB-C (J17 near the reset button SW1). You will see a virtual com port in the Windows device manager. A built-in serial terminal in MCUXpresso can be used to connect it. Go to "Terminal" tab, click on terminal icon near the top right corner. Choose Serial Terminal, and set the baud rate to 115200. And OK to open the terminal. Then, disconnect it by clicking the red N shape "Disconnect Terminal Connection" icon.


Figure 14. Connecting to VCOM.


Click "Debug" in the Quickstart panel, and OK in the pop up dialog for your hardware. MCUXpresso will download the firmware into the board. If you see a dialog to select the primary core, just click OK to use the default device 0. Thereafter, click "Resume" (play button) to run the program.


Figure 15. Running the program.


Select the terminal tab and connect the virtual com port. You can double click on the tab to maximize it. Then enter 'help' to see the list of commands. Stop the debugging by clicking 'Stop' icon.


Figure 16. Using the serial terminal.


The default project uses simulated sensor data. Since we have attached the ACCEL_4_CLICK board, we can modify the project to use real data from the hardware accelerometer. Open hardware.c, comment out the reigster_sensor_hal_dummy lines (line 75 ~ 76), and uncomment register_sensor_hal_FXLS8974 section (line 66 ~ 73) as shown below. Details on how to add your own sensor to the HAL can be found in the README.pdf in the project.


Figure 17. Using the real hardware accelerometer.


Build the project and start the debugging again. Open the terminal. And enter 'start pre' to see the classification results. And you can enter 'stop' to stop it.


Data Logging


In the terminal, use command 'get info' to check the sensor used, output data rate (ODR), sample count (SC), etc.


Figure 18. Get info.


So far, we have used sample data set from TSS. Let us find out how to get and use our own training data set. Enter 'start log' in the terminal to see the sensor data on the terminal. The blue LED on the board will blink. Ensure data keep printing, and disconnect the terminal.


Figure 19. Confirming data logging function.


Go to "Data Logging" in TSS. Select the correct com port and baud rate, then click connect. The number of channel to 3 for x,y, and z axis of the accelerometer. And the classes to 2 (normal and abnormal) for the new abnormality project. Then, click on check mark button on the right. To start with class 1 for normal condition, give 'Normal_train.csv' for filename. And the number of line to 100 for training data. Ensure the board is in stable normal condition and click start to collect normal training data.


Figure 19. Data collection.


Once it is finished, you can see the csv file by clicking 'open saved data set' button. You should keep the Windows explorer open to know the full path of saved files. Follow the same steps with 50 lines for test data, with the file name 'normal_test.csv'.

Then, repeat the procedure for abnormal condition. For that we will softly tap the board with a finger during the data collection so that you can see vibration in the collected data as shown in the following figure. For the training data set, we will use 100 lines for 'abnormal_train.csv' and 50 lines for 'abnormal_test.csv'.


Figure 20. Repeating the collection for abnormal data set.



Anomaly Detection

Click "Amonaly Detection" task in TSS. Create new project, enter project name, set the target to MCXN947, define the number of channel as 3, and click confirm and create.


Figure 21. Creating an anomaly detection project.


In the "Dataset" tab, import both the normal and abnormal training datasets which we collected in the previous section.


Figure 22. Importing datasets.


In the Training tab, start new training with quick search enabled.


Figure 23. Training an anomaly detection model.


Once the training is finished, go to emulation tab, import both normal and abnormal test data, select PCA model and start "New Emulation".


Figure 24. Emulation of the anomaly detection model.


If the model is OK, click on "Deployment" tab, select project option checkbox, and generate the project following the steps similar to the previous example.


Figure 25. Deploying the anomaly detection model.


Open MCUXpresso IDE, and import the generated project using 'Import prorject form file system' in Quickstart panel tab. Please note that if there is another project with the same name you will get issues when importing it. Delete or rename the existing project which has the same name. Once the generated zip file is imported to MCUXpresso IDE, rename this project as MCXN947_anomaly_fan1. Modify hardware.c to use the real hardware accelerometer as mentioned previously. And build the project, connect the board again using USB C cable. Thereafter, click debug to load the firmware and , run the program. Connect to the virtual com port using terminal, and enter "get info" to confirm the sensor information. Now, you can enter "start pre" to start the prediction. You should see normal label when the board is stable and abnormal when you are tapping the board.


Figure 26. Running anomaly detection.





Figure 27. NXP technology day in Auckland.


No comments:

Post a Comment

Comments are moderated and don't be surprised if your comment does not appear promptly.