swd: expose release pins

This commit is contained in:
King Kévin 2021-03-12 13:10:59 +01:00
parent 7318d70dcd
commit 210fab8eae
2 changed files with 14 additions and 2 deletions

View File

@ -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:

View File

@ -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