105
105
/**
106
106
* Missing event typedefs.
107
107
*/
108
- typedef enum
109
- {
108
+ typedef enum {
110
109
NRF_UARTE_EVENT_TXDRDY = offsetof(NRF_UARTE_Type , EVENTS_TXDRDY ),
111
110
} nrf_uarte_event_extra_t ;
112
111
@@ -505,8 +504,7 @@ static void nordic_nrf5_uart_event_handler_endrx_asynch(int instance)
505
504
static void nordic_nrf5_uart_event_handler (int instance )
506
505
{
507
506
/* 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 )) {
510
508
nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDRX );
511
509
512
510
#if DEVICE_SERIAL_ASYNCH
@@ -528,16 +526,14 @@ static void nordic_nrf5_uart_event_handler(int instance)
528
526
* will setup the wrong DMA buffer and cause data to be lost.
529
527
*/
530
528
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 )) {
533
530
nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_RXSTARTED );
534
531
535
532
nordic_nrf5_uart_event_handler_rxstarted (instance );
536
533
}
537
534
538
535
/* 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 )) {
541
537
nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_ENDTX );
542
538
543
539
/* Use SWI to de-prioritize callback. */
@@ -691,7 +687,7 @@ static void nordic_nrf5_uart_configure_rx(int instance)
691
687
{
692
688
/* Disable interrupts during confiration. */
693
689
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 );
695
691
696
692
/* Clear FIFO buffer. */
697
693
nrf_atfifo_clear (nordic_nrf5_uart_state [instance ].fifo );
@@ -720,7 +716,7 @@ static void nordic_nrf5_uart_configure_rx(int instance)
720
716
721
717
/* Enable interrupts again. */
722
718
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 );
724
720
}
725
721
726
722
#if DEVICE_SERIAL_ASYNCH
@@ -733,7 +729,7 @@ static void nordic_nrf5_uart_configure_rx_asynch(int instance)
733
729
{
734
730
/* Disable Rx related interrupts. */
735
731
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 );
737
733
738
734
/* Clear Rx related events. */
739
735
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)
803
799
nrf_uarte_task_trigger (nordic_nrf5_uart_register [instance ],
804
800
NRF_UARTE_TASK_STARTRX );
805
801
806
- /* Owner hasn't changed but mode has. Reconfigure. */
802
+ /* Owner hasn't changed but mode has. Reconfigure. */
807
803
} else if ((uart_object -> rx_asynch == true) && (nordic_nrf5_uart_state [instance ].rx_asynch == false)) {
808
804
809
805
nordic_nrf5_uart_configure_rx_asynch (instance );
@@ -942,8 +938,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
942
938
bool done = false;
943
939
do {
944
940
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);
947
943
}
948
944
949
945
/* Store pins in serial object. */
@@ -1008,7 +1004,7 @@ void serial_free(serial_t *obj)
1008
1004
if (nordic_nrf5_uart_state [instance ].usage_counter == 0 ) {
1009
1005
1010
1006
nrf_uarte_disable (nordic_nrf5_uart_register [instance ]);
1011
-
1007
+
1012
1008
/* Turn NRF_UARTE0_BASE or NRF_UARTE1_BASE power off and on to reset peripheral. */
1013
1009
if (instance == 0 ) {
1014
1010
* (volatile uint32_t * )0x40002FFC = 0 ;
@@ -1022,7 +1018,7 @@ void serial_free(serial_t *obj)
1022
1018
* (volatile uint32_t * )0x40028FFC = 1 ;
1023
1019
}
1024
1020
#endif
1025
-
1021
+
1026
1022
}
1027
1023
}
1028
1024
}
@@ -1273,6 +1269,8 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
1273
1269
struct serial_s * uart_object = obj ;
1274
1270
#endif
1275
1271
1272
+ int instance = uart_object -> instance ;
1273
+
1276
1274
/* Convert Mbed type to Nordic IRQ mask. */
1277
1275
uint32_t type = (irq == TxIrq ) ? NORDIC_TX_IRQ : NORDIC_RX_IRQ ;
1278
1276
@@ -1282,10 +1280,20 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
1282
1280
uart_object -> mask |= type ;
1283
1281
nordic_nrf5_serial_configure (obj );
1284
1282
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
+ }
1285
1291
} else {
1286
1292
1287
1293
uart_object -> mask &= ~type ;
1288
1294
}
1295
+
1296
+
1289
1297
}
1290
1298
1291
1299
/** Get character. This is a blocking call, waiting for a character
@@ -1358,7 +1366,7 @@ void serial_putc(serial_t *obj, int character)
1358
1366
/* Wait until UART is ready to send next character. */
1359
1367
do {
1360
1368
done = nrf_uarte_event_check (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_TXDRDY );
1361
- } while (done == false);
1369
+ } while (done == false);
1362
1370
1363
1371
nrf_uarte_event_clear (nordic_nrf5_uart_register [instance ], NRF_UARTE_EVENT_TXDRDY );
1364
1372
0 commit comments