Skip to content

Commit 857e579

Browse files
mstumpf-vectedkartben
authored andcommitted
drivers: flash: flexspi: Fix XIP during flash write
XIP prefetching seems to still be running, even while interrupts are disabled. Therefore it is important to wait for the FlexSPI to be idle before performing a write/erase operation. Signed-off-by: Martin Stumpf <martin.stumpf@vected.de>
1 parent 0dc1436 commit 857e579

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/flash/flash_mcux_flexspi_nor.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
345345
* code and data accessed must reside in ram.
346346
*/
347347
key = irq_lock();
348+
memc_flexspi_wait_bus_idle(&data->controller);
348349
}
349350

350351
while (len) {
@@ -355,6 +356,13 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
355356
i = MIN(SPI_NOR_PAGE_SIZE - (offset % SPI_NOR_PAGE_SIZE), len);
356357
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
357358
memcpy(nor_write_buf, src, i);
359+
360+
/* As memcpy could cause an XIP access,
361+
* we need to wait for XIP prefetch to be finished again
362+
*/
363+
if (memc_flexspi_is_running_xip(&data->controller)) {
364+
memc_flexspi_wait_bus_idle(&data->controller);
365+
}
358366
#endif
359367
flash_flexspi_nor_write_enable(data);
360368
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
@@ -412,6 +420,7 @@ static int flash_flexspi_nor_erase(const struct device *dev, off_t offset,
412420
* code and data accessed must reside in ram.
413421
*/
414422
key = irq_lock();
423+
memc_flexspi_wait_bus_idle(&data->controller);
415424
}
416425

417426
if ((offset == 0) && (size == data->config.flashSize * KB(1))) {

0 commit comments

Comments
 (0)