Skip to content

Commit 805964f

Browse files
committed
esp32: Fixes active core detection upon halt on stalled core
1 parent 936fdf6 commit 805964f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/target/esp32.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ static int xtensa_poll(struct target *target)
18241824
target->state = TARGET_HALTED;
18251825
esp32_fetch_all_regs(target, 0x3);
18261826
//Examine why the target was halted
1827-
target->debug_reason = DBG_REASON_DBGRQ;
1827+
target->debug_reason = DBG_REASON_UNDEFINED;
18281828
uint32_t halt_cause[ESP32_CPU_COUNT_MAX] = {0};
18291829
for (size_t i = 0; i < esp32->configured_cores_num; i++)
18301830
{
@@ -1851,6 +1851,12 @@ static int xtensa_poll(struct target *target)
18511851
esp32->active_cpu = k-1;
18521852
}
18531853
}
1854+
// Handle special case when halt is send to the stalled active core.
1855+
// We need to switch focus to another core in order to be able to run algorithms.
1856+
if (target->debug_reason == DBG_REASON_DBGRQ && (dsr[esp32->active_cpu] & OCDDSR_RUNSTALLSAMPLE)) {
1857+
LOG_DEBUG("Received debug request on stalled active core %d. Switch active core.", (int)esp32->active_cpu);
1858+
esp32->active_cpu = esp32->active_cpu == ESP32_PRO_CPU_ID ? ESP32_APP_CPU_ID : ESP32_PRO_CPU_ID;
1859+
}
18541860
for (size_t k = esp32->configured_cores_num; k > 0; k--) {
18551861
if (halt_cause[k-1] & DEBUGCAUSE_IC)
18561862
{

0 commit comments

Comments
 (0)