Skip to content

Commit 84ec871

Browse files
author
jferrari
committed
Initial commit
0 parents  commit 84ec871

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

Diff for: Makefile.mk

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# --------------------------------------------User Configuration Begins--------------------------------------------------------
2+
STATIC_LIB_DIR = ./lib
3+
STATIC_LIB_FILE_NAME = libcmsisnn.a
4+
# Compiler
5+
CC = arm-none-eabi-gcc
6+
# Archiver
7+
AR = arm-none-eabi-ar
8+
9+
# Depending on your hardware target, uncomment one of the lines below to define a CFLAGS variable for the CMSIS-NN Makefile. You must have the correct CFLAGS set
10+
# for your target type to ensure proper functionality of the CMSIS-NN libraries in the generated code. Be sure to remove the identifier (i.e. STM32F4-Discovery) in
11+
# the line you uncomment.
12+
13+
#STM32F746G-Discovery: CFLAGS= -fPIC -c -mcpu=cortex-m7 -Ofast -DNDEBUG -mfloat-abi=hard -mfpu=fpv5-sp-d16
14+
#STM32F769I-Discovery: CFLAGS= -fPIC -c -mcpu=cfortex-m7 -Ofast -DNDEBUG -mfloat-abi=hard -mfpu=fpv5-d16
15+
#STM32F4-Discovery: CFLAGS= -fPIC -c -mcpu=cortex-m4 -Ofast -DNDEBUG -mfloat-abi=hard -mfpu=fpv4-sp-d16
16+
#Custom: CFLAGS= -fPIC -c -mcpu=? -Ofast -DNDEBUG -mfloat-abi=? -mfpu=?
17+
18+
# --------------------------------------------User Configuration Ends----------------------------------------------------------
19+
20+
# Check if CFLAGS is defined, warn if not
21+
ifndef CFLAGS
22+
$(warning CFLAGS is not set! You must ensure CFLAGS is correctly defined for your hardware target.)
23+
endif
24+
25+
INC = -I../Core/Include -I../DSP/PrivateInclude -I../DSP/Include -I../NN/Include
26+
27+
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
28+
29+
SOURCE_FILES = $(call rwildcard,Source,*.c)
30+
OBJECT_FILES = $(patsubst %.c,%.o,$(wildcard $(SOURCE_FILES)))
31+
32+
$(STATIC_LIB_FILE_NAME): $(OBJECT_FILES)
33+
$(AR) -r -o $(STATIC_LIB_DIR)/$@ $^
34+
35+
#Compiling every *.c to *.o
36+
%.o: %.c dirmake
37+
$(CC) -c $(INC) $(CFLAGS) -o $@ $<
38+
39+
dirmake:
40+
@mkdir -p $(STATIC_LIB_DIR)
41+
42+
clean:
43+
rm -f $(OBJECT_FILES) $(STATIC_LIB_DIR)/$(STATIC_LIB_FILE_NAME)

