From 93468be3fa691d2f01854eca5b62cce4835cf81d Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Mon, 24 Jun 2019 18:46:34 +0300 Subject: [PATCH] esp32: Tries to select non-stalled CPU for any debug reason --- src/target/esp32.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/target/esp32.c b/src/target/esp32.c index e60e303d6e..4590ea90e1 100755 --- a/src/target/esp32.c +++ b/src/target/esp32.c @@ -1851,12 +1851,6 @@ static int xtensa_poll(struct target *target) esp32->active_cpu = k-1; } } - // Handle special case when halt is send to the stalled active core. - // We need to switch focus to another core in order to be able to run algorithms. - if (target->debug_reason == DBG_REASON_DBGRQ && (dsr[esp32->active_cpu] & OCDDSR_RUNSTALLSAMPLE)) { - LOG_DEBUG("Received debug request on stalled active core %d. Switch active core.", (int)esp32->active_cpu); - esp32->active_cpu = esp32->active_cpu == ESP32_PRO_CPU_ID ? ESP32_APP_CPU_ID : ESP32_PRO_CPU_ID; - } for (size_t k = esp32->configured_cores_num; k > 0; k--) { if (halt_cause[k-1] & DEBUGCAUSE_IC) { @@ -1879,6 +1873,16 @@ static int xtensa_poll(struct target *target) esp32->active_cpu = k-1; } } + // Handle special case when halt is send to the stalled active core. + // We need to switch focus to another core in order to be able to run algorithms. + if (dsr[esp32->active_cpu] & OCDDSR_RUNSTALLSAMPLE) { + LOG_WARNING("Received debug request on stalled active core %d.", (int)esp32->active_cpu); + int other_core = esp32->active_cpu == ESP32_PRO_CPU_ID ? ESP32_APP_CPU_ID : ESP32_PRO_CPU_ID; + if ((dsr[other_core] & OCDDSR_RUNSTALLSAMPLE) == 0) { + LOG_DEBUG("Switch active core to %d.", other_core); + esp32->active_cpu = other_core; + } + } if (esp32->configured_cores_num > 1) { LOG_INFO("Target halted. PRO_CPU: PC=0x%08X %s APP_CPU: PC=0x%08X %s", esp108_reg_get(&esp32->core_caches[0]->reg_list[XT_REG_IDX_PC]),