From 210fab8eae3a194bacbcbc7b24ad85c657699783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 12 Mar 2021 13:10:59 +0100 Subject: [PATCH] swd: expose release pins --- lib/swd.c | 14 ++++++++++++-- lib/swd.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/swd.c b/lib/swd.c index 2fe4be7..a4756ee 100644 --- a/lib/swd.c +++ b/lib/swd.c @@ -78,7 +78,7 @@ void swd_setup(uint32_t freq) } /** release used pins */ -static void swd_release_pins(void) +void swd_release_pins(void) { // release GPIO gpio_mode_setup(swd_swclk_port, GPIO_MODE_INPUT, GPIO_PUPD_NONE, swd_swclk_pin); // put clock signal pin back to input floating @@ -97,9 +97,19 @@ void swd_release(void) bool swd_set_pins(uint32_t swclk_port, uint32_t swclk_pin, uint32_t swdio_port, uint32_t swdio_pin) { - if (swclk_pin > (1 << 15) || swdio_pin > (1 << 15) || __builtin_popcount(swclk_pin) != 1 || __builtin_popcount(swdio_pin) != 1) { // check if pin exists and is unique + // check if pin exists and is unique + if (__builtin_popcount(swclk_pin) != 1 || __builtin_popcount(swdio_pin) != 1) { return false; } + // check if pin really exists + if (swclk_pin > (1 << 15) || swdio_pin > (1 << 15)) { + return false; + } + // ensure pin is different + if (swclk_port == swdio_port && swclk_pin == swdio_pin) { + return false; + } + uint32_t swclk_rcc = 0; switch (swclk_port) { case GPIOA: diff --git a/lib/swd.h b/lib/swd.h index 57bae6b..13a7bbe 100644 --- a/lib/swd.h +++ b/lib/swd.h @@ -90,6 +90,8 @@ void swd_setup(uint32_t freq); /** release 1-wire peripheral */ void swd_release(void); +/** release used pins */ +void swd_release_pins(void); /** set SWCLK and SWDIO pins * @param[in] swclk_port port for SWCLK pin * @param[in] swclk_pin pin for SWCLK pin