diff --git a/targets/TARGET_STM/TARGET_STM32L4/serial_device.c b/targets/TARGET_STM/TARGET_STM32L4/serial_device.c index 773984d139..9c866edd41 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32L4/serial_device.c @@ -667,6 +667,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con if (type == FlowControlRTS) { // Enable RTS MBED_ASSERT(pinmap->rx_flow_pin != NC); + obj_s->hw_flow_ctl = UART_HWCONTROL_RTS; obj_s->pin_rts = pinmap->rx_flow_pin; // Enable the pin for RTS function pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function); diff --git a/targets/TARGET_STM/serial_api.c b/targets/TARGET_STM/serial_api.c index 62f6054866..51f4f761fd 100644 --- a/targets/TARGET_STM/serial_api.c +++ b/targets/TARGET_STM/serial_api.c @@ -355,6 +355,15 @@ void serial_free(serial_t *obj) pin_function(obj_s->pin_rx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); +#if DEVICE_SERIAL_FC + if ( (obj_s->hw_flow_ctl == UART_HWCONTROL_RTS) || (obj_s->hw_flow_ctl == UART_HWCONTROL_RTS_CTS) ) { + pin_function(obj_s->pin_rts, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + } + if ( (obj_s->hw_flow_ctl == UART_HWCONTROL_CTS) || (obj_s->hw_flow_ctl == UART_HWCONTROL_RTS_CTS) ) { + pin_function(obj_s->pin_cts, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + } +#endif + serial_irq_ids[obj_s->index] = 0; }