mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
refactor(spi_flash): reorganize header files and improve API encapsulation
This commit reorganizes SPI flash header files to better reflect their visibility and intended usage: 1. Rename `esp_flash_port/` to `esp_flash_chips/`: - Better reflects that these headers are for chip driver implementations - All chip driver headers moved to `esp_flash_chips/` directory - Added README.md explaining semi-public nature of these headers 2. Move internal headers to `esp_private/`: - `esp_flash_internal.h` -> `esp_private/esp_flash_internal.h` - `memspi_host_driver.h` -> `esp_private/memspi_host_driver.h` 3. Move chip driver related headers to `esp_flash_chips/`: - `esp_private/esp_flash_types.h` -> `esp_flash_chips/esp_flash_types.h` - `spi_flash/spi_flash_defs.h` -> `esp_flash_chips/spi_flash_defs.h` - `spi_flash_override.h` -> `esp_flash_chips/spi_flash_override.h` - All `spi_flash_chip_*.h` headers moved to `esp_flash_chips/` 4. Code improvements: - Remove unused includes (e.g., `spi_flash_override.h` from `cache_utils.c`) - Use public API `esp_flash_get_size()` instead of direct member access - Add `esp_flash_is_quad_mode` to linker.lf for IRAM placement 5. Documentation updates: - Add README.md in `esp_flash_chips/` explaining semi-public headers - Update programming guide with warnings about internal headers - Update both English and Chinese documentation 6. Update all references across the codebase: - Update includes in `spi_flash` component - Update `bootloader_support`, `app_update`, `esp_tee`, `espcoredump` - Update example projects Breaking changes: - Headers moved to new locations require include path updates - `custom_flash_driver` example temporarily disabled until external components are updated
This commit is contained in:
@@ -175,6 +175,10 @@ flash 在 {IDF_TARGET_CACHE_SIZE} 页进行映射。内存映射硬件既可将
|
||||
SPI flash 实现
|
||||
--------------
|
||||
|
||||
.. note::
|
||||
|
||||
实现部分的头文件(例如 ``esp_flash_chips/``、``esp_private/``)是**内部**的 - 它们面向需要为不支持的 flash 芯片实现自定义芯片驱动的专家用户,但**不被视为稳定 API**,可能会在不通知的情况下更改。对于大多数用例,您应该使用 ``esp_flash.h`` 中的公共 API。
|
||||
|
||||
``esp_flash_t`` 结构体包含芯片数据和该 API 的三个重要部分:
|
||||
|
||||
1. 主机驱动,为访问芯片提供硬件支持;
|
||||
@@ -193,7 +197,7 @@ SPI flash 实现
|
||||
芯片驱动
|
||||
^^^^^^^^^^^
|
||||
|
||||
芯片驱动在 ``spi_flash_chip_driver.h`` 中进行定义,并将主机驱动提供的基本函数进行封装以供 API 层使用。
|
||||
芯片驱动在 ``esp_flash_chips/spi_flash_chip_driver.h`` 中进行定义,并将主机驱动提供的基本函数进行封装以供 API 层使用。
|
||||
|
||||
有些操作需在执行前先发送命令,或在执行后读取状态,因此有些芯片需要不同的命令或值以及通信方式。
|
||||
|
||||
|
||||
@@ -149,7 +149,12 @@
|
||||
应用程序中的 flash 驱动程序用于读取、写入、擦除、保存数据等操作,且支持 OTA 等高级功能。可参考下列指南,为你的 flash 芯片自定义驱动程序。
|
||||
|
||||
- 步骤 1:`default_registered_chips` 的最后一项应为 `通用芯片驱动程序 <https://github.com/espressif/esp-idf/blob/master/components/spi_flash/spi_flash_chip_generic.c>`_。如果你的 flash 芯片无法匹配以上列出的任何一个芯片驱动程序,则将使用通用驱动。请检查你的 flash 芯片行为与通用驱动是否存在差异,包括但不限于不同的命令、dummy 周期、数据字节以及状态寄存器。
|
||||
- 步骤 2:如果你的 flash 芯片行为与通用驱动存在差异,则需要实现自定义的芯片驱动程序。请创建一个名为 ``spi_flash_chip_<vendor>.c`` 的新文件,在其中实现特定行为。可以将 ``esp_flash_chip_generic`` 结构体复制到文件中进行修改。记得在文件中包含 ``spi_flash_chip_generic.h``。详情请参阅示例 `esp_flash_nor <https://github.com/espressif/esp-flash-drivers/tree/main/esp_flash_nor/>`_。
|
||||
- 步骤 2:如果你的 flash 芯片行为与通用驱动存在差异,则需要实现自定义的芯片驱动程序。请创建一个名为 ``spi_flash_chip_<vendor>.c`` 的新文件,在其中实现特定行为。可以将 ``esp_flash_chip_generic`` 结构体复制到文件中进行修改。记得在文件中包含 ``esp_flash_chips/spi_flash_chip_generic.h``。详情请参阅示例 `esp_flash_nor <https://github.com/espressif/esp-flash-drivers/tree/main/esp_flash_nor/>`_。
|
||||
|
||||
.. note::
|
||||
|
||||
芯片驱动程序头文件位于 ``esp_flash_chips/`` 目录中(例如 ``components/spi_flash/include/esp_flash_chips/``)。这些头文件是**半公开的** - 它们面向需要实现自定义芯片驱动程序的高级用户,但**不被视为稳定的 API**,可能会在未通知的情况下更改。
|
||||
|
||||
- 步骤 3:实现与通用驱动程序存在差异的函数,并从 ``spi_flash_chip_t`` 结构体中指向这些函数。注意:如果 flash 芯片的某些行为与通用驱动相同,那么可以保留通用驱动程序的函数,无需自定义,只要为与通用驱动不同的部分编写自定义函数即可。请参考以下示例:
|
||||
|
||||
.. important::
|
||||
|
||||
Reference in New Issue
Block a user