From e1b4b4e1b7133fc93fd22c67d096422b6e102763 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 13 May 2024 21:49:10 +0100 Subject: [PATCH] hosted/stlinkv2: Corrected how line reset is generated for ST-Link adaptors, and switched to issuing a warning when attempting to re-select a multi-drop part --- src/platforms/hosted/stlinkv2.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/platforms/hosted/stlinkv2.c b/src/platforms/hosted/stlinkv2.c index 34d6ee3e548..0c9839c0fb4 100644 --- a/src/platforms/hosted/stlinkv2.c +++ b/src/platforms/hosted/stlinkv2.c @@ -502,6 +502,15 @@ int stlink_hwversion(void) return stlink.ver_stlink; } +static void stlink_line_reset(void) +{ + stlink_simple_query(STLINK_DEBUG_COMMAND, STLINK_DEBUG_EXIT, NULL, 0); + uint8_t data[2]; + stlink_simple_request( + STLINK_DEBUG_COMMAND, STLINK_DEBUG_APIV2_ENTER, STLINK_DEBUG_ENTER_SWD_NO_RESET, data, sizeof(data)); + stlink_usb_error_check(data, true); +} + uint32_t stlink_adiv5_clear_error(adiv5_debug_port_s *const dp, const bool protocol_recovery) { DEBUG_PROBE("%s (protocol recovery: %s)\n", __func__, protocol_recovery ? "true" : "false"); @@ -512,9 +521,16 @@ uint32_t stlink_adiv5_clear_error(adiv5_debug_port_s *const dp, const bool proto * we must then re-select the target to bring the device back * into the expected state. */ - stlink_reset_adaptor(); + stlink_line_reset(); if (dp->version >= 2) - adiv5_dp_write(dp, ADIV5_DP_TARGETSEL, dp->targetsel); + /* + * The correct thing to do here is some form of this: + * adiv5_dp_write(dp, ADIV5_DP_TARGETSEL, dp->targetsel); + * but ST-Link adaptors cannot handle this properly right now, so warn instead. + */ + DEBUG_WARN("ST-Link v2/v3 adaptors cannot handle multi-drop correctly, pretending everything's fine\n"); + /* Re-select the current AP on completion so we keep talking with the same thing */ + stlink_ap_setup(stlink.apsel); adiv5_dp_read(dp, ADIV5_DP_DPIDR); } const uint32_t err = adiv5_dp_read(dp, ADIV5_DP_CTRLSTAT) &