spi_flash(new driver): Add vTaskDelay while a long erasing
This commit is contained in:
parent
3cb655eaab
commit
ae89f98d59
1 changed files with 16 additions and 1 deletions
|
@ -23,6 +23,8 @@
|
|||
#include "sdkconfig.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_flash_internal.h"
|
||||
#include <freertos/task.h>
|
||||
#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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue