esp32: Switch SPIRAM stack in esp_restart_noos() to internal stack

If esp_restart_noos() is run and the stack address points to external memory (SPIRAM)
then Cache_Read_Disable() raises up the error "Cache disabled but cached memory region accessed"
to fix this we switch stack to internal RAM before disable cache.

Added unit tests.

Closes: https://github.com/espressif/esp-idf/issues/5107
This commit is contained in:
KonstantinKondrashov
2020-05-16 17:52:33 +08:00
parent d6a6ac4d2d
commit 4275056423
4 changed files with 171 additions and 1 deletions

View File

@@ -88,6 +88,16 @@ void IRAM_ATTR esp_restart_noos(void)
uart_tx_wait_idle(1);
uart_tx_wait_idle(2);
#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
if (esp_ptr_external_ram(get_sp())) {
// If stack_addr is from External Memory (CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY is used)
// then need to switch SP to Internal Memory otherwise
// we will get the "Cache disabled but cached memory region accessed" error after Cache_Read_Disable.
uint32_t new_sp = SOC_DRAM_LOW + (SOC_DRAM_HIGH - SOC_DRAM_LOW) / 2;
SET_STACK(new_sp);
}
#endif
// Disable cache
Cache_Read_Disable(0);
Cache_Read_Disable(1);