Build C++ Library with STM32CubeIDE

Here’s something that might help. This was added a few weeks ago so you might have missed out - https://docs.edgeimpulse.com/docs/cli-data-forwarder#classifying-data

Check the Mbed OS example and use the code to gather Raw features from sensor data so you do not need to copy-paste it from the EdgeImpulse studio

1 Like

Did you solve this error when you try to add CMSIS-PACK?

No I did not. I used C++ libraries instead.

1 Like

I think I will do the same till they find the solution!

Hi,
I try the ei-keyword-spotting tutorial from @ShawnHymel with NUCLEO L476RG and SPH0645 mic, but I have some problems (ERROR: audio buffer overrun).
I measure the inference time execution and it’s about 480 ms, which I think is too much if the sampling rate is 32K and the buffer size is 6400 samples.(but probably I didn’t get exactly the flow)

Do you have some suggestions to solve it?

thank you so much for the tutorial and work

I think 32 kHz is too fast. The example I use is 16 kHz, which is what Edge Impulse uses by default. Even though my I2S mic samples at 32 kHz, I drop every other sample to make it 16 kHz. I know, I should be using a low-pass filter to avoid aliasing if I’m down-sampling, but that would take what little resources I have, so I just have to assume that I won’t encounter frequencies above 8 kHz (as my application is for vocal range anyway).

If you look for audio_buffer_inference_callback() function in my main.cpp of the L476 example, you can see where I drop samples and convert the 24-bit audio to 16-bit audio.

6400 is the size of my I2S buffer. Every time half of that is filled up, it calls the audio_buffer_inference_callback() function. Here, the audio samples are converted to 16-bit PCM and 16 kHz and stored in one of the inference.buffers (it’s a double buffer). The size of that buffer is EI_CLASSIFIER_SLICE_SIZE.

One of these inference.buffers is sent to run_classifier_continuous() each time it’s filled up. That function should take no more than 250 ms to perform feature extraction (MFCCs) and inference, as it needs to meet the goal of performing inference 4 times per second.

Hope that helps!

1 Like

Thank you so much for your support!

I did some debug with the oscilloscope, and I found a strange behavior.
The inference algorithm seems to work properly for the first 3 times and then, it takes too much time.

I put a toggle pin UP-DOWN across “run_classifier_continuous” function The YELLOW

and a toggle pin UP-DOWN across half callback and complete callback --> the BLUE signal

The project I tried is the one downloaded from the repository (same BOARD and MIC), compile with timing optimization

If I can give you other information let me know.

Thank you so much

What is the “timing optimization” option? It’s been a couple of months since I made that project, so I may not remember. Is there a particular checkbox in preferences or flag you set that’s different from my example project?

Good morning,
I did two tests:

  • The first test with all the same preferences you set, but the behaviour is the same as the image I posted.
  • The second one with “timing optimization” (is in properties-> C/C++ build -> Settings-> MCU GCC Compiler-> Optimization) With the same result.

Do you have some other suggestion?

thank you so much

@Fede99 if you set EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW to 2 does it not time out?

I tried now, but it goes in overrun anyway.

@Fede99 so a full frame of inference costs 480ms. when doing only half that this will be even further reduced, so I’m surprised about that. I’d follow Shawn’s suggestion and downsample to 16KHz on the device.

Hello Edge Team,
I had followed the instructions to include *.pack library into STM32CubeIDE but after compiling the c++ project i got below compiler error:

./Middlewares/Third_Party/EdgeImpulse_AudioPCBM_MachineLearning/edgeimpulse/edge-impulse-sdk/dsp/spectral/processing.hpp:26:10: fatal error: vector: No such file or directory
26 | | #include

same for #include

looks like below two include file are not able to fine into below include path from g++ include settings
…/Middlewares/Third_Party/EdgeImpulse_AudioPCBM_MachineLearning/edgeimpulse/

Kindly help me to resolve the compiler error related to header file not able locate in above path.

-Vikas B

Hi @vikas Are you sure you have a C++ project? Do you have C++11 or higher selected?

it is select as
image

Any updates or suggestion to resolve the compiler issue?

I could able to compile the code by creating new cubeMx C++ project but now I’m getting the RAM memory overflow error by 3KiB but i look at deployment result as shown below it far less than the memory on STMF401VC i.e it has 256KiB Flash and 64KiB RAM.

So why there is huge difference that will overflow RAM usage with edge impulse Library?

@vikas can you email me your project at jan@edgeimpulse.com ?

I had email the source project .

@vikas in main.cpp mark your features array as const:

static const float features[] = {

Otherwise this whole array is loaded into RAM. Fixed this in the docs!