Industry

Edge AI: smart sensor on a microcontroller with integrated NPU

NXP Semiconductors · Internship · M1 · May – Sept. 2024

Full Edge AI pipeline: SPI accelerometer acquisition, dataset generation, Conv1D CNN training, INT8 quantization, deployment on NXP Neutron NPU — ×42 speedup on int8 Conv1D operations.

99.3%
Accuracy
×42
NPU speedup
131 kB
Peak RAM

01Context

Project carried out during my internship at NXP Semiconductors, in connection with ENSEEIHT. Goal: demonstrate a complete Edge AI pipeline on a microcontroller with an integrated NPU (FRDM-MCXN947 board), documented well enough to be reused as lab material.

02Technical pipeline

  1. FXLS8974 via SPI
  2. C state machine
  3. CSV dataset (UART)
  4. Conv1D CNN (GPU)
  5. PTQ INT8
  6. Neutron NPU eIQ

03What I did

  1. Hardware configuration on MCXN947: SPI master (non-blocking LPSPI), GPIO, timer, UART via NXP SDK.

  2. C state machine (INIT→ACQUIRE→SAVE→SEND) synchronized on FXLS8974 INT1. Two’s complement reading via non-blocking SPI, decimal conversion. Python UART→CSV script with regex parsing.

  3. Manual dataset collection: gestures (digits 0–9), organized by class for supervised training.

  4. Conv1D CNN design and training (3 conv layers, BatchNorm, Dropout, AveragePooling, Dense — 13,010 parameters). GPU training with EarlyStopping + ReduceLROnPlateau. Accuracy 99.3%.

  5. PTQ int8 quantization with representative dataset, float32→int8 conversion, post-quantization evaluation. Memory estimation via tflite-tools (peak: 131,440 bytes).

  6. NPU deployment: conversion via eIQ Portal (Neutron Converter), mandatory Softmax layer removal (tflite-extractor). C++ MCU integration: .tflite as .rodata, MicroMutableOpResolver, scale/zero-point adjustment.

  7. Wrote the 37-page technical deployment guide, reused as the reference document.

04Measured results

99.3%
CNN accuracy
×42
NPU vs CPU speedup
131 kB
Estimated peak RAM
256 kB
Allocated RAM (margin)
13,010
Model parameters
10 classes
Classified gestures

05Challenges

  • Toolchain compatibility: GNU ARM v12.3 required (v13.2 NPU-incompatible)
  • NPU supports int8 PCQ only: mandatory Softmax removal via tflite-extractor
  • Peak RAM empirically unpredictable (131 kB estimated → 256 kB allocated for safety)
  • MCU debugging: JSON probe errors, serial port conflicts, INT1 accelerometer sync

Want to talk it through?

Happy to go into the technical choices, the measurements and what I would do differently.

Get in touch