From 95053b3b4ec118a42beabe1413762742df3a1264 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 26 Aug 2018 21:48:03 +0200 Subject: [PATCH] Change the ST-Link SRST function to use libopencm3 helper functions and fix waiting for the pin-state, change init to use the SRST function for reset de-assertion --- src/platforms/stlink/platform.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index a879791..cb54900 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -68,9 +68,8 @@ void platform_init(void) GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TDI_PIN); - gpio_set(SRST_PORT, srst_pin); - gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin); + + platform_srst_set_val(false); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); @@ -90,21 +89,17 @@ void platform_init(void) void platform_srst_set_val(bool assert) { - uint32_t crl = GPIOB_CRL; - uint32_t shift = (srst_pin == GPIO0) ? 0 : 4; - uint32_t mask = 0xf << shift; - crl &= ~mask; if (assert) { - /* Set SRST as Open-Drain, 50 Mhz, low.*/ - GPIOB_BRR = srst_pin; - GPIOB_CRL = crl | (7 << shift); + gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin); + gpio_clear(SRST_PORT, srst_pin); + while (gpio_get(SRST_PORT, srst_pin)) {}; } else { - /* Set SRST as input, pull-up. - * SRST might be unconnected, e.g on Nucleo-P!*/ - GPIOB_CRL = crl | (8 << shift); - GPIOB_BSRR = srst_pin; + gpio_set_mode(SRST_PORT, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, srst_pin); + gpio_set(SRST_PORT, srst_pin); + while (!gpio_get(SRST_PORT, srst_pin)) {}; } - while (gpio_get(SRST_PORT, srst_pin) == assert) {}; } bool platform_srst_get_val()