diff --git a/components/esp8266/Kconfig b/components/esp8266/Kconfig index ee62e2fd..4783b5af 100644 --- a/components/esp8266/Kconfig +++ b/components/esp8266/Kconfig @@ -92,6 +92,21 @@ config LINK_ETS_PRINTF_TO_IRAM Note: Bootloader can't use this function. +config ETS_PRINTF_EXIT_WHEN_FLASH_RW + bool "ets_printf exits when flash R/W" + default y + depends on !LINK_ETS_PRINTF_TO_IRAM + help + By default option, we link the ets_printf function and its calling functions + in SPI Flash. So when the SPI Flash is working in read/write mode, and we + call ets_printf in high level interrupt like NMI, this behavior will cause a + crash, and the EXCCAUSE=0. + + Enable this option, we link the ets_printf in IRAM, and its calling functions + in SPI Flash. In the entry of ets_printf, we check if the SPI Flash is working + in read/write mode, and exit if it is. So that ets_printf will not call functions + in SPI Flash. + config SOC_FULL_ICACHE bool "Enable full cache mode" default n diff --git a/components/esp8266/source/ets_printf.c b/components/esp8266/source/ets_printf.c index 3e066dcc..0df4e11b 100644 --- a/components/esp8266/source/ets_printf.c +++ b/components/esp8266/source/ets_printf.c @@ -24,6 +24,12 @@ #include "esp8266/uart_register.h" #include "esp8266/rom_functions.h" +#ifdef CONFIG_ETS_PRINTF_EXIT_WHEN_FLASH_RW +#define ETS_PRINTF_ATTR IRAM_ATTR +#else +#define ETS_PRINTF_ATTR +#endif + #ifndef CONFIG_ESP_CONSOLE_UART_NONE static void uart_putc(int c) { @@ -285,11 +291,19 @@ int ets_vprintf(const char *fmt, va_list ap) * "%s": 172 Bytes * "%p", "%d, "%i, "%u", "%x": 215 Bytes */ -int ets_printf(const char *fmt, ...) +int ETS_PRINTF_ATTR ets_printf(const char *fmt, ...) { va_list ap; int ret; +#ifdef CONFIG_ETS_PRINTF_EXIT_WHEN_FLASH_RW + extern uint8_t FlashIsOnGoing; + + if (FlashIsOnGoing) { + return -1; + } +#endif + va_start(ap, fmt); ret = ets_vprintf(fmt, ap); va_end(ap);