Skip to content

Commit

Permalink
swdptap: Handle no_delay parity/turnaround as well
Browse files Browse the repository at this point in the history
* This allows dropping the 0-loops check from delay_busy
  • Loading branch information
ALTracer committed Dec 31, 2023
1 parent a3a8427 commit 1c102fe
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/platforms/common/swdptap.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ static void swdptap_turnaround(const swdio_status_t dir)
SWDIO_MODE_FLOAT();
} else {
gpio_clear(SWCLK_PORT, SWCLK_PIN);
platform_delay_busy(target_clk_divider + 1);
if (target_clk_divider != UINT32_MAX)
platform_delay_busy(target_clk_divider);
}

gpio_set(SWCLK_PORT, SWCLK_PIN);
platform_delay_busy(target_clk_divider + 1);
if (target_clk_divider != UINT32_MAX)
platform_delay_busy(target_clk_divider);

if (dir == SWDIO_STATUS_DRIVE) {
SWDIO_MODE_DRIVE();
Expand Down Expand Up @@ -134,13 +136,15 @@ static uint32_t swdptap_seq_in(size_t clock_cycles)
static bool swdptap_seq_in_parity(uint32_t *ret, size_t clock_cycles)
{
const uint32_t result = swdptap_seq_in(clock_cycles);
platform_delay_busy(target_clk_divider + 1);
if (target_clk_divider != UINT32_MAX)
platform_delay_busy(target_clk_divider);

const bool parity = calculate_odd_parity(result);
const bool bit = gpio_get(SWDIO_IN_PORT, SWDIO_IN_PIN);

gpio_set(SWCLK_PORT, SWCLK_PIN);
platform_delay_busy(target_clk_divider + 1);
if (target_clk_divider != UINT32_MAX)
platform_delay_busy(target_clk_divider);

*ret = result;
/* Terminate the read cycle now */
Expand Down Expand Up @@ -193,8 +197,12 @@ static void swdptap_seq_out_parity(const uint32_t tms_states, const size_t clock
const bool parity = calculate_odd_parity(tms_states);
swdptap_seq_out(tms_states, clock_cycles);
gpio_set_val(SWDIO_PORT, SWDIO_PIN, parity);
platform_delay_busy(target_clk_divider + 1);
if (target_clk_divider != UINT32_MAX)
platform_delay_busy(target_clk_divider);

gpio_set(SWCLK_PORT, SWCLK_PIN);
platform_delay_busy(target_clk_divider + 1);
if (target_clk_divider != UINT32_MAX)
platform_delay_busy(target_clk_divider);

gpio_clear(SWCLK_PORT, SWCLK_PIN);
}

0 comments on commit 1c102fe

Please sign in to comment.