diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index e917d1f..44edcb6 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -50,8 +50,6 @@ int adiv5_swdp_scan(void) ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp)); swdptap_init(); - if(connect_assert_srst) - jtagtap_srst(true); /* will be deasserted after attach */ /* Read the SW-DP IDCODE register to syncronise */ /* This could be done with adiv_swdp_low_access(), but this doesn't * allow the ack to be checked here. */ diff --git a/src/command.c b/src/command.c index 7a5444c..3de4ec0 100644 --- a/src/command.c +++ b/src/command.c @@ -68,6 +68,7 @@ const struct command_s cmd_list[] = { {NULL, NULL, NULL} }; +static bool connect_assert_srst; int command_process(target *t, char *cmd) { @@ -151,6 +152,9 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv) irlens[argc-1] = 0; } + if(connect_assert_srst) + platform_srst_set_val(true); /* will be deasserted after attach */ + int devs = -1; volatile struct exception e; TRY_CATCH (e, EXCEPTION_ALL) { @@ -165,14 +169,11 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv) break; } - if(devs < 0) { + if(devs <= 0) { + platform_srst_set_val(false); gdb_out("JTAG device scan failed!\n"); return false; } - if(devs == 0) { - gdb_out("JTAG scan found no devices!\n"); - return false; - } gdb_outf("Device IR Len IDCODE Description\n"); for(int i = 0; i < jtag_dev_count; i++) gdb_outf("%d\t%d\t0x%08lX %s\n", i, @@ -187,6 +188,9 @@ bool cmd_swdp_scan(void) { gdb_outf("Target voltage: %s\n", platform_target_voltage()); + if(connect_assert_srst) + platform_srst_set_val(true); /* will be deasserted after attach */ + int devs = -1; volatile struct exception e; TRY_CATCH (e, EXCEPTION_ALL) { @@ -201,7 +205,8 @@ bool cmd_swdp_scan(void) break; } - if(devs < 0) { + if(devs <= 0) { + platform_srst_set_val(false); gdb_out("SW-DP scan failed!\n"); return false; } diff --git a/src/cortexm.c b/src/cortexm.c index 599212e..1d0fdfb 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -27,8 +27,6 @@ */ #include "general.h" #include "exception.h" -#include "jtagtap.h" -#include "jtag_scan.h" #include "adiv5.h" #include "target.h" #include "command.h" @@ -273,7 +271,7 @@ bool cortexm_attach(target *t) target_halt_request(t); tries = 10; - while(!connect_assert_srst && !target_halt_wait(t) && --tries) + while(!platform_srst_get_val() && !target_halt_wait(t) && --tries) platform_delay(2); if(!tries) return false; @@ -318,8 +316,7 @@ bool cortexm_attach(target *t) t->clear_hw_wp = cortexm_clear_hw_wp; t->check_hw_wp = cortexm_check_hw_wp; - if(connect_assert_srst) - jtagtap_srst(false); + platform_srst_set_val(false); return true; } @@ -426,8 +423,8 @@ static void cortexm_pc_write(target *t, const uint32_t val) static void cortexm_reset(target *t) { if ((t->target_options & CORTEXM_TOPT_INHIBIT_SRST) == 0) { - jtagtap_srst(true); - jtagtap_srst(false); + platform_srst_set_val(true); + platform_srst_set_val(false); } /* Read DHCSR here to clear S_RESET_ST bit before reset */ diff --git a/src/include/jtagtap.h b/src/include/jtagtap.h index 0072594..898b9c8 100644 --- a/src/include/jtagtap.h +++ b/src/include/jtagtap.h @@ -27,8 +27,6 @@ int jtagtap_init(void); void jtagtap_reset(void); -void jtagtap_srst(bool assert); - uint8_t jtagtap_next(const uint8_t TMS, const uint8_t TDI); /* tap_next executes one state transision in the JTAG TAP state machine: * - Ensure TCK is low diff --git a/src/include/platform_support.h b/src/include/platform_support.h index 2bfbe65..3db7ad3 100644 --- a/src/include/platform_support.h +++ b/src/include/platform_support.h @@ -36,6 +36,7 @@ void platform_timeout_set(uint32_t ms); bool platform_timeout_is_expired(void); void platform_delay(uint32_t delay); void platform_srst_set_val(bool assert); +bool platform_srst_get_val(void); bool platform_target_get_power(void); void platform_target_set_power(bool power); void platform_request_boot(void); diff --git a/src/include/target.h b/src/include/target.h index 7d9943e..1a4138f 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -206,7 +206,6 @@ struct target_command_s { }; extern target *target_list; -extern bool connect_assert_srst; target *target_new(unsigned size); void target_list_free(void); diff --git a/src/jtag_scan.c b/src/jtag_scan.c index f46a148..2d2194c 100644 --- a/src/jtag_scan.c +++ b/src/jtag_scan.c @@ -105,8 +105,6 @@ int jtag_scan(const uint8_t *irlens) */ DEBUG("Resetting TAP\n"); jtagtap_init(); - if(connect_assert_srst) - jtagtap_srst(true); /* will be deasserted after attach */ jtagtap_reset(); if (irlens) { diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index e85ebd5..1e03404 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -78,6 +78,9 @@ void platform_init(void) cdcacm_init(); } +void platform_srst_set_val(bool assert) { (void)assert; } +bool platform_srst_get_val(void) { return false; } + const char *platform_target_voltage(void) { return "ABSENT!"; diff --git a/src/platforms/hydrabus/platform.c b/src/platforms/hydrabus/platform.c index 4774b36..3993a10 100644 --- a/src/platforms/hydrabus/platform.c +++ b/src/platforms/hydrabus/platform.c @@ -78,6 +78,9 @@ void platform_init(void) cdcacm_init(); } +void platform_srst_set_val(bool assert) { (void)assert; } +bool platform_srst_get_val(void) { return false; } + const char *platform_target_voltage(void) { return "ABSENT!"; diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index be7e517..24c4aa0 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -85,6 +85,22 @@ platform_init(void) 0xff, 0xff); } +void platform_srst_set_val(bool assert) +{ + volatile int i; + if (assert) { + gpio_clear(SRST_PORT, SRST_PIN); + for(i = 0; i < 10000; i++) asm("nop"); + } else { + gpio_set(SRST_PORT, SRST_PIN); + } +} + +bool platform_srst_get_val(void) +{ + return gpio_get(SRST_PORT, SRST_PIN) == 0; +} + void platform_timeout_set(uint32_t ms) { timeout_counter = ms / 10; diff --git a/src/platforms/libftdi/jtagtap.c b/src/platforms/libftdi/jtagtap.c index c416892..0ac8b6c 100644 --- a/src/platforms/libftdi/jtagtap.c +++ b/src/platforms/libftdi/jtagtap.c @@ -67,15 +67,6 @@ void jtagtap_reset(void) jtagtap_soft_reset(); } -void jtagtap_srst(bool assert) -{ - (void)assert; - platform_buffer_flush(); - //ftdi_write_data(ftdic, "\x80\x88\xAB", 3); - //usleep(1000); - //ftdi_write_data(ftdic, "\x80\xA8\xAB", 3); -} - #ifndef PROVIDE_GENERIC_TAP_TMS_SEQ void jtagtap_tms_seq(uint32_t MS, int ticks) diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index af3e1e7..00a97ee 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -229,6 +229,14 @@ void platform_init(int argc, char **argv) assert(gdb_if_init() == 0); } +void platform_srst_set_val(bool assert) +{ + (void)assert; + platform_buffer_flush(); +} + +bool platform_srst_get_val(void) { return false; } + void platform_buffer_flush(void) { assert(ftdi_write_data(ftdic, outbuf, bufptr) == bufptr); diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index a5a3508..7c727f5 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -164,6 +164,18 @@ void platform_srst_set_val(bool assert) } else { gpio_set_val(SRST_PORT, SRST_PIN, !assert); } + if (assert) { + for(int i = 0; i < 10000; i++) asm("nop"); + } +} + +bool platform_srst_get_val(void) +{ + if (platform_hwversion() == 0) { + return gpio_get(SRST_PORT, SRST_SENSE_PIN) == 0; + } else { + return gpio_get(SRST_PORT, SRST_PIN) == 0; + } } bool platform_target_get_power(void) diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index fd8c3ec..3797f11 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -80,6 +80,7 @@ #define PWR_BR_PIN GPIO1 #define SRST_PORT GPIOA #define SRST_PIN GPIO2 +#define SRST_SENSE_PIN GPIO7 #define USB_PU_PORT GPIOA #define USB_PU_PIN GPIO8 @@ -111,9 +112,6 @@ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); -#define SRST_SET_VAL(x) \ - platform_srst_set_val(x) - #define USB_DRIVER stm32f103_usb_driver #define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ #define USB_ISR usb_lp_can_rx0_isr diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index dd501a4..33f231c 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -118,6 +118,13 @@ void platform_srst_set_val(bool assert) gpio_set(SRST_PORT, pin); } +bool platform_srst_get_val() +{ + uint16_t pin; + pin = platform_hwversion() == 0 ? SRST_PIN_V1 : SRST_PIN_V2; + return gpio_get(SRST_PORT, pin) == 0; +} + const char *platform_target_voltage(void) { return "unknown"; diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 6db6d45..06afe1d 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -98,9 +98,6 @@ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); -#define SRST_SET_VAL(x) \ - platform_srst_set_val(x) - #define USB_DRIVER stm32f103_usb_driver #define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ #define USB_ISR usb_lp_can_rx0_isr diff --git a/src/platforms/stm32/jtagtap.c b/src/platforms/stm32/jtagtap.c index 3c45a81..4026fe3 100644 --- a/src/platforms/stm32/jtagtap.c +++ b/src/platforms/stm32/jtagtap.c @@ -50,19 +50,6 @@ void jtagtap_reset(void) jtagtap_soft_reset(); } -void jtagtap_srst(bool assert) -{ - (void)assert; -#ifdef SRST_SET_VAL - SRST_SET_VAL(assert); - if(assert) { - int i; - for(i = 0; i < 10000; i++) - asm volatile("nop"); - } -#endif -} - inline uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDO) { uint16_t ret; diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 02cde19..921e7e8 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -84,6 +84,9 @@ void platform_init(void) usbuart_init(); } +void platform_srst_set_val(bool assert) { (void)assert; } +bool platform_srst_get_val(void) { return false; } + const char *platform_target_voltage(void) { return "unknown"; diff --git a/src/platforms/tm4c/jtagtap.c b/src/platforms/tm4c/jtagtap.c index e0bdd68..c32a437 100644 --- a/src/platforms/tm4c/jtagtap.c +++ b/src/platforms/tm4c/jtagtap.c @@ -25,18 +25,6 @@ jtagtap_reset(void) jtagtap_soft_reset(); } -void -jtagtap_srst(bool assert) -{ - volatile int i; - if (assert) { - gpio_clear(SRST_PORT, SRST_PIN); - for(i = 0; i < 10000; i++) asm("nop"); - } else { - gpio_set(SRST_PORT, SRST_PIN); - } -} - uint8_t jtagtap_next(const uint8_t dTMS, const uint8_t dTDO) { diff --git a/src/samd.c b/src/samd.c index ae38255..a39cc37 100644 --- a/src/samd.c +++ b/src/samd.c @@ -426,7 +426,7 @@ bool samd_probe(target *t) target_add_commands(t, samd_cmd_list, "SAMD"); /* If we're not in reset here */ - if (!connect_assert_srst) { + if (!platform_srst_get_val()) { /* We'll have to release the target from * extended reset to make attach possible */ if (target_mem_read32(t, SAMD_DSU_CTRLSTAT) & diff --git a/src/target.c b/src/target.c index 8f33e70..5e44c48 100644 --- a/src/target.c +++ b/src/target.c @@ -22,7 +22,6 @@ #include "target.h" target *target_list = NULL; -bool connect_assert_srst; target *target_new(unsigned size) {