target/arm_adi_v5, cortex_m: retry ahbap_debugport_init few times in case of an error

Some targets need arbitrary amount of time (usually not too long)
after reset (both sysresetreq and srst) to do initialisation, and
SWD/JTAG is not available during that. According to PSoC4 docs, the
debugger should try connecting until it succeeds.

Also ahbap_debugport_init might be necessary to perform after using
hardware srst too, so add it there (except for the targets that
support srst_nogate since they are very unlikely to need it).

Change-Id: I3598d5ff7b8e0bf3a5566a57dec4b0b2b243d297
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2601
Tested-by: jenkins
__archive__
Paul Fertser 2015-03-13 17:55:51 +03:00
parent 13ac3d556c
commit bdfd5bbe04
2 changed files with 68 additions and 51 deletions

View File

@ -642,6 +642,8 @@ extern const struct dap_ops jtag_dp_ops;
*/
int ahbap_debugport_init(struct adiv5_dap *dap)
{
/* check that we support packed transfers */
uint32_t csw, cfg;
int retval;
LOG_DEBUG(" ");
@ -663,26 +665,27 @@ int ahbap_debugport_init(struct adiv5_dap *dap)
dap_ap_select(dap, 0);
dap->last_read = NULL;
for (size_t i = 0; i < 10; i++) {
/* DP initialization */
dap->dp_bank_value = 0;
retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_queue_dp_write(dap, DP_CTRL_STAT, SSTICKYERR);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
if (retval != ERROR_OK)
return retval;
continue;
dap->dp_ctrl_stat = CDBGPWRUPREQ | CSYSPWRUPREQ;
retval = dap_queue_dp_write(dap, DP_CTRL_STAT, dap->dp_ctrl_stat);
if (retval != ERROR_OK)
return retval;
continue;
/* Check that we have debug power domains activated */
LOG_DEBUG("DAP: wait CDBGPWRUPACK");
@ -690,43 +693,46 @@ int ahbap_debugport_init(struct adiv5_dap *dap)
CDBGPWRUPACK, CDBGPWRUPACK,
DAP_POWER_DOMAIN_TIMEOUT);
if (retval != ERROR_OK)
return retval;
continue;
LOG_DEBUG("DAP: wait CSYSPWRUPACK");
retval = dap_dp_poll_register(dap, DP_CTRL_STAT,
CSYSPWRUPACK, CSYSPWRUPACK,
DAP_POWER_DOMAIN_TIMEOUT);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
if (retval != ERROR_OK)
return retval;
continue;
/* With debug power on we can activate OVERRUN checking */
dap->dp_ctrl_stat = CDBGPWRUPREQ | CSYSPWRUPREQ | CORUNDETECT;
retval = dap_queue_dp_write(dap, DP_CTRL_STAT, dap->dp_ctrl_stat);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
if (retval != ERROR_OK)
return retval;
/* check that we support packed transfers */
uint32_t csw, cfg;
continue;
retval = dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_PACKED, 0);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_queue_ap_read(dap, AP_REG_CSW, &csw);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_queue_ap_read(dap, AP_REG_CFG, &cfg);
if (retval != ERROR_OK)
return retval;
continue;
retval = dap_run(dap);
if (retval != ERROR_OK)
continue;
break;
}
if (retval != ERROR_OK)
return retval;

View File

@ -1107,6 +1107,17 @@ static int cortex_m_deassert_reset(struct target *target)
/* deassert reset lines */
adapter_deassert_reset();
enum reset_types jtag_reset_config = jtag_get_reset_config();
if ((jtag_reset_config & RESET_HAS_SRST) &&
!(jtag_reset_config & RESET_SRST_NO_GATING)) {
int retval = ahbap_debugport_init(target_to_cm(target)->armv7m.arm.dap);
if (retval != ERROR_OK) {
LOG_ERROR("DP initialisation failed");
return retval;
}
}
return ERROR_OK;
}