This repository contains instructions for integrating an Edge Impulse Studio project into an MPLAB X project for any xc32 supported platform.
Notes:
- This script has only been tested under linux (ubuntu), Git Bash, and macOS.
*.options.ini
can be modified to set additional project options; for help call the mplab scriptprjMakefilesGenerator -setoptions=@ -help
- NB: all relative paths are considered relative to the project root folder (.X folder)
*.project.ini
is just a placeholder - the languageToolchain and device variables are replaced when building the project - others will take default values if unspecified.
- MPLAB® X IDE >=6.00 (https://microchip.com/mplab/mplab-x-ide)
The first step in building an MPLAB project for Edge Impulse is of course to deploy the Edge Impulse model.
-
Open Edge Impulse Studio.
-
Click on the Deployment step in the sidebar menu.
-
Under Create Library select C++ library, then click Build to download the library.
The following steps cover compiling the Edge Impulse library into a static library object.
-
Extract the library from the step above directly into this folder.
-
(Optional) Open
options.ini
and modify as needed. -
Set the environment variables
MPLABX_VERSION XC_VERSION XC_NUMBER_BITS
as desired, then runbuild.sh
to generate the library object. For example:MPLABX_VERSION=6.00 XC_VERSION=4.00 XC_NUMBER_BITS=32 ./build.sh ATSAME54P20A libedgeimpulse .
If MPLAB X or the XC compiler are in non-default install locations, set the corresponding path directly through the
MPLABX_PATH
andXC_PATH
environment variables.
To launch a Docker build for a specific target build arguments must be set as
shown in the included example .args
files. See docker_build.sh
for a full
example for building the docker image and generating the Edge Impulse
library/project. This script can be run by passing the target name and .args
file e.g.:
./docker_build.sh ATSAME54P20A args/SAME54.args
This will output the result of the build into a folder dist/
under your
current working directory.
See packs.download.microchip.com for device family pack listings.
Below are instructions for integrating the library object, compiled with the steps above, into an MPLAB X project.
-
Add the library object from the step above into an existing MPLAB project as shown below.
-
Add the
src/ei_classifier_porting.cpp
file from this repository to your project, this implements the required Edge Impulse stubs. -
Use
src/main.cpp
as a template for integrating the Edge Impulse library into your project. -
Add the path to the directory where the SDK is extracted in your include path under Project Properties -> XC32 Global Options -> Common include dirs
-
The Edge Impulse SDK uses dynamic memory allocation so allocate additional heap memory under Project Properties -> xc32-ld -> Heap size (see (1) in the image below). The number will vary based on your Edge Impulse project parameters (especially the maximum width of your neural network layers).
-
Ensure that the
Remove unused sections
option under Project Properties -> xc32-ld is enabled (see (2) in the image below); this will eliminate any unused data or functions from the SDK to reclaim device memory.
You should now have your Edge Impulse model fully integrated with an MPLAB X project. In order to update the deployed model, simply repeat the steps from the build instructions section above.
Some special care has to be taken to ensure the library is integrated correctly with your project:
-
If the CMSIS libraries are included in the build, make sure your project doesn't link the pre-built CMSIS library optionally included with MPLAB Harmony projects.
-
The Edge Impulse SDK will automatically determine whether to include the CMSIS NN/DSP libraries. You can use
EIDSP_USE_CMSIS_DSP=0
andEI_CLASSIFIER_TFLITE_ENABLE_CMSIS_NN=0
to manually disable this behavior.