From 9198f5b630687c4b5d2f1b4cf306cea9eaf25e20 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 9 Aug 2022 23:33:10 +0100 Subject: [PATCH] native: Properly handled the TCK/SWCLK processor pin when doing clock tristating --- src/platforms/native/platform.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 0a08140..710e607 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -340,8 +340,16 @@ void platform_request_boot(void) void platform_target_clk_output_enable(bool enable) { - if (platform_hwversion() >= 6) + if (platform_hwversion() >= 6) { + /* If we're switching to tristate mode, first convert the processor pin to an input */ + if (!enable) + gpio_set_mode(TCK_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, TCK_PIN); + /* Reconfigure the logic levelt translator */ gpio_set_val(TCK_DIR_PORT, TCK_DIR_PIN, enable); + /* If we're switching back out of tristate mode, we're now safe to make the processor pin an output again */ + if (enable) + gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); + } } void exti15_10_isr(void)