mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
spi_flash: don't call vTaskDelay in non-os context
Fixes regression in core dump, when a crash happens in interrupt context.
This commit is contained in:
@@ -71,6 +71,7 @@ static spi_flash_counters_t s_flash_stats;
|
|||||||
|
|
||||||
static esp_err_t spi_flash_translate_rc(esp_rom_spiflash_result_t rc);
|
static esp_err_t spi_flash_translate_rc(esp_rom_spiflash_result_t rc);
|
||||||
static bool is_safe_write_address(size_t addr, size_t size);
|
static bool is_safe_write_address(size_t addr, size_t size);
|
||||||
|
static void spi_flash_os_yield(void);
|
||||||
|
|
||||||
const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = {
|
const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = {
|
||||||
.start = spi_flash_disable_interrupts_caches_and_other_cpu,
|
.start = spi_flash_disable_interrupts_caches_and_other_cpu,
|
||||||
@@ -78,18 +79,20 @@ const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = {
|
|||||||
.op_lock = spi_flash_op_lock,
|
.op_lock = spi_flash_op_lock,
|
||||||
.op_unlock = spi_flash_op_unlock,
|
.op_unlock = spi_flash_op_unlock,
|
||||||
#if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED
|
#if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED
|
||||||
.is_safe_write_address = is_safe_write_address
|
.is_safe_write_address = is_safe_write_address,
|
||||||
#endif
|
#endif
|
||||||
|
.yield = spi_flash_os_yield,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_no_os_ops = {
|
const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_no_os_ops = {
|
||||||
.start = spi_flash_disable_interrupts_caches_and_other_cpu_no_os,
|
.start = spi_flash_disable_interrupts_caches_and_other_cpu_no_os,
|
||||||
.end = spi_flash_enable_interrupts_caches_no_os,
|
.end = spi_flash_enable_interrupts_caches_no_os,
|
||||||
.op_lock = 0,
|
.op_lock = NULL,
|
||||||
.op_unlock = 0,
|
.op_unlock = NULL,
|
||||||
#if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED
|
#if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED
|
||||||
.is_safe_write_address = 0
|
.is_safe_write_address = NULL,
|
||||||
#endif
|
#endif
|
||||||
|
.yield = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const spi_flash_guard_funcs_t *s_flash_guard_ops;
|
static const spi_flash_guard_funcs_t *s_flash_guard_ops;
|
||||||
@@ -184,6 +187,13 @@ static inline void IRAM_ATTR spi_flash_guard_op_unlock()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void IRAM_ATTR spi_flash_os_yield(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE
|
||||||
|
vTaskDelay(CONFIG_SPI_FLASH_ERASE_YIELD_TICKS);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static esp_rom_spiflash_result_t IRAM_ATTR spi_flash_unlock()
|
static esp_rom_spiflash_result_t IRAM_ATTR spi_flash_unlock()
|
||||||
{
|
{
|
||||||
static bool unlocked = false;
|
static bool unlocked = false;
|
||||||
@@ -247,7 +257,9 @@ esp_err_t IRAM_ATTR spi_flash_erase_range(uint32_t start_addr, uint32_t size)
|
|||||||
* In this case we need to call vTaskDelay because
|
* In this case we need to call vTaskDelay because
|
||||||
* the duration of this command + the next command probably will exceed more than 20.
|
* the duration of this command + the next command probably will exceed more than 20.
|
||||||
*/
|
*/
|
||||||
vTaskDelay(CONFIG_SPI_FLASH_ERASE_YIELD_TICKS);
|
if (s_flash_guard_ops && s_flash_guard_ops->yield) {
|
||||||
|
s_flash_guard_ops->yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -317,6 +317,10 @@ typedef void (*spi_flash_op_unlock_func_t)(void);
|
|||||||
* @brief Function to protect SPI flash critical regions corruption.
|
* @brief Function to protect SPI flash critical regions corruption.
|
||||||
*/
|
*/
|
||||||
typedef bool (*spi_flash_is_safe_write_address_t)(size_t addr, size_t size);
|
typedef bool (*spi_flash_is_safe_write_address_t)(size_t addr, size_t size);
|
||||||
|
/**
|
||||||
|
* @brief Function to yield to the OS during erase operation.
|
||||||
|
*/
|
||||||
|
typedef void (*spi_flash_os_yield_t)(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure holding SPI flash access critical sections management functions.
|
* Structure holding SPI flash access critical sections management functions.
|
||||||
@@ -357,6 +361,7 @@ typedef struct {
|
|||||||
#if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED
|
#if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED
|
||||||
spi_flash_is_safe_write_address_t is_safe_write_address; /**< checks flash write addresses.*/
|
spi_flash_is_safe_write_address_t is_safe_write_address; /**< checks flash write addresses.*/
|
||||||
#endif
|
#endif
|
||||||
|
spi_flash_os_yield_t yield; /**< yield to the OS during flash erase */
|
||||||
} spi_flash_guard_funcs_t;
|
} spi_flash_guard_funcs_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user