Skip to content

Commit 574e47e

Browse files
committed
mimxrt/flash.c: Invalidate cache after disabling IRQ.
It used to happen before disabling IRQ. This change stopped problems with USB IRQ happening during flash writes. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 600851f commit 574e47e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ports/mimxrt/flash.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ void flash_init(void) {
4545
__attribute__((section(".ram_functions"))) status_t flash_erase_block(uint32_t erase_addr) {
4646
status_t status = kStatus_Fail;
4747

48+
__disable_irq();
4849
SCB_CleanInvalidateDCache();
4950
SCB_DisableDCache();
50-
__disable_irq();
5151

5252
status = flexspi_nor_flash_erase_block(BOARD_FLEX_SPI, erase_addr);
5353

54-
__enable_irq();
5554
SCB_EnableDCache();
55+
__enable_irq();
5656

5757
return status;
5858
}
@@ -62,14 +62,14 @@ __attribute__((section(".ram_functions"))) status_t flash_erase_block(uint32_t e
6262
__attribute__((section(".ram_functions"))) status_t flash_erase_sector(uint32_t erase_addr) {
6363
status_t status = kStatus_Fail;
6464

65+
__disable_irq();
6566
SCB_CleanInvalidateDCache();
6667
SCB_DisableDCache();
67-
__disable_irq();
6868

6969
status = flexspi_nor_flash_erase_sector(BOARD_FLEX_SPI, erase_addr);
7070

71-
__enable_irq();
7271
SCB_EnableDCache();
72+
__enable_irq();
7373

7474
return status;
7575
}
@@ -86,8 +86,6 @@ __attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t d
8686
status = kStatus_Success; // Nothing to do
8787
} else {
8888

89-
SCB_CleanInvalidateDCache();
90-
SCB_DisableDCache();
9189

9290
// write data in chunks not crossing a page boundary
9391
do {
@@ -98,7 +96,12 @@ __attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t d
9896
}
9997

10098
__disable_irq();
99+
SCB_CleanInvalidateDCache();
100+
SCB_DisableDCache();
101+
101102
status = flexspi_nor_flash_page_program(BOARD_FLEX_SPI, dest_addr, (uint32_t *)src, write_length);
103+
104+
SCB_EnableDCache();
102105
__enable_irq();
103106

104107
// Update remaining data length
@@ -109,7 +112,6 @@ __attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t d
109112
dest_addr += write_length;
110113
} while ((length > 0) && (status == kStatus_Success));
111114

112-
SCB_EnableDCache();
113115

114116
}
115117
return status;

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