Skip to content

Commit 5127713

Browse files
tlyustansotn
authored andcommitted
common/platform: fix SWD turnaround
Fix two problems with SWD turnaround: * When going from output to input, add a missing delay loop, so the clock low period is consistent. This prevents problems with a missed clock edge when the clock speed is intentionally slowed to accommodate lower bandwidth connections to the target. * Always set the clock low at the end of a turnaround. Otherwise, when floating the clock after a read transaction, the most recent clock state was driven high. If there's a pull down on the clock, a subsequent clock reactivation would drive the clock high, producing an extra rising clock edge. This sometimes causes (recoverable) protocol error states when re-attaching after a detach. Co-Authored-By: Stanislav Sotnikov <stanislav.sotnikov145@gmail.com>
1 parent 082e388 commit 5127713

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/platforms/common/swdptap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,18 @@ static void swdptap_turnaround(const swdio_status_t dir)
6767

6868
if (dir == SWDIO_STATUS_FLOAT) {
6969
SWDIO_MODE_FLOAT();
70-
} else {
70+
} else
7171
gpio_clear(SWCLK_PORT, SWCLK_PIN);
72-
for (volatile uint32_t counter = target_clk_divider + 1; counter > 0; --counter)
73-
continue;
74-
}
72+
73+
for (volatile uint32_t counter = target_clk_divider + 1; counter > 0; --counter)
74+
continue;
7575

7676
gpio_set(SWCLK_PORT, SWCLK_PIN);
7777
for (volatile uint32_t counter = target_clk_divider + 1; counter > 0; --counter)
7878
continue;
7979

8080
if (dir == SWDIO_STATUS_DRIVE) {
81+
gpio_clear(SWCLK_PORT, SWCLK_PIN);
8182
SWDIO_MODE_DRIVE();
8283
}
8384
}

0 commit comments

Comments
 (0)