Skip to content

Commit

Permalink
jtagtap: Equalize _next & _cycle, replace line reset
Browse files Browse the repository at this point in the history
* SWD line reset needs 50 clocks with high TMS/SWDIO,
  this was achieved by looping over jtagtap_next() which incurs function call delays;
* Use jtagtap_cycle() instead which seems appropriate here, and discards TDO anyways;
* The adiv5_swd.c:swd_line_reset_sequence() counterpart seems less fitting to duplicate in jtagtap.

* Annotate any new nops in hot no_delay path.
  • Loading branch information
ALTracer committed Dec 31, 2023
1 parent f694b4c commit 3a29354
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/platforms/common/jtagtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ void jtagtap_init(void)
jtag_proc.tap_idle_cycles = 1;

/* Ensure we're in JTAG mode */
for (size_t i = 0; i <= 50U; ++i)
jtagtap_next(true, false); /* 50 + 1 idle cycles for SWD reset */
jtagtap_tms_seq(0xe73cU, 16U); /* SWD to JTAG sequence */
jtagtap_cycle(true, false, 51U); /* 50 + 1 idle cycles for SWD reset */
jtagtap_tms_seq(0xe73cU, 16U); /* SWD to JTAG sequence */
}

static void jtagtap_reset(void)
Expand Down Expand Up @@ -93,8 +92,12 @@ static bool jtagtap_next_no_delay() __attribute__((optimize(3)));
static bool jtagtap_next_no_delay()
{
gpio_set(TCK_PORT, TCK_PIN);
/* Stretch the clock high time */
__asm__("nop" ::: "memory");
const uint16_t result = gpio_get(TDO_PORT, TDO_PIN);
gpio_clear(TCK_PORT, TCK_PIN);
/* Stretch the clock low time */
__asm__("nop" ::: "memory");
return result != 0;
}

Expand Down Expand Up @@ -318,8 +321,11 @@ static void jtagtap_cycle_no_delay(const size_t clock_cycles)
{
for (size_t cycle = 0; cycle < clock_cycles; ++cycle) {
gpio_set(TCK_PORT, TCK_PIN);
/* Stretch the clock high time */
__asm__ volatile("nop" ::: "memory");
gpio_clear(TCK_PORT, TCK_PIN);
/* Stretch the clock low time */
__asm__ volatile("nop" ::: "memory");
}
}

Expand Down

0 comments on commit 3a29354

Please sign in to comment.