diff --git a/mongoose.c b/mongoose.c index 33a5231e8b..76aad60076 100644 --- a/mongoose.c +++ b/mongoose.c @@ -5644,8 +5644,8 @@ MG_IRAM static bool flash_page_start(volatile uint32_t *dst) { // Note: the get_config function below works both for RT1020 and 1060 #if MG_OTA == MG_OTA_RT1020 MG_IRAM static int flexspi_nor_get_config( - struct mg_flexspi_nor_config *config) { - struct mg_flexspi_nor_config default_config = { + struct mg_flexspi_nor_config *config) { + static struct mg_flexspi_nor_config default_config = { .memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG, .version = MG_FLEXSPI_CFG_BLK_VERSION, .readSampleClkSrc = 1, // ReadSampleClk_LoopbackFromDqsPad @@ -5662,8 +5662,11 @@ MG_IRAM static int flexspi_nor_get_config( .ipcmdSerialClkFreq = 1, .blockSize = 64 * 1024, .isUniformBlockSize = false}; - - *config = default_config; + const uint8_t *src = (const uint8_t *)&default_config; + volatile uint8_t *dst = (uint8_t *)config; + for (volatile size_t i = 0; i < sizeof(struct mg_flexspi_nor_config); i++) { + dst[i] = src[i]; + } return 0; } #else @@ -5684,6 +5687,15 @@ MG_IRAM static int flexspi_nor_get_config( } #endif +MG_IRAM static void mg_spin(volatile uint32_t count) { + while (count--) (void) 0; +} + +MG_IRAM static void flash_wait(void) { + while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0) + mg_spin(1); +} + MG_IRAM static bool flash_erase(struct mg_flexspi_nor_config *config, void *addr) { if (flash_page_start(addr) == false) { @@ -5708,7 +5720,7 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) { MG_ARM_DISABLE_IRQ(); ret = (flexspi_nor_get_config(&config) == 0); if (ret) ret = flash_erase(&config, addr); - MG_ARM_ENABLE_IRQ(); + if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ(); return ret; } #endif @@ -5717,15 +5729,6 @@ MG_IRAM bool mg_imxrt_swap(void) { return true; } -static inline void spin(volatile uint32_t count) { - while (count--) (void) 0; -} - -static inline void flash_wait(void) { - while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0) - spin(1); -} - MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) { struct mg_flexspi_nor_config config; bool ok = false; diff --git a/src/ota_imxrt.c b/src/ota_imxrt.c index fc6fdbbdb4..7caaf22d8b 100644 --- a/src/ota_imxrt.c +++ b/src/ota_imxrt.c @@ -194,8 +194,8 @@ MG_IRAM static bool flash_page_start(volatile uint32_t *dst) { // Note: the get_config function below works both for RT1020 and 1060 #if MG_OTA == MG_OTA_RT1020 MG_IRAM static int flexspi_nor_get_config( - struct mg_flexspi_nor_config *config) { - struct mg_flexspi_nor_config default_config = { + struct mg_flexspi_nor_config *config) { + static struct mg_flexspi_nor_config default_config = { .memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG, .version = MG_FLEXSPI_CFG_BLK_VERSION, .readSampleClkSrc = 1, // ReadSampleClk_LoopbackFromDqsPad @@ -212,8 +212,11 @@ MG_IRAM static int flexspi_nor_get_config( .ipcmdSerialClkFreq = 1, .blockSize = 64 * 1024, .isUniformBlockSize = false}; - - *config = default_config; + const uint8_t *src = (const uint8_t *)&default_config; + volatile uint8_t *dst = (uint8_t *)config; + for (volatile size_t i = 0; i < sizeof(struct mg_flexspi_nor_config); i++) { + dst[i] = src[i]; + } return 0; } #else @@ -234,6 +237,15 @@ MG_IRAM static int flexspi_nor_get_config( } #endif +MG_IRAM static void mg_spin(volatile uint32_t count) { + while (count--) (void) 0; +} + +MG_IRAM static void flash_wait(void) { + while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0) + mg_spin(1); +} + MG_IRAM static bool flash_erase(struct mg_flexspi_nor_config *config, void *addr) { if (flash_page_start(addr) == false) { @@ -258,7 +270,7 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) { MG_ARM_DISABLE_IRQ(); ret = (flexspi_nor_get_config(&config) == 0); if (ret) ret = flash_erase(&config, addr); - MG_ARM_ENABLE_IRQ(); + if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ(); return ret; } #endif @@ -267,15 +279,6 @@ MG_IRAM bool mg_imxrt_swap(void) { return true; } -static inline void spin(volatile uint32_t count) { - while (count--) (void) 0; -} - -static inline void flash_wait(void) { - while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0) - spin(1); -} - MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) { struct mg_flexspi_nor_config config; bool ok = false;