CMSIS-DSP support for the Adafruit NRF52 Arduino Boards

I was able to get big improvement on a siren detector by increasing the FFT size to 512 and the Filters to 64. Unfortunately, the DSP now takes 6sec for 2sec of audio. The Adafruit NRF52 board defs do not seem to support CMSIS for the DSP. It only takes about a 1sec of DSP on the Arduino Nano, which is built on MBed and supports CMSIS. I tried to force CMSIS for the DSP using EIDSP_USE_CMSIS_DSP & EIDSP_LOAD_CMSIS_DSP_SOURCES but I get the following error:

/src/edge-impulse-sdk/dsp/spectral/../numpy.hpp:1133: undefined reference to `arm_rfft_fast_f32'
/src/edge-impulse-sdk/dsp/spectral/../numpy.hpp:1141: undefined reference to `arm_rms_f32'

I am in way over my head, but it looks like support for CMSIS v5 has been included:

Is there a way to enable CMSIS-DSP support for CMSIS capable boards not based on MBed?

Hi @Robotastic, I’m not sure how the Adafruit boards do their include chain, and apparently declaring the macro early in the sketch does not work on these boards. But if you add the following lines to src/edge-impulse-sdk/dsp/config.hpp (in the libary folder) on line 26 it compiles for me:

#define EIDSP_USE_CMSIS_DSP		        1
#define EIDSP_LOAD_CMSIS_DSP_SOURCES    1

I don’t have the board so cannot verify how fast it runs, but would be great if you could report back.

Ah - of course! I added that to config.hpp instead of the Arduino sketch and it worked perfectly. It brought the DSP time down from 6000ms to 1300ms for 2s of audio!

It doesn’t look like Adafruit is defining __TARGET_CPU_CORTEX_M4 or something like that. I looked through their code, but didn’t see any similar macros being defined.

1 Like

Yeah this is the pain with Arduino. Very loosely defined spec for the HAL and no default macros for mcu family or capabilities… and no way to set macros from the IDE unfortunately either.

Just wanted to report back that making a similar change also enables CMSIS for inference.

Add #define EI_CLASSIFIER_TFLITE_ENABLE_CMSIS_NN 1 to line 26 of edge-impulse-sdk/classifier/ei_classifier_config.h

1 Like

I did a little research, the Adafruit NRF52 Core makes these defines:
ARDUINO_NRF52_ADAFRUIT & NRF52_SERIES
here: https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/platform.txt#L67

Would it be possible to a test for one of these defines when evaluating when to use CMSIS? It would improve support for those Adafruit boards.

So:
ei-lib/src/edge-impulse-sdk/classifier/ei_classifier_config.h : Line 35
#elif defined(ARDUINO_NRF52_ADAFRUIT) || defined(__TARGET_CPU_CORTEX_M0) || defined(__TARGET_CPU_CORTEX_M0PLUS) || defined(__TARGET_CPU_CORTEX_M3) || defined(__TARGET_CPU_CORTEX_M4) || defined(__TARGET_CPU_CORTEX_M7)

And:
ei-lib/src/edge-impulse-sdk/dsp/config.hpp : Line 28
#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(__MBED__) || defined(__TARGET_CPU_CORTEX_M0) || defined(__TARGET_CPU_CORTEX_M0PLUS) || defined(__TARGET_CPU_CORTEX_M3) || defined(__TARGET_CPU_CORTEX_M4) || defined(__TARGET_CPU_CORTEX_M7) || defined(USE_HAL_DRIVER)

Yep, added to the backlog.

Fix will be released during this weeks SDK release!

edit: This is now released.

Awesome!! I just tested and it works great!

Thanks! This removes one of the things that I can screw up during deployment.

1 Like