From 61e341e791d513734f68c1fefd9c4d69c42df8b0 Mon Sep 17 00:00:00 2001 From: jiangguangming Date: Tue, 21 Jul 2020 18:04:27 +0800 Subject: [PATCH 1/2] flash_mmap: can mmap after get enough free MMU pages --- components/spi_flash/test/test_mmap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/spi_flash/test/test_mmap.c b/components/spi_flash/test/test_mmap.c index 4c38511f57..ab0772eceb 100644 --- a/components/spi_flash/test/test_mmap.c +++ b/components/spi_flash/test/test_mmap.c @@ -324,9 +324,8 @@ TEST_CASE("flash_mmap can mmap after get enough free MMU pages", "[spi_flash][mm } } uint32_t free_pages = spi_flash_mmap_get_free_pages(SPI_FLASH_MMAP_DATA); - if (spi_flash_get_chip_size() <= 0x200000) { - free_pages -= 0x200000/0x10000; - } + uint32_t flash_pages = spi_flash_get_chip_size() / SPI_FLASH_MMU_PAGE_SIZE; + free_pages = (free_pages > flash_pages) ? flash_pages : free_pages; printf("Mapping %x (+%x)\n", 0, free_pages * SPI_FLASH_MMU_PAGE_SIZE); const void *ptr2; From 052f88f1d194e78f369bddb5e7ed361321087c34 Mon Sep 17 00:00:00 2001 From: jiangguangming Date: Wed, 22 Jul 2020 15:08:53 +0800 Subject: [PATCH 2/2] flash_mmap: restore interrupt and cache before err return --- components/spi_flash/flash_mmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/spi_flash/flash_mmap.c b/components/spi_flash/flash_mmap.c index 6789d4211a..4c63b6a958 100644 --- a/components/spi_flash/flash_mmap.c +++ b/components/spi_flash/flash_mmap.c @@ -191,6 +191,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(const int *pages, size_t page_count, sp uint32_t region_addr; // base address of memory region get_mmu_region(memory,®ion_begin,®ion_size,®ion_addr); if (region_size < page_count) { + spi_flash_enable_interrupts_caches_and_other_cpu(); return ESP_ERR_NO_MEM; } // The following part searches for a range of MMU entries which can be used.