Skip to content

Commit

Permalink
hosted/jlink_swd: remove now redundant swd error handling
Browse files Browse the repository at this point in the history
This function duplicated firmware_swdp_error in target/adiv5_swd,
jlink support now provides all the methods required to perform the routine
  • Loading branch information
perigoso authored and dragonmux committed Oct 29, 2023
1 parent 2ac5fcd commit 57cb707
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions src/platforms/hosted/jlink_swd.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,13 @@ static const uint8_t jlink_adiv5_read_request[5] = {
/* clang-format on */
};

/* 60 cycles of SWDIO held high + 4 cycles of it low (idle) */
static const uint8_t jlink_line_reset_data[8] = {0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xf0U};
/* Define the direction as output for the entire lot */
static const uint8_t jlink_line_reset_dir[8] = {0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU};

static uint32_t jlink_swd_seq_in(size_t clock_cycles);
static bool jlink_swd_seq_in_parity(uint32_t *result, size_t clock_cycles);
static void jlink_swd_seq_out(uint32_t tms_states, size_t clock_cycles);
static void jlink_swd_seq_out_parity(uint32_t tms_states, size_t clock_cycles);

static bool jlink_adiv5_raw_write_no_check(uint16_t addr, uint32_t data);
static uint32_t jlink_adiv5_raw_read_no_check(uint16_t addr);
static uint32_t jlink_adiv5_clear_error(adiv5_debug_port_s *dp, bool protocol_recovery);
static uint32_t jlink_adiv5_raw_access(adiv5_debug_port_s *dp, uint8_t rnw, uint16_t addr, uint32_t request_value);

bool jlink_swd_init(adiv5_debug_port_s *dp)
Expand All @@ -103,7 +97,6 @@ bool jlink_swd_init(adiv5_debug_port_s *dp)
dp->write_no_check = jlink_adiv5_raw_write_no_check;
dp->read_no_check = jlink_adiv5_raw_read_no_check;
dp->dp_read = firmware_swdp_read;
dp->error = jlink_adiv5_clear_error;
dp->low_access = jlink_adiv5_raw_access;
return true;
}
Expand Down Expand Up @@ -226,56 +219,6 @@ static uint32_t jlink_adiv5_raw_read_no_check(const uint16_t addr)
return ack == SWDP_ACK_OK ? data : 0U;
}

static bool jlink_swd_line_reset(void)
{
/*
* We have to send at least 50 cycles (actually at least 51 because of non-conformance
* in STM32 devices) of SWDIO held high to perform the line reset, then 4 cycles of it low
* to complete the reset and put the device back in idle
*/
const bool result = jlink_transfer(64U, jlink_line_reset_dir, jlink_line_reset_data, NULL);
if (!result)
DEBUG_ERROR("%s failed\n", __func__);
return result;
}

static uint32_t jlink_adiv5_clear_error(adiv5_debug_port_s *const dp, const bool protocol_recovery)
{
DEBUG_PROBE("jlink_adiv5_clear_error (protocol recovery? %s)\n", protocol_recovery ? "true" : "false");
/* Only do the comms reset dance on DPv2+ w/ fault or to perform protocol recovery. */
if ((dp->version >= 2 && dp->fault) || protocol_recovery) {
/*
* Note that on DPv2+ devices, during a protocol error condition
* the target becomes deselected during line reset. Once reset,
* we must then re-select the target to bring the device back
* into the expected state.
*/
jlink_swd_line_reset();
if (dp->version >= 2)
jlink_adiv5_raw_write_no_check(ADIV5_DP_TARGETSEL, dp->targetsel);
jlink_adiv5_raw_read_no_check(ADIV5_DP_DPIDR);
/* Exception here is unexpected, so do not catch */
}
const uint32_t err = jlink_adiv5_raw_read_no_check(ADIV5_DP_CTRLSTAT) &
(ADIV5_DP_CTRLSTAT_STICKYORUN | ADIV5_DP_CTRLSTAT_STICKYCMP | ADIV5_DP_CTRLSTAT_STICKYERR |
ADIV5_DP_CTRLSTAT_WDATAERR);
uint32_t clr = 0;

if (err & ADIV5_DP_CTRLSTAT_STICKYORUN)
clr |= ADIV5_DP_ABORT_ORUNERRCLR;
if (err & ADIV5_DP_CTRLSTAT_STICKYCMP)
clr |= ADIV5_DP_ABORT_STKCMPCLR;
if (err & ADIV5_DP_CTRLSTAT_STICKYERR)
clr |= ADIV5_DP_ABORT_STKERRCLR;
if (err & ADIV5_DP_CTRLSTAT_WDATAERR)
clr |= ADIV5_DP_ABORT_WDERRCLR;

if (clr)
jlink_adiv5_raw_write_no_check(ADIV5_DP_ABORT, clr);
dp->fault = 0;
return err;
}

static uint32_t jlink_adiv5_raw_read(adiv5_debug_port_s *const dp)
{
uint8_t result[5] = {0};
Expand Down

0 comments on commit 57cb707

Please sign in to comment.