Skip to content
Open
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
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/model)

# This firmware uses X-Nucleo IKS02A1 shield
set(SHIELD x_nucleo_iks02a1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(ei-zephyr-imu-inference)

include(utils/cmake/utils.cmake)
project(ei-zephyr-mic-kws-inference)

# Needed for colorful output
zephyr_compile_options(-fdiagnostics-color=always)

# Disable warnings as errors for Edge Impulse SDK
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-error=maybe-uninitialized>)

# Project include directories
set(INCLUDES
.
Expand All @@ -26,6 +24,5 @@ include_directories(${INCLUDES})

# add all sources to the project
target_sources(app PRIVATE src/main.cpp)
target_sources(app PRIVATE src/sensors/ei_accelerometer.cpp)
target_sources(app PRIVATE src/sensors/ei_inertial.cpp)
target_sources(app PRIVATE src/sensors/ei_microphone.cpp)
target_sources(app PRIVATE src/inference/inferencing.cpp)
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Edge Impulse IMU Inference on Zephyr
# Edge Impulse Microphone Inference on Zephyr

This repository demonstrates how to run IMU-based Edge Impulse models on Zephyr using the **Edge Impulse Zephyr Module**.
Drop in your model > build > flash > get real-time motion inference.
This repository demonstrates how to run microphone-based Edge Impulse models on Zephyr using the **Edge Impulse Zephyr Module**.
Drop in your model > build > flash > get real-time audio inference.

## Initialize This Repo

```bash
west init https://github.com/edgeimpulse/ei-zephyr-imu-inference.git
cd ei-zephyr-imu-inference
west init https://github.com/edgeimpulse/ei-zephyr-mic-kws-inference.git
cd ei-zephyr-mic-kws-inference
west update
```

Expand Down Expand Up @@ -37,10 +37,10 @@ Your `model/` directory should contain:

## Build

Choose your board (Example: Nucleo U585ZI):
Choose your board (Example: Nordic thingy53):

```bash
west build --pristine -b nucleo_u585zi_q
west build --pristine -b thingy53/nrf5340/cpuapp
```

## Flash
Expand All @@ -57,9 +57,9 @@ west flash --runner nrfjprog
west flash --runner openocd
```

## Sensors Supported
## Microphones Supported

All sensors accessible through I²C/SPI + Zephyr sensor drivers are compatible.
PDM microphones accessible through Zephyr's DMIC driver are compatible.

## Project Structure

Expand All @@ -71,14 +71,14 @@ All sensors accessible through I²C/SPI + Zephyr sensor drivers are compatible.
└── src/
├── main.cpp
├── inference/ # Inference state machine
└── sensors/ # IMU interface
└── microphone/ # Microphone interface
```

## How It Works

1. **Initialize** - Sensor setup via Zephyr sensor API
2. **Sample** - Continuous data collection at model frequency
3. **Buffer** - Circular buffer stores samples
1. **Initialize** - Microphone setup via Zephyr DMIC API
2. **Sample** - Continuous audio data collection at model frequency
3. **Buffer** - Circular buffer stores audio samples
4. **Infer** - Run classifier when buffer full
5. **Output** - Print classification results
6. **Loop** - Repeat
Expand All @@ -88,10 +88,9 @@ All sensors accessible through I²C/SPI + Zephyr sensor drivers are compatible.
Key settings in `prj.conf`:

```properties
CONFIG_EDGE_IMPULSE_SDK=y # Enable Edge Impulse SDK
CONFIG_MAIN_STACK_SIZE=8192 # Adjust for your model size
CONFIG_SENSOR=y # Enable sensor subsystem
CONFIG_I2C=y # Enable I2C for sensors
CONFIG_AUDIO=y # Enable audio subsystem
CONFIG_AUDIO_DMIC=y # Enable DMIC for PDM microphones
```

For larger models, increase stack size:
Expand Down
20 changes: 20 additions & 0 deletions boards/thingy53_nrf5340_cpuapp.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2025 EdgeImpulse Inc.
* SPDX-License-Identifier: BSD-3-Clause
*/

&pinctrl {
pdm0_default: pdm0_default {
group1 {
psels = <NRF_PSEL(PDM_CLK, 0, 25)>,
<NRF_PSEL(PDM_DIN, 0, 26)>;
};
};
};

&pdm0 {
status = "okay";
pinctrl-0 = <&pdm0_default>;
pinctrl-names = "default";
clock-source = "PCLK32M_HFXO";
};
8 changes: 4 additions & 4 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ CONFIG_EDGE_IMPULSE_SDK=y

# Audio/PDM support
#CONFIG_I2S=y
#CONFIG_AUDIO=y
#CONFIG_AUDIO_DMIC=y
CONFIG_AUDIO=y
CONFIG_AUDIO_DMIC=y

# Sensors on X-Nucleo IKS02A1
CONFIG_I2C=y
CONFIG_SENSOR=y
#CONFIG_I2C=y
#CONFIG_SENSOR=y
5 changes: 2 additions & 3 deletions src/inference/inferencing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
#include "inference/inferencing.h"
#include "edge-impulse-sdk/classifier/ei_run_classifier.h"
#include "edge-impulse-sdk/dsp/numpy.hpp"
#include "sensors/ei_accelerometer.h"
#include "sensors/ei_inertial.h"
#include "sensors/ei_microphone.h"

static bool ei_run_inference(void);
static bool ei_start_impulse(void);
Expand Down Expand Up @@ -91,7 +90,7 @@ bool ei_inference_sm(void)
while(INFERENCE_STATE_STOP != state) {
switch(state){
case INFERENCE_STATE_SAMPLING:
ei_fusion_accelerometer_read_data(3);
ei_microphone_sample();
ei_sleep(EI_CLASSIFIER_INTERVAL_MS);
// wait for data
break;
Expand Down
6 changes: 2 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
*/

#include <zephyr/kernel.h>
#include "sensors/ei_accelerometer.h"
#include "sensors/ei_inertial.h"
#include "sensors/ei_microphone.h"
#include "inference/inferencing.h"
#include <stdio.h>

Expand All @@ -45,8 +44,7 @@ int main(void)
// This is needed so that output of printf is output immediately without buffering
setvbuf(stdout, NULL, _IONBF, 0);

ei_inertial_init();
ei_accelerometer_init();
ei_microphone_init();

ei_inference_sm(); // run state machine

Expand Down
101 changes: 0 additions & 101 deletions src/sensors/ei_accelerometer.cpp

This file was deleted.

Loading