From 8dcfa1b384ad6a84e46fabe1ef72f0068d607b50 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Wed, 18 Aug 2021 23:55:39 +0800 Subject: [PATCH] spi_flash: fix the corruption of ROM after calling bootloader_execute_flash_command The user register, especially dummy related ones, needs to be restored, otherwise the ROM function will not work. Introduced in dd40123129bc5670ae081c31d519907f0125e4db. --- components/bootloader_support/src/bootloader_flash.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/bootloader_support/src/bootloader_flash.c b/components/bootloader_support/src/bootloader_flash.c index 708e7dcbf5..880da3d507 100644 --- a/components/bootloader_support/src/bootloader_flash.c +++ b/components/bootloader_support/src/bootloader_flash.c @@ -578,6 +578,7 @@ IRAM_ATTR static uint32_t bootloader_flash_execute_command_common( assert(mosi_len <= 32); assert(miso_len <= 32); uint32_t old_ctrl_reg = SPIFLASH.ctrl.val; + uint32_t old_user_reg = SPIFLASH.user.val; #if CONFIG_IDF_TARGET_ESP32 SPIFLASH.ctrl.val = SPI_WP_REG_M; // keep WP high while idle, otherwise leave DIO mode #else @@ -624,6 +625,7 @@ IRAM_ATTR static uint32_t bootloader_flash_execute_command_common( while (SPIFLASH.cmd.usr != 0) { } SPIFLASH.ctrl.val = old_ctrl_reg; + SPIFLASH.user.val = old_user_reg; uint32_t ret = SPIFLASH.data_buf[0]; if (miso_len < 32) {