diff --git a/components/base_nodemcu/user_main.c b/components/base_nodemcu/user_main.c index 14df47a9..02744439 100644 --- a/components/base_nodemcu/user_main.c +++ b/components/base_nodemcu/user_main.c @@ -76,6 +76,8 @@ void nodemcu_init(void) } #if defined ( CONFIG_BUILD_SPIFFS ) + // This can take a while, so be nice and provide some feedback while waiting + printf ("Mounting flash filesystem...\n"); if (!vfs_mount("/FLASH", 0)) { // Failed to mount -- try reformat NODE_ERR("Formatting file system. Please wait...\n"); diff --git a/components/platform/flash_api.c b/components/platform/flash_api.c index cee98b0b..94ae68d6 100644 --- a/components/platform/flash_api.c +++ b/components/platform/flash_api.c @@ -7,6 +7,7 @@ #include #include #include +#include "rom/spi_flash.h" #include "../../bootloader/src/main/bootloader_config.h" @@ -24,7 +25,14 @@ static inline struct flash_hdr flash_load_rom_header (void) return hdr; } -static uint32_t flash_detect_size_byte(void) +#define IRAM_SECTION __attribute__((section(".iram1"))) +static void IRAM_SECTION do_flash_cfg_workaround (uint32_t sz) +{ + // workaround: configure SPI flash size manually (2nd argument) + SPIParamCfg (0x1540ef, sz, 64*1024, 4096, 256, 0xffff); +} + +static uint32_t __attribute__((section(".iram1"))) flash_detect_size_byte(void) { #define DETECT_SZ 32 uint32_t detected_size = FLASH_SIZE_1MBYTE; @@ -33,6 +41,7 @@ static uint32_t flash_detect_size_byte(void) // Detect read failure or wrap-around on flash read to find end of flash if (ESP_OK == spi_flash_read (0, (uint32_t *)data_orig, DETECT_SZ)) { + do_flash_cfg_workaround (FLASH_SIZE_16MBYTE); while ((detected_size < FLASH_SIZE_16MBYTE) && (ESP_OK == spi_flash_read ( detected_size, (uint32_t *)data_new, DETECT_SZ)) && @@ -40,6 +49,7 @@ static uint32_t flash_detect_size_byte(void) { detected_size *= 2; } + do_flash_cfg_workaround (detected_size); }; return detected_size; #undef FLASH_BUFFER_SIZE_DETECT