From 606b73601c2673114b4124c4ad7fd9bf90e70afc Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Sun, 27 Nov 2016 16:56:09 -0800 Subject: [PATCH] Added TMS/SWDIO direction pin & adjusted SRST sense. 1) This version uses a direction control level shifters. We need to control the direction of the TMS/SWDIO pin. 2.1) Because we want to support a large voltage range for SRST we use an external dual MOSFET for asserting and sensing the SRST line. We have added the hardware version 3 to be handled the same way as version 0. Meaning using separate pins for assertion and sensing of the SRST line. 2.2) The new SRST sense circuit is inverting, thus we have dedicated code for hardware version 3 that inverts the SRST status pin on read. --- src/platforms/native/platform.c | 20 ++++++++++++-------- src/platforms/native/platform.h | 23 ++++++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 7af41e2..8c8d777 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -112,13 +112,13 @@ void platform_init(void) gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, - TMS_PIN | TCK_PIN | TDI_PIN); + TMS_DIR_PIN | TMS_PIN | TCK_PIN | TDI_PIN); /* This needs some fixing... */ /* Toggle required to sort out line drivers... */ - gpio_port_write(GPIOA, 0x8100); + gpio_port_write(GPIOA, 0x8102); gpio_port_write(GPIOB, 0x2000); - gpio_port_write(GPIOA, 0x8180); + gpio_port_write(GPIOA, 0x8182); gpio_port_write(GPIOB, 0x2002); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, @@ -135,9 +135,10 @@ void platform_init(void) */ platform_srst_set_val(false); gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, - (platform_hwversion() == 0 - ? GPIO_CNF_OUTPUT_PUSHPULL - : GPIO_CNF_OUTPUT_OPENDRAIN), + (((platform_hwversion() == 0) || + (platform_hwversion() >= 3)) + ? GPIO_CNF_OUTPUT_PUSHPULL + : GPIO_CNF_OUTPUT_OPENDRAIN), SRST_PIN); /* Enable internal pull-up on PWR_BR so that we don't drive @@ -175,7 +176,8 @@ void platform_init(void) void platform_srst_set_val(bool assert) { - if (platform_hwversion() == 0) { + if ((platform_hwversion() == 0) || + (platform_hwversion() >= 3)) { gpio_set_val(SRST_PORT, SRST_PIN, assert); } else { gpio_set_val(SRST_PORT, SRST_PIN, !assert); @@ -188,7 +190,9 @@ void platform_srst_set_val(bool assert) bool platform_srst_get_val(void) { if (platform_hwversion() == 0) { - return gpio_get(SRST_PORT, SRST_SENSE_PIN) == 0; + return gpio_get(SRST_SENSE_PORT, SRST_SENSE_PIN) == 0; + } else if (platform_hwversion() >= 3) { + return gpio_get(SRST_SENSE_PORT, SRST_SENSE_PIN) != 0; } else { return gpio_get(SRST_PORT, SRST_PIN) == 0; } diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index a6c39b6..386291a 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -48,12 +48,13 @@ * LED2 = PB11 (Red LED : Error) * * TPWR = RB0 (input) -- analogue on mini design ADC1, ch8 - * nTRST = PB1 [blackmagic] - * PWR_BR = PB1 [blackmagic_mini] -- supply power to the target, active low - * SRST_OUT = PA2 - * TDI = PA3 - * TMS = PA4 (input for SWDP) - * TCK = PA5 + * nTRST = PB1 (output) [blackmagic] + * PWR_BR = PB1 (output) [blackmagic_mini] -- supply power to the target, active low + * TMS_DIR = PA1 (output) [blackmagic_mini v2.1] -- choose direction of the TCK pin, input low, output high + * SRST_OUT = PA2 (output) + * TDI = PA3 (output) + * TMS = PA4 (input/output for SWDIO) + * TCK = PA5 (output SWCLK) * TDO = PA6 (input) * nSRST = PA7 (input) * @@ -66,16 +67,20 @@ /* Hardware definitions... */ #define JTAG_PORT GPIOA #define TDI_PORT JTAG_PORT +#define TMS_DIR_PORT JTAG_PORT #define TMS_PORT JTAG_PORT #define TCK_PORT JTAG_PORT #define TDO_PORT JTAG_PORT #define TDI_PIN GPIO3 +#define TMS_DIR_PIN GPIO1 #define TMS_PIN GPIO4 #define TCK_PIN GPIO5 #define TDO_PIN GPIO6 +#define SWDIO_DIR_PORT JTAG_PORT #define SWDIO_PORT JTAG_PORT #define SWCLK_PORT JTAG_PORT +#define SWDIO_DIR_PIN TMS_DIR_PIN #define SWDIO_PIN TMS_PIN #define SWCLK_PIN TCK_PIN @@ -85,6 +90,7 @@ #define PWR_BR_PIN GPIO1 #define SRST_PORT GPIOA #define SRST_PIN GPIO2 +#define SRST_SENSE_PORT GPIOA #define SRST_SENSE_PIN GPIO7 #define USB_PU_PORT GPIOA @@ -104,12 +110,15 @@ #define LED_ERROR LED_2 #define TMS_SET_MODE() \ + gpio_set(TMS_DIR_PORT, TMS_DIR_PIN); \ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); #define SWDIO_MODE_FLOAT() \ gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); + GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); \ + gpio_clear(SWDIO_DIR_PORT, SWDIO_DIR_PIN); #define SWDIO_MODE_DRIVE() \ + gpio_set(SWDIO_DIR_PORT, SWDIO_DIR_PIN); \ gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN);