Enabling CMSIS-NN in PlatformIO

Hi,

I understand that CMSIS-NN, allows integration of machine learning (neural-networks) using ARM Cortext M processors.

I have been struggling to #include the <arm_nnfunctions.h> header file based found in the original pack ARM CMSIS-5 library.

I tried multiple things but they didn’t work.

Appreciate the help.

Rajesh

1 Like

Please upload the current state of your PlatformIO project to github or somewhere else so that we can see what multiple things you tried and we can reproduce them.

Hi Max,

Apologies for not doing this in my basic post.

Setup:

  1. Windows
  2. ARM board: STM32 L476VG
  3. Selected mbed as the framework when creating PlatformIO project as that was the only option for this board
  4. As CMSIS-NN was not detected by the PlatformIO ‘Libraries’ search feature, downloaded the ARM.CMSIS.5.4.0 folder structure and stored on my hard-drive (Ref. image.1)

Here are the things I tried in order as none of them worked:

  1. Modified the c_cpp_properties.json file (.vscode project folder) to include the path that had arm_nnfunctions.h (Image.2)
  2. Within the platformio.ini, used PlatformIO lib_deps option to list the dependent libraries by listing the folders where arm_nnfunctions.h was stored (Image.3)
  3. Went back to using the Libraries feature (Image.4). It was able to find the CMSIS Core library and when that didn’t work, also tried loading the CMSIS DSP. With this I was hoping that the basic functions will be found.
  4. Finally, I changed the board to another board, which allowed choosing the cmsis as the framework when using the PlatformIO New-Project dialog box

[I later realized as a new user I can only upload one image]

This will surely make VSCode see that include path, but the compilation process will not see it unless you add build_flags = -I lib/ARM.CMSIS.5.3.0/CMSIS/NN/Include -I .... in your platformio.ini . Can you just quickly upload the project to github or google drive?

1 Like

Hi Max,

Firstly thank you for taking up this issue and helping.

Google Drive upload > Link

So I tried all day - unfortunately it still does not work :frowning:

I looked up the build_flags documentation and I even tried other flags after trying the “-I” flag you suggested.

I tried the following two flags:
-Idir packages/framework-cmsis
-Idir lib/ARM.CMSIS.5.3.0/CMSIS/NN/Include

And also a include flag with the absolute path.

Please find error output that I keep getting eblow:

Hi Max @maxgerhardt

Hope you are able to see my earlier post (with Google drive upload and images). I had a lot of trouble connecting with this page (and entire forum) earlier in the day.

Of course if you have seen the post - please ignore this post - don’t mean to bother you. Just hoping you can help me out.

thanks, Rajesh

1 Like

Can you please git clone GitHub - maxgerhardt/pio-cmsis-nn: Example project with the Neural Network functions of CMSIS 5 and tell me the serial output of that program on your board.

1 Like

Hi Max,

I compiled the program and will test on the board in another 6-7 hours time and give you an update. The good news is that it compiled without errors! It was able to find the headers.

Thank you so much for taking this up.

Dear Max,

I did try connecting the card and downloading the successfully compiled code. However it gave the error (image below).

I tried to look for where this 500 Hz setting is - but I did not find it.

I then tried to see what the difference in your project set up was against my very simple program and spotted the CMSIS_NN folder. I picked it up as in and pasted in my project and that compiled successfully and also downloaded the firmware.

Is the error below related to Serial connection? The board I use - I do not need to do any of that and I am able to simply put a printf() and it shows in my Serial.Monitor.

If you help me with where I can change the settings/code I will do that and retry downloading your compiled code and give you an update.

Once again - Thank you very much for helping.

Remove the upload_protocol = stlink line from pio-cmsis-nn/platformio.ini at master · maxgerhardt/pio-cmsis-nn · GitHub and retry please. What upload method is it using in your project where the upload is working?

Dear Max,

  1. I removed upload_protocol = stlink, but then there was nothing in the serial monitor output.

  2. My simple program that shows printf() output right away in the serial monitor is shown below along with the settings. I simply have used default settings when the project was created. Please right hand side of image.

Okay so great the CMSIS-NN library is working :slight_smile: The baud rate of the my example (which is exactly ARM’s cifar10 example) is at 115200 baud, not 9600. So I wanted to see if the ARM example is able to run on the board. But if the library works for you, it’s all done I guess.

1 Like

Hi Max,

Can you please confirm then - that copying the CMSIS-NN folder into the project structure is what solved it?

Mighty thanks for all the help Max!

Rajesh

Yes exactly. Starting from CMSIS_5/CMSIS/NN at develop · ARM-software/CMSIS_5 · GitHub, I created a new lib folder CMSIS_NN with include/ files from Include/ and src/ file from Source/. That way the library headers are found automatically and there’s no need to hack include flags or library dependencies or something. Note that CMSIS-NN depends on CMSIS-DSP, which mbed-os has (here). When using this without mbed-os one must create / copy the CMSIS-DSP library, too.

2 Likes

Ok then Max - thank you Have a good day! :grinning: