From 6ad49c1146592a9129a653047d4d3b864e3e58ba Mon Sep 17 00:00:00 2001 From: "C.S.M" Date: Mon, 28 Jul 2025 18:16:19 +0800 Subject: [PATCH] refactor(spi_flash): Remove sdkconfig dependency in flash hal layer --- components/hal/include/hal/spi_flash_hal.h | 1 + components/hal/spi_flash_hal.c | 8 ++++---- components/hal/spi_flash_hal_common.inc | 3 +-- components/spi_flash/esp_flash_spi_init.c | 4 ++++ tools/ci/sg_rules/no_kconfig_in_hal_component.yml | 1 - 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/hal/include/hal/spi_flash_hal.h b/components/hal/include/hal/spi_flash_hal.h index e21a42fec2..bba228d8d4 100644 --- a/components/hal/include/hal/spi_flash_hal.h +++ b/components/hal/include/hal/spi_flash_hal.h @@ -97,6 +97,7 @@ typedef struct { uint8_t tsus_val; ///< Tsus value of suspend (us). uint8_t trs_val; ///< Trs value of suspend (us) bool auto_waiti_pes; ///< True for auto-wait idle after suspend command. False for using time delay. + bool software_resume; ///< True for software resume, false for hardware resume. } spi_flash_hal_config_t; /** diff --git a/components/hal/spi_flash_hal.c b/components/hal/spi_flash_hal.c index 8b0f1e2fa3..98d3199bc2 100644 --- a/components/hal/spi_flash_hal.c +++ b/components/hal/spi_flash_hal.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -135,9 +135,9 @@ esp_err_t spi_flash_hal_init(spi_flash_hal_context_t *data_out, const spi_flash_ data_out->auto_waiti_pes = cfg->auto_waiti_pes; } -#if CONFIG_SPI_FLASH_SOFTWARE_RESUME - data_out->flags &= ~SPI_FLASH_HOST_CONTEXT_FLAG_AUTO_RESUME; -#endif + if (cfg->software_resume) { + data_out->flags &= ~SPI_FLASH_HOST_CONTEXT_FLAG_AUTO_RESUME; + } #if SOC_SPI_MEM_SUPPORT_FLASH_OPI_MODE if (cfg->octal_mode_en) { diff --git a/components/hal/spi_flash_hal_common.inc b/components/hal/spi_flash_hal_common.inc index 4f8947ecd2..83757d8dd9 100644 --- a/components/hal/spi_flash_hal_common.inc +++ b/components/hal/spi_flash_hal_common.inc @@ -19,7 +19,6 @@ #include "soc/soc_caps.h" #include "soc/chip_revision.h" #include "hal/efuse_hal.h" -#include "sdkconfig.h" #define ADDRESS_MASK_24BIT 0xFFFFFF #define COMPUTE_DUMMY_CYCLELEN(host, base) ((base) + ((spi_flash_hal_context_t*)host)->extra_dummy) @@ -141,7 +140,7 @@ esp_err_t spi_flash_hal_configure_host_io_mode( gpspi_flash_ll_set_dummy_out(dev, (conf_required? 1: 0), 1); #endif -#if CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) // TODO: This is temporarily for ESP32P4-ECO0, please remove it when eco0 is not widly used. IDF-10019 unsigned chip_version = efuse_hal_chip_revision(); if (unlikely(!ESP_CHIP_REV_ABOVE(chip_version, 1))) { diff --git a/components/spi_flash/esp_flash_spi_init.c b/components/spi_flash/esp_flash_spi_init.c index 93a55afdbd..ead712d192 100644 --- a/components/spi_flash/esp_flash_spi_init.c +++ b/components/spi_flash/esp_flash_spi_init.c @@ -541,6 +541,10 @@ esp_err_t esp_flash_init_default_chip(void) cfg.auto_waiti_pes = true; #endif + #if CONFIG_SPI_FLASH_AUTO_RESUME + cfg.software_resume = true; + #endif + //the host is already initialized, only do init for the data and load it to the host esp_err_t err = memspi_host_init_pointers(&esp_flash_default_host, &cfg); if (err != ESP_OK) { diff --git a/tools/ci/sg_rules/no_kconfig_in_hal_component.yml b/tools/ci/sg_rules/no_kconfig_in_hal_component.yml index affb2cca3d..567f79be01 100644 --- a/tools/ci/sg_rules/no_kconfig_in_hal_component.yml +++ b/tools/ci/sg_rules/no_kconfig_in_hal_component.yml @@ -15,7 +15,6 @@ ignores: - "components/hal/cache_hal.c" - "components/hal/ecdsa_hal.c" - "components/hal/mmu_hal.c" - - "components/hal/spi_flash_hal.c" - "components/hal/twai_hal_sja1000.c" - "components/hal/esp32/gpio_hal_workaround.c" - "components/hal/esp32/include/hal/twai_ll.h"