Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
janjongboom committed Aug 31, 2021
1 parent b6f4c05 commit a45d67c
Show file tree
Hide file tree
Showing 1,144 changed files with 516,778 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build/
.vscode/*
tags
tags.lock
.west/
bootloader/
modules/
tools/
zephyr/
*.hex
board-controller/build/
94 changes: 94 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
cmake_minimum_required(VERSION 3.13.1)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(spm_CONF_FILE
prj.conf
${CMAKE_CURRENT_LIST_DIR}/boards/spm.conf
)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(example-standalone-inferencing-zephyr)

include(utils/cmake/utils.cmake)
# Needed for colorful output
zephyr_compile_options(-fdiagnostics-color=always)

# Use hardware acceleration for DSP and Neural Network code
# You'll need to disable these on non-Arm cores
add_definitions(-DEIDSP_USE_CMSIS_DSP=1
-DEIDSP_LOAD_CMSIS_DSP_SOURCES=1
-DEI_CLASSIFIER_TFLITE_ENABLE_CMSIS_NN=1
-DEIDSP_QUANTIZE_FILTERBANK=0
-DARM_MATH_LOOPUNROLL
-DEI_SENSOR_AQ_STREAM=FILE
)

# Edge impulse SDK include directories
set(INCLUDES
.
src
tflite-model
model-parameters
edge-impulse-sdk
edge-impulse-sdk/third_party/ruy
edge-impulse-sdk/third_party/gemmlowp
edge-impulse-sdk/third_party/flatbuffers/include
edge-impulse-sdk/third_party
edge-impulse-sdk/tensorflow
edge-impulse-sdk/dsp
edge-impulse-sdk/classifier
edge-impulse-sdk/anomaly
edge-impulse-sdk/CMSIS/NN/Include
edge-impulse-sdk/CMSIS/DSP/PrivateInclude
edge-impulse-sdk/CMSIS/DSP/Include
edge-impulse-sdk/CMSIS/Core/Include
edge-impulse/ingestion-sdk-c
edge-impulse/ingestion-sdk-platform/NordicSemi-nrf91
edge-impulse/ingestion-sdk-platform/NordicSemi-nrf91/sensors
edge-impulse/mbedtls_hmac_sha256_sw
edge-impulse/QCBOR/inc
edge-impulse/QCBOR/src
edge-impulse/repl
edge-impulse-sdk/porting
)
include_directories(${INCLUDES})

#file(GLOB PLATFORM "${CMAKE_CURRENT_LIST_DIR}/ingestion-sdk-platform/eta-compute/*.cpp")
#file(GLOB REPL "${CMAKE_CURRENT_LIST_DIR}/repl/*.cpp")
#file(GLOB INGESTION "${CMAKE_CURRENT_LIST_DIR}/ingestion-sdk-c/*.cpp")
#file(GLOB QCBOR "${CMAKE_CURRENT_LIST_DIR}/QCBOR/src/*.c")
#file(GLOB MBEDTLS "${CMAKE_CURRENT_LIST_DIR}/mbedtls_hmac_sha256_sw/mbedtls/src/*.c")
#file(GLOB EIPORT "${CMAKE_CURRENT_LIST_DIR}/edge-impulse-sdk/porting/YOURTARGET/*.cpp")

RECURSIVE_FIND_FILE(SOURCE_FILES "edge-impulse-sdk" "*.cpp")
RECURSIVE_FIND_FILE(MODEL_FILES "tflite-model" "*.cpp")
RECURSIVE_FIND_FILE(CC_FILES "edge-impulse-sdk" "*.cc")
RECURSIVE_FIND_FILE(S_FILES "edge-impulse-sdk" "*.s")
RECURSIVE_FIND_FILE(C_FILES "edge-impulse-sdk" "*.c")

RECURSIVE_FIND_FILE(PLATFORM_FILES "edge-impulse/ingestion-sdk-platform/NordicSemi-nrf91" "*.cpp")
RECURSIVE_FIND_FILE(REPL_FILES "edge-impulse/repl" "*.cpp")
RECURSIVE_FIND_FILE(INGESTION_FILES "edge-impulse/ingestion-sdk-c/" "*.cpp")
RECURSIVE_FIND_FILE(QCBOR_FILES "edge-impulse/QCBOR/src" "*.c")
RECURSIVE_FIND_FILE(MBEDTLS_FILES "edge-impulse/mbedtls_hmac_sha256_sw/mbedtls/src" "*.c")
RECURSIVE_FIND_FILE(PORTING_FILES "edge-impulse-sdk/porting/zephyr" "*.cpp")


list(APPEND SOURCE_FILES ${S_FILES})
list(APPEND SOURCE_FILES ${C_FILES})
list(APPEND SOURCE_FILES ${CC_FILES})
list(APPEND SOURCE_FILES ${MODEL_FILES})

list(APPEND SOURCE_FILES ${PLATFORM_FILES})
list(APPEND SOURCE_FILES ${REPL_FILES})
list(APPEND SOURCE_FILES ${INGESTION_FILES})
list(APPEND SOURCE_FILES ${QCBOR_FILES})
list(APPEND SOURCE_FILES ${MBEDTLS_FILES})
list(APPEND SOURCE_FILES ${PORTING_FILES})

# add all sources to the project
target_sources(app PRIVATE ${SOURCE_FILES})
target_sources(app PRIVATE src/main.cpp)
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# syntax = docker/dockerfile:experimental
FROM ubuntu:18.04

WORKDIR /app

ARG DEBIAN_FRONTEND=noninteractive

# APT packages
RUN apt update && apt install -y --no-install-recommends git ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev curl

# Install recent CMake
RUN mkdir -p /opt/cmake && \
cd /opt/cmake && \
wget https://github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2-Linux-x86_64.sh && \
sh cmake-3.17.2-Linux-x86_64.sh --prefix=/opt/cmake --skip-license && \
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake

# GCC ARM
RUN cd .. && \
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 && \
tar xjf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 && \
echo "PATH=$PATH:/gcc-arm-none-eabi-9-2019-q4-major/bin" >> ~/.bashrc && \
cd /app

ENV PATH="/gcc-arm-none-eabi-9-2019-q4-major/bin:${PATH}"
ENV ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
ENV GNUARMEMB_TOOLCHAIN_PATH="/gcc-arm-none-eabi-9-2019-q4-major"

# Newest version of pip
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
python3 get-pip.py

# Install west and the nRF Connect SDK
RUN pip3 install west==0.11.0
RUN mkdir /ncs
RUN cd /ncs && west init -m https://github.com/nrfconnect/sdk-nrf --mr 7a076c22df511ae6758e30bc69e47fcd78be14a3
RUN cd /ncs && west update
RUN cd /ncs && west zephyr-export
RUN pip3 install -r /ncs/zephyr/scripts/requirements.txt

ENV ZEPHYR_BASE="/ncs/zephyr"
125 changes: 123 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,123 @@
# firmware-nrf-91
Edge Impulse firmware for the nRF9160 DK
# Edge Impulse firmware for nRF9160 DK

[Edge Impulse](https://www.edgeimpulse.com) enables developers to create the next generation of intelligent device solutions with embedded Machine Learning. This repository contains the Edge Impulse firmware for the Nordic Semiconductor nRF9160 DK development boards, in combination with the ST IKS02A shield. This combination supports all Edge Impulse device features, including ingestion, remote management and inferencing.

> **Note:** Do you just want to use this development board with Edge Impulse? No need to build this firmware. See [these instructions](https://docs.edgeimpulse.com/docs/nordic-semi-nrf9160-dk) for prebuilt images and instructions, or use the [data forwarder](https://docs.edgeimpulse.com/docs/cli-data-forwarder) to capture data from any sensor.
## Requirements

**Hardware**

* Nordic Semiconductor [nRF9160 DK](https://docs.edgeimpulse.com/docs/nordic-semi-nrf9160-dk) development board.
* [X-NUCLEO-IKS02A1](https://www.st.com/en/ecosystems/x-nucleo-iks02a1.html) shield.

> No IKS02A1 shield? You can modify this firmware relatively easily to work with other accelerometers or PDM microphones that are supported in Zephyr. See [Working with other sensors](#working-with-other-sensors).
**Software**

* [nRF Connect SDK](https://www.nordicsemi.com/Software-and-tools/Software/nRF-Connect-SDK) - make sure you select version v1.6.0.
* [GNU ARM Embedded Toolchain 9-2019-q4-major](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads).
* [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download).

Or you can build this application with Docker (see below).

## Building the device firmware (locally)

1. Install and configure the nRF Connect SDK:
1. [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_installing.html) in a *separate* folder from this repository (e.g. `~/repos/ncs`).
1. Check out NCS version 1.6.0:

```
$ cd ~/repos/ncs/nrf
$ git checkout v1.6.0
$ cd ..
$ west update
```

1. Set your `ZEPHYR_BASE` environment variable to `~/repos/ncs/zephyr`.

1. Clone this repository:

```
$ git clone https://github.com/edgeimpulse/firmware-nrf91
```

1. You'll need to flash the board controller *once*:

1. Ensure that the `PROG/DEBUG` switch is in `nRF52` postion.

![nRF9160DK PROG/DEBUG switch location](./doc/nrf9160dk-prog-sw.jpg)

1. Run:

```
$ cd board-controller/
$ west build -b [email protected]
$ west flash
```

1. Build and flash the application:

1. Ensure that the `PROG/DEBUG` switch is in `nRF91` postion.

![nRF9160DK PROG/DEBUG switch location](./doc/nrf9160dk-prog-sw.jpg)

1. Build the application (make sure you're in the `firmware-nrf91` folder again, not in the `board-controller`!):

```
$ west build -b [email protected]
```

1. Flash the application:

```
$ west flash
```

## Building the device firmware (Docker)

1. Clone this repository:

```
$ git clone https://github.com/edgeimpulse/firmware-nrf91
```

1. Build the Docker container:

```
$ docker build -t edge-impulse-nordic .
```

1. You'll need to flash the board controller *once*:

1. Ensure that the `PROG/DEBUG` switch is in `nRF52` postion.

![nRF9160DK PROG/DEBUG switch location](./doc/nrf9160dk-prog-sw.jpg)

1. Run:

```
$ docker run --rm -v $PWD:/app edge-impulse-nordic /bin/bash -c "cd board-controller && west build -b [email protected]"
```

1. Copy `board-controller/build/zephyr/zephyr.bin` to the `JLINK` mass storage device.


1. Build and flash the application:

1. Ensure that the `PROG/DEBUG` switch is in `nRF91` postion.

![nRF9160DK PROG/DEBUG switch location](./doc/nrf9160dk-prog-sw.jpg)

1. Build the application:

```
$ docker run --rm -v $PWD:/app edge-impulse-nordic /bin/bash -c "west build -b [email protected]"
```

1. Copy `build/zephyr/zephyr.bin` to the `JLINK` mass storage device.


## Working with other sensors

You can easily add support for other accelerometers, PDM microphones or even completely different sensors to this firmware through either built-in Zephyr drivers, or through the Zephyr sensor API. See the [examples for the nRF52840 DK](https://github.com/edgeimpulse/firmware-nrf52840-5340-dk#working-with-other-sensors) for more info.
7 changes: 7 additions & 0 deletions board-controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(board-controller)

target_sources(app PRIVATE src/main.c)
29 changes: 29 additions & 0 deletions board-controller/boards/nrf9160dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021, Copyright (c) 2020 EdgeImpulse Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

&led1_pin_routing {
status = "disabled";
};

&led2_pin_routing {
status = "disabled";
};

&led3_pin_routing {
status = "disabled";
};

&led4_pin_routing {
status = "disabled";
};

&io_expander_pins_routing {
status = "okay";
};

&external_flash_pins_routing {
status = "okay";
};
1 change: 1 addition & 0 deletions board-controller/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_GPIO=y
2 changes: 2 additions & 0 deletions board-controller/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sample:
name: Board Controller for nRF9160 DK >0.14.0
17 changes: 17 additions & 0 deletions board-controller/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <device.h>
#include <devicetree.h>

void main(void)
{
while (1)
{
k_msleep(10);
}
}
9 changes: 9 additions & 0 deletions boards/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2020, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

&i2c0 {
clock-frequency = <I2C_BITRATE_FAST>;
};
10 changes: 10 additions & 0 deletions boards/nrf5340dk_nrf5340_cpuapp.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2020, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

&i2c1 {
clock-frequency = <I2C_BITRATE_FAST>;
};

34 changes: 34 additions & 0 deletions boards/nrf9160dk_nrf9160ns.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

&i2c2 {
clock-frequency = <I2C_BITRATE_FAST>;
};

/* max. frequency lower due to level shifters max. frequency on the X-NUCLEO-IKA02A1 */
&mx25r64 {
spi-max-frequency = <4000000>;
};

&pcal6408a {
status = "okay";
};

&led0 {
gpios = <&pcal6408a 4 GPIO_ACTIVE_HIGH>;
};

&led1 {
gpios = <&pcal6408a 5 GPIO_ACTIVE_HIGH>;
};

&led2 {
gpios = <&pcal6408a 6 GPIO_ACTIVE_HIGH>;
};

&led3 {
gpios = <&pcal6408a 7 GPIO_ACTIVE_HIGH>;
};
Loading

0 comments on commit a45d67c

Please sign in to comment.