Skip to content

Commit e4169b7

Browse files
committed
STM32: update init procedure
- STDIO_UART define is no more used - configuring a new serial with the same UART as STDIO is no more allowed
1 parent af9e073 commit e4169b7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

targets/TARGET_STM/serial_api.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
4242
{
4343
struct serial_s *obj_s = SERIAL_S(obj);
4444
int IndexNumber = 0;
45+
uint8_t stdio_config = 0;
4546

4647
// Determine the UART to use (UART_1, UART_2, ...)
4748
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
@@ -51,6 +52,15 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
5152
obj_s->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
5253
MBED_ASSERT(obj_s->uart != (UARTName)NC);
5354

55+
if ((tx == STDIO_UART_TX) || (rx == STDIO_UART_RX)) {
56+
stdio_config = 1;
57+
}
58+
else {
59+
if (uart_tx == pinmap_peripheral(STDIO_UART_TX, PinMap_UART_TX)) {
60+
error("Error: new serial object is using same UART as STDIO");
61+
}
62+
}
63+
5464
// Enable USART clock
5565
#if defined(USART1_BASE)
5666
if (obj_s->uart == UART_1) {
@@ -216,7 +226,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
216226

217227
// Configure UART
218228
obj_s->baudrate = 9600; // baudrate default value
219-
if (obj_s->uart == STDIO_UART) {
229+
if (stdio_config) {
220230
#if MBED_CONF_PLATFORM_STDIO_BAUD_RATE
221231
obj_s->baudrate = MBED_CONF_PLATFORM_STDIO_BAUD_RATE; // baudrate takes value from platform/mbed_lib.json
222232
#endif /* MBED_CONF_PLATFORM_STDIO_BAUD_RATE */
@@ -239,8 +249,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
239249

240250
init_uart(obj); /* init_uart will be called again in serial_baud function, so don't worry if init_uart returns HAL_ERROR */
241251

242-
// For stdio management
243-
if (obj_s->uart == STDIO_UART) { // STDIO_UART defined in PeripheralNames.h
252+
// For stdio management in platform/mbed_board.c and platform/mbed_retarget.cpp
253+
if (stdio_config) {
244254
stdio_uart_inited = 1;
245255
memcpy(&stdio_uart, obj, sizeof(serial_t));
246256
}

0 commit comments

Comments
 (0)