Skip to content

Commit e8b1876

Browse files
yamtxiaoxiang781216
authored andcommitted
esp32: enable APP_CPU cache earlier
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.
1 parent ebbd585 commit e8b1876

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

arch/xtensa/src/esp32/esp32_cpustart.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ static volatile spinlock_t g_appcpu_interlock;
5757
* ROM function prototypes
5858
****************************************************************************/
5959

60-
extern void cache_flush(int cpu);
61-
extern void cache_read_enable(int cpu);
6260
extern void ets_set_appcpu_boot_addr(uint32_t start);
6361

6462
/****************************************************************************
@@ -245,11 +243,6 @@ int up_cpu_start(int cpu)
245243

246244
spin_initialize(&g_appcpu_interlock, SP_LOCKED);
247245

248-
/* Flush and enable I-cache for APP CPU */
249-
250-
cache_flush(cpu);
251-
cache_read_enable(cpu);
252-
253246
/* Unstall the APP CPU */
254247

255248
regval = getreg32(RTC_CNTL_SW_CPU_STALL_REG);

arch/xtensa/src/esp32/esp32_spiram.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
# error "FLASH speed can only be equal to or higher than SRAM speed while SRAM is enabled!"
6969
#endif
7070

71+
/****************************************************************************
72+
* ROM Function Prototypes
73+
****************************************************************************/
74+
75+
extern void cache_flush(int cpu);
76+
extern void cache_read_enable(int cpu);
77+
7178
/****************************************************************************
7279
* Private Data
7380
****************************************************************************/
@@ -238,6 +245,8 @@ void IRAM_ATTR esp_spiram_init_cache(void)
238245
/* Flush and enable icache for APP CPU */
239246

240247
#ifdef CONFIG_SMP
248+
cache_flush(APP_CPU_NUM);
249+
cache_read_enable(APP_CPU_NUM);
241250
regval = getreg32(DPORT_APP_CACHE_CTRL1_REG);
242251
regval &= ~(1 << DPORT_APP_CACHE_MASK_DRAM1);
243252
putreg32(regval, DPORT_APP_CACHE_CTRL1_REG);

0 commit comments

Comments
 (0)