docs: Update translation for SPI flash and RAM Usage

This commit is contained in:
Zhang Shuxian
2025-02-28 16:07:42 +08:00
parent 87024c3da1
commit f6cc4f6140
3 changed files with 172 additions and 21 deletions

View File

@@ -145,7 +145,7 @@ Refer to the :doc:`Flash Encryption documentation </security/flash-encryption>`
Memory Mapping API
------------------
{IDF_TARGET_CACHE_SIZE:default="64 KB", esp32c2=16 ~ 64 KB}
{IDF_TARGET_CACHE_SIZE:default="64 KB", esp32c2=16~64 KB}
{IDF_TARGET_NAME} features memory hardware which allows regions of flash memory to be mapped into instruction and data address spaces. This mapping works only for read operations. It is not possible to modify contents of flash memory by writing to a mapped memory region.
@@ -265,7 +265,7 @@ In a single core environment (:ref:`CONFIG_FREERTOS_UNICORE` enabled), you need
Internal Memory Saving For Flash Driver
---------------------------------------
The ESP-IDF provides options to optimize the usage of IRAM by selectively placing certain functions into flash memory via turning off :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM`. It allows SPI flash operation functions to be executed from flash memory instead of IRAM. Thus it will save some IRAM memory for other significant time-critical functions or tasks.
The ESP-IDF provides options to optimize the usage of IRAM by selectively placing certain functions into flash memory via turning off :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM`. It allows SPI flash operation functions to be executed from flash memory instead of IRAM. Thus it saves IRAM memory for other significant time-critical functions or tasks.
However, this has some implications for flash itself. Functions placed into flash memory may have slightly increased execution times compared to those placed in IRAM. Applications with strict timing requirements or those heavily reliant on SPI flash operations may need to evaluate the trade-offs before enabling this option.
@@ -276,30 +276,83 @@ In a single core environment (:ref:`CONFIG_FREERTOS_UNICORE` enabled), you need
Resource Consumption
^^^^^^^^^^^^^^^^^^^^
Use the :doc:`/api-guides/tools/idf-size` tool to check the code and data consumption of the SPI flash driver. The following are the test conditions (using ESP32-C2 as an example):
Use the :doc:`/api-guides/tools/idf-size` tool to check the code and data consumption of the SPI flash driver. The following are the test results under 2 different conditions (using ESP32-C2 as an example):
**Note that the following data are not exact values and are for reference only; they may differ on different chip models.**
Resource consumption when :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` is enabled.
Resource consumption when :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` is enabled:
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
| Component Layer | Total Size | DIRAM | .bss | .data | .text | Flash Code | .text | Flash Data | .rodata |
+==================+============+=======+======+=======+=======+============+=======+============+=========+
| hal | 4624 | 4038 | 0 | 0 | 4038 | 586 | 586 | 0 | 0 |
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
| spi_flash | 14074 | 11597 | 82 | 1589 | 9926 | 2230 | 2230 | 247 | 247 |
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
.. list-table:: Resource Consumption
:widths: 20 10 10 10 10 10 10 10 10 10
:header-rows: 1
Resource consumption when :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` is disabled.
* - Component Layer
- Total Size
- DIRAM
- .bss
- .data
- .text
- Flash Code
- .text
- Flash Data
- .rodata
* - hal
- 4624
- 4038
- 0
- 0
- 4038
- 586
- 586
- 0
- 0
* - spi_flash
- 14074
- 11597
- 82
- 1589
- 9926
- 2230
- 2230
- 247
- 247
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
| Component Layer | Total Size | DIRAM | .bss | .data | .text | Flash Code | .text | Flash Data | .rodata |
+==================+============+=======+======+=======+=======+============+=======+============+=========+
| hal | 4632 | 0 | 0 | 0 | 0 | 4632 | 4632 | 0 | 0 |
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
| spi_flash | 14569 | 1399 | 22 | 429 | 948 | 11648 | 11648 | 1522 | 1522 |
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
Resource consumption when :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` is disabled:
.. list-table:: Resource Consumption
:widths: 20 10 10 10 10 10 10 10 10 10
:header-rows: 1
* - Component Layer
- Total Size
- DIRAM
- .bss
- .data
- .text
- Flash Code
- .text
- Flash Data
- .rodata
* - hal
- 4632
- 0
- 0
- 0
- 0
- 4632
- 4632
- 0
- 0
* - spi_flash
- 14569
- 1399
- 22
- 429
- 948
- 11648
- 11648
- 1522
- 1522
Related Documents
------------------

View File

