105105/**
106106 * Missing event typedefs.
107107 */
108- typedef enum
109- {
108+ typedef enum {
110109 NRF_UARTE_EVENT_TXDRDY = offsetof(NRF_UARTE_Type , EVENTS_TXDRDY ),
111110} nrf_uarte_event_extra_t ;
112111
@@ -505,8 +504,7 @@ static void nordic_nrf5_uart_event_handler_endrx_asynch(int instance)
505504static void nordic_nrf5_uart_event_handler (int instance )
506505{
507506 /* DMA buffer is full or has been swapped out by idle timeout. */
508- if (nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDRX ))
509- {
507+ if (nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDRX )) {
510508 nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDRX );
511509
512510#if DEVICE_SERIAL_ASYNCH
@@ -528,16 +526,14 @@ static void nordic_nrf5_uart_event_handler(int instance)
528526 * will setup the wrong DMA buffer and cause data to be lost.
529527 */
530528 if (nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_RXSTARTED ) &&
531- !nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDRX ))
532- {
529+ !nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDRX )) {
533530 nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_RXSTARTED );
534531
535532 nordic_nrf5_uart_event_handler_rxstarted (instance );
536533 }
537534
538535 /* Tx DMA buffer has been sent. */
539- if (nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDTX ))
540- {
536+ if (nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDTX )) {
541537 nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDTX );
542538
543539 /* Use SWI to de-prioritize callback. */
@@ -691,7 +687,7 @@ static void nordic_nrf5_uart_configure_rx(int instance)
691687{
692688 /* Disable interrupts during confiration. */
693689 nrf_uarte_int_disable (nordic_nrf5_uart_register [instance ], NRF_UARTE_INT_RXSTARTED_MASK |
694- NRF_UARTE_INT_ENDRX_MASK );
690+ NRF_UARTE_INT_ENDRX_MASK );
695691
696692 /* Clear FIFO buffer. */
697693 nrf_atfifo_clear (nordic_nrf5_uart_state [instance ].fifo );
@@ -720,7 +716,7 @@ static void nordic_nrf5_uart_configure_rx(int instance)
720716
721717 /* Enable interrupts again. */
722718 nrf_uarte_int_enable (nordic_nrf5_uart_register [instance ], NRF_UARTE_INT_RXSTARTED_MASK |
723- NRF_UARTE_INT_ENDRX_MASK );
719+ NRF_UARTE_INT_ENDRX_MASK );
724720}
725721
726722#if DEVICE_SERIAL_ASYNCH
@@ -733,7 +729,7 @@ static void nordic_nrf5_uart_configure_rx_asynch(int instance)
733729{
734730 /* Disable Rx related interrupts. */
735731 nrf_uarte_int_disable (nordic_nrf5_uart_register [instance ], NRF_UARTE_INT_RXSTARTED_MASK |
736- NRF_UARTE_INT_ENDRX_MASK );
732+ NRF_UARTE_INT_ENDRX_MASK );
737733
738734 /* Clear Rx related events. */
739735 nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_RXSTARTED );
@@ -803,7 +799,7 @@ static void nordic_nrf5_serial_configure(serial_t *obj)
803799 nrf_uarte_task_trigger (nordic_nrf5_uart_register [instance ],
804800 NRF_UARTE_TASK_STARTRX );
805801
806- /* Owner hasn't changed but mode has. Reconfigure. */
802+ /* Owner hasn't changed but mode has. Reconfigure. */
807803 } else if ((uart_object -> rx_asynch == true) && (nordic_nrf5_uart_state [instance ].rx_asynch == false)) {
808804
809805 nordic_nrf5_uart_configure_rx_asynch (instance );
@@ -942,8 +938,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
942938 bool done = false;
943939 do {
944940 done = nrf_uarte_event_check (nordic_nrf5_uart_register [instance ],
945- (nrf_uarte_event_t ) NRF_UARTE_EVENT_TXDRDY );
946- } while (done == false);
941+ (nrf_uarte_event_t ) NRF_UARTE_EVENT_TXDRDY );
942+ } while (done == false);
947943 }
948944
949945 /* Store pins in serial object. */
@@ -1008,7 +1004,7 @@ void serial_free(serial_t *obj)
10081004 if (nordic_nrf5_uart_state [instance ].usage_counter == 0 ) {
10091005
10101006 nrf_uarte_disable (nordic_nrf5_uart_register [instance ]);
1011-
1007+
10121008 /* Turn NRF_UARTE0_BASE or NRF_UARTE1_BASE power off and on to reset peripheral. */
10131009 if (instance == 0 ) {
10141010 * (volatile uint32_t * )0x40002FFC = 0 ;
@@ -1022,7 +1018,7 @@ void serial_free(serial_t *obj)
10221018 * (volatile uint32_t * )0x40028FFC = 1 ;
10231019 }
10241020#endif
1025-
1021+
10261022 }
10271023 }
10281024}
@@ -1273,6 +1269,8 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
12731269 struct serial_s * uart_object = obj ;
12741270#endif
12751271
1272+ int instance = uart_object -> instance ;
1273+
12761274 /* Convert Mbed type to Nordic IRQ mask. */
12771275 uint32_t type = (irq == TxIrq ) ? NORDIC_TX_IRQ : NORDIC_RX_IRQ ;
12781276
@@ -1282,10 +1280,20 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
12821280 uart_object -> mask |= type ;
12831281 nordic_nrf5_serial_configure (obj );
12841282
1283+ /* It is required by Mbed HAL API to generate TxIrq interrupt when TXD register is empty (also after enabling TxIrq interrupt).
1284+ Driver uses DMA to perform uart transfer and TxIrq is generated after the transfer is finished.
1285+ Trigger TxIrq interrupt manually on enabling the TxIrq. */
1286+ if (irq == TxIrq ) {
1287+ if (nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_TXDRDY )) {
1288+ nordic_swi_tx_trigger (instance );
1289+ }
1290+ }
12851291 } else {
12861292
12871293 uart_object -> mask &= ~type ;
12881294 }
1295+
1296+
12891297}
12901298
12911299/** Get character. This is a blocking call, waiting for a character
@@ -1358,7 +1366,7 @@ void serial_putc(serial_t *obj, int character)
13581366 /* Wait until UART is ready to send next character. */
13591367 do {
13601368 done = nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_TXDRDY );
1361- } while (done == false);
1369+ } while (done == false);
13621370
13631371 nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_TXDRDY );
13641372
0 commit comments