Has anyone implemented some persistent storage scheme on the 33BLE ? - SD cards not included !
I don't need a lot of room... 1K at the most.
Thanks
Has anyone implemented some persistent storage scheme on the 33BLE ? - SD cards not included !
I don't need a lot of room... 1K at the most.
Thanks
Can you implement EEPROM or a file system?
I just checked, the nRF52840 doesn't seem to have a built-in EEPROM
This thread is about implementing EEPROM on the Nano33.
I just found out that that library does not save data in flash during upload. The library fails the OP's persistent data requirement, sorry.
There are some other recommendations in the thread here:
I think that all approaches that use the internal flash will be subject to erasure on upload. However, they could still be considered "persistent" in that the data does persist through power off and resets. So it really depends on your requirements.
I think that if you need persistence through uploads then you will need to add an external storage component such as an EEPROM chip.
I don't need persistence after uploads, just after power offs.
And as its only a few variables, probably kvstore will work.
Is there an example somewhere?
Here is an example from one of Arduino's developers for using Mbed OS's KVStore in an Arduino sketch:
https://github.com/arduino/ArduinoCore-nRF528x-mbedos/issues/16#issuecomment-536932296
I found I had to add this line to make it compile:
#include <mbed_error.h>
Unfortunately, I find this example difficult to understand and didn't discover much information to help me out. The official Mbed OS documentation is here:
You can see that the example sketch is a slightly modified version of the official Mbed OS example program.
This line:
REDIRECT_STDOUT_TO(Serial)
causes the printf
calls in the sketch to print to Serial
, as we are accustomed to doing via Serial.print
, etc. calls.
The FlashStorage library that is linked in the thread in reply #4 has examples.
And as its only a few variables, probably kvstore will work.
Is there an example somewhere?
//https://os.mbed.com/docs/mbed-os/v6.12/apis/kvstore.html
//KVStore. TDBStore - Default implementation of the KVStore API. It provides static wear-leveling and quick access for when you have a small number of KV pairs.
//https://os.mbed.com/docs/mbed-os/v6.12/apis/data-architecture.html
#include "KVStore.h"
#include "kvstore_global_api.h"
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("--- Mbed OS KVStore Simplified example--- ");
/* Start By Resetting the KV Storage */
Serial.println("kv_reset");
kv_reset("/kv/");//comment out when retreiving saved data
Serial.println();
const char* const Key1 = "store_cString";
const char* const Key2 = "store_longArray";
const char* const Key3 = "store_Struct";
/* Set First Key/Value pair*/
const char* const cStringToStore = "Hello World/Goodnight Moon";//const pointer to constant string
Serial.print("kv_set key: ");
Serial.println(Key1);
kv_set(Key1, cStringToStore, strlen(cStringToStore), 0); //0 for flags?
/* Read the KV Pair you've just set */
char Key1Out[strlen(cStringToStore) + 1] = "";
memset(Key1Out, '\0', strlen(cStringToStore) + 1); //clear and null terminate
kv_get(Key1, Key1Out, strlen(cStringToStore) + 1 , 0);
Serial.print("kv_get key: ");
Serial.println(Key1);
Serial.print("kv_get key Value: ");
Serial.println(Key1Out);
Serial.println();
/* Set Second Key/Value pair*/
uint32_t km[3];
km[0] = 123456789;
km[1] = 234567891;
km[2] = 345678912;
Serial.print("kv_set key: ");
Serial.println(Key2);
kv_set(Key2, (uint8_t*)&km, sizeof(km), 0);
/* Read the KV Pair you've just set */
uint32_t kmOut[3];
kmOut[0] = 0;
kmOut[1] = 0;
kmOut[2] = 0;
Serial.print("kv_get key: ");
Serial.println(Key2);
kv_get(Key2, (byte*)&kmOut, sizeof(kmOut), 0);
Serial.print("kv_get key Value: ");
for (byte i = 0; i < 3; i++)
{
Serial.print(kmOut[i]);
if (i != 2)
Serial.print(',');
}
Serial.println();
Serial.println();
/* Set Third Key/Value pair*/
typedef struct {
unsigned long timeStamp;
float accel;
char pres[4];
} structData;
structData dataSaved;
structData dataRetreived;
dataSaved.timeStamp = 445566;
dataSaved.accel = 1.23;
strcpy(dataSaved.pres, "789");
dataRetreived.timeStamp = 0;
dataRetreived.accel = 0;
strcpy(dataRetreived.pres, "---");
Serial.print("kv_set key: ");
Serial.println(Key3);
kv_set(Key3, (uint8_t*)&dataSaved, sizeof(dataSaved), 0);
Serial.print("kv_get key: ");
Serial.println(Key3);
kv_get(Key3, (byte*)&dataRetreived, sizeof(dataRetreived), 0);
Serial.print("kv_get key Value: ");
Serial.print(dataRetreived.timeStamp);
Serial.print(',');
Serial.print(dataRetreived.accel);
Serial.print(',');
Serial.print(dataRetreived.pres);
Serial.println();
/* Finally, reset will format kvstore and remove All Keys (including write-once keys) */
//Serial.println("kv_reset");
//kv_reset("/kv/");
}
void loop() {}
//https://os.mbed.com/docs/mbed-os/v6.12/apis/kvstore.html
//KVStore. TDBStore - Default implementation of the KVStore API. It provides static wear-leveling and quick access for when you have a small number of KV pairs.
//https://os.mbed.com/docs/mbed-os/v6.12/apis/data-architecture.html
#include "KVStore.h"
#include "kvstore_global_api.h"
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("--- Mbed OS KVStore Simplified example--- ");
/* Start By Resetting the KV Storage */
Serial.println("kv_reset");
kv_reset("/kv/");//comment out when retreiving saved data
Serial.println();
uint16_t maxAmountStored = 1234;
uint16_t maxAmountReadBack = 0;
kv_set("TankCapMax", (uint8_t*)&maxAmountStored, sizeof(maxAmountStored), 0);
kv_get("TankCapMax", (uint8_t*)&maxAmountReadBack, sizeof(maxAmountReadBack), 0);
Serial.print("max amount = ");
Serial.println(maxAmountReadBack);
}
void loop() {}
Thanks for the help.
The KVstore is amazingly easy to use. I was expecting something more complex.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.