]> granicus.if.org Git - esp-idf/commitdiff
esp32: reset APP CPU when doing esp_restart
authorIvan Grokhotkov <ivan@espressif.com>
Wed, 14 Jun 2017 10:07:15 +0000 (18:07 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 15 Jun 2017 10:15:35 +0000 (18:15 +0800)
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
components/esp32/test/test_restart.c [new file with mode: 0644]

index 942807600c21e6dc4f47d01c9104807573b83cf6..30f6a684c0e2609aae9b2296ec110a6729d4bf13 100644 (file)
@@ -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 (file)
index 0000000..94f5741
--- /dev/null
@@ -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) {
+        ;
+    }
+}
+
+