Skip to content

Commit 26301c4

Browse files
FBOSTMtarek-bochkati
authored andcommitted
target/cortex_m: fix soft_reset_halt
in GDB event "gdb-flash-erase-start", a soft reset dont perform correctly target need to halt Unfortunately, the execution of soft reset fails with time out error (after 100 ms: S_HALT not raised => Target not halted => reset not performed). After investigation, Accordingly to ARM DDI0403E.B, chapter “B3.2.6 Application Interrupt and Reset Control Register, AIRCR” before setting DEMCR.VC_CORERESET to perform local system reset, we must halt the core otherwisethe behavior is unpredictable. Change-Id: I440c66dca5effa2079ae330a31e2311525539e29 Signed-off-by: fedi BOUZAZI <fedi.bouzazi@st.com>
1 parent 17ad4a0 commit 26301c4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/target/cortex_m.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,29 @@ static int cortex_m_soft_reset_halt(struct target *target)
10411041
if (retval != ERROR_OK)
10421042
return retval;
10431043

1044+
/* Enter Debug state before setting 1 to AIRCR_VECTRESET */
1045+
retval = cortex_m_write_debug_halt_mask(target, C_HALT, 0);
1046+
if (retval != ERROR_OK)
1047+
return retval;
1048+
1049+
/* Ensure core halted */
1050+
while (timeout < 100) {
1051+
retval = cortex_m_read_dhcsr_atomic_sticky(target);
1052+
if (retval == ERROR_OK) {
1053+
if (cortex_m->dcb_dhcsr & S_HALT) {
1054+
LOG_TARGET_DEBUG(target, "core halted, DHCSR 0x%08" PRIx32, cortex_m->dcb_dhcsr);
1055+
cortex_m_poll(target);
1056+
return ERROR_OK;
1057+
} else {
1058+
LOG_TARGET_DEBUG(target, "waiting for system reset-halt, "
1059+
"DHCSR 0x%08" PRIx32 ", %d ms",
1060+
cortex_m->dcb_dhcsr, timeout);
1061+
}
1062+
}
1063+
timeout++;
1064+
alive_sleep(1);
1065+
}
1066+
10441067
/* Enter debug state on reset; restore DEMCR in endreset_event() */
10451068
retval = mem_ap_write_u32(armv7m->debug_ap, DCB_DEMCR,
10461069
TRCENA | VC_HARDERR | VC_BUSERR | VC_CORERESET);
@@ -1057,6 +1080,9 @@ static int cortex_m_soft_reset_halt(struct target *target)
10571080
/* registers are now invalid */
10581081
register_cache_invalidate(cortex_m->armv7m.arm.core_cache);
10591082

1083+
/* reset timeout to 0 */
1084+
timeout = 0;
1085+
10601086
while (timeout < 100) {
10611087
retval = cortex_m_read_dhcsr_atomic_sticky(target);
10621088
if (retval == ERROR_OK) {

0 commit comments

Comments
 (0)