Skip to content

Commit

Permalink
swdptap: Tweak _no_delay() timings for a more even duty cycle
Browse files Browse the repository at this point in the history
* Reference: jtagtap_tms_seq_no_delay(). Also add comments.
* Use appropriate type for TMS state output.
  • Loading branch information
ALTracer committed Dec 31, 2023
1 parent b01a687 commit a3a8427
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/platforms/common/swdptap.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ static uint32_t swdptap_seq_in_no_delay(const size_t clock_cycles)
for (size_t cycle = 0; cycle < clock_cycles; ++cycle) {
gpio_clear(SWCLK_PORT, SWCLK_PIN);
value |= gpio_get(SWDIO_IN_PORT, SWDIO_IN_PIN) ? 1U << cycle : 0U;
/* Reordering barrier (in place of a delay) to retain timings */
__asm__("" ::: "memory");
gpio_set(SWCLK_PORT, SWCLK_PIN);
__asm__("nop");
__asm__("" ::: "memory");
}
gpio_clear(SWCLK_PORT, SWCLK_PIN);
return value;
Expand Down Expand Up @@ -165,9 +167,14 @@ static void swdptap_seq_out_no_delay(uint32_t tms_states, size_t clock_cycles) _
static void swdptap_seq_out_no_delay(const uint32_t tms_states, const size_t clock_cycles)
{
for (size_t cycle = 0; cycle < clock_cycles; ++cycle) {
const bool state = tms_states & (1U << cycle);
/* Block the compiler from re-ordering the TMS states calculation to preserve timings */
__asm__("" ::: "memory");
gpio_clear(SWCLK_PORT, SWCLK_PIN);
gpio_set_val(SWDIO_PORT, SWDIO_PIN, tms_states & (1 << cycle));
gpio_set_val(SWDIO_PORT, SWDIO_PIN, state);
__asm__("" ::: "memory");
gpio_set(SWCLK_PORT, SWCLK_PIN);
__asm__("" ::: "memory");
}
gpio_clear(SWCLK_PORT, SWCLK_PIN);
}
Expand Down

0 comments on commit a3a8427

Please sign in to comment.