Skip to content

Commit 8f371a5

Browse files
committed
docs(spi_flash): Add docs for spi_flash IRAM usage
1 parent b66e140 commit 8f371a5

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

docs/en/api-guides/performance/ram-usage.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ The following options will reduce IRAM usage of some ESP-IDF features:
216216
Any memory that ends up unused for static IRAM will be added to the heap.
217217

218218

219-
.. only:: esp32c3
219+
.. only:: SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND
220220

221221
Flash Suspend Feature
222222
^^^^^^^^^^^^^^^^^^^^^
@@ -232,6 +232,8 @@ The following options will reduce IRAM usage of some ESP-IDF features:
232232

233233
Placing additional code into IRAM will exacerbate IRAM usage. For this reason, there is :ref:`CONFIG_SPI_FLASH_AUTO_SUSPEND`, which can alleviate the aforementioned kinds of IRAM usage. By enabling this feature, the Cache will not be disabled when SPI flash driver APIs and SPI flash driver-based APIs are used. Therefore, code and data in flash can be executed or accessed normally, but with some minor delay. See :ref:`auto-suspend` for more details about this feature.
234234

235+
IRAM usage for flash driver can be declined with :ref:`CONFIG_SPI_FLASH_AUTO_SUSPEND` enabled. Please refer to :ref:`internal_memory_saving_for_flash_driver` for more detailed information.
236+
235237
Regarding the flash suspend feature usage, and corresponding response time delay, please also see this example :example:`system/flash_suspend`.
236238

237239

docs/en/api-reference/peripherals/spi_flash/index.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,49 @@ Additionally, all API functions are protected with a mutex (``s_flash_op_mutex``
258258

259259
In a single core environment (:ref:`CONFIG_FREERTOS_UNICORE` enabled), you need to disable both caches, so that no inter-CPU communication can take place.
260260

261+
.. only:: SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND
262+
263+
.. _internal_memory_saving_for_flash_driver:
264+
265+
Internal Memory Saving For Flash Driver
266+
---------------------------------------
267+
268+
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.
269+
270+
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.
271+
272+
.. note::
273+
274+
:ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` should not be turned off when :ref:`CONFIG_SPI_FLASH_AUTO_SUSPEND` is not enabled, otherwise it will cause critical crash. As for flash suspend feature, please refer to :ref:`auto-suspend` for more information.
275+
276+
Resource Consumption
277+
^^^^^^^^^^^^^^^^^^^^
278+
279+
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):
280+
281+
**Note that the following data are not exact values and are for reference only; they may differ on different chip models.**
282+
283+
Resource consumption when :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` is enabled.
284+
285+
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
286+
| Component Layer | Total Size | DIRAM | .bss | .data | .text | Flash Code | .text | Flash Data | .rodata |
287+
+==================+============+=======+======+=======+=======+============+=======+============+=========+
288+
| hal | 4624 | 4038 | 0 | 0 | 4038 | 586 | 586 | 0 | 0 |
289+
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
290+
| spi_flash | 14074 | 11597 | 82 | 1589 | 9926 | 2230 | 2230 | 247 | 247 |
291+
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
292+
293+
Resource consumption when :ref:`CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM` is disabled.
294+
295+
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
296+
| Component Layer | Total Size | DIRAM | .bss | .data | .text | Flash Code | .text | Flash Data | .rodata |
297+
+==================+============+=======+======+=======+=======+============+=======+============+=========+
298+
| hal | 4632 | 0 | 0 | 0 | 0 | 4632 | 4632 | 0 | 0 |
299+
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
300+
| spi_flash | 14569 | 1399 | 22 | 429 | 948 | 11648 | 11648 | 1522 | 1522 |
301+
+------------------+------------+-------+------+-------+-------+------------+-------+------------+---------+
302+
303+
261304
Related Documents
262305
------------------
263306

0 commit comments

Comments
 (0)