mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 02:37:19 +02:00
refactor(examples/storage): update document links
This commit is contained in:
@ -186,6 +186,6 @@ The current bootloader implementation allows a project to extend it or modify it
|
||||
|
||||
In the bootloader space, you cannot use the drivers and functions from other components unless they explicitly support run in bootloader. If necessary, then the required functionality should be placed in the project's `bootloader_components` directory (note that this will increase its size). Examples of components that can be used in the bootloader are:
|
||||
|
||||
* :example:`storage/nvs_bootloader`
|
||||
* :example:`storage/nvs/nvs_bootloader`
|
||||
|
||||
If the bootloader grows too large then it can collide with the partition table, which is flashed at offset 0x8000 by default. Increase the :ref:`partition table offset <CONFIG_PARTITION_TABLE_OFFSET>` value to place the partition table later in the flash. This increases the space available for the bootloader.
|
||||
|
@ -181,8 +181,8 @@ Points to keep in mind when developing NVS related code:
|
||||
|
||||
**Examples:**
|
||||
|
||||
- :example:`storage/nvs_rw_value` demonstrates how to use NVS to write and read a single integer value.
|
||||
- :example:`storage/nvs_rw_blob` demonstrates how to use NVS to write and read a blob.
|
||||
- :example:`storage/nvs/nvs_rw_value` demonstrates how to use NVS to write and read a single integer value.
|
||||
- :example:`storage/nvs/nvs_rw_blob` demonstrates how to use NVS to write and read a blob.
|
||||
- :example:`security/nvs_encryption_hmac` demonstrates NVS encryption using the HMAC peripheral, where the encryption keys are derived from the HMAC key burnt in eFuse.
|
||||
- :example:`security/flash_encryption` demonstrates the flash encryption workflow including NVS partition creation and usage.
|
||||
|
||||
|
@ -47,16 +47,18 @@ Examples
|
||||
|
||||
* - **Code Example**
|
||||
- **Description**
|
||||
* - :example:`nvs_rw_blob <storage/nvs_rw_blob>`
|
||||
* - :example:`nvs_rw_blob <storage/nvs/nvs_rw_blob>`
|
||||
- Shows the use of the C-style API to read and write blob data types in NVS flash.
|
||||
* - :example:`nvs_rw_value <storage/nvs_rw_value>`
|
||||
* - :example:`nvs_rw_value <storage/nvs/nvs_rw_value>`
|
||||
- Shows the use of the C-style API to read and write integer data types in NVS flash.
|
||||
* - :example:`nvs_rw_value_cxx <storage/nvs_rw_value_cxx>`
|
||||
* - :example:`nvs_rw_value_cxx <storage/nvs/nvs_rw_value_cxx>`
|
||||
- Shows the use of the C++-style API to read and write integer data types in NVS flash.
|
||||
* - :example:`nvs_bootloader <storage/nvs_bootloader>`
|
||||
* - :example:`nvs_bootloader <storage/nvs/nvs_bootloader>`
|
||||
- Shows the use of the API available to the bootloader code to read NVS data.
|
||||
* - :example:`nvsgen <storage/nvsgen>`
|
||||
* - :example:`nvsgen <storage/nvs/nvsgen>`
|
||||
- Demonstrates how to use the Python-based NVS image generation tool to create an NVS partition image from the contents of a CSV file.
|
||||
* - :example:`nvs_console <storage/nvs/nvs_console>`
|
||||
- Demonstrates how to use NVS through an interactive console interface.
|
||||
|
||||
.. list-table:: Common Filesystem API
|
||||
:widths: 25 75
|
||||
|
@ -37,7 +37,7 @@ Applications are expected to follow the steps below in order to enable decryptio
|
||||
Application Example
|
||||
-------------------
|
||||
|
||||
You can find code examples in :example:`storage/nvs_bootloader` (in the :example:`storage` directory of ESP-IDF examples).
|
||||
You can find code examples in :example:`storage/nvs/nvs_bootloader` (in the :example:`storage/nvs` directory of ESP-IDF examples).
|
||||
|
||||
This section demonstrates how to prepare data in the input-output structure for various data types, namespaces, and keys. It includes an example of reading string data from NVS.
|
||||
|
||||
|
@ -154,9 +154,9 @@ If ``FLASH_IN_PROJECT`` is not specified, the image will still be generated, but
|
||||
Application Example
|
||||
-------------------
|
||||
|
||||
You can find code examples in the :example:`storage` directory of ESP-IDF examples:
|
||||
You can find code examples in the :example:`storage/nvs` directory of ESP-IDF examples:
|
||||
|
||||
:example:`storage/nvs_rw_value`
|
||||
:example:`storage/nvs/nvs_rw_value`
|
||||
|
||||
Demonstrates how to read a single integer value from, and write it to NVS.
|
||||
|
||||
@ -164,7 +164,7 @@ You can find code examples in the :example:`storage` directory of ESP-IDF exampl
|
||||
|
||||
The example also shows how to check if a read/write operation was successful, or if a certain value has not been initialized in NVS. The diagnostic procedure is provided in plain text to help you track the program flow and capture any issues on the way.
|
||||
|
||||
:example:`storage/nvs_rw_blob`
|
||||
:example:`storage/nvs/nvs_rw_blob`
|
||||
|
||||
Demonstrates how to read a single integer value and a blob (binary large object), and write them to NVS to preserve this value between {IDF_TARGET_NAME} module restarts.
|
||||
|
||||
@ -173,9 +173,9 @@ You can find code examples in the :example:`storage` directory of ESP-IDF exampl
|
||||
|
||||
The example also shows how to implement the diagnostic procedure to check if the read/write operation was successful.
|
||||
|
||||
:example:`storage/nvs_rw_value_cxx`
|
||||
:example:`storage/nvs/nvs_rw_value_cxx`
|
||||
|
||||
This example does exactly the same as :example:`storage/nvs_rw_value`, except that it uses the C++ NVS handle class.
|
||||
This example does exactly the same as :example:`storage/nvs/nvs_rw_value`, except that it uses the C++ NVS handle class.
|
||||
|
||||
Internals
|
||||
---------
|
||||
|
@ -186,6 +186,6 @@ ESP-IDF 二级引导加载程序位于 flash 的 {IDF_TARGET_CONFIG_BOOTLOADER_O
|
||||
|
||||
在引导加载程序的代码中,不能使用其他组件提供的驱动和函数,除非某个驱动或函数明确声明支持在引导加载程序中运行。如果确实需要,请将所需功能放在项目的 `bootloader_components` 目录中(注意,这会增加引导加载程序的大小)。以下是可以在引导加载程序中使用的组件示例:
|
||||
|
||||
* :example:`storage/nvs_bootloader`
|
||||
* :example:`storage/nvs/nvs_bootloader`
|
||||
|
||||
如果引导加载程序过大,则可能与内存中的分区表重叠,分区表默认烧录在偏移量 0x8000 处。增加 :ref:`分区表偏移量 <CONFIG_PARTITION_TABLE_OFFSET>` ,将分区表放在 flash 中靠后的区域,这样可以增加引导加载程序的可用空间。
|
||||
|
@ -181,8 +181,8 @@ NVS 具有如下特性:
|
||||
|
||||
**示例:**
|
||||
|
||||
- :example:`storage/nvs_rw_value` 演示了如何写入和读取一个整数值。
|
||||
- :example:`storage/nvs_rw_blob` 演示如何写入和读取一个 blob。
|
||||
- :example:`storage/nvs/nvs_rw_value` 演示了如何写入和读取一个整数值。
|
||||
- :example:`storage/nvs/nvs_rw_blob` 演示如何写入和读取一个 blob。
|
||||
- :example:`security/nvs_encryption_hmac` 演示了如何用 HMAC 外设进行 NVS 加密,并通过 efuse 中的 HMAC 密钥生成加密密钥。
|
||||
- :example:`security/flash_encryption` 演示了如何进行 flash 加密,包括创建和使用 NVS 分区。
|
||||
|
||||
|
@ -47,16 +47,18 @@
|
||||
|
||||
* - **例程**
|
||||
- **描述**
|
||||
* - :example:`nvs_rw_blob <storage/nvs_rw_blob>`
|
||||
* - :example:`nvs_rw_blob <storage/nvs/nvs_rw_blob>`
|
||||
- 演示了如何在 NVS flash 中使用 C 语言 API 读写 blob 数据类型。
|
||||
* - :example:`nvs_rw_value <storage/nvs_rw_value>`
|
||||
* - :example:`nvs_rw_value <storage/nvs/nvs_rw_value>`
|
||||
- 演示了如何在 NVS flash 中使用 C 语言 API 读写整数数据类型。
|
||||
* - :example:`nvs_rw_value <storage/nvs_rw_value>`
|
||||
* - :example:`nvs_rw_value <storage/nvs/nvs_rw_value_cxx>`
|
||||
- 演示了如何在 NVS flash 中使用 C++ 语言 API 读写整数数据类型。
|
||||
* - :example:`nvs_bootloader <storage/nvs_bootloader>`
|
||||
* - :example:`nvs_bootloader <storage/nvs/nvs_bootloader>`
|
||||
- 演示了如何使用引导加载程序代码中可用的 API 来读取 NVS 数据。
|
||||
* - :example:`nvsgen <storage/nvsgen>`
|
||||
* - :example:`nvsgen <storage/nvs/nvsgen>`
|
||||
- 演示了如何使用基于 Python 的 NVS 镜像生成工具,根据 CSV 文件内容创建 NVS 分区镜像。
|
||||
* - :example:`nvs_console <storage/nvs/nvs_console>`
|
||||
- 演示了如何通过交互式控制台界面使用 NVS。
|
||||
|
||||
.. list-table:: 常用文件系统 API
|
||||
:widths: 25 75
|
||||
|
@ -37,7 +37,7 @@
|
||||
应用示例
|
||||
-----------
|
||||
|
||||
代码示例请参阅 ESP-IDF 示例 :example:`storage` 目录下的 :example:`storage/nvs_bootloader`。
|
||||
代码示例请参阅 ESP-IDF 示例 :example:`storage/nvs` 目录下的 :example:`storage/nvs/nvs_bootloader`。
|
||||
|
||||
本节演示了如何在输入/输出结构中准备数据,以支持不同的数据类型、命名空间和键。此外,还包含从 NVS 读取字符串数据的示例。
|
||||
|
||||
|
@ -154,9 +154,9 @@ NVS 分区生成程序帮助生成 NVS 分区二进制文件,可使用烧录
|
||||
应用示例
|
||||
-------------------
|
||||
|
||||
ESP-IDF :example:`storage` 目录下提供了数个代码示例:
|
||||
ESP-IDF :example:`storage/nvs` 目录下提供了数个代码示例:
|
||||
|
||||
:example:`storage/nvs_rw_value`
|
||||
:example:`storage/nvs/nvs_rw_value`
|
||||
|
||||
演示如何读取及写入 NVS 单个整数值。
|
||||
|
||||
@ -164,7 +164,7 @@ ESP-IDF :example:`storage` 目录下提供了数个代码示例:
|
||||
|
||||
该示例也演示了如何检测读取/写入操作是否成功,以及某个特定值是否在 NVS 中尚未初始化。诊断程序以纯文本形式提供,有助于追踪程序流程,及时发现问题。
|
||||
|
||||
:example:`storage/nvs_rw_blob`
|
||||
:example:`storage/nvs/nvs_rw_blob`
|
||||
|
||||
演示如何读取及写入 NVS 单个整数值和 BLOB(二进制大对象),并在 NVS 中存储这一数值,即便 {IDF_TARGET_NAME} 模组重启也不会消失。
|
||||
|
||||
@ -173,9 +173,9 @@ ESP-IDF :example:`storage` 目录下提供了数个代码示例:
|
||||
|
||||
该示例也演示了如何执行诊断程序以检测读取/写入操作是否成功。
|
||||
|
||||
:example:`storage/nvs_rw_value_cxx`
|
||||
:example:`storage/nvs/nvs_rw_value_cxx`
|
||||
|
||||
这个例子与 :example:`storage/nvs_rw_value` 完全一样,只是使用了 C++ 的 NVS 句柄类。
|
||||
这个例子与 :example:`storage/nvs/nvs_rw_value` 完全一样,只是使用了 C++ 的 NVS 句柄类。
|
||||
|
||||
内部实现
|
||||
---------
|
||||
|
@ -17,6 +17,7 @@ The examples are grouped into sub-directories by category. Each category directo
|
||||
* `nvs_rw_blob` example demonstrates how to read and write a single integer value and a blob (binary large object) using NVS to preserve them between ESP module restarts.
|
||||
* `nvs_rw_value` example demonstrates how to read and write a single integer value using NVS.
|
||||
* `nvs_rw_value_cxx` example demonstrates how to read and write a single integer value using NVS (it uses the C++ NVS handle API).
|
||||
* `nvs_console` example demonstrates how to use NVS through an interactive console interface.
|
||||
* `partition_api` examples demonstrate how to use different partition APIs.
|
||||
* `parttool` example demonstrates common operations the partitions tool allows the user to perform.
|
||||
* `sd_card` examples demonstrate how to use an SD card with an ESP device.
|
||||
|
@ -1,18 +1,9 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |
|
||||
|
||||
# NVS Console Example
|
||||
|
||||
This example demonstrates how to use Non-Volatile Storage (NVS) through an interactive console interface. It provides a set of commands to read, write, and manage data in NVS.
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
## Overview
|
||||
|
||||
The example implements a command-line interface with the following features:
|
||||
- Interactive console with command history
|
||||
- Command auto-completion
|
||||
- Command hints
|
||||
- Persistent command history (optional)
|
||||
- Color-coded output (on supported terminals)
|
||||
This example demonstrates how to use Non-Volatile Storage (NVS) through an interactive console interface. It provides a set of commands to read, write, and manage data in NVS.
|
||||
|
||||
## Hardware Required
|
||||
|
||||
@ -49,6 +40,7 @@ The following commands are available:
|
||||
- type can be: i8, u8, i16, u16 i32, u32 i64, u64, str, blob
|
||||
- Example: `nvs_set counter i32 -v 42`
|
||||
- Example: `nvs_set name str -v "esp"`
|
||||
- Example: `nvs_set blob_val blob -v "657370"` - To set a blob value, provide the hex representation of the data you want to store. For example, 65 (e), 73 (s), 70 (p).
|
||||
|
||||
- `nvs_get <key>` - Get a value from NVS
|
||||
- Example: `nvs_get counter`
|
||||
@ -56,7 +48,8 @@ The following commands are available:
|
||||
- `nvs_erase <key>` - Erase a key from NVS
|
||||
- Example: `nvs_erase counter`
|
||||
|
||||
- `nvs_list <partition> [-n <namespace>] [-t <type>]` - List stored key-value pairs stored in NVS.
|
||||
- `nvs_list <partition> [-n <namespace>] [-t <type>]` - List stored key-value pairs stored in NVS. Use default partition name 'nvs' for listing the stored data.
|
||||
- Example: `nvs_list nvs` - This command lists all namespaces and their stored key-value pairs in the 'nvs' partition.
|
||||
- Example: `nvs_list nvs -n storage -t i8`
|
||||
|
||||
- `nvs_erase_namespace <namespace>` - Erases specified namespace
|
||||
@ -66,7 +59,7 @@ The following commands are available:
|
||||
- `help` - List all commands
|
||||
- `free` - Get the current size of free heap memory
|
||||
- `restart` - Software reset of the chip
|
||||
- `version` - Get version of chip and SDK
|
||||
- `version` - Get the chip info together with ESP-IDF version used in the application
|
||||
- `heap` - Get minimum size of free heap memory that was available during program execution
|
||||
|
||||
### Example Output
|
||||
|
@ -25,16 +25,9 @@
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#define STORAGE_NAMESPACE "storage"
|
||||
#define BLOB_EXAMPLE_DATA_SIZE 256
|
||||
|
||||
static const char *TAG = "nvs_blob_example";
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
#define BOOT_MODE_PIN GPIO_NUM_9
|
||||
#else
|
||||
#define BOOT_MODE_PIN GPIO_NUM_0
|
||||
#endif //CONFIG_IDF_TARGET_ESP32C3
|
||||
|
||||
/* Test data structure to demonstrate different data types in blob */
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
@ -217,20 +210,5 @@ void app_main(void)
|
||||
ESP_LOGE(TAG, "Error (%s) reading updated data!", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "\nBlob operations completed. Monitoring GPIO for reset...");
|
||||
|
||||
// Setup GPIO for reset monitoring
|
||||
gpio_reset_pin(BOOT_MODE_PIN);
|
||||
gpio_set_direction(BOOT_MODE_PIN, GPIO_MODE_INPUT);
|
||||
|
||||
while (1) {
|
||||
if (gpio_get_level(BOOT_MODE_PIN) == 0) {
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
if(gpio_get_level(BOOT_MODE_PIN) == 0) {
|
||||
ESP_LOGI(TAG, "Reset button pressed, restarting...");
|
||||
esp_restart();
|
||||
}
|
||||
}
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
}
|
||||
ESP_LOGI(TAG, "\nBlob operations completed.");
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ def test_examples_nvs_rw_blob(dut: Dut) -> None:
|
||||
dut.expect('Reading test data blob:', timeout=20)
|
||||
# Verify array data reading
|
||||
dut.expect('Reading array data blob:', timeout=20)
|
||||
dut.expect('Blob operations completed. Monitoring GPIO for reset...', timeout=20)
|
||||
dut.expect('Blob operations completed.', timeout=20)
|
||||
|
Reference in New Issue
Block a user