Skip to content

Commit eec7126

Browse files
committed
STM32 Serial Flow Control
Crash occured when RTS=CTS=NC Now we chek if used pins are the same UART as TX and RX
1 parent d1b367f commit eec7126

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

targets/TARGET_STM/TARGET_STM32F0/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
742742
{
743743
struct serial_s *obj_s = SERIAL_S(obj);
744744

745-
// Determine the UART to use (UART_1, UART_2, ...)
745+
// Checked used UART name (UART_1, UART_2, ...)
746746
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
747747
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
748-
749-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
750-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
751-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
748+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
749+
MBED_ASSERT(0);
750+
return;
751+
}
752752

753753
if (type == FlowControlNone) {
754754
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32F1/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
613613
{
614614
struct serial_s *obj_s = SERIAL_S(obj);
615615

616-
// Determine the UART to use (UART_1, UART_2, ...)
616+
// Checked used UART name (UART_1, UART_2, ...)
617617
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
618618
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
619-
620-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
621-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
622-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
619+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
620+
MBED_ASSERT(0);
621+
return;
622+
}
623623

624624
if (type == FlowControlNone) {
625625
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32F2/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,13 +696,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
696696
{
697697
struct serial_s *obj_s = SERIAL_S(obj);
698698

699-
// Determine the UART to use (UART_1, UART_2, ...)
699+
// Checked used UART name (UART_1, UART_2, ...)
700700
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
701701
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
702-
703-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
704-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
705-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
702+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
703+
MBED_ASSERT(0);
704+
return;
705+
}
706706

707707
if (type == FlowControlNone) {
708708
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32F3/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
659659
{
660660
struct serial_s *obj_s = SERIAL_S(obj);
661661

662-
// Determine the UART to use (UART_1, UART_2, ...)
662+
// Checked used UART name (UART_1, UART_2, ...)
663663
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
664664
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
665-
666-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
667-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
668-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
665+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
666+
MBED_ASSERT(0);
667+
return;
668+
}
669669

670670
if (type == FlowControlNone) {
671671
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32F4/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
741741
{
742742
struct serial_s *obj_s = SERIAL_S(obj);
743743

744-
// Determine the UART to use (UART_1, UART_2, ...)
744+
// Checked used UART name (UART_1, UART_2, ...)
745745
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
746746
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
747-
748-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
749-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
750-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
747+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
748+
MBED_ASSERT(0);
749+
return;
750+
}
751751

752752
if (type == FlowControlNone) {
753753
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32F7/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
700700
{
701701
struct serial_s *obj_s = SERIAL_S(obj);
702702

703-
// Determine the UART to use (UART_1, UART_2, ...)
703+
// Checked used UART name (UART_1, UART_2, ...)
704704
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
705705
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
706-
707-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
708-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
709-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
706+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
707+
MBED_ASSERT(0);
708+
return;
709+
}
710710

711711
if (type == FlowControlNone) {
712712
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32H7/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
700700
{
701701
struct serial_s *obj_s = SERIAL_S(obj);
702702

703-
// Determine the UART to use (UART_1, UART_2, ...)
703+
// Checked used UART name (UART_1, UART_2, ...)
704704
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
705705
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
706-
707-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
708-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
709-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
706+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
707+
MBED_ASSERT(0);
708+
return;
709+
}
710710

711711
if (type == FlowControlNone) {
712712
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32L0/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
646646
{
647647
struct serial_s *obj_s = SERIAL_S(obj);
648648

649-
// Determine the UART to use (UART_1, UART_2, ...)
649+
// Checked used UART name (UART_1, UART_2, ...)
650650
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
651651
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
652-
653-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
654-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
655-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
652+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
653+
MBED_ASSERT(0);
654+
return;
655+
}
656656

657657
if (type == FlowControlNone) {
658658
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32L1/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
649649
{
650650
struct serial_s *obj_s = SERIAL_S(obj);
651651

652-
// Determine the UART to use (UART_1, UART_2, ...)
652+
// Checked used UART name (UART_1, UART_2, ...)
653653
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
654654
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
655-
656-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
657-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
658-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
655+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
656+
MBED_ASSERT(0);
657+
return;
658+
}
659659

660660
if (type == FlowControlNone) {
661661
// Disable hardware flow control

targets/TARGET_STM/TARGET_STM32L4/serial_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,13 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
673673
{
674674
struct serial_s *obj_s = SERIAL_S(obj);
675675

676-
// Determine the UART to use (UART_1, UART_2, ...)
676+
// Checked used UART name (UART_1, UART_2, ...)
677677
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
678678
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
679-
680-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
681-
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
682-
MBED_ASSERT(obj_s->uart != (UARTName)NC);
679+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
680+
MBED_ASSERT(0);
681+
return;
682+
}
683683

684684
if (type == FlowControlNone) {
685685
// Disable hardware flow control

0 commit comments

Comments
 (0)