From b744d8b0c9d31fe1ddc09a1288dc46539a51ef70 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 22 Sep 2018 14:46:32 +0200 Subject: [PATCH] swlink: Implement NRST. --- src/platforms/swlink/platform.c | 35 ++++++++++++++++++++++++++------- src/platforms/swlink/platform.h | 4 ++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 3aa5477e..13f88eb3 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -73,17 +73,18 @@ void platform_init(void) gpio_set_mode(TDO_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, TDO_PIN); - if (rev == 1) { + switch (rev) { + case 0: + break; + case 1: /* Enable MCO Out on PA8*/ RCC_CFGR &= ~(0xf << 24); RCC_CFGR |= (RCC_CFGR_MCO_HSE << 24); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO8); + break; } - - gpio_set(NRST_PORT,NRST_PIN); - gpio_set_mode(NRST_PORT, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, NRST_PIN); + platform_srst_set_val(false); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_IDLE_RUN); @@ -109,8 +110,28 @@ void platform_init(void) usbuart_init(); } -void platform_srst_set_val(bool assert) { (void)assert; } -bool platform_srst_get_val(void) { return false; } +void platform_srst_set_val(bool assert) +{ + /* We reuse JSRST as SRST.*/ + if (assert) { + gpio_set_mode(JRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, JRST_PIN); + /* Wait until requested value is active.*/ + while (gpio_get(JRST_PORT, JRST_PIN)) + gpio_clear(JRST_PORT, JRST_PIN); + } else { + gpio_set_mode(JRST_PORT, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, JRST_PIN); + /* Wait until requested value is active.*/ + while (!gpio_get(JRST_PORT, JRST_PIN)) + gpio_set(JRST_PORT, JRST_PIN); + } +} + +bool platform_srst_get_val(void) +{ + return gpio_get(JRST_PORT, JRST_PIN) == 0; +} const char *platform_target_voltage(void) { diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index e7dbe0a3..f069c294 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -41,12 +41,12 @@ #define TCK_PORT GPIOA #define TDI_PORT GPIOA #define TDO_PORT GPIOB -#define NRST_PORT GPIOB +#define JRST_PORT GPIOB #define TMS_PIN GPIO13 #define TCK_PIN GPIO14 #define TDI_PIN GPIO15 #define TDO_PIN GPIO3 -#define NRST_PIN GPIO4 +#define JRST_PIN GPIO4 #define SWDIO_PORT TMS_PORT #define SWCLK_PORT TCK_PORT