Skip to content

Commit

Permalink
esp32: fix a crash with PSRAM + SMP
Browse files Browse the repository at this point in the history
this function is called via esp_spiram_init_cache early in the boot.
  • Loading branch information
yamt committed Aug 28, 2024
1 parent 263f895 commit 1f46498
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions arch/xtensa/src/esp32/esp32_spiram.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
uint32_t regval;
#ifdef CONFIG_SMP
int cpu_to_stop = 0;
bool smp_start = OSINIT_OS_READY();
#endif
const bool os_ready = OSINIT_OS_READY();
unsigned int i;
unsigned int shift;
unsigned int mask_s;
Expand Down Expand Up @@ -169,14 +169,18 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
* the flash guards to make sure the cache is disabled.
*/

flags = enter_critical_section();
flags = 0; /* suppress GCC warning */
if (os_ready)
{
flags = enter_critical_section();
}

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

if (smp_start)
if (os_ready)
{
cpu_to_stop = up_cpu_index() == 1 ? 0 : 1;
up_cpu_pause(cpu_to_stop);
Expand Down Expand Up @@ -215,13 +219,17 @@ unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid,
#ifdef CONFIG_SMP
spi_enable_cache(1);

if (smp_start)
if (os_ready)
{
up_cpu_resume(cpu_to_stop);
}
#endif

leave_critical_section(flags);
if (os_ready)
{
leave_critical_section(flags);
}

return 0;
}

Expand Down

0 comments on commit 1f46498

Please sign in to comment.