@@ -42,6 +42,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
42
42
{
43
43
struct serial_s * obj_s = SERIAL_S (obj );
44
44
int IndexNumber = 0 ;
45
+ uint8_t stdio_config = 0 ;
45
46
46
47
// Determine the UART to use (UART_1, UART_2, ...)
47
48
UARTName uart_tx = (UARTName )pinmap_peripheral (tx , PinMap_UART_TX );
@@ -51,6 +52,15 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
51
52
obj_s -> uart = (UARTName )pinmap_merge (uart_tx , uart_rx );
52
53
MBED_ASSERT (obj_s -> uart != (UARTName )NC );
53
54
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
+
54
64
// Enable USART clock
55
65
#if defined(USART1_BASE )
56
66
if (obj_s -> uart == UART_1 ) {
@@ -216,7 +226,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
216
226
217
227
// Configure UART
218
228
obj_s -> baudrate = 9600 ; // baudrate default value
219
- if (obj_s -> uart == STDIO_UART ) {
229
+ if (stdio_config ) {
220
230
#if MBED_CONF_PLATFORM_STDIO_BAUD_RATE
221
231
obj_s -> baudrate = MBED_CONF_PLATFORM_STDIO_BAUD_RATE ; // baudrate takes value from platform/mbed_lib.json
222
232
#endif /* MBED_CONF_PLATFORM_STDIO_BAUD_RATE */
@@ -239,8 +249,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
239
249
240
250
init_uart (obj ); /* init_uart will be called again in serial_baud function, so don't worry if init_uart returns HAL_ERROR */
241
251
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 ) {
244
254
stdio_uart_inited = 1 ;
245
255
memcpy (& stdio_uart , obj , sizeof (serial_t ));
246
256
}
0 commit comments