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
committed by bot
parent 3467c44ff8
commit b902d6be39
5 changed files with 188 additions and 0 deletions

View File

@@ -31,6 +31,7 @@
#include "soc/cpu.h"
#include "soc/rtc.h"
#include "soc/rtc_wdt.h"
#include "soc/soc_memory_layout.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/xtensa_api.h"
@@ -286,6 +287,16 @@ void IRAM_ATTR esp_restart_noos()
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);