From 8a938ea77744604f4c93614c6ad9559afc7488f8 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 10 Jan 2020 14:59:28 +0100 Subject: [PATCH] STM serial free: Set pin function only if pin is defined (not NC) --- targets/TARGET_STM/serial_api.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/serial_api.c b/targets/TARGET_STM/serial_api.c index ab3d8f9c70..030bbeddef 100644 --- a/targets/TARGET_STM/serial_api.c +++ b/targets/TARGET_STM/serial_api.c @@ -355,8 +355,13 @@ void serial_free(serial_t *obj) #endif /* DUAL_CORE */ // Configure GPIOs - pin_function(obj_s->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); - pin_function(obj_s->pin_rx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + if (obj_s->pin_tx != NC) { + pin_function(obj_s->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + } + + if (obj_s->pin_rx != NC) { + pin_function(obj_s->pin_rx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + } serial_irq_ids[obj_s->index] = 0; }