Skip to content

Commit c06a742

Browse files
yamttmedicci
authored andcommitted
esp32: fix a crash with PSRAM + SMP
this function is called via esp_spiram_init_cache early in the boot.
1 parent f084685 commit c06a742

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

arch/xtensa/src/esp32/esp32_spiram.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
9393
uint32_t regval;
9494
#ifdef CONFIG_SMP
9595
int cpu_to_stop = 0;
96-
bool smp_start = OSINIT_OS_READY();
9796
#endif
97+
const bool os_ready = OSINIT_OS_READY();
9898
unsigned int i;
9999
unsigned int shift;
100100
unsigned int mask_s;
@@ -176,14 +176,18 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
176176
* the flash guards to make sure the cache is disabled.
177177
*/
178178

179-
flags = enter_critical_section();
179+
flags = 0; /* suppress GCC warning */
180+
if (os_ready)
181+
{
182+
flags = enter_critical_section();
183+
}
180184

181185
#ifdef CONFIG_SMP
182186
/* The other CPU might be accessing the cache at the same time, just by
183187
* using variables in external RAM.
184188
*/
185189

186-
if (smp_start)
190+
if (os_ready)
187191
{
188192
cpu_to_stop = up_cpu_index() == 1 ? 0 : 1;
189193
up_cpu_pause(cpu_to_stop);
@@ -222,13 +226,17 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
222226
#ifdef CONFIG_SMP
223227
spi_enable_cache(1);
224228

225-
if (smp_start)
229+
if (os_ready)
226230
{
227231
up_cpu_resume(cpu_to_stop);
228232
}
229233
#endif
230234

231-
leave_critical_section(flags);
235+
if (os_ready)
236+
{
237+
leave_critical_section(flags);
238+
}
239+
232240
return 0;
233241
}
234242

0 commit comments

Comments
 (0)