Nicla Sense ME Running out of memory

I am participating in the K-Way + Arduino challenge and I am working on a solution that include the Nicla Sense ME running and Edge Impulse model and sending data through BLE, but the board can’t support BLE together with an Edge Impulse model.

I’ve tried different precompiled (optimized) mbed OS for the Nicla from this forum

This is the error with the Original BSP of the Nicla Sense ME 3.5.4:

Edge Impulse Sensor Fusion Inference

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: _stack_buffer != NULL
Location: 0x4B381
File: NRFCordioHCIDriver.cpp+186
Error Value: 0x0
Current Thread: main Id: 0x20003FA0 Entry: 0x22583 StackSize: 0xC00 StackMem: 0x20003FE8 SP: 0x20004AE4 
For more info, visit: https://mbed.com/s/error?error=0x80FF0144&tgt=NICLA
-- MbedOS Error Info --

The 3 options shared there doesn’t work for me, just receiving hard faults when trying them.

++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R   0: 2000BA28
R   1: 00000001
R   2: 20006564
R   3: 6C646E61
R   4: 2000372C
R   5: 00000026
R   6: 0005ECD9
R   7: 00000000
R   8: 00000000
R   9: 00000000
R  10: 00000000
R  11: 00000000
R  12: FFFFFFFF
SP   : 20007488
LR   : 0001F811
PC   : 6C646E60
xPSR : 21070000
PSP  : 20007468
MSP  : 2000FFC0
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000000
BFSR : 00000001
UFSR : 00000000
DFSR : 00000000
AFSR : 00000000
Mode : Thread
Priv : Privileged
Stack: PSP

-- MbedOS Fault Handler --



++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x6C646E60
Error Value: 0x2000A594
Current Thread: main Id: 0x20003F80 Entry: 0x22557 StackSize: 0xC00 StackMem: 0x200068D0 SP: 0x20007488 
For more info, visit: https://mbed.com/s/error?error=0x80FF013D&tgt=NICLA
-- MbedOS Error Info --

I would appreciate it if you can help me here, please.

I think that the ArduinoBLE library I am using is very big, maybe having a simplified version of it could help.

Thankse

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.