Skip to content

Commit 4ba3eb8

Browse files
igrrgerekon
authored andcommitted
esp32: configure DCR when the core comes online
1 parent a242a75 commit 4ba3eb8

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

src/target/esp32.c

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ static int xtensa_do_step(struct target *target,
140140
static int xtensa_poll(struct target *target);
141141
static int xtensa_assert_reset(struct target *target);
142142
static int xtensa_deassert_reset(struct target *target);
143+
static int xtensa_smpbreak_set(struct target *target);
144+
static int xtensa_smpbreak_set_core(struct target *target, int core);
143145
static int xtensa_read_memory(struct target *target,
144146
uint32_t address,
145147
uint32_t size,
@@ -849,23 +851,31 @@ static int xtensa_assert_reset(struct target *target)
849851
}
850852

851853
static int xtensa_smpbreak_set(struct target *target)
854+
{
855+
int res = ERROR_OK;
856+
for (int core = 0; core < ESP32_CPU_COUNT && res == ERROR_OK; core++)
857+
{
858+
res = xtensa_smpbreak_set_core(target, core);
859+
}
860+
return res;
861+
}
862+
863+
static int xtensa_smpbreak_set_core(struct target *target, int core)
852864
{
853865
struct esp32_common *esp32 = (struct esp32_common*)target->arch_info;
854866
int res;
855867
uint32_t dsr_data = 0x00110000;
856868
uint32_t set = 0, clear = 0;
857-
set |= OCDDCR_BREAKINEN | OCDDCR_BREAKOUTEN | OCDDCR_RUNSTALLINEN;
869+
set |= OCDDCR_BREAKINEN | OCDDCR_BREAKOUTEN | OCDDCR_RUNSTALLINEN | OCDDCR_ENABLEOCD;
858870
clear = set ^ (OCDDCR_BREAKINEN | OCDDCR_BREAKOUTEN | OCDDCR_RUNSTALLINEN | OCDDCR_DEBUGMODEOUTEN);
859871

860-
for (int core = 0; core < ESP32_CPU_COUNT; core++)
861-
{
862-
esp108_queue_nexus_reg_write(esp32->esp32_targets[core], NARADR_DCRSET, set);
863-
esp108_queue_nexus_reg_write(esp32->esp32_targets[core], NARADR_DCRCLR, clear);
864-
esp108_queue_nexus_reg_write(esp32->esp32_targets[core], NARADR_DSR, dsr_data);
865-
esp108_queue_tdi_idle(esp32->esp32_targets[core]);
866-
}
872+
esp108_queue_nexus_reg_write(esp32->esp32_targets[core], NARADR_DCRSET, set);
873+
esp108_queue_nexus_reg_write(esp32->esp32_targets[core], NARADR_DCRCLR, clear);
874+
esp108_queue_nexus_reg_write(esp32->esp32_targets[core], NARADR_DSR, dsr_data);
875+
esp108_queue_tdi_idle(esp32->esp32_targets[core]);
867876
res = jtag_execute_queue();
868-
LOG_DEBUG("%s[%s] set smpbreak=%i, state=%i", __func__, target->cmd_name, set, target->state);
877+
878+
LOG_DEBUG("%s[%s] core %d, set smpbreak=%x, state=%i", __func__, target->cmd_name, core, set, target->state);
869879
return res;
870880
}
871881

@@ -1567,17 +1577,41 @@ static int xtensa_poll(struct target *target)
15671577
int res, cmd;
15681578
uint8_t traxstat[ESP32_CPU_COUNT][4] = {{0}}, traxctl[ESP32_CPU_COUNT][4] = {{0}};
15691579
unsigned int dsr[ESP32_CPU_COUNT] = {0};
1580+
uint32_t idcode[ESP32_CPU_COUNT] = {0};
15701581

15711582
//Read reset state
1583+
uint32_t core_poweron_mask = 0;
15721584
for (size_t i = 0; i < ESP32_CPU_COUNT; i++)
15731585
{
1586+
esp108_queue_idcode_read(esp32->esp32_targets[i], (uint8_t*) &idcode[i]);
15741587
esp108_queue_pwrstat_readclear(esp32->esp32_targets[i], &pwrstat[i]);
15751588
//Read again, to see if the state holds...
15761589
esp108_queue_pwrstat_readclear(esp32->esp32_targets[i], &pwrstath[i]);
15771590
esp108_queue_tdi_idle(esp32->esp32_targets[i]);
15781591
res = jtag_execute_queue();
15791592
if (res != ERROR_OK) return res;
1593+
if (idcode[i] != 0xffffffff && idcode[i] != 0) {
1594+
core_poweron_mask |= (1 << i);
1595+
}
1596+
}
1597+
1598+
// Target might be held in reset by external signal.
1599+
// Sanity check target responses using idcode (checking CPU0 is sufficient).
1600+
if (core_poweron_mask == 0) {
1601+
if (target->state != TARGET_UNKNOWN) {
1602+
LOG_INFO("%s: Target offline", __func__);
1603+
target->state = TARGET_UNKNOWN;
1604+
}
1605+
esp32->prevpwrstat = 0;
1606+
esp32->core_poweron_mask = 0;
1607+
return ERROR_TARGET_FAILURE;
1608+
}
1609+
uint32_t cores_came_online = core_poweron_mask & (~esp32->core_poweron_mask);
1610+
esp32->core_poweron_mask = core_poweron_mask;
1611+
if (cores_came_online != 0) {
1612+
LOG_DEBUG("%s: core_poweron_mask=%x", __func__, core_poweron_mask);
15801613
}
1614+
15811615
if (!(esp32->prevpwrstat&PWRSTAT_DEBUGWASRESET) && pwrstat[ESP32_PRO_CPU_ID] & PWRSTAT_DEBUGWASRESET) {
15821616
LOG_INFO("%s: Debug controller was reset (pwrstat=0x%02X, after clear 0x%02X).", target->cmd_name, pwrstat[ESP32_PRO_CPU_ID], pwrstath[ESP32_PRO_CPU_ID]);
15831617
}
@@ -1605,6 +1639,11 @@ static int xtensa_poll(struct target *target)
16051639

16061640
for (size_t i = 0; i < ESP32_CPU_COUNT; i++)
16071641
{
1642+
if (cores_came_online & (1 << i)) {
1643+
LOG_DEBUG("%s: Core %d came online, setting up DCR", __func__, (int) i);
1644+
xtensa_smpbreak_set_core(target, i);
1645+
}
1646+
16081647
uint8_t dsr_buf[4] = {0};
16091648
esp108_queue_nexus_reg_write(esp32->esp32_targets[i], NARADR_DCRSET, OCDDCR_ENABLEOCD);
16101649
esp108_queue_nexus_reg_read(esp32->esp32_targets[i], NARADR_DSR, dsr_buf);

src/target/esp32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct esp32_common {
114114
size_t active_cpu;
115115
struct reg_cache * core_caches[ESP32_CPU_COUNT];
116116
size_t cores_num;
117+
uint32_t core_poweron_mask;
117118
// TODO: Below are candidates to be moved to ESP108_COMMON_FIELDS
118119
int64_t current_threadid;
119120
enum esp32_isrmasking_mode isrmasking_mode;

tcl/target/esp32.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ proc esp_core_halt { tgt } {
5050
#ToDo: Figure out how to kill the RTC WDT
5151
}
5252

53-
proc esp_smp_break_config { } {
54-
esp32 smpbreak BreakInOut RunStallIn
55-
}
56-
5753
proc configure_esp32_core { TGT } {
5854
$TGT configure -event halted [list esp_core_halt $TGT]
59-
$TGT configure -event examine-end [list esp_smp_break_config]
6055
}
6156

6257
proc configure_esp32_workarea { TGT } {

0 commit comments

Comments
 (0)