From 9353666cc14be63826fdff7ccedb883339e318a0 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 14 Jun 2017 18:07:15 +0800 Subject: [PATCH] esp32: reset APP CPU when doing esp_restart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a bug introduced by !848, where APP CPU would not be reset during esp_restart, if esp_restart was called from a task running on APP CPU, and wouldn’t be reset by PRO CPU on startup. This change replaces stalling APP CPU with resetting it. Also adds a non-automated esp_restart tests. --- components/esp32/system_api.c | 7 +++++-- components/esp32/test/test_restart.c | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 components/esp32/test/test_restart.c 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) { + ; + } +} + +