Is there any example available that shows how to use flash memory to store data with the Arduino Nano 33 BLE board? As the board is quite limited with 256KB of RAM, I will need to use the flash memory to store some additional things that will be used later in the application. Here I mean, some example that shows how to store, and later read data from the flash when it is needed.
int myDataInRam[1000] = {1,2,3,4,5}; // in ram
const int myDataInFlash[1000] = {1,2,3,4,5); // in flash
The Arduino Uno has a ATmega328P, which is a microcontroller. It can not execute code from RAM and it can not read data from Flash. It is designed that way, because it is optimized for low level input and output.
However, reading data from Flash is possible with special instructions and special functions. It is only slower.
The Nano 33 BLE has a nRF52840, which is a ARM Cortex-M4 processor. It is a normal processor that can do thing that normal processors can do (sorry for being so vague ). In the world of normal processors, use 'const'.
Thanks a lot for the explanation! I have already used the nRF52840 DK (Nordic board) in my previous project, and I know this board is based on the same chip, but I am not able to use the same code. In the previous implementation, we used Mesh library to enable this flash part, and it was super easy to write/read to/from the flash memory. Shouldn't be there some additional functions for writing/reading to/from the flash? Based on what you wrote, seems that I just need to use const and that's it? In my case, it's quite tricky as I am planning to store one tinyML model in the flash. Is that operation possible?
The compiler/linker gives information about flash and ram usage. There are defines that you can print in setup() and I assume that there is some kind of function to get the used ram runtime.
It should be easy to keep track of the flash and ram usage.
The Arduino Nano 33 BLE uses a Arduino layer on top of Mbed with its own special things: https://github.com/arduino/ArduinoCore-mbed/tree/master/variants/ARDUINO_NANO33BLE
Perhaps there is a function in Mbed to request the amount of free ram.
Sorry that I don't know enough of that. I think that FreeRTOS (ESP32) and Mbed keep an eye on the stack to detect when it crashes, so there already some safety.
hope this may help! The nRF52840 user manual is my bed' side for few weeks, even if it is far away from my league knowledge.
Ram or Flash may be accessible to read and store with their adresses. You may need a deeper read in the manual to check it according to your needs, but here is a register mapping