|
| 1 | +# Build Steps for CMSIS-NN Library |
| 2 | +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. The following describes the build steps for CMSIS-NN on Windows® and Linux® 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®. |
| 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® Embedded Toolchain version 8.3.0 |
| 19 | +* Windows platforms: GNU ARM® 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. |
0 commit comments