Arduino Nano RP2040 Connect Flash memory

Hi, I've got a problem with using flash memory on Arduino Nano RP2040 Connect, firstly on Arduino Docs it says it has no EEPROM or Flash Memory(But on IDE and other sites it says it has 16mb of flash memory):


So then I tried searching and trying different codes, but all off them had a error and it was saying that architecture we are using is different that code uses. All I want is just to save some data on flash memory and to have oportunity to turn off arduino and it will have this data not on SRAM so data will be accessible even after reloading arduino.

Hi @madredman.

Although the Nano RP2040 Connect board doesn't have integrated EEPROM memory, it does have flash.

Unlike the classic AVR chips which have internal flash memory, the flash is provided by a dedicated IC on the board. This might be the reason why you found information that it doesn't have flash memory (since that is correct if we are speaking of the RP2040 microcontroller alone rather than the Nano RP2040 Connect board as a whole).

The "Arduino Mbed OS Nano Boards" platform of the Nano RP2040 Connect board is based on the free open source Mbed OS operating system. This means you can use the "KVStore" API provided by Mbed OS for non-volatile data storage in the flash memory of the Nano RP2040 Connect board:

https://os.mbed.com/docs/mbed-os/latest/apis/static-global-api.html

I'll provide a simple demonstration sketch:

// Demonstration of storing data to non-volatile memory using Mbed OS kvstore_global_api.
// See: https://os.mbed.com/docs/mbed-os/latest/apis/static-global-api.html

#include <kvstore_global_api.h>
#include <mbed_error.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ;  // wait for serial port to connect.
  }

  char key[] = "foo-key";  // Arbitrary data key.

  // Write data to the store.
  char value[] = "Hello, world!";
  byte valueSize = sizeof(value);

  int result = kv_set(key, value, valueSize, 0);
  if (result != MBED_SUCCESS) {
    Serial.print("kv_set failed with error code ");
    Serial.println(result);
    while (true) {}  // Do not continue.
  }


  // Read data from the store.
  // Get the size of the value.
  kv_info_t infoBuffer;
  result = kv_get_info(key, &infoBuffer);  // Information for the key will be written to infoBuffer.
  if (result != MBED_SUCCESS) {
    Serial.print("kv_get_info failed with error code ");
    Serial.println(result);
    while (true) {}  // Do not continue.
  }
  // Prepare a buffer of the appropriate size to contain the value.
  char readBuffer[infoBuffer.size];
  result = kv_get(key, readBuffer, infoBuffer.size, nullptr);  // Information for the key will be written to readBuffer.
  if (result != MBED_SUCCESS) {
    Serial.print("kv_get failed with error code ");
    Serial.println(result);
    while (true) {}  // Do not continue.
  }
  Serial.print("Key: ");
  Serial.println(key);
  Serial.print("Value: ");
  Serial.println(readBuffer);
}

void loop() {}

Obviously the sketch above is silly because it writes to the store and then immediately reads back what was written. However, once that data has been written, it is stored in non-volatile memory and could be retrieved at any time later by any sketch, even after a power cycle.

2 Likes

Thanks a lot for your explanation, you have helped me a lot!

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

1 Like

Hello! thanks a lot for the explanation, I'm going to test it out! One question... How many read/write cycles can be done in the Flash Memory of this chip (Arduino Nano RP2040 Connect). I cannot write infinite times I guess. Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.