Nicla Sense ME Running out of memory

Yes, it is usually a memory issue, try a smaller BLE stack can be the solution.

How can I define the BLE reserved stack?

1 Like

Hello guys. I’m having the same issue. The problem appears exactly when I call the function BLE.begin(). Before this everything is okey.

Is there a guide on how to modify the Stack reserved for the BLE?

1 Like

The key was using Platform IO, thanks!

1 Like

Can you give me a brief explanation of how to do that?

@Pablo9815 put an “at” sign in front of the name and @mcmchris will get an email notice.

Perfect @MMarcial I’ll do that.
@mcmchris Can you give me a brief explanation of how to do that?
Thank you

I have had the same exact issues and I am going through the same steps (the v1-3 of libmbed and mbed_config files) and those didn’t work. @mcmchris, if you could, some details would be appreciated on how you got it working on PlatformIO, for those of us who don’t use that IDE often. Thanks!

OK, I was able to figure out how to import a project into PlatformIO (an extension in VS Code) and the project does compile and run. However, I get an out of memory error (Failed to run DSP process (-1002)) as soon as I make a BLE connection to my app. I remember running into memory issues on a prior Nicla Sense ME project and I ended up just using it as a shield on the MKR Wifi 1010. Obviously, with the K-way project we can’t do that.

Has anyone been successful in running an EI model and ArduinoBLE without running out of memory? I feel I have a pretty lightweight accelerometer model with a 1 second inference window. Any suggestions? Thanks!

Hi all, apologies for the multiple messages, but I found a project that was able to figure out the memory constraint issue. See here. You have to go into the Arduino_BHY2 library and change the buffer size (WORK_BUFFER_SIZE) in BoschSensorTec.h. In his project, @nickbild changed the value from 2048 to 64, and that worked for me as well. I can now run inference and BLE at the same time, although I’m not sure what the second order effects are of changing the buffer size. For my relatively simple project, I think that should work.

@louis and @janjongboom , I’ve seen at least 3 people, plus myself, with this issue of running inference and BLE at the same time with the limited 64 kB SRAM of the Nicla Sense ME. We might want to get the word out that this change is required in order to not run out of memory while running an EI inference + BLE. Thanks! And thanks @nickbild for documenting the required change!

2 Likes

I didn’t have to do that, but I’m glad you solved your problem.

1 Like

Hello @jlutzwpi, I tried this solution, but when I change the WORK_BUFFER_SIZE the serial monitor says ERR: Failed to run DSP process (-1002), at least it doesn’t show the memory issue.
Did you only change this parameter and then the system worked correctly?

That error message means you are out of memory. See this thread: https://forum.edgeimpulse.com/t/err-mfcc-failed-1002/2075

I also built and uploaded in PlatformIO per mcmchris’s suggestion.

Hi everybody, I’m also doing a project using an Edge Impulse model and sending the data trough BLE.
@mcmchris said the solution was using Platform IO but I can’t get it to work, my question is can you use the same libraries that you used in Arduino? and also do you have to do any additional configuration in Platform IO? It’s my first time using it and I’m a littlle bit lost.
I have also tried the solution of changing the value of WORK_BUFFER_SIZE and compiling in Arduino IDE but it doesn’t work.

Try following this tutorial I made using the Nicla Sense ME and Edge Impulse.

Here is the repository with the PlatformIO code, you can download it and use it as a template for your project.

@mcmchris using different IDE should not be related at all. That is just an IDE, you can customize the compilers etc. Your repo lacks lib files. Also it would be better if you remove the Solution tick from there.

@jlutzwpi What I have found that, when we both run BLE and BHY we are limited with 70% of the RAM

#include “Arduino_BHY2.h”
#include “ArduinoBLE.h”

int all_readings[2200];

void setup() {
Serial.begin(115200);
while(!Serial);
all_readings[0] = 0;
while(!BHY2.begin());
while(!BLE.begin());
}

void loop() {
BHY2.update();
Serial.println(“We are working fine!”);
delay(1000);
}

This occupies:

RAM: [======= ] 70.9% (used 45608 bytes from 64288 bytes)

If we increase to int all_readings[2250]; we get memory error. Sadly, changing that buffer size did not work for me. I am trying to find a way to use BHI260AP’s RAM instead.

Edit: @jlutzwpi I see now. Changing that buffer size will just save you as much as the change, so if you borderline out of RAM it is helpful but otherwise not.

Look back to who created this topic, and who found the solution to make it work without messing up with buffers and that level modifications.

Also, go for the REAL implemented and working project I could develop just by switching the IDE (we were in a contest with a limited time).

Note: using this solution other participants of the contest could achieve their entries successfully.

Other note: if the board core was updated with a solution since this post, my solution may not be necessary anymore. But it was before.

I am well-aware that you created the topic. I have seen your question in Bosch forum as well. @mcmchris the IDEs can come with different compilers, lib versions etc. At the time you have done that the PlatformIO might be using a different stuff than Arduino IDE, so at that time, highly likely, PlatformIO was using libs occupying less RAM space, so by pure chance you get that working because you only needed just a bit more space. I wish you at least would provide what were the lib/os versions so the answer you tick would make a little sense at least.

Run the above script I provided in Arduino IDE or PlatformIO IDE, whereever you want, you will get an error with the current versions.

The solution offered by @jlutzwpi will work anytime if you just out of like 2KB RAM, so that is a useful one.

Another useful thing one can try to recompile the mbed-os. The link I provide has a guide on that. However if you need like at least 20KB space, that is also not enough.

One amazing solution would be using the RAM of BHI260AP which is 264KB which I am currently working on.