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
- Software Setup
- Building a Classification Project
- Deploying the Model
- MCUXpresso IDE
- Data Logging
- Anomaly Detection
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.
Software Setup
- MCUXpresso IDE v24.12 or later -
An Eclipse-based IDE customized for NXP MCUs.
Download here -
eIQ Toolkit 1.14 -
A complete AI/ML development suite for NXP processors. Avoid installing optional add-ons to keep setup time minimal.
Download the toolkit here - SDK 24.12 for FRDM-MCXN947 -
Includes drivers, middleware, and examples.
Available via NXP's MCUXpresso Github repository, or MCUXpresso SDK portal.
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.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".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.
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.Repeat for other 3 classes. You should see even distribution in the sample chart.
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.
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".
Analyze the accuracy and download the report if you want.
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.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'.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.
You can now build the project, by clicking 'Build' in the Quickstart panel.
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.
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.
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.
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.
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.
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.
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.
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'.
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.In the "Dataset" tab, import both the normal and abnormal training datasets which we collected in the previous section.
In the Training tab, start new training with quick search enabled.
Once the training is finished, go to emulation tab, import both normal and abnormal test data, select PCA model and start "New Emulation".
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.
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.
No comments:
Post a Comment
Comments are moderated and don't be surprised if your comment does not appear promptly.