Diff for: README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Build Steps for CMSIS-NN Library
2+
To generate and run C code for deep neural networks on Cortex&reg;-M hardware, you must have the CMSIS-NN (Cortex Microcontroller Software Interface Standard - Neural Networks) library. The following describes the build steps for CMSIS-NN on Windows&reg; and Linux&reg; platforms that use a cross-compiler toolchain.
3+
4+
## Requirements
5+
6+
### Makefile
7+
To build the CMSIS-NN static library, you must first create a Makefile. Create a copy of the `Makefile.mk` file in this repository and save it to your computer. **To avoid errors during code generation, you must supply the appropriate CFLAGS variable for your target hardware.** The Makefile shared here includes several CFLAGS variables pre-validated for popular Cortex-M development boards supported by MATLAB&reg;.
8+
9+
For example, for an STM32F746G-Discovery board, define `CFLAGS` in the Makefile as:
10+
11+
```
12+
CFLAGS = -fPIC -c -mcpu=cortex-m7 -Ofast -DNDEBUG -mfloat-abi=hard -mfpu=fpv5-sp-d16
13+
```
14+
If you do not see your hardware target listed, you must create a custom CFLAGS variable with the necessary `-mcpu`, `-mfloat-abi`, and `-mfpu` flags.
15+
16+
### Toolchain
17+
We recommend using the same toolchain for building your MATLAB-based application and the CMSIS-NN library. We have validated the CMSIS-NN library build processes below using the following toolchains:
18+
* Linux platforms: GNU ARM&reg; Embedded Toolchain version 8.3.0
19+
* Windows platforms: GNU ARM&reg; Embedded Toolchain version 10.3.1
20+
21+
22+
## Linux Install Steps
23+
1. Install the open-source, AArch32 bare-metal target (arm-eabi) GNU Arm Embedded Toolchain (v8.3.0) provided by ARM (https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads/8-3-2019-03).
24+
2. Download the source code for CMSIS version 5.7.0 (available at https://github.com/ARM-software/CMSIS_5/archive/refs/tags/5.7.0.zip).
25+
3. Unzip the CMSIS source code to a folder and follow these steps to build and generate the static library:
26+
* Open a Linux terminal.
27+
* Change directory to the CMSIS-NN source folder by running the below command. Here, ```<CMSIS Root folder>``` refers to the extracted CMSIS folder.
28+
```
29+
cd <CMSIS Root folder>/CMSIS/NN
30+
```
31+
* Copy your `Makefile.mk` file to the current directory (```<CMSIS Root folder>/CMSIS/NN```). Ensure the `CFLAGS` variable is correctly defined for your hardware target in the Makefile.
32+
* At the terminal, run the makefile by using the `make` command:
33+
```
34+
make -f Makefile.mk
35+
```
36+
* Running the makefile creates the static library `libcmsisnn.a` in the ```<CMSIS Root folder>/CMSIS/NN/lib``` folder.
37+
4. Configure the MATLAB environment to generate code that uses the CMSIS-NN library:
38+
* At `/usr/local/`, create a folder named `cmsisnn`.
39+
* 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`.
40+
* Copy the generated static library located at ```<CMSIS Root folder>/CMSIS/NN/Include``` to the location `/usr/local/cmsisnn/lib`.
41+
* Open a Linux terminal and use the below command to create a `CMSISNN_PATH` environment variable:
42+
```
43+
export CMSISNN_PATH=/usr/local/cmsisnn
44+
```
45+
46+
## Windows Install Steps
47+
1. Install the open-source GNU Arm Embedded Toolchain provided by ARM (available at https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-win32.exe).
48+
2. Download and install the `make` tool. We have tested this step with Cygwin (available at https://www.cygwin.com/install.html). Within the Cygwin installer, during package selection, find the `make` package under "Devel". Open the dropdown list and replace the default selection "Skip" with the version number of `make` to install. Finish the installation process.
49+
3. Download the source code for CMSIS version 5.7.0 (available at https://github.com/ARM-software/CMSIS_5/archive/refs/tags/5.7.0.zip).
50+
4. Unzip the source code to a folder, and follow these steps to build and generate the static library:
51+
* Open a Windows command prompt.
52+
* Change directory to the CMSIS-NN source folder by running the below command. Here, ```<CMSIS Root folder>``` refers to the location where the CMSIS folder was extacted.
53+
```
54+
cd <CMSIS Root folder>\CMSIS\NN
55+
```
56+
* Copy your `Makefile.mk` file to the current directory (```<CMSIS Root folder>\CMSIS\NN```). Ensure the `CFLAGS` variable is correctly defined for your hardware target in the Makefile.
57+
* At the command prompt, run the Makefile with the `make` command:
58+
```
59+
make -f Makefile.mk
60+
```
61+
* Running the Makefile creates the static library `libcmsisnn.a` in the ```<CMSIS Root folder>\CMSIS\NN\lib``` folder.
62+
5. Configure the MATLAB environment to generate code that uses the CMSIS-NN library:
63+
* Create a folder named `cmsisnn` in an arbitrary location. Ensure the file path does not include any space. For example, we validated the following steps with the file path `C:\cmsisnn`.
64+
* Copy the header files located at ```<CMSIS Root folder>\CMSIS\DSP\Include``` and ```<CMSIS Root folder>\CMSIS\NN\Include``` to the location `..\cmsisnn\include` in the new folder you created in the previous step.
65+
* Copy the generated static library located at ```<CMSIS Root folder>\CMSIS\NN\Include``` to the location `..\cmsisnn\lib`.
66+
* Create a Windows system environment variable named `CMSISNN_PATH` with the value ```<filepath>\cmsisnn```:
67+
* For Windows 10, right-click the start menu and select System.
68+
* Click System Info.
69+
* Click Advanced System Settings.
70+
* In the Advanced tab, click Environment Variables.
71+
* Click New.
72+
* You will be presented with a prompt to enter a new environment variable. In the Variable name field, enter `CMSISNN_PATH`. In the Variable value field, enter the file path to the `cmsisnn` folder you created.

Diff for: SECURITY.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reporting Security Vulnerabilities
2+
3+
If you believe you have discovered a security vulnerability, please report it to
4+
[[email protected]](mailto:[email protected]). Please see
5+
[MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html)
6+
for additional information.

0 commit comments

Comments
 (0)