Skip to content

Commit

Permalink
hosted/stlinkv2: Corrected how line reset is generated for ST-Link ad…
Browse files Browse the repository at this point in the history
…aptors, and switched to issuing a warning when attempting to re-select a multi-drop part
  • Loading branch information
dragonmux committed May 18, 2024
1 parent d388872 commit e1b4b4e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/platforms/hosted/stlinkv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) &
Expand Down

0 comments on commit e1b4b4e

Please sign in to comment.