Skip to content

Commit ddc709a

Browse files
author
Marcus Chang
committed
Make serial_putc non-blocking for the NRF52 series
Previous implementation would block until character had been completely sent, which is not what the API specifies.
1 parent a42f1d7 commit ddc709a

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,16 @@ static void nordic_nrf5_uart_event_handler(int instance)
675675

676676
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY);
677677

678-
/* In non-async transfers this will generate and interrupt if callback and mask is set. */
678+
/* In non-async transfers this will generate an interrupt if callback and mask is set. */
679679
if (!nordic_nrf5_uart_state[instance].tx_asynch) {
680680

681+
/* Disable TXDRDY event again. */
682+
nordic_nrf5_uart_register[instance]->INTEN &= ~NRF_UARTE_INT_TXDRDY_MASK;
683+
684+
/* Release mutex. As the owner this call is safe. */
685+
nordic_nrf5_uart_state[instance].tx_in_progress = 0;
686+
687+
/* Call event handler. */
681688
nordic_nrf5_uart_event_handler_endtx(instance);
682689
}
683690
}
@@ -1449,9 +1456,7 @@ void serial_putc(serial_t *obj, int character)
14491456
* been transmitted and ENDTX when the entire buffer has been sent.
14501457
*
14511458
* For the blocking serial_putc, TXDRDY interrupts are enabled and only used for the
1452-
* single character TX IRQ callback handler. The ENDTX event does not generate an interrupt
1453-
* but is caught using a busy-wait loop. Once ENDTX has been generated we disable TXDRDY
1454-
* interrupts again.
1459+
* single character TX IRQ callback handler.
14551460
*/
14561461

14571462
/* Arm Tx DMA buffer. */
@@ -1470,15 +1475,6 @@ void serial_putc(serial_t *obj, int character)
14701475
/* Trigger DMA transfer. */
14711476
nrf_uarte_task_trigger(nordic_nrf5_uart_register[instance],
14721477
NRF_UARTE_TASK_STARTTX);
1473-
1474-
/* Busy-wait until the ENDTX event occurs. */
1475-
while (!nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDTX));
1476-
1477-
/* Disable TXDRDY event again. */
1478-
nordic_nrf5_uart_register[instance]->INTEN &= ~NRF_UARTE_INT_TXDRDY_MASK;
1479-
1480-
/* Release mutex. As the owner this call is safe. */
1481-
nordic_nrf5_uart_state[instance].tx_in_progress = 0;
14821478
}
14831479

14841480
/** Check if the serial peripheral is readable

0 commit comments

Comments
 (0)