Skip to content

Commit 2a80d5c

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt/flash: Swap the order of disabling IRQ and disabling the cache.
This change stopped problems with USB IRQ happening during flash writes. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent b251aec commit 2a80d5c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

ports/mimxrt/flash.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ void flash_init(void) {
4343
__attribute__((section(".ram_functions"))) status_t flash_erase_block(uint32_t erase_addr) {
4444
status_t status = kStatus_Fail;
4545

46-
SCB_CleanInvalidateDCache();
47-
SCB_DisableDCache();
4846
__disable_irq();
47+
SCB_DisableDCache();
4948

5049
status = flexspi_nor_flash_erase_block(BOARD_FLEX_SPI, erase_addr);
5150

52-
__enable_irq();
5351
SCB_EnableDCache();
52+
__enable_irq();
5453

5554
return status;
5655
}
@@ -60,14 +59,13 @@ __attribute__((section(".ram_functions"))) status_t flash_erase_block(uint32_t e
6059
__attribute__((section(".ram_functions"))) status_t flash_erase_sector(uint32_t erase_addr) {
6160
status_t status = kStatus_Fail;
6261

63-
SCB_CleanInvalidateDCache();
64-
SCB_DisableDCache();
6562
__disable_irq();
63+
SCB_DisableDCache();
6664

6765
status = flexspi_nor_flash_erase_sector(BOARD_FLEX_SPI, erase_addr);
6866

69-
__enable_irq();
7067
SCB_EnableDCache();
68+
__enable_irq();
7169

7270
return status;
7371
}
@@ -83,10 +81,6 @@ __attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t d
8381
if (length == 0) {
8482
status = kStatus_Success; // Nothing to do
8583
} else {
86-
87-
SCB_CleanInvalidateDCache();
88-
SCB_DisableDCache();
89-
9084
// write data in chunks not crossing a page boundary
9185
do {
9286
next_addr = dest_addr - (dest_addr % PAGE_SIZE_BYTES) + PAGE_SIZE_BYTES; // next page boundary
@@ -96,7 +90,11 @@ __attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t d
9690
}
9791

9892
__disable_irq();
93+
SCB_DisableDCache();
94+
9995
status = flexspi_nor_flash_page_program(BOARD_FLEX_SPI, dest_addr, (uint32_t *)src, write_length);
96+
97+
SCB_EnableDCache();
10098
__enable_irq();
10199

102100
// Update remaining data length
@@ -106,9 +104,6 @@ __attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t d
106104
src += write_length;
107105
dest_addr += write_length;
108106
} while ((length > 0) && (status == kStatus_Success));
109-
110-
SCB_EnableDCache();
111-
112107
}
113108
return status;
114109
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy