- Why do we need this FlashStorage_RTL8720 library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- Limited number of writes
- Usage
- Examples
- Example StoreNameAndSurname
- Debug Terminal Output Samples
- FAQ
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need this FlashStorage_RTL8720 library
The FlashStorage_RTL8720 library, inspired by Cristian Maglie's FlashStorage, provides a convenient way to store and retrieve user's data using FlashStorage, from the non-volatile flash memory of RTL8720.
The flash memory, generally used to store the firmware code, can also be used to store / retrieve more user's data and faster than from EEPROM. Thanks to the buffered data writing and reading, the flash access time is greatly reduced to increase the life of the flash.
- RTL8720DN, RTL8722DM, RTM8722CSM, etc. boards
Arduino IDE 1.8.19+
for Arduino.Arduino AmebaD core 3.1.4+
for Realtek RTL8720DN, RTL8722DM and RTM8722CSM.
The best and easiest way is to use Arduino Library Manager
. Search for FlashStorage_RTL8720, then select / install the latest version.
You can also use this link for more detailed instructions.
Another way to install is to:
- Navigate to FlashStorage_RTL8720 page.
- Download the latest release
FlashStorage_RTL8720-main.zip
. - Extract the zip file to
FlashStorage_RTL8720-main
directory - Copy whole
FlashStorage_RTL8720-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install FlashStorage_RTL8720 library by using Library Manager. Search for FlashStorage_RTL8720 in Platform.io Author's Libraries
- Please visit documentation for the other options and examples at Project Configuration File
To avoid compile error relating to PROGMEM, you have to copy the file Realtek AmebaD core pgmspace.h into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h).
Supposing the Realtek AmebaD core version is 3.1.4. This file must be copied into the directory:
~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:
~/.arduino15/packages/realtek/hardware/AmebaD/x.yy.zz/cores/ambd/avr/pgmspace.h
The flash memory has a limited amount of write cycles. Typical flash memories can perform about 10000 writes cycles to the same flash block before starting to "wear out" and begin to lose the ability to retain data.
So BEWARE: IMPROPER USE OF THIS LIBRARY CAN QUICKLY AND PERMANENTLY DESTROY THE FLASH MEMORY OF YOUR MICRO, in particular you should avoid to call the FlashStorage.writeByte(), FlashStorage.writeWord()
functions, without calling FlashStorage.setCommitASAP(false)
, too often. Also make sure that in the entire life of the number of calls to write
or commit()
stay well below the above limit of 10000 (it's a good rule-of-thumb to keep that number in mind even if the manufacturer of the micro guarantees a bigger number of cycles).
The same caution must be taken if you're using the FlashStorage API (see below) with the FlashStorage.commit()
function.
Include FlashStorage_RTL8720.h
to get a FlashStorage with the internal flash memory.
See FlashStoreAndRetrieve sketch for an example.
The API is very similar to the FlashStorage_SAMD.h API, with these functions:
void writeByte(uint32_t offset, uint8_t data)
uint8_t readByte(uint32_t offset)
void updateByte(uint32_t offset, uint8_t value)
void writeWord(uint32_t offset, uint32_t data)
uint32_t readWord(uint32_t offset)
void updateWord(uint32_t offset, uint32_t value)
template< typename T > T &get( uint32_t offset, T &t )
template< typename T > const T &put( uint32_t offset, const T &t )
void readFlashToBuffer()
bool isValid()
uint16_t length()
void setCommitASAP(bool value = true)
bool getCommitASAP()
void eraseFlashSector()
-
bool isValid()
returnstrue
if data in the FlashStorage is valid (the data written to flash at least once byFlashStorage.commit()
orFlashStorage.put()
). Otherwise FlashStorage data is "dirty" and the function returnsfalse
. -
void commit()
store the FlashStorage buffer data in FlashStorage. Use this with care: Every call writes the complete FlashStorage buffer data to flash. This will reduce the remaining flash-write-cycles. Don't call this method in a loop or you will kill your flash soon. -
void setCommitASAP(bool value = true)
to set or clear the_commitASAP
private variable (default istrue
to be safe). If_commitASAP
is false, the call toFlashStorage.put(), etc
won't force theFlashStorage.commit()
to extend the flash life. You'll have to remember to callFlashStorage.commit()
manually to save the FlashStorage buffered data into FlashStorage or data will be lost. -
bool getCommitASAP()
to return the current value of_commitASAP
.
- FlashStorage_Clear
- FlashStorage_CRC
- FlashStorage_get
- FlashStorage_iteration
- FlashStorage_put
- FlashStorage_read
- FlashStorage_update
- FlashStorage_write
- FlashStoreAndRetrieve
- StoreNameAndSurname
- multiFileProject New
Example StoreNameAndSurname
FlashStorage_RTL8720/examples/StoreNameAndSurname/StoreNameAndSurname.ino
Lines 15 to 106 in bd12b4e
Start StoreNameAndSurname on Rtlduino RTL8720DN
FlashStorage_RTL8720 v1.1.0
FlashStorage length: 4096
EEPROM is empty, writing WRITTEN_SIGNATURE and some example data:
Insert your name : First_Name
Insert your surname : Last_Name
<< Your name: First_Name. Your surname: Last_Name >> have been saved. Thank you!
Start StoreNameAndSurname on Rtlduino RTL8720DN
FlashStorage_RTL8720 v1.1.0
FlashStorage length: 4096
Hi First_Name Last_Name, nice to see you again :-)
Clearing WRITTEN_SIGNATURE for next try
Done clearing signature in FlashStorage. You can reset now
The following is the sample terminal output when running example FlashStorage_read on Rtlduino RTL8720DN
Start FlashStorage_read on Rtlduino RTL8720DN
FlashStorage_RTL8720 v1.1.0
FlashStorage length: 4096
0 100
1 101
2 102
3 103
4 104
5 105
...
Yes, you can declare a complex struct
with more fields and call a FlashStorage.put()
to store the entire structure. See the StoreNameAndSurname for how to do it.
Not with RTL8720DN, RTL8722DM, RTM8722CSM, etc.
No. If your board provides an integrated-EEPROM, it's advisable to use that because EEPROM has longer lifetime, number of write cycles, etc.
In the absence of an integrated-EEPROM or its size is too small for your use-case, you can use this library to use a small portion flash memory as FlashStorage, provided that you keep in mind the limits as in Limited number of writes
If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
Submit issues to: FlashStorage_RTL8720 issues
- Search for bug and improvement.
- Similar features for remaining Arduino boards
- Basic FlashStorage for RTL8720.
- Add Table of Contents
- Fix
multiple-definitions
linker error. - Add astyle using
allman
style. Restyle the library
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
- Inspired by Cristian Maglie's FlashStorage.
⭐️ Cristian Maglie |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under MIT
Copyrigh (c) 2021- Khoi Hoang