@@ -258,11 +258,15 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
258
258
nrf_gpio_cfg_input (UART_CB .pselrxd , NRF_GPIO_PIN_NOPULL );
259
259
}
260
260
261
- // UART pins must only be configured when the peripheral is disabled.
262
- nrf_uart_disable (UART_INSTANCE );
263
-
264
261
if (UART_CB .initialized ) {
265
- // Reconfigure RX/TX pins only.
262
+ // For already initialized peripheral it is sufficient to reconfigure
263
+ // RX/TX pins only.
264
+
265
+ // Ensure that there is no unfinished TX transfer.
266
+ while (!serial_writable (obj )) {
267
+ }
268
+ // UART pins can be configured only when the peripheral is disabled.
269
+ nrf_uart_disable (UART_INSTANCE );
266
270
nrf_uart_txrx_pins_set (UART_INSTANCE , UART_CB .pseltxd , UART_CB .pselrxd );
267
271
nrf_uart_enable (UART_INSTANCE );
268
272
}
@@ -310,7 +314,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
310
314
nrf_uart_configure (UART_INSTANCE , UART_CB .parity , UART_CB .hwfc );
311
315
if (UART_CB .hwfc == NRF_UART_HWFC_ENABLED ) {
312
316
serial_set_flow_control (obj , FlowControlRTSCTS ,
313
- UART_CB .pselrts , UART_CB .pselcts );
317
+ ( PinName ) UART_CB .pselrts , ( PinName ) UART_CB .pselcts );
314
318
}
315
319
nrf_uart_enable (UART_INSTANCE );
316
320
@@ -479,9 +483,6 @@ void serial_putc(serial_t *obj, int c)
479
483
480
484
nrf_uart_event_clear (UART_INSTANCE , NRF_UART_EVENT_TXDRDY );
481
485
nrf_uart_txd_set (UART_INSTANCE , (uint8_t )c );
482
- // Wait until sending is completed.
483
- while (!nrf_uart_event_check (UART_INSTANCE , NRF_UART_EVENT_TXDRDY )) {
484
- }
485
486
}
486
487
487
488
int serial_readable (serial_t * obj )
0 commit comments