From ae89f98d59c3391cf68cf4678e6e161fbac28d30 Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Thu, 2 Apr 2020 17:29:21 +0800 Subject: [PATCH] spi_flash(new driver): Add vTaskDelay while a long erasing --- components/spi_flash/esp_flash_api.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/spi_flash/esp_flash_api.c b/components/spi_flash/esp_flash_api.c index a5c04a47b7..3dd70b4bf6 100644 --- a/components/spi_flash/esp_flash_api.c +++ b/components/spi_flash/esp_flash_api.c @@ -23,6 +23,8 @@ #include "sdkconfig.h" #include "esp_heap_caps.h" #include "esp_flash_internal.h" +#include +#include "esp_timer.h" static const char TAG[] = "spi_flash"; @@ -337,8 +339,13 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui err = spiflash_end(chip, err); } - +#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE + int64_t no_yield_time_us = 0; +#endif while (err == ESP_OK && len >= sector_size) { +#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE + int64_t start_time_us = esp_timer_get_time(); +#endif err = spiflash_start(chip); if (err != ESP_OK) { return err; @@ -358,6 +365,14 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui } err = spiflash_end(chip, err); + +#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE + no_yield_time_us += (esp_timer_get_time() - start_time_us); + if (no_yield_time_us / 1000 >= CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS) { + no_yield_time_us = 0; + vTaskDelay(CONFIG_SPI_FLASH_ERASE_YIELD_TICKS); + } +#endif } return err; }