Skip to content

Commit

Permalink
drivers: flash: flexspi: Fix XIP during flash write
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mstumpf-vected authored and kartben committed Dec 23, 2024
1 parent 0dc1436 commit 857e579
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/flash/flash_mcux_flexspi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
* code and data accessed must reside in ram.
*/
key = irq_lock();
memc_flexspi_wait_bus_idle(&data->controller);
}

while (len) {
Expand All @@ -355,6 +356,13 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
i = MIN(SPI_NOR_PAGE_SIZE - (offset % SPI_NOR_PAGE_SIZE), len);
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
memcpy(nor_write_buf, src, i);

/* As memcpy could cause an XIP access,
* we need to wait for XIP prefetch to be finished again
*/
if (memc_flexspi_is_running_xip(&data->controller)) {
memc_flexspi_wait_bus_idle(&data->controller);
}
#endif
flash_flexspi_nor_write_enable(data);
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
Expand Down Expand Up @@ -412,6 +420,7 @@ static int flash_flexspi_nor_erase(const struct device *dev, off_t offset,
* code and data accessed must reside in ram.
*/
key = irq_lock();
memc_flexspi_wait_bus_idle(&data->controller);
}

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

0 comments on commit 857e579

Please sign in to comment.