diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 942807600..30f6a684c 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -298,6 +298,9 @@ void IRAM_ATTR esp_restart_noos() // Set CPU back to XTAL source, no PLL, same as hard reset rtc_clk_cpu_freq_set(RTC_CPU_FREQ_XTAL); + // Clear entry point for APP CPU + DPORT_REG_WRITE(DPORT_APPCPU_CTRL_D_REG, 0); + // Reset CPUs if (core_id == 0) { // Running on PRO CPU: APP CPU is stalled. Can reset both CPUs. @@ -305,10 +308,10 @@ void IRAM_ATTR esp_restart_noos() RTC_CNTL_SW_PROCPU_RST_M | RTC_CNTL_SW_APPCPU_RST_M); } else { // Running on APP CPU: need to reset PRO CPU and unstall it, - // then stall APP CPU + // then reset APP CPU SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_PROCPU_RST_M); esp_cpu_unstall(0); - esp_cpu_stall(1); + SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_APPCPU_RST_M); } while(true) { ; diff --git a/components/esp32/test/test_restart.c b/components/esp32/test/test_restart.c new file mode 100644 index 000000000..94f5741af --- /dev/null +++ b/components/esp32/test/test_restart.c @@ -0,0 +1,26 @@ +#include "unity.h" +#include "esp_system.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + + +TEST_CASE("restart from PRO CPU", "[restart][ignore]") +{ + esp_restart(); +} + +static void restart_task(void* arg) +{ + esp_restart(); +} + +TEST_CASE("restart from APP CPU", "[restart][ignore]") +{ + xTaskCreatePinnedToCore(&restart_task, "restart", 2048, NULL, 5, NULL, 1); + + while(true) { + ; + } +} + +