Skip to content

edgeimpulse/example-standalone-inferencing-alif

Repository files navigation

Edge Impulse Example: stand-alone inferencing (Alif)

This builds and runs an exported impulse locally on your machine.

Prerequisites

  1. Create an edge impulse account at edgeimpulse.com

  2. Install the latest Alif Security Toolkit:

    • Navigate to the Alif Semiconductor Kit documentation page (you will need to register to create an account or log in). and download the latest App Security Toolkit (tested with version 0.54.0) for windows or linux. If you are using MacOS, download the linux version.
    • Extract archive and place app-release in the root of this repo
    • Follow the instructions in local the Alif Security Toolkit Quickstart Guide to finalize the installation.
  3. Install either arm gcc or arm clang:

gcc

Tested with:

gcc version 10.2.1 20201103 (release) (GNU Arm Embedded Toolchain 10-2020-q4-major)

clang

ARM clang compiler and ensure it is added to your path:

which armclang

Downloading your Edge Impulse model

Using an Edge Impulse project with the Alif beta enabled, navigate to the Deployment tab. Here you should see an Ethos-U library deployment option. Select this and click build to download a zip file of the contents.

Add static features

Edge Impulse static examples show the minimal code to run inference, with no peripherals connected to provide data. Instead, we provide a static buffer of data obtained from a studio sample. Follow the steps described here to extract sample features from studio, and use these to populate the features array in source/main.cpp

Build the firmware

with Docker

This repository contains a docker image with the required dependencies for building with gcc:

docker build -t alif-firmware .

Build the the firmware with following command:

docker run --rm -it -v "${PWD}":/app alif-firmware /bin/bash -c "sh build_appkit.sh"

With your local gcc or armclang toolchain

  1. Ensure you have a compatible version of ARM GCC installed and added to your path
  2. Extract the zip file downloaded from edge impulse into the source directory of this repository
  3. Run build_appkit.sh

Flash your device

  1. Ensure your board is configured for programming over the SEUART interface by following the Edge Impulse Ensemble E7 setup guide
  2. Copy ./build/bin/app.bin into the Alif Security Toolkit directory ./app-release/build/images
  3. Copy the ei-app-gcc.json file into the Alif Security Toolkit directory ./app-release/build/config
  4. Execute the following commands to program your board:
cd app-release
./app-gen-toc -f ./build/config/ei-app-gcc.json
./app-write-mram.py -d

When prompted to select the serial interface to program over. Select the corresponding the FTDI COM interface.

Once programmed, the firmware will run inference and print the results over the UART2 serial port.

Serial out is on UART2, which is connected to baseboard pins P3_16,P3_17 (on connector J413).

  • Baud 115200
  • "8,N,1" (the typical settings for everything else, 8 bit, no parity, 1 stop bit)
  • 1.8 Vcc

Other details

Timing

Timing calculations are performed in ei_classifier_porting.cpp and make use of an interrupt attached to SysTick.

  • An RTOS may take over this interrupt handler, in which case you should reimplement ei_read_timer_us and _ms.
  • The default calculation is based on the default clock rates of the Alif dev kit (400 MHz for HP core, 160 MHz for HE core). If you change this, redefine EI_CORE_CLOCK_HZ.

Memory placement

Alif M55 processors have a private fast DTCM, and also access to a larger, but slower, chip global SRAM.

  • For armclang the linker file attempts to place as much as possible in DTCM, and overflows into SRAM if needed.
  • For gcc, the linker is unable to auto place based on size. When your entire program can't fit into DTCM, sometimes customizing placement of objects can improve performance. See ensemble.sct for example placement commands (currently commented out)