mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-27 16:56:43 +03:00
Before: The cache won't be disabled when XIP on psram. But during flash erasing/programming, read data will be courrupt. When XIP in psram is enabled, the image is not mapped to the cache so usually there will be no flash access. The only way to read from flash is via the driver or use mmap. The driver has protection during erasing, while th mmap region not. Now: Mmap APIs provide a flag to make mmap->unmap region mutually exclusive to flash erase/programming when XIP from psram. SPI Flash write APIs will benefit from this. When the flag is used, no concurrent access to mapped region will happen while writing; otherwise the cache will be disable to avoid data corruption. Most ESP-IDF APIs calls mmap with this flag. As for users calling mmap-like APIs directly, they can choose whether to enable this by a flag. Closes https://github.com/espressif/esp-idf/issues/14897
48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include "sdkconfig.h"
|
|
#include "esp_rom_caps.h"
|
|
#include "esp_err.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
//executables are placed on flash
|
|
#define MMAP_EXECUTABLES_FROM_FLASH (!((CONFIG_SPIRAM_FETCH_INSTRUCTIONS && CONFIG_SPIRAM_RODATA) || CONFIG_APP_BUILD_TYPE_RAM))
|
|
#define MMAP_ROM_IMPL_ENABLED (CONFIG_SPI_FLASH_ROM_IMPL && ESP_ROM_HAS_SPI_FLASH_MMAP)
|
|
|
|
#if !CONFIG_IDF_TARGET_ESP32
|
|
//No mmap lock for ESP32, since it's useless to block while can't read from flash with SPI0 (cache) and SPI1 (driver) at the same time.
|
|
|
|
/**
|
|
* Initialize the internal lock earlier to bypass the memory leak check.
|
|
*/
|
|
esp_err_t flash_mmap_lock_init(void);
|
|
|
|
/**
|
|
* Freeze the mmap table
|
|
*/
|
|
void flash_mmap_lock_freeze(void);
|
|
|
|
/**
|
|
* Unfreeze the mmap table
|
|
*/
|
|
void flash_mmap_lock_unfreeze(void);
|
|
|
|
/**
|
|
* Return whether there is remaining mmap regions, must be called between flash_mmap_lock_freeze() and flash_mmap_lock_unfreeze().
|
|
*/
|
|
bool flash_mmap_remain(void);
|
|
|
|
#endif //!CONFIG_IDF_TARGET_ESP32
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|