This is an old answer that has since been updated, and is kept here for reference only. Please see this post for up-to-date instructions.
To generate and run C code for deep neural networks on Cortex-M hardware, you must have the CMSIS-NN (Cortex Microcontroller Software Interface Standard - Neural Networks) library. This following describes the build steps for CMSIS-NN on Windows and Linux platforms that use a cross-compiler toolchain.
Requirements
To build the CMSIS-NN static library, you must first create a makefile. Copy the following code snippet into a file and save it as Makefile.mk. This sample makefile builds the CMSIS-NN library for the Cortex-M7 core. To build the library for other targets, modify the CFLAGS variable as appropriate for your target hardware.
STATIC_LIB_FILE_NAME = libcmsisnn.a
CFLAGS= -fPIC -c -mcpu=cortex-m7 -Ofast -DNDEBUG
INC = -I../Core/Include -I../DSP/PrivateInclude -I../DSP/Include -I../NN/Include
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,
SOURCE_FILES = $(call rwildcard,Source,*.c)
OBJECT_FILES = $(patsubst
$(STATIC_LIB_FILE_NAME): $(OBJECT_FILES)
ar -r -o $(STATIC_LIB_DIR)/$@ $^
#Compiling every *.c to *.o
arm-none-eabi-gcc -c $(INC) $(CFLAGS) -o $@ $<
@mkdir -p $(STATIC_LIB_DIR)
rm -f $(OBJECT_FILES) $(STATIC_LIB_DIR)/$(STATIC_LIB_FILE_NAME)
Note: Make sure that Makefile was written properly, using the above code, and following makefile indentation rules.
We have validated the CMSIS-NN library build process below using:
- Windows platform: GNU Arm Embedded Toolchain version 10.3.1
- Linux platform: GNU Arm Embedded Toolchain version 8.3.0
Linux Platform
3. Unzip the source code to a folder and follow these steps to build and generate the static library:
- Open a Linux terminal.
- Change directory to the CMSIS-NN source folder by running this command. Here, <CMSIS Root folder> points to the extracted CMSIS folder.
cd <CMSIS Root folder>/CMSIS/NN
- Copy the Makefile.mk file that you created to the current directory.
- Run the makefile by using the make command.
- Running the makefile creates the static library libcmsisnn.a in the ./lib folder.
4. Configure the MATLAB environment to generate code that uses the CMSIS-NN library:
- At /usr/local, create a folder named cmsisnn.
- Copy the header files located at <CMSIS Root folder>/CMSIS/DSP/Include and <CMSIS Root folder>/CMSIS/NN/Include to the location /usr/local/cmsisnn/include.
- Copy the generated static library located at <CMSIS Root folder>/CMSIS/NN/Include to the location /usr/local/cmsisnn/lib.
- At the MATLAB command window, set the MATLAB environment variable CMSISNN_PATH to the location of the CMSIS-NN install folder.
setenv('CMSISNN_PATH’, ‘/usr/local/cmsisnn’)
Windows Platform
2. Download and install the 'build system(make.exe)' and 'archiving(ar.exe)' tools. We have tested this step by using Cygwin (available at https://www.cygwin.com/) to run the makefile. 4. Unzip the source code to a folder, and follow these steps to build and generate the static library:
- Open a Windows command prompt.
- Change directory to the CMSIS-NN source folder by running this command. Here, <CMSIS Root folder> points to the extracted CMSIS folder.
cd <CMSIS Root folder>\CMSIS\NN
- Copy the Makefile.mk file that you created to the current directory.
- Run the makefile by using the make command.
- Running the makefile creates the static library libcmsisnn.a in the .\lib folder.
5. Configure the MATLAB environment to generate code that uses the CMSIS-NN library:
- At C:\Program Files, create a folder named cmsisnn.
- Copy the header files located at <CMSIS Root folder>\CMSIS\DSP\Include and <CMSIS Root folder>\CMSIS\NN\Include to the location C:\Program Files\cmsisnn\include.
- Copy the generated static library located at <CMSIS Root folder>\CMSIS\NN\Include to the location C:\Program Files\cmsisnn\lib.
- At the MATLAB command window, set the MATLAB environment variable CMSISNN_PATH to the location of the CMSIS-NN install folder.
setenv('CMSISNN_PATH’, ‘C:\Program Files\cmsisnn’)