Skip to content

Commit d3bcc61

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 d3bcc61

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/flash/flash_mcux_flexspi_hyperflash.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <zephyr/kernel.h>
1111
#include <errno.h>
1212
#include <zephyr/drivers/flash.h>
13+
#include <zephyr/cache.h>
1314

1415
#include <zephyr/logging/log.h>
1516

@@ -408,7 +409,6 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
408409
const void *buffer, size_t len)
409410
{
410411
struct flash_flexspi_hyperflash_data *data = dev->data;
411-
size_t size = len;
412412
uint8_t *src = (uint8_t *)buffer;
413413
unsigned int key = 0;
414414
int i, j;
@@ -421,6 +421,9 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
421421
return -EINVAL;
422422
}
423423

424+
sys_cache_instr_disable();
425+
sys_cache_data_disable();
426+
424427
if (memc_flexspi_is_running_xip(&data->controller)) {
425428
/*
426429
* ==== ENTER CRITICAL SECTION ====
@@ -475,13 +478,12 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
475478
len -= i;
476479
}
477480

478-
/* Clock FlexSPI at 332 MHZ (166 MHz SCLK in DDR mode) */
481+
/* Clock FlexSPI at 200 MHZ (100 MHz SCLK in DDR mode) */
479482
(void)memc_flexspi_update_clock(&data->controller, &data->config,
480-
data->port, MHZ(332));
483+
data->port, MHZ(200));
481484

482-
#ifdef CONFIG_HAS_MCUX_CACHE
483-
DCACHE_InvalidateByRange((uint32_t) dst, size);
484-
#endif
485+
sys_cache_instr_enable();
486+
sys_cache_data_enable();
485487

486488
if (memc_flexspi_is_running_xip(&data->controller)) {
487489
/* ==== EXIT CRITICAL SECTION ==== */
@@ -503,6 +505,10 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
503505
data->port,
504506
offset);
505507

508+
509+
sys_cache_instr_disable();
510+
sys_cache_data_disable();
511+
506512
if (!dst) {
507513
return -EINVAL;
508514
}
@@ -560,9 +566,8 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
560566
offset += SPI_HYPERFLASH_SECTOR_SIZE;
561567
}
562568

563-
#ifdef CONFIG_HAS_MCUX_CACHE
564-
DCACHE_InvalidateByRange((uint32_t) dst, size);
565-
#endif
569+
sys_cache_instr_enable();
570+
sys_cache_data_enable();
566571

567572
if (memc_flexspi_is_running_xip(&data->controller)) {
568573
/* ==== EXIT CRITICAL SECTION ==== */

0 commit comments

Comments
 (0)