Hi,
I need persistent storage of ~100 bytes on the Bluefruit nRF52 Feather. What are my options? I was not able to find any mention of it in the Adafruit literature, nor in the nRF52 Product Specification. But some variants of the Cortex M4 do have EEPROM.
There is this https://github.com/cmaglie/FlashStorage library. However, I am concerned about longevity, as 10k cycles is within reasonable limits of my expected usage.
Thanks!
Persistence (EEPROM) on Feather NRF52
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- hathach
- Posts: 1269
- Joined: Tue Apr 23, 2013 1:02 am
Re: Persistence (EEPROM) on Feather NRF52
nrf52 does not has EEPROM, you should try the Newtron Flash File System aka nffs. It is used internally by bluefruit library
here is one of its example
https://github.com/adafruit/Adafruit_nR ... dWrite.ino
here is one of its example
https://github.com/adafruit/Adafruit_nR ... dWrite.ino
- machinalabs
- Posts: 4
- Joined: Sun Dec 02, 2012 11:29 pm
Re: Persistence (EEPROM) on Feather NRF52
Ah, clever! Do you know if NFFS supports built-in wear leveling, and/or built-in checking for value change (so that it doesn't rewrite the same value?)
- hathach
- Posts: 1269
- Joined: Tue Apr 23, 2013 1:02 am
Re: Persistence (EEPROM) on Feather NRF52
You can check out its feature from its creator here
https://mynewt.apache.org/master/os/mod ... nffs/nffs/
https://mynewt.apache.org/master/os/mod ... nffs/nffs/
- machinalabs
- Posts: 4
- Joined: Sun Dec 02, 2012 11:29 pm
Re: Persistence (EEPROM) on Feather NRF52
I've been reading that, and some other related posts on this forum. Still trying to wrap my head around what is the bare minimum of the api in order to store a handful of variables.
What is the significance of 7 pages? Is that how much the Bluefruit config allocates? Why would it be using 7 pages? seems like overkill.
viewtopic.php?f=25&t=121640#p627815
update:
I'm starting to get the hang of it, but there are still a lot of gaps in my knowledge, and I don't want to inadvertently brick my device. For example, if i call EraseNffs, will that remove the adafruit/bond data? Will that screw up my BLE Feather?
My FS currently:
Here is your erasure example code:
https://github.com/adafruit/Adafruit_nR ... seNffs.ino
What is the significance of 7 pages? Is that how much the Bluefruit config allocates? Why would it be using 7 pages? seems like overkill.
viewtopic.php?f=25&t=121640#p627815
update:
I'm starting to get the hang of it, but there are still a lot of gaps in my knowledge, and I don't want to inadvertently brick my device. For example, if i call EraseNffs, will that remove the adafruit/bond data? Will that screw up my BLE Feather?
My FS currently:
Code: Select all
root
|_ adafruit/
| |_ bond/
|_ adafruit.txt 40 Bytes
|_ lost+found/
https://github.com/adafruit/Adafruit_nR ... seNffs.ino
Last edited by machinalabs on Mon Mar 12, 2018 4:55 pm, edited 1 time in total.
- machinalabs
- Posts: 4
- Joined: Sun Dec 02, 2012 11:29 pm
Re: Persistence (EEPROM) on Feather NRF52
Any idea why calling file.write(uint8_t b) causes the filesystem to get corrupted and I have to erase it? By "corrupted", what happens is any file open calls in the future fail. And since file.open() only returns a bool (fs_open() returns an int, seems to be a way of conveying errors in the lower level api), I have no idea what kind of error is going on under the hood :/ .
Code: Select all
const char * basedir = "foo";
test_write_bytes() {
uint8_t sz = 0;
char path[BUFSIZE];
char data[MSGARG_SIZE];
memset(path, 0, BUFSIZE);
memset(path, 0, MSGARG_SIZE);
strcpy(path, basedir);
sprintf(data, "%02x.dat", myByte);
strcat(path, data);
NffsFile file;
// todo: redundancy checks
io.printf("Opening file, %s\n", path);
int res = file.open(path, FS_ACCESS_WRITE);
if (res) {
io.printf("Open success file, %s\n", path);
} else {
io.printf("Failed to open file, %s\n", path);
}
for (uint8_t i=0; i<4; i++) {
sz += file.write(i+66); // normally I would copy from a buffer but this is just to test
}
sz += file.write( (uint8_t) 0);
file.close();
io.printf("Closing\n");
return sz;
}
- hathach
- Posts: 1269
- Joined: Tue Apr 23, 2013 1:02 am
Re: Persistence (EEPROM) on Feather NRF52
FYI, NFFS is replaced by ARM little file system starting from BSP 0.9.0. Hopefully it will be more stable. The littlefs use the exact API as SD library https://www.arduino.cc/en/Reference/SD
- buddhafragt
- Posts: 1
- Joined: Fri Nov 30, 2018 11:19 am
Re: Persistence (EEPROM) on Feather NRF52
Hi,
is a example available, how to use littlefs in Arduino?
best regards, Michael
is a example available, how to use littlefs in Arduino?
best regards, Michael
- hathach
- Posts: 1269
- Joined: Tue Apr 23, 2013 1:02 am
Re: Persistence (EEPROM) on Feather NRF52
here it is
https://github.com/adafruit/Adafruit_nR ... m/examples
Internal use LittleFS on 28KB internal flash
https://github.com/adafruit/Adafruit_nR ... m/examples
Internal use LittleFS on 28KB internal flash
- oldpapa2003
- Posts: 43
- Joined: Fri Jun 12, 2015 9:56 am
Re: Persistence (EEPROM) on Feather NRF52
Found a topic that I need.. And found the master Hathach.
If you seen my posts, I'm moving from Simblee to Adafruit Feather nrF52840. The rewite is doing well and I have most conversion done.
Now I'm at a little pass of storing mac address into the file system here. I have tested reading and writing, but now I need to erase the data and write new.
Overview:
I'm using 4 filenames.. FSMac.txt (for Footswitch mac), HSMac.txt (for Handset mac), FSBatt.txt(Battery condition from Footswitch as a 0 or 1 or a value), and HSBatt.txt(Handset Battery like the footswitch conditions).
I did this with the Simblee, but it took pages for storing.. Worked well.
Reason for mac storing is to store 2 devices to 1 receiver unit. This is select-able by data switch, either or, or both.
Problem.. I can test to see if any of the txt files exist, if not I create it. I then write a bogus mac (bunch of zero's) to the file when I create.
After that I then will go get the mac and store.. But it is appending the mac to the file.. So I end up with a bunch of zero's and the mac.
But, what I would like to do is to remove the txt file and rewrite it. Looking at the Internal FS.h file I see remove. Is this usable? and also format? The format I see does it all, or can this like format the file to empty? (Sounds stupid to me, but asking..)
The issue will show up more under the battery tests. If I do just a 0 or 1 which says the battery is bad or good (less than 2.1 volts triggers the 0), the conditions will append.
Unless I can erase just the 1 file and write the replacement..
The reason for this is to show the battery condition of the devices and store it so when power off, it will show the condition when power comes back.
The Footswitch and Handsets have no LED's, only the receiver which has external power.
Saving the MAC's do 2 things.. One is to ignore any other MAC except for the ones I allow and the other determines who is a foot switch and who is a handset.
Foot switch has priority over handset. So I use the mac as the test condition (I do send ascii H for handset and F for foot switch as well).
I Like I said, I have pretty much converted the Foot Switch and Handset code (Both are the same BTW, just a logic switch tells what to send as H or F)
Just a little slowdown on the receiver.
If you like to see the current product (uses old technology), you can check the company I work for webpage. The current units need charging every other day.
The Simblee units (of which we have limited Simblee modules on hand) batteries last for around 2 months.
I'm expecting the Adafruit nRF52840's after I have limited testing, can last from 3 to 4 months using 3 volt batteries that are 3 Ah.
Wayne
If you seen my posts, I'm moving from Simblee to Adafruit Feather nrF52840. The rewite is doing well and I have most conversion done.
Now I'm at a little pass of storing mac address into the file system here. I have tested reading and writing, but now I need to erase the data and write new.
Overview:
I'm using 4 filenames.. FSMac.txt (for Footswitch mac), HSMac.txt (for Handset mac), FSBatt.txt(Battery condition from Footswitch as a 0 or 1 or a value), and HSBatt.txt(Handset Battery like the footswitch conditions).
I did this with the Simblee, but it took pages for storing.. Worked well.
Reason for mac storing is to store 2 devices to 1 receiver unit. This is select-able by data switch, either or, or both.
Problem.. I can test to see if any of the txt files exist, if not I create it. I then write a bogus mac (bunch of zero's) to the file when I create.
After that I then will go get the mac and store.. But it is appending the mac to the file.. So I end up with a bunch of zero's and the mac.
But, what I would like to do is to remove the txt file and rewrite it. Looking at the Internal FS.h file I see remove. Is this usable? and also format? The format I see does it all, or can this like format the file to empty? (Sounds stupid to me, but asking..)
The issue will show up more under the battery tests. If I do just a 0 or 1 which says the battery is bad or good (less than 2.1 volts triggers the 0), the conditions will append.
Unless I can erase just the 1 file and write the replacement..
The reason for this is to show the battery condition of the devices and store it so when power off, it will show the condition when power comes back.
The Footswitch and Handsets have no LED's, only the receiver which has external power.
Saving the MAC's do 2 things.. One is to ignore any other MAC except for the ones I allow and the other determines who is a foot switch and who is a handset.
Foot switch has priority over handset. So I use the mac as the test condition (I do send ascii H for handset and F for foot switch as well).
I Like I said, I have pretty much converted the Foot Switch and Handset code (Both are the same BTW, just a logic switch tells what to send as H or F)
Just a little slowdown on the receiver.
If you like to see the current product (uses old technology), you can check the company I work for webpage. The current units need charging every other day.
The Simblee units (of which we have limited Simblee modules on hand) batteries last for around 2 months.
I'm expecting the Adafruit nRF52840's after I have limited testing, can last from 3 to 4 months using 3 volt batteries that are 3 Ah.
Wayne
- oldpapa2003
- Posts: 43
- Joined: Fri Jun 12, 2015 9:56 am
Re: Persistence (EEPROM) on Feather NRF52
Wow, I figured it out.. This is soooo Kool..
Its is InternalFS.rmdir(FILENAME); under the FILE_READ.. It removed the folder!!..
But using InternalFS.remove(FILENAME); is the correct way..
Its is InternalFS.rmdir(FILENAME); under the FILE_READ.. It removed the folder!!..
But using InternalFS.remove(FILENAME); is the correct way..
- hathach
- Posts: 1269
- Joined: Tue Apr 23, 2013 1:02 am
Re: Persistence (EEPROM) on Feather NRF52
did you mean everytime you open file, it is appended instead of overwrite. Yes, since it is non-standard Arduino API
https://www.arduino.cc/en/Reference/SDopen
FILE_WRITE is always append by default. If you want to write at beginning, use seek(0) or remove current file and re-create it, whichever suite you.
https://www.arduino.cc/en/Reference/SDopen
FILE_WRITE is always append by default. If you want to write at beginning, use seek(0) or remove current file and re-create it, whichever suite you.
- oldpapa2003
- Posts: 43
- Joined: Fri Jun 12, 2015 9:56 am
Re: Persistence (EEPROM) on Feather NRF52
I see it all now.. SD would work, but using the nRF52840 with-out SD. Doing internalFS..
Thanks for the pointers...
Thanks for the pointers...
Please be positive and constructive with your questions and comments.