From 23f68359b5c33db569169fc9768a84c4fec60e9c Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Tue, 29 Jan 2019 14:53:22 +0100 Subject: [PATCH] STM32 Serial Flow Control Crash occured when RTS=CTS=NC Now we chek if used pins are the same UART as TX and RX --- targets/TARGET_STM/TARGET_STM32F0/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32F1/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32F2/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32F3/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32F4/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32F7/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32H7/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32L0/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32L1/serial_device.c | 10 +++++----- targets/TARGET_STM/TARGET_STM32L4/serial_device.c | 10 +++++----- 10 files changed, 50 insertions(+), 50 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F0/serial_device.c b/targets/TARGET_STM/TARGET_STM32F0/serial_device.c index f14389d330..7c4b42d76f 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F0/serial_device.c @@ -742,13 +742,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32F1/serial_device.c b/targets/TARGET_STM/TARGET_STM32F1/serial_device.c index 197867da5d..3675668b07 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F1/serial_device.c @@ -613,13 +613,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32F2/serial_device.c b/targets/TARGET_STM/TARGET_STM32F2/serial_device.c index 6901f4cdcf..9ed602867e 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F2/serial_device.c @@ -696,13 +696,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32F3/serial_device.c b/targets/TARGET_STM/TARGET_STM32F3/serial_device.c index e13601f75f..36b45df4f7 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F3/serial_device.c @@ -659,13 +659,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32F4/serial_device.c b/targets/TARGET_STM/TARGET_STM32F4/serial_device.c index 0454ca134d..79a76bf689 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/serial_device.c @@ -741,13 +741,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32F7/serial_device.c b/targets/TARGET_STM/TARGET_STM32F7/serial_device.c index d2571618ed..581c871674 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F7/serial_device.c @@ -700,13 +700,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32H7/serial_device.c b/targets/TARGET_STM/TARGET_STM32H7/serial_device.c index 643f7f249f..b64a5195cb 100644 --- a/targets/TARGET_STM/TARGET_STM32H7/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32H7/serial_device.c @@ -700,13 +700,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32L0/serial_device.c b/targets/TARGET_STM/TARGET_STM32L0/serial_device.c index 9cb90929d6..002b667528 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32L0/serial_device.c @@ -646,13 +646,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32L1/serial_device.c b/targets/TARGET_STM/TARGET_STM32L1/serial_device.c index 80a2de3287..3b84db9d63 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32L1/serial_device.c @@ -649,13 +649,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control diff --git a/targets/TARGET_STM/TARGET_STM32L4/serial_device.c b/targets/TARGET_STM/TARGET_STM32L4/serial_device.c index 52f27d74d4..2019c2afdd 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32L4/serial_device.c @@ -673,13 +673,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi { struct serial_s *obj_s = SERIAL_S(obj); - // Determine the UART to use (UART_1, UART_2, ...) + // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - - // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts); - MBED_ASSERT(obj_s->uart != (UARTName)NC); + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } if (type == FlowControlNone) { // Disable hardware flow control