@@ -216,7 +216,7 @@ IRAM 优化
任何最终未用于静态 IRAM 的内存都将添加到堆内存中。
.. only:: esp32c3
.. only:: SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND
flash 暂停特性
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -232,6 +232,8 @@ IRAM 优化
将额外代码放置到 IRAM 中,将增加 IRAM 使用量ESP-IDF 提供了 :ref:`CONFIG_SPI_FLASH_AUTO_SUSPEND` 选项,可以缓解 IRAM 的使用。通过启用此功能,使用 SPI flash API 和基于 SPI flash API 的 API 时,不会导致缓存禁用,因此 flash 中的代码和数据仍可正常执行或访问,但会有些延迟。有关此功能的详细信息,请参阅 :ref:`auto-suspend`
启用 :ref:`CONFIG_SPI_FLASH_AUTO_SUSPEND` 后,可以减少 flash 驱动的 IRAM 使用。更多详细信息请参阅 :ref:`internal_memory_saving_for_flash_driver`
有关 flash 暂停特性的使用及其相应的响应时间延迟,请参阅 :example:`system/flash_suspend`

View File

@@ -161,7 +161,7 @@ flash 在 {IDF_TARGET_CACHE_SIZE} 页进行映射。内存映射硬件既可将
- :cpp:func:`spi_flash_munmap`:取消上述区域的映射;
- :cpp:func:`esp_partition_mmap`:将分区的一部分映射至 CPU 指令空间或数据空间;
:cpp:func:`spi_flash_mmap`:cpp:func:`esp_partition_mmap` 的区别如下:
:cpp:func:`spi_flash_mmap`:cpp:func:`esp_partition_mmap` 的区别如下:
- :cpp:func:`spi_flash_mmap`:需要给定一个 {IDF_TARGET_CACHE_SIZE} 对齐的物理地址;
- :cpp:func:`esp_partition_mmap`:给定分区内任意偏移量即可,此函数根据需要将返回的指针调整至指向映射内存。
@@ -258,6 +258,102 @@ flash 操作完成后CPU A 上的函数将设置另一标志位,即 ``s_fla
在单核环境中(启用 :ref:`CONFIG_FREERTOS_UNICORE`),需要禁用上述两个 cache以防发生 CPU 间通信。
.. only:: SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND
.. _internal_memory_saving_for_flash_driver:
flash 驱动的内部存储优化
-----------------------------
ESP-IDF 提供了优化 IRAM 使用的选项。通过禁用 :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` 选项,可以选择性地将某些函数地放入 flash使 SPI flash 操作函数在 flash 中执行,而不是从 IRAM 中执行。这种方式能够节省 IRAM 内存,用于其他对时间敏感的函数或任务。
然而,这种方式对 flash 性能具有一定的影响。与 IRAM 中的函数相比,放在 flash 中的函数执行时间可能略有增加。因此对于具有严格时序要求或严重依赖 SPI flash 操作的应用程序,采取此方式前需进行权衡。
.. note::
未启用 :ref:`CONFIG_SPI_FLASH_AUTO_SUSPEND` 时,不应禁用 :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM`,否则会导致严重崩溃。关于 flash 挂起功能,请参阅 :ref:`auto-suspend`
资源消耗
^^^^^^^^^^^^
使用 :doc:`/api-guides/tools/idf-size` 工具来检查 SPI flash 驱动的代码和数据消耗。以下是测试条件(以 ESP32-C2 为例):
**请注意,以下数据并非精确值,仅供参考;不同芯片型号可能会有所差异。**
启用 :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` 时的资源消耗如下表所示:
.. list-table:: 选项启用时的资源消耗
:widths: 20 10 10 10 10 10 10 10 10 10
:header-rows: 1
* - 组件层
- 总大小
- DIRAM
- .bss
- .data
- .text
- flash 代码
- .text
- flash 数据
- .rodata
* - hal
- 4624
- 4038
- 0
- 0
- 4038
- 586
- 586
- 0
- 0
* - spi_flash
- 14074
- 11597
- 82
- 1589
- 9926
- 2230
- 2230
- 247
- 247
禁用 :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` 时的资源消耗如下表所示:
.. list-table:: 选项禁用时的资源消耗
:widths: 20 10 10 10 10 10 10 10 10 10
:header-rows: 1
* - 组件层
- 总大小
- DIRAM
- .bss
- .data
- .text
- flash 代码
- .text
- flash 数据
- .rodata
* - hal
- 4632
- 0
- 0
- 0
- 0
- 4632
- 4632
- 0
- 0
* - spi_flash
- 14569
- 1399
- 22
- 429
- 948
- 11648
- 11648
- 1522
- 1522
相关文档
-----------------