Skip to content

Commit 7f23e09

Browse files
drivers: flash: flash_mcux_flexspi_hyperflash: disable cache during prgm
Disable the cache during erase and programming operations, as cache pre-fetch operations can cause flash access outside of the application's control Also, reduce the SCLK frequency used after erase operations to 200MHz. Without this, the RT1050 appears to hang after flash program operations Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 79d899e commit 7f23e09

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

drivers/flash/flash_mcux_flexspi_hyperflash.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
408408
const void *buffer, size_t len)
409409
{
410410
struct flash_flexspi_hyperflash_data *data = dev->data;
411-
size_t size = len;
412411
uint8_t *src = (uint8_t *)buffer;
413412
unsigned int key = 0;
414413
int i, j;
@@ -421,6 +420,11 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
421420
return -EINVAL;
422421
}
423422

423+
#ifdef CONFIG_HAS_MCUX_CACHE
424+
L1CACHE_DisableICache();
425+
L1CACHE_DisableDCache();
426+
#endif
427+
424428
if (memc_flexspi_is_running_xip(&data->controller)) {
425429
/*
426430
* ==== ENTER CRITICAL SECTION ====
@@ -475,12 +479,13 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
475479
len -= i;
476480
}
477481

478-
/* Clock FlexSPI at 332 MHZ (166 MHz SCLK in DDR mode) */
482+
/* Clock FlexSPI at 200 MHZ (100 MHz SCLK in DDR mode) */
479483
(void)memc_flexspi_update_clock(&data->controller, &data->config,
480-
data->port, MHZ(332));
484+
data->port, MHZ(200));
481485

482486
#ifdef CONFIG_HAS_MCUX_CACHE
483-
DCACHE_InvalidateByRange((uint32_t) dst, size);
487+
L1CACHE_EnableICache();
488+
L1CACHE_EnableDCache();
484489
#endif
485490

486491
if (memc_flexspi_is_running_xip(&data->controller)) {
@@ -503,6 +508,12 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
503508
data->port,
504509
offset);
505510

511+
512+
#ifdef CONFIG_HAS_MCUX_CACHE
513+
L1CACHE_DisableICache();
514+
L1CACHE_DisableDCache();
515+
#endif
516+
506517
if (!dst) {
507518
return -EINVAL;
508519
}
@@ -561,7 +572,8 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
561572
}
562573

563574
#ifdef CONFIG_HAS_MCUX_CACHE
564-
DCACHE_InvalidateByRange((uint32_t) dst, size);
575+
L1CACHE_EnableICache();
576+
L1CACHE_EnableDCache();
565577
#endif
566578

567579
if (memc_flexspi_is_running_xip(&data->controller)) {

0 commit comments

Comments
 (0)