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 committed Dec 19, 2024
1 parent 75463fe commit 14ee06c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,12 @@ 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);

// memcpy could cause an XIP access,

Check failure on line 360 in drivers/flash/flash_mcux_flexspi_nor.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

drivers/flash/flash_mcux_flexspi_nor.c:360 do not use C99 // comments
// so we need to wait for XIP prefetch to be finished again

Check failure on line 361 in drivers/flash/flash_mcux_flexspi_nor.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

drivers/flash/flash_mcux_flexspi_nor.c:361 do not use C99 // comments
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 +419,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 14ee06c

Please sign in to comment.