Skip to content

Commit 9278de2

Browse files
mmahadevan108kartben
authored andcommitted
drivers: flash: flexspi: Fix XIP during flash write
Commit 857e579 fix the flash_mcux_flexspi_nor.c driver to wait for the FlexSPI to be idle before performing write/erase operations. Add a similar check to these drivers that also use the FlexSPI NOR block. Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent bb0f192 commit 9278de2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

drivers/flash/flash_mcux_flexspi_hyperflash.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
431431
* code and data accessed must reside in ram.
432432
*/
433433
key = irq_lock();
434+
memc_flexspi_wait_bus_idle(&data->controller);
434435
}
435436

436437
/* Clock FlexSPI at 84 MHZ (42MHz SCLK in DDR mode) */
@@ -448,6 +449,12 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
448449
for (j = 0; j < i; j++) {
449450
hyperflash_write_buf[j] = src[j];
450451
}
452+
/* As memcpy could cause an XIP access,
453+
* we need to wait for XIP prefetch to be finished again
454+
*/
455+
if (memc_flexspi_is_running_xip(&data->controller)) {
456+
memc_flexspi_wait_bus_idle(&data->controller);
457+
}
451458
#endif
452459
ret = flash_flexspi_hyperflash_write_enable(dev, offset);
453460
if (ret != 0) {
@@ -527,6 +534,7 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
527534
* code and data accessed must reside in ram.
528535
*/
529536
key = irq_lock();
537+
memc_flexspi_wait_bus_idle(&data->controller);
530538
}
531539

532540
for (i = 0; i < num_sectors; i++) {

drivers/flash/flash_mcux_flexspi_mx25um51345g.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
390390
* code and data accessed must reside in ram.
391391
*/
392392
key = irq_lock();
393+
memc_flexspi_wait_bus_idle(data->controller);
393394
}
394395
if (IS_ENABLED(CONFIG_FLASH_MCUX_FLEXSPI_MX25UM51345G_OPI_DTR)) {
395396
/* Check that write size and length are even */
@@ -406,6 +407,12 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
406407
i = MIN(SPI_NOR_PAGE_SIZE - (offset % SPI_NOR_PAGE_SIZE), len);
407408
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
408409
memcpy(nor_write_buf, src, i);
410+
/* As memcpy could cause an XIP access,
411+
* we need to wait for XIP prefetch to be finished again
412+
*/
413+
if (memc_flexspi_is_running_xip(data->controller)) {
414+
memc_flexspi_wait_bus_idle(data->controller);
415+
}
409416
#endif
410417
flash_flexspi_nor_write_enable(dev, true);
411418
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
@@ -461,6 +468,7 @@ static int flash_flexspi_nor_erase(const struct device *dev, off_t offset,
461468
* code and data accessed must reside in ram.
462469
*/
463470
key = irq_lock();
471+
memc_flexspi_wait_bus_idle(data->controller);
464472
}
465473

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

0 commit comments

Comments
 (0)