Skip to content

Commit c774ab8

Browse files
committed
fix(uart): avoid infinite loop during init of serial_debug
Since rts/cts has been introduced, the serial debug on dedicated pins was broken as by default the serial_debug pin cts/rts was set to 0 (valid pinname). So core_debug was called during the init leading to an infinite loop. Signed-off-by: Frederic Pillon <[email protected]>
1 parent 9622de3 commit c774ab8

File tree

1 file changed

+23
-7
lines changed
  • libraries/SrcWrapper/src/stm32

1 file changed

+23
-7
lines changed

libraries/SrcWrapper/src/stm32/uart.c

+23-7
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ typedef enum {
7878
} uart_index_t;
7979

8080
static UART_HandleTypeDef *uart_handlers[UART_NUM] = {NULL};
81-
82-
static serial_t serial_debug = { .uart = NP, .index = UART_NUM };
81+
static serial_t serial_debug = {
82+
.uart = NP,
83+
.pin_tx = NC,
84+
.pin_rx = NC,
85+
.pin_rts = NC,
86+
.pin_cts = NC,
87+
.index = UART_NUM
88+
};
8389

8490
/* Aim of the function is to get serial_s pointer using huart pointer */
8591
/* Highly inspired from magical linux kernel's "container_of" */
@@ -115,22 +121,30 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
115121

116122
/* Pin Tx must not be NP */
117123
if (uart_tx == NP) {
118-
core_debug("ERROR: [U(S)ART] Tx pin has no peripheral!\n");
124+
if (obj != &serial_debug) {
125+
core_debug("ERROR: [U(S)ART] Tx pin has no peripheral!\n");
126+
}
119127
return;
120128
}
121129
/* Pin Rx must not be NP if not half-duplex */
122130
if ((obj->pin_rx != NC) && (uart_rx == NP)) {
123-
core_debug("ERROR: [U(S)ART] Rx pin has no peripheral!\n");
131+
if (obj != &serial_debug) {
132+
core_debug("ERROR: [U(S)ART] Rx pin has no peripheral!\n");
133+
}
124134
return;
125135
}
126136
/* Pin RTS must not be NP if flow control is enabled */
127137
if ((obj->pin_rts != NC) && (uart_rts == NP)) {
128-
core_debug("ERROR: [U(S)ART] RTS pin has no peripheral!\n");
138+
if (obj != &serial_debug) {
139+
core_debug("ERROR: [U(S)ART] RTS pin has no peripheral!\n");
140+
}
129141
return;
130142
}
131143
/* Pin CTS must not be NP if flow control is enabled */
132144
if ((obj->pin_cts != NC) && (uart_cts == NP)) {
133-
core_debug("ERROR: [U(S)ART] CTS pin has no peripheral!\n");
145+
if (obj != &serial_debug) {
146+
core_debug("ERROR: [U(S)ART] CTS pin has no peripheral!\n");
147+
}
134148
return;
135149
}
136150

@@ -144,7 +158,9 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
144158
obj->uart = pinmap_merge_peripheral(obj->uart, uart_cts);
145159

146160
if (obj->uart == NP) {
147-
core_debug("ERROR: [U(S)ART] Rx/Tx/RTS/CTS pins peripherals mismatch!\n");
161+
if (obj != &serial_debug) {
162+
core_debug("ERROR: [U(S)ART] Rx/Tx/RTS/CTS pins peripherals mismatch!\n");
163+
}
148164
return;
149165
}
150166

0 commit comments

Comments
 (0)