arduino / nicla-sense-me-fw

Arduino Nicla Sense ME resources (libraries, bootloader, host pc utilities)
GNU Affero General Public License v3.0
47 stars 27 forks source link

High RAM usage of Arduino_BHY2. #109

Open hkayann opened 1 year ago

hkayann commented 1 year ago

I appreciate if someone can explain why this library consumes so much ram.

Here is the empty sketch usage:

RAM:   [=         ]  12.0% (used 7720 bytes from 64288 bytes)
Flash: [=         ]   7.6% (used 40184 bytes from 527616 bytes)

If I include Arduino_BHY2:

RAM:   [======    ]  55.5% (used 35672 bytes from 64288 bytes)
Flash: [=====     ]  50.8% (used 267952 bytes from 527616 bytes)

As, I am trying to run my ML model, I am having diffuculties regarding RAM availability.

bstbud commented 1 year ago

Hi @hkayann the Ardunio_BHY2 uses mbed's BLE stack which is the biggest consumer of the RAM. If you don't need BLE, you could use proper parameters for BHY2.begin() to turn off the BLE, which should help reduce the RAM usage significantly. Example: BHY2.begin(NICLA_STANDALONE);

sebromero commented 1 year ago

Hi @hkayann ! We're you able to configure the sketch to use less RAM as suggested by @bstbud ?

hkayann commented 10 months ago

@sebromero I am not so still looking for a way to do this.

@bstbud is there any way to reduce the RAM used by the BLE library?

hkayann commented 9 months ago

Another interesting thing is that the Arduino_BHY2 requiresArduinoBLE.h anyway.

bstbud commented 9 months ago

@sebromero I am not so still looking for a way to do this.

@bstbud is there any way to reduce the RAM used by the BLE library?

based on my knowledge, the memory of the BLE stack has been optimized already, and there is only little wiggling room.

hkayann commented 9 months ago

Thanks for the reply @bstbud, I am trying alternative ways now.

One of them is to load my variables into the RAM of BHI260AP as that chip 256KB SRAM while Nicla offers 64 KB only.

I appreciate any lead on that. I know it is not directly related to this issue, sorry for that. So if you want, feel free to close this one.

bstbud commented 9 months ago

Another interesting thing is that the Arduino_BHY2 requiresArduinoBLE.h anyway.

@hkayann, even though the ArduinoBLE.h header is included, it does not mean the RAM will be used/claimed by the BLE stack automatically although by default this is the case. If you don't need BLE in your project, you could change the parameters of the BHY2.begin() function, for example, you could pass NICLA_I2C instead of NICLA_BLE_AND_I2C (by default) and the BLE stack won't set up the memory pool in this case.

hkayann commented 9 months ago

@bstbud I see. I need BLE. Any suggestion on this?

One of them is to load my variables into the RAM of BHI260AP as that chip 256KB SRAM while Nicla offers 64 KB only.

bstbud commented 9 months ago

@bstbud I see. I need BLE. Any suggestion on this?

One of them is to load my variables into the RAM of BHI260AP as that chip 256KB SRAM while Nicla offers 64 KB only.

Hi @hkayann yes, this is the same suggestion I would give. The BHI260AP has more memory, and sensor processing related tasks could be handled on the BHI260AP which is also much more power efficient than the main MCU. The Nordic MCU could be used for connectivity tasks. Now the SDK for BHI260AP is publicly available. You could refer to: https://www.bosch-sensortec.com/products/smart-sensor-systems/bhi260ap/#technical for how to use the SDK.

hkayann commented 9 months ago

Hi @bstbud,

I am playing with that right now. I would really appreciate if at least, very briefly if you can tell me the steps required to implement that for Nicla Sense ME?

bstbud commented 9 months ago

Hi @bstbud,

I am playing with that right now. I would really appreciate if at least, very briefly if you can tell me the steps required to implement that for Nicla Sense ME?

I would start with the SDK and the quick start guide provided to implement some simple example algorithms to understand the basics and then step up to implement your own algorithm. If you encounter specific issues, I suggest to post some questions on Bosch Sensortec online community.