Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/storage: adjust readme files according to standard
- Loading branch information
Showing
5 changed files
with
317 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,79 @@ | ||
# Non-Volatile Storage (NVS) Read and Write Example | ||
|
||
Demonstrates how to read and write a single integer value and a blob (binary large object) using NVS to preserve them between ESP32 module restarts. | ||
(See the README.md file in the upper level 'examples' directory for more information about examples.) | ||
|
||
This example demonstrates how to read and write a single integer value and a blob (binary large object) using NVS to preserve them between ESP32 module restarts. | ||
|
||
* value - tracks number of ESP32 module soft and hard restarts. | ||
* blob - contains a table with module run times. The table is read from NVS to dynamically allocated RAM. New run time is added to the table on each manually triggered soft restart and written back to NVS. Triggering is done by pulling down GPIO0. | ||
|
||
Example also shows how to implement diagnostics if read / write operation was successful. | ||
|
||
Detailed functional description of NVS and API is provided in [documentation](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html). | ||
|
||
If not done already, consider checking simpler example *storage/nvs_rw_value*, that has been used as a starting point for preparing this one. | ||
|
||
Detailed functional description of NVS and API is provided in [documentation](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html). | ||
## How to use example | ||
|
||
### Hardware required | ||
|
||
This example can be run on most common development boards which have an active button connected to GPIO0. On most boards, this button is labeled as "Boot". When pressed, the button connects GPIO0 to ground. | ||
|
||
### Configure the project | ||
|
||
If using Make based build system, run `make menuconfig` and set serial port under Serial Flasher Options. | ||
|
||
If using CMake based build system, no configuration is required. | ||
|
||
### Build and flash | ||
|
||
Build the project and flash it to the board, then run monitor tool to view serial output: | ||
|
||
``` | ||
make -j4 flash monitor | ||
``` | ||
|
||
Or, for CMake based build system (replace PORT with serial port name): | ||
|
||
``` | ||
idf.py -p PORT flash monitor | ||
``` | ||
|
||
(To exit the serial monitor, type ``Ctrl-]``.) | ||
|
||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. | ||
|
||
## Example Output | ||
|
||
First run: | ||
``` | ||
Restart counter = 0 | ||
Run time: | ||
Nothing saved yet! | ||
``` | ||
|
||
At this point, press "Boot" button and hold it for a second. The board will perform software restart, printing: | ||
|
||
``` | ||
Restarting... | ||
``` | ||
|
||
After booting again, restart counter and run time array will be printed: | ||
|
||
``` | ||
Restart counter = 1 | ||
Run time: | ||
1: 5110 | ||
``` | ||
|
||
After pressing "Boot" once more: | ||
|
||
``` | ||
Restart counter = 2 | ||
Run time: | ||
1: 5110 | ||
2: 5860 | ||
``` | ||
|
||
To reset the counter and run time array, erase the contents of flash memory using `make erase_flash` (or `idf.py erase_flash`, if using CMake build system), then upload the program again as described above. | ||
|
||
See the README.md file in the upper level 'examples' directory for more information about examples. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,94 @@ | ||
# Non-Volatile Storage (NVS) Read and Write Example | ||
|
||
Demonstrates how to read and write a single integer value using NVS. | ||
(See the README.md file in the upper level 'examples' directory for more information about examples.) | ||
|
||
The value holds the number of ESP32 module restarts. Since it is written to NVS, the value is preserved between restarts. | ||
This example demonstrates how to read and write a single integer value using NVS. | ||
|
||
Example also shows how to check if read / write operation was successful, or certain value is not initialized in NVS. Diagnostic is provided in plain text to help track program flow and capture any issues on the way. | ||
In this example, value which is saved holds the number of ESP32 module restarts. Since it is written to NVS, the value is preserved between restarts. | ||
|
||
Check another example *storage/nvs_rw_blob*, that shows how to read and write variable length binary data (blob). | ||
Example also shows how to check if read / write operation was successful, or certain value is not initialized in NVS. Diagnostic is provided in plain text to help track program flow and capture any issues on the way. | ||
|
||
Detailed functional description of NVS and API is provided in [documentation](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html). | ||
|
||
See the README.md file in the upper level 'examples' directory for more information about examples. | ||
Check another example *storage/nvs_rw_blob*, which shows how to read and write variable length binary data (blob). | ||
|
||
## How to use example | ||
|
||
### Hardware required | ||
|
||
This example does not require any special hardware, and can be run on any common development board. | ||
|
||
### Configure the project | ||
|
||
If using Make based build system, run `make menuconfig` and set serial port under Serial Flasher Options. | ||
|
||
If using CMake based build system, no configuration is required. | ||
|
||
### Build and flash | ||
|
||
Build the project and flash it to the board, then run monitor tool to view serial output: | ||
|
||
``` | ||
make -j4 flash monitor | ||
``` | ||
|
||
Or, for CMake based build system (replace PORT with serial port name): | ||
|
||
``` | ||
idf.py -p PORT flash monitor | ||
``` | ||
|
||
(To exit the serial monitor, type ``Ctrl-]``.) | ||
|
||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. | ||
|
||
## Example Output | ||
|
||
First run: | ||
``` | ||
Opening Non-Volatile Storage (NVS) handle... Done | ||
Reading restart counter from NVS ... The value is not initialized yet! | ||
Updating restart counter in NVS ... Done | ||
Committing updates in NVS ... Done | ||
Restarting in 10 seconds... | ||
Restarting in 9 seconds... | ||
Restarting in 8 seconds... | ||
Restarting in 7 seconds... | ||
Restarting in 6 seconds... | ||
Restarting in 5 seconds... | ||
Restarting in 4 seconds... | ||
Restarting in 3 seconds... | ||
Restarting in 2 seconds... | ||
Restarting in 1 seconds... | ||
Restarting in 0 seconds... | ||
Restarting now. | ||
``` | ||
|
||
Subsequent runs: | ||
|
||
``` | ||
Opening Non-Volatile Storage (NVS) handle... Done | ||
Reading restart counter from NVS ... Done | ||
Restart counter = 1 | ||
Updating restart counter in NVS ... Done | ||
Committing updates in NVS ... Done | ||
Restarting in 10 seconds... | ||
Restarting in 9 seconds... | ||
Restarting in 8 seconds... | ||
Restarting in 7 seconds... | ||
Restarting in 6 seconds... | ||
Restarting in 5 seconds... | ||
Restarting in 4 seconds... | ||
Restarting in 3 seconds... | ||
Restarting in 2 seconds... | ||
Restarting in 1 seconds... | ||
Restarting in 0 seconds... | ||
Restarting now. | ||
``` | ||
|
||
Restart counter will increment on each run. | ||
|
||
To reset the counter, erase the contents of flash memory using `make erase_flash` (or `idf.py erase_flash`, if using CMake build system), then upload the program again as described above. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.