From 4310ae9d7bd55280823cab76e07d4140928218a9 Mon Sep 17 00:00:00 2001 From: "C.S.M" Date: Thu, 26 Mar 2026 11:42:40 +0800 Subject: [PATCH] feat(spi_flash): Add entire support for h21 external flash --- components/esp_hal_mspi/esp32h21/include/hal/gpspi_flash_ll.h | 3 +-- .../esp_hal_mspi/esp32h21/include/hal/spimem_flash_ll.h | 2 ++ components/soc/esp32h21/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32h21/include/soc/soc_caps.h | 3 ++- components/soc/esp32s31/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32s31/include/soc/soc_caps.h | 1 + examples/storage/fatfs/ext_flash/README.md | 4 ++-- 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/components/esp_hal_mspi/esp32h21/include/hal/gpspi_flash_ll.h b/components/esp_hal_mspi/esp32h21/include/hal/gpspi_flash_ll.h index c2705cbd89a..8dad09ade71 100644 --- a/components/esp_hal_mspi/esp32h21/include/hal/gpspi_flash_ll.h +++ b/components/esp_hal_mspi/esp32h21/include/hal/gpspi_flash_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -31,7 +31,6 @@ extern "C" { #define gpspi_flash_ll_hw_get_id(dev) ( ((dev) == (void*)&GPSPI2) ? SPI2_HOST : -1 ) typedef typeof(GPSPI2.clock.val) gpspi_flash_ll_clock_reg_t; -#define GPSPI_FLASH_LL_PERIPHERAL_FREQUENCY_MHZ (32) // (register default)0: XTAL_CLK /*------------------------------------------------------------------------------ * Control diff --git a/components/esp_hal_mspi/esp32h21/include/hal/spimem_flash_ll.h b/components/esp_hal_mspi/esp32h21/include/hal/spimem_flash_ll.h index 4a960b9b751..77af0c544b5 100644 --- a/components/esp_hal_mspi/esp32h21/include/hal/spimem_flash_ll.h +++ b/components/esp_hal_mspi/esp32h21/include/hal/spimem_flash_ll.h @@ -346,6 +346,7 @@ static inline void spimem_flash_ll_exit_dpd(spi_mem_dev_t *dev) * @param buffer Buffer to hold the output data * @param read_len Length to get out of the buffer */ +__attribute__((always_inline)) static inline void spimem_flash_ll_get_buffer_data(spi_mem_dev_t *dev, void *buffer, uint32_t read_len) { if (((intptr_t)buffer % 4 == 0) && (read_len % 4 == 0)) { @@ -371,6 +372,7 @@ static inline void spimem_flash_ll_get_buffer_data(spi_mem_dev_t *dev, void *buf * @param buffer Buffer holding the data * @param length Length of data in bytes. */ +__attribute__((always_inline)) static inline void spimem_flash_ll_set_buffer_data(spi_mem_dev_t *dev, const void *buffer, uint32_t length) { // Load data registers, word at a time diff --git a/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in index 5ceeff5eb83..16d2b110919 100644 --- a/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in @@ -163,6 +163,10 @@ config SOC_SPI_FLASH_SUPPORTED bool default y +config SOC_SPI_EXTERNAL_NOR_FLASH_SUPPORTED + bool + default y + config SOC_MODEM_CLOCK_SUPPORTED bool default y diff --git a/components/soc/esp32h21/include/soc/soc_caps.h b/components/soc/esp32h21/include/soc/soc_caps.h index 5646c72ff09..5ae89659d17 100644 --- a/components/soc/esp32h21/include/soc/soc_caps.h +++ b/components/soc/esp32h21/include/soc/soc_caps.h @@ -69,7 +69,8 @@ #define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1 #define SOC_RTC_WDT_SUPPORTED 1 -#define SOC_SPI_FLASH_SUPPORTED 1 //TODO: [ESP32H21] IDF-11526 +#define SOC_SPI_FLASH_SUPPORTED 1 +#define SOC_SPI_EXTERNAL_NOR_FLASH_SUPPORTED 1 // #define SOC_RNG_SUPPORTED 1 //TODO: [ESP32H21] IDF-11503 #define SOC_MODEM_CLOCK_SUPPORTED 1 #define SOC_REGI2C_SUPPORTED 1 diff --git a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in index a8bf900c0ff..defdef34342 100644 --- a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in @@ -331,6 +331,10 @@ config SOC_EMAC_SUPPORTED bool default y +config SOC_SPI_EXTERNAL_NOR_FLASH_SUPPORTED + bool + default y + config SOC_EMAC_SUPPORT_1000M bool default y diff --git a/components/soc/esp32s31/include/soc/soc_caps.h b/components/soc/esp32s31/include/soc/soc_caps.h index 8907cf8458b..9ffab77eac7 100644 --- a/components/soc/esp32s31/include/soc/soc_caps.h +++ b/components/soc/esp32s31/include/soc/soc_caps.h @@ -112,6 +112,7 @@ #define SOC_REGI2C_SUPPORTED 1 #define SOC_JPEG_CODEC_SUPPORTED 1 #define SOC_EMAC_SUPPORTED 1 +#define SOC_SPI_EXTERNAL_NOR_FLASH_SUPPORTED 1 /*-------------------------- EMAC CAPS ----------------------------------------*/ #define SOC_EMAC_SUPPORT_1000M (1) /*!< EMAC Supports 1000Mbps mode */ diff --git a/examples/storage/fatfs/ext_flash/README.md b/examples/storage/fatfs/ext_flash/README.md index 550101d8b4d..41df7c62d7e 100644 --- a/examples/storage/fatfs/ext_flash/README.md +++ b/examples/storage/fatfs/ext_flash/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | --------- | # FAT FS on External Flash example