From acff8d44976c0ffec1821318c73ce8948a19d0d2 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 10 Jun 2012 17:08:14 +1200 Subject: Made jtagtap.c and swdptap.c STM32 generic. --- src/platforms/native/jtagtap.c | 32 ++++++++++++-------------------- src/platforms/native/platform.c | 8 ++++++++ src/platforms/native/platform.h | 12 +++++++++++- src/platforms/native/swdptap.c | 24 ++++++++++++------------ 4 files changed, 43 insertions(+), 33 deletions(-) (limited to 'src/platforms') diff --git a/src/platforms/native/jtagtap.c b/src/platforms/native/jtagtap.c index 3703279..8160be8 100644 --- a/src/platforms/native/jtagtap.c +++ b/src/platforms/native/jtagtap.c @@ -28,15 +28,7 @@ int jtagtap_init(void) { - /* This needs some fixing... */ - /* Toggle required to sort out line drivers... */ - gpio_port_write(GPIOA, 0x8100); - gpio_port_write(GPIOB, 0x2000); - - gpio_port_write(GPIOA, 0x8180); - gpio_port_write(GPIOB, 0x2002); - - gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); /* Go to JTAG mode for SWJ-DP */ @@ -50,33 +42,33 @@ int jtagtap_init(void) void jtagtap_reset(void) { volatile int i; - gpio_clear(GPIOB, GPIO1); + gpio_clear(TRST_PORT, TRST_PIN); for(i = 0; i < 10000; i++) asm("nop"); - gpio_set(GPIOB, GPIO1); + gpio_set(TRST_PORT, TRST_PIN); jtagtap_soft_reset(); } void jtagtap_srst(void) { volatile int i; - gpio_set(GPIOA, GPIO2); + gpio_set(SRST_PORT, SRST_PIN); for(i = 0; i < 10000; i++) asm("nop"); - gpio_clear(GPIOA, GPIO2); + gpio_clear(SRST_PORT, SRST_PIN); } inline uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDO) { - uint8_t ret; + uint16_t ret; - gpio_set_val(JTAG_PORT, TMS_PIN, dTMS); - gpio_set_val(JTAG_PORT, TDI_PIN, dTDO); - gpio_set(JTAG_PORT, TCK_PIN); - ret = gpio_get(JTAG_PORT, TDO_PIN); - gpio_clear(JTAG_PORT, TCK_PIN); + gpio_set_val(TMS_PORT, TMS_PIN, dTMS); + gpio_set_val(TDI_PORT, TDI_PIN, dTDO); + gpio_set(TCK_PORT, TCK_PIN); + ret = gpio_get(TDO_PORT, TDO_PIN); + gpio_clear(TCK_PORT, TCK_PIN); DEBUG("jtagtap_next(TMS = %d, TDO = %d) = %d\n", dTMS, dTDO, ret); - return ret; + return ret != 0; } diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 4aff924..0b26272 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -84,6 +84,14 @@ int platform_init(void) GPIO_CNF_OUTPUT_PUSHPULL, 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(GPIOB, 0x2000); + + gpio_port_write(GPIOA, 0x8180); + gpio_port_write(GPIOB, 0x2002); + gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_UART | LED_IDLE_RUN | LED_ERROR); diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 56e0b77..c8f5f2b 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -58,15 +58,25 @@ /* Hardware definitions... */ #define JTAG_PORT GPIOA +#define TDI_PORT JTAG_PORT +#define TMS_PORT JTAG_PORT +#define TCK_PORT JTAG_PORT +#define TDO_PORT JTAG_PORT #define TDI_PIN GPIO3 #define TMS_PIN GPIO4 #define TCK_PIN GPIO5 #define TDO_PIN GPIO6 -#define SWDP_PORT JTAG_PORT +#define SWDIO_PORT JTAG_PORT +#define SWCLK_PORT JTAG_PORT #define SWDIO_PIN TMS_PIN #define SWCLK_PIN TCK_PIN +#define TRST_PORT GPIOB +#define TRST_PIN GPIO1 +#define SRST_PORT GPIOA +#define SRST_PIN GPIO2 + #define USB_PU_PORT GPIOA #define USB_PU_PIN GPIO8 diff --git a/src/platforms/native/swdptap.c b/src/platforms/native/swdptap.c index 8ac78b2..dceb23e 100644 --- a/src/platforms/native/swdptap.c +++ b/src/platforms/native/swdptap.c @@ -39,35 +39,35 @@ static void swdptap_turnaround(uint8_t dir) olddir = dir; if(dir) - gpio_set_mode(SWDP_PORT, GPIO_MODE_INPUT, + gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); - gpio_set(SWDP_PORT, SWCLK_PIN); - gpio_clear(SWDP_PORT, SWCLK_PIN); + gpio_set(SWCLK_PORT, SWCLK_PIN); + gpio_clear(SWCLK_PORT, SWCLK_PIN); if(!dir) - gpio_set_mode(SWDP_PORT, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); } static uint8_t swdptap_bit_in(void) { - uint8_t ret; + uint16_t ret; - ret = gpio_get(SWDP_PORT, SWDIO_PIN); - gpio_set(SWDP_PORT, SWCLK_PIN); - gpio_clear(SWDP_PORT, SWCLK_PIN); + ret = gpio_get(SWDIO_PORT, SWDIO_PIN); + gpio_set(SWCLK_PORT, SWCLK_PIN); + gpio_clear(SWCLK_PORT, SWCLK_PIN); DEBUG("%d", ret?1:0); - return ret; + return ret != 0; } static void swdptap_bit_out(uint8_t val) { DEBUG("%d", val); - gpio_set_val(SWDP_PORT, SWDIO_PIN, val); - gpio_set(SWDP_PORT, SWCLK_PIN); - gpio_clear(SWDP_PORT, SWCLK_PIN); + gpio_set_val(SWDIO_PORT, SWDIO_PIN, val); + gpio_set(SWCLK_PORT, SWCLK_PIN); + gpio_clear(SWCLK_PORT, SWCLK_PIN); } int swdptap_init(void) -- cgit v1.2.3