From 59e03dea2789e1ee4698c9a1a5c1deeedf67ed5d Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 7 Mar 2018 15:57:00 +0100 Subject: [PATCH] Keep TMS floating until scanning. NRF5x shares nRST with SWDIO and otherwise does not run until scan is done. --- src/platforms/common/swdptap.c | 23 ++++++++++++++--------- src/platforms/f4discovery/platform.c | 4 +++- src/platforms/hydrabus/platform.c | 4 +++- src/platforms/launchpad-icdi/platform.c | 2 +- src/platforms/native/platform.c | 5 +++++ src/platforms/stlink/platform.c | 2 +- src/platforms/swlink/platform.c | 2 +- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/platforms/common/swdptap.c b/src/platforms/common/swdptap.c index 46d5a672..9d9638de 100644 --- a/src/platforms/common/swdptap.c +++ b/src/platforms/common/swdptap.c @@ -23,6 +23,11 @@ #include "general.h" #include "swdptap.h" +enum { + SWDIO_STATUS_FLOAT = 0, + SWDIO_STATUS_DRIVE +}; + int swdptap_init(void) { return 0; @@ -30,7 +35,7 @@ int swdptap_init(void) static void swdptap_turnaround(int dir) { - static int olddir = 0; + static int olddir = SWDIO_STATUS_FLOAT; /* Don't turnaround if direction not changing */ if(dir == olddir) return; @@ -40,12 +45,12 @@ static void swdptap_turnaround(int dir) DEBUG("%s", dir ? "\n-> ":"\n<- "); #endif - if(dir) + if(dir == SWDIO_STATUS_FLOAT) SWDIO_MODE_FLOAT(); gpio_set(SWCLK_PORT, SWCLK_PIN); gpio_set(SWCLK_PORT, SWCLK_PIN); gpio_clear(SWCLK_PORT, SWCLK_PIN); - if(!dir) + if(dir == SWDIO_STATUS_DRIVE) SWDIO_MODE_DRIVE(); } @@ -53,7 +58,7 @@ bool swdptap_bit_in(void) { uint16_t ret; - swdptap_turnaround(1); + swdptap_turnaround(SWDIO_STATUS_FLOAT); ret = gpio_get(SWDIO_PORT, SWDIO_PIN); gpio_set(SWCLK_PORT, SWCLK_PIN); @@ -74,7 +79,7 @@ swdptap_seq_in(int ticks) uint32_t ret = 0; int len = ticks; - swdptap_turnaround(1); + swdptap_turnaround(SWDIO_STATUS_FLOAT); while (len--) { int res; res = gpio_get(SWDIO_PORT, SWDIO_PIN); @@ -101,7 +106,7 @@ swdptap_seq_in_parity(uint32_t *ret, int ticks) bool bit; int len = ticks; - swdptap_turnaround(1); + swdptap_turnaround(SWDIO_STATUS_FLOAT); while (len--) { bit = gpio_get(SWDIO_PORT, SWDIO_PIN); gpio_set(SWCLK_PORT, SWCLK_PIN); @@ -131,7 +136,7 @@ void swdptap_bit_out(bool val) DEBUG("%d", val); #endif - swdptap_turnaround(0); + swdptap_turnaround(SWDIO_STATUS_DRIVE); gpio_set_val(SWDIO_PORT, SWDIO_PIN, val); gpio_clear(SWCLK_PORT, SWCLK_PIN); @@ -147,7 +152,7 @@ swdptap_seq_out(uint32_t MS, int ticks) for (int i = 0; i < ticks; i++) DEBUG("%d", (MS & (1 << i)) ? 1 : 0); #endif - swdptap_turnaround(0); + swdptap_turnaround(SWDIO_STATUS_DRIVE); while (ticks--) { gpio_set_val(SWDIO_PORT, SWDIO_PIN, data); MS >>= 1; @@ -167,7 +172,7 @@ swdptap_seq_out_parity(uint32_t MS, int ticks) for (int i = 0; i < ticks; i++) DEBUG("%d", (MS & (1 << i)) ? 1 : 0); #endif - swdptap_turnaround(0); + swdptap_turnaround(SWDIO_STATUS_DRIVE); while (ticks--) { gpio_set_val(SWDIO_PORT, SWDIO_PIN, data); diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index 8e3b9d37..89b82c16 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -78,7 +78,9 @@ void platform_init(void) GPIOC_OSPEEDR |= 0xA20; gpio_mode_setup(JTAG_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - TMS_PIN | TCK_PIN | TDI_PIN); + TCK_PIN | TDI_PIN); + gpio_mode_setup(JTAG_PORT, GPIO_MODE_INPUT, + GPIO_PUPD_NONE, TMS_PIN); gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, diff --git a/src/platforms/hydrabus/platform.c b/src/platforms/hydrabus/platform.c index c6a60c26..bf3db04b 100644 --- a/src/platforms/hydrabus/platform.c +++ b/src/platforms/hydrabus/platform.c @@ -63,7 +63,9 @@ void platform_init(void) GPIOC_OSPEEDR |= 0xA20; gpio_mode_setup(JTAG_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - TMS_PIN | TCK_PIN | TDI_PIN); + TCK_PIN | TDI_PIN); + gpio_mode_setup(JTAG_PORT, GPIO_MODE_INPUT, + GPIO_PUPD_NONE, TMS_PIN); gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index 5ecfb541..70bb72a0 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -62,7 +62,7 @@ platform_init(void) gpio_enable_ahb_aperture(); - gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TMS_PIN); + gpio_mode_setup(TMS_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, TMS_PIN); gpio_mode_setup(TCK_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TCK_PIN); gpio_mode_setup(TDI_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TDI_PIN); gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, TDO_PIN); diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index c69eea3b..7d750572 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -113,6 +113,11 @@ void platform_init(void) gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_DIR_PIN | TMS_PIN | TCK_PIN | TDI_PIN); + gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, + TMS_DIR_PIN | TCK_PIN | TDI_PIN); + gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_INPUT_FLOAT, TMS_PIN); /* This needs some fixing... */ /* Toggle required to sort out line drivers... */ gpio_port_write(GPIOA, 0x8102); diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 591c2cba..a8797912 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -63,7 +63,7 @@ void platform_init(void) } /* Setup GPIO ports */ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); + GPIO_CNF_INPUT_FLOAT, TMS_PIN); gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_50_MHZ, diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 651ab9b1..15458336 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -58,7 +58,7 @@ void platform_init(void) AFIO_MAPR = data; /* Setup JTAG GPIO ports */ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_10_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); + GPIO_CNF_INPUT_FLOAT, TMS_PIN); gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_10_MHZ,