diff --git a/src/target/atxmega.c b/src/target/atxmega.c index a15ed0de39e..c114f60e8b2 100644 --- a/src/target/atxmega.c +++ b/src/target/atxmega.c @@ -503,6 +503,26 @@ static void atxmega_halt_resume(target_s *const target, const bool step) continue; pdi->halt_reason = TARGET_HALT_STEPPING; } else { + /* + * To resume the processor we go through the following specific steps: + * Write the program counter to ensure we start where we expect + * Then we release the externally (PDI) applied reset + * We then poke the debug control register to indicate debug-supervised run + * Ensure that PDI is still in debug mode (r4 = 1) + * Read r3 to see that the processor is resuming + */ + /* Check that we are in administrative halt */ + if (avr_pdi_reg_read(pdi, PDI_REG_R3) != 0x04U || + /* Try to configure the breakpoints */ + !atxmega_config_breakpoints(pdi, step) || avr_pdi_reg_read(pdi, PDI_REG_R3) != 0x04U || + /* Set the program counter and release reset */ + !avr_pdi_write(pdi, PDI_DATA_32, ATXMEGA_DBG_PC, pdi->program_counter) || + !avr_pdi_reg_write(pdi, PDI_REG_RESET, 0U) || + /* Configure the debug controller */ + !avr_pdi_write(pdi, PDI_DATA_8, ATXMEGA_DBG_CTRL, 0U) || avr_pdi_reg_read(pdi, PDI_REG_R3) != 0x04U || + /* And try to execute the request */ + !avr_pdi_reg_write(pdi, PDI_REG_R4, 1U)) + raise_exception(EXCEPTION_ERROR, "Error resuming device, device in incorrect state"); pdi->halt_reason = TARGET_HALT_RUNNING; } }