Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ADIv5 handling issues #1826

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions src/target/adiv5.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ void advi5_mem_read_bytes(adiv5_access_port_s *const ap, void *dest, const targe
* Check if the address doesn't overflow the 10-bit auto increment bound for TAR,
* if it's not the first transfer (offset == 0)
*/
if (begin != src && (begin & 0x00000effU) == 0U) {
if (begin != src && (begin & 0x000003ffU) == 0U) {
/* Update TAR to adjust the upper bits */
if (ap->flags & ADIV5_AP_FLAGS_64BIT)
adiv5_dp_write(ap->dp, ADIV5_AP_TAR_HIGH, (uint32_t)(begin >> 32));
Expand Down Expand Up @@ -1321,7 +1321,7 @@ void adiv5_mem_write_bytes(
* Check if the address doesn't overflow the 10-bit auto increment bound for TAR,
* if it's not the first transfer (offset == 0)
*/
if (begin != dest && (begin & 0x00000effU) == 0U) {
if (begin != dest && (begin & 0x000003ffU) == 0U) {
/* Update TAR to adjust the upper bits */
if (ap->flags & ADIV5_AP_FLAGS_64BIT)
adiv5_dp_write(ap->dp, ADIV5_AP_TAR_HIGH, (uint32_t)(begin >> 32));
Expand Down
2 changes: 1 addition & 1 deletion src/target/adiv5_swd.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void adiv5_swd_multidrop_scan(adiv5_debug_port_s *const dp, const uint32_t targe

/* Allocate a new target DP for this instance */
adiv5_debug_port_s *const target_dp = calloc(1, sizeof(*dp));
if (!dp) { /* calloc failed: heap exhaustion */
if (!target_dp) { /* calloc failed: heap exhaustion */
DEBUG_ERROR("calloc: failed in %s\n", __func__);
break;
}
Expand Down
Loading