From: Ivan Grokhotkov Date: Mon, 12 Jun 2017 07:16:57 +0000 (+0800) Subject: esp32: don’t reset APP CPU if it was already reset by OpenOCD X-Git-Tag: v2.1-rc1~58^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f327a9b1cff1f6965ca3cc1f226f0c41e3461bbb;p=esp-idf esp32: don’t reset APP CPU if it was already reset by OpenOCD When ‘reset halt’ command is executed, OpenOCD will take the APP CPU out of reset and enable the clock. At this point, user can set a breakpoint on code which will run on APP CPU. Previously, app startup code would do another reset of APP CPU, thereby removing any breakpoints which may have been set. This change makes APP CPU reset conditional on DPORT_APPCPU_CLKGATE_EN bit, which is 0 by default but is set to 1 by OpenOCD after reset. --- diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index ac18081102..dc29d3dd18 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -142,11 +142,16 @@ void IRAM_ATTR call_start_cpu0() Cache_Flush(1); Cache_Read_Enable(1); esp_cpu_unstall(1); - //Enable clock gating and reset the app cpu. - DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL); - DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING); - DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING); + // Enable clock and reset APP CPU. Note that OpenOCD may have already + // enabled clock and taken APP CPU out of reset. In this case don't reset + // APP CPU again, as that will clear the breakpoints which may have already + // been set. + if (!DPORT_GET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN)) { + DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL); + DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING); + DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING); + } ets_set_appcpu_boot_addr((uint32_t)call_start_cpu1); while (!app_cpu_started) {