From 8d73f51280930bd7edda11d2708384e1ad6bcb18 Mon Sep 17 00:00:00 2001 From: ALTracer Date: Sun, 26 Nov 2023 00:47:22 +0300 Subject: [PATCH] jtagtap: Equalize _next & _cycle, replace line reset * 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. --- src/platforms/common/jtagtap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/platforms/common/jtagtap.c b/src/platforms/common/jtagtap.c index ab91c55a197..b8eca99b525 100644 --- a/src/platforms/common/jtagtap.c +++ b/src/platforms/common/jtagtap.c @@ -53,8 +53,12 @@ void jtagtap_init(void) jtag_proc.tap_idle_cycles = 1; /* Ensure we're in JTAG mode */ +#if 1 + jtagtap_cycle(true, false, 51U); +#else for (size_t i = 0; i <= 50U; ++i) jtagtap_next(true, false); /* 50 + 1 idle cycles for SWD reset */ +#endif jtagtap_tms_seq(0xe73cU, 16U); /* SWD to JTAG sequence */ } @@ -100,8 +104,10 @@ static bool jtagtap_next_no_delay() __attribute__((optimize(3))); static bool jtagtap_next_no_delay() { gpio_set(TCK_PORT, TCK_PIN); + __asm__("nop" ::: "memory"); const uint16_t result = gpio_get(TDO_PORT, TDO_PIN); gpio_clear(TCK_PORT, TCK_PIN); + __asm__("nop" ::: "memory"); return result != 0; } @@ -327,6 +333,7 @@ static void jtagtap_cycle_no_delay(const size_t clock_cycles) gpio_set(TCK_PORT, TCK_PIN); __asm__ volatile("nop" ::: "memory"); gpio_clear(TCK_PORT, TCK_PIN); + __asm__ volatile("nop" ::: "memory"); } }