From 9de69bb3ab5e31998ff2ad935bc3214a9bd80e99 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 22 Sep 2021 11:45:09 +0200 Subject: [PATCH] Adiv5/Initial halt: More fixes for dd28fa5743. #925 Stlink does not like low level access and aborts with STLINK_SWD_DP_ERROR. Either our implementation still has faults or stlink can not handle MINDP devices with BMP/Firmware also seemm not to like low level access, either du to some hidden error in BMP or by design --- src/target/adiv5.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/target/adiv5.c b/src/target/adiv5.c index 20179d7..e6ecb41 100644 --- a/src/target/adiv5.c +++ b/src/target/adiv5.c @@ -322,15 +322,22 @@ static uint32_t cortexm_initial_halt(ADIv5_AP_t *ap) uint32_t dhcsr_ctl = CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_DEBUGEN | CORTEXM_DHCSR_C_HALT; uint32_t dhcsr_valid = CORTEXM_DHCSR_S_HALT | CORTEXM_DHCSR_C_DEBUGEN; - uint32_t dhcsr; bool reset_seen = false; - if (!(ap->dp->idcode & ADIV5_MINDP)) { + bool is_mindp = (ap->dp->idcode & ADIV5_MINDP); +#if PC_HOSTED == 1 + bool use_low_access = (!(ap->dp->ap_setup) && !is_mindp); +#else + bool use_low_access = (!is_mindp); +#endif + if (use_low_access) { + DEBUG_WARN("Using low access\n"); + /* ap_mem_access_setup() sets ADIV5_AP_CSW_ADDRINC_SINGLE -> unusable!*/ adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_WORD); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, - CORTEXM_DHCSR); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, CORTEXM_DHCSR); } while (!platform_timeout_is_expired(&to)) { - if (!(ap->dp->idcode & ADIV5_MINDP)) { + uint32_t dhcsr ; + if (use_low_access) { adiv5_dp_write(ap->dp, ADIV5_DP_CTRLSTAT, ctrlstat | (0xfff * ADIV5_DP_CTRLSTAT_TRNCNT)); adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DRW,