Skip to content

Commit

Permalink
esp32: enable APP_CPU cache earlier
Browse files Browse the repository at this point in the history
NuttX uses PSRAM, possibly using the APP_CPU cache MMU,
way before starting the APP_CPU in up_cpu_start().
Flushing the cache when launching the APP_CPU can cause
data corruptions on PSRAM.
Eg. mm_heap structures if the PSRAM is added to a heap.
  • Loading branch information
yamt committed Aug 30, 2024
1 parent 1086a05 commit d863a10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 0 additions & 7 deletions arch/xtensa/src/esp32/esp32_cpustart.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ static volatile spinlock_t g_appcpu_interlock;
* ROM function prototypes
****************************************************************************/

extern void cache_flush(int cpu);
extern void cache_read_enable(int cpu);
extern void ets_set_appcpu_boot_addr(uint32_t start);

/****************************************************************************
Expand Down Expand Up @@ -245,11 +243,6 @@ int up_cpu_start(int cpu)

spin_initialize(&g_appcpu_interlock, SP_LOCKED);

/* Flush and enable I-cache for APP CPU */

cache_flush(cpu);
cache_read_enable(cpu);

/* Unstall the APP CPU */

regval = getreg32(RTC_CNTL_SW_CPU_STALL_REG);
Expand Down
9 changes: 9 additions & 0 deletions arch/xtensa/src/esp32/esp32_spiram.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
# error "FLASH speed can only be equal to or higher than SRAM speed while SRAM is enabled!"
#endif

/****************************************************************************
* ROM Function Prototypes
****************************************************************************/

extern void cache_flush(int cpu);
extern void cache_read_enable(int cpu);

/****************************************************************************
* Private Data
****************************************************************************/
Expand Down Expand Up @@ -238,6 +245,8 @@ void IRAM_ATTR esp_spiram_init_cache(void)
/* Flush and enable icache for APP CPU */

#ifdef CONFIG_SMP
cache_flush(cpu);
cache_read_enable(cpu);
regval = getreg32(DPORT_APP_CACHE_CTRL1_REG);
regval &= ~(1 << DPORT_APP_CACHE_MASK_DRAM1);
putreg32(regval, DPORT_APP_CACHE_CTRL1_REG);
Expand Down

0 comments on commit d863a10

Please sign in to comment.