@@ -593,6 +593,20 @@ static void nordic_nrf5_uart_event_handler_endrx(int instance)
593
593
594
594
if (available > 0 ) {
595
595
596
+ /* Check if hardware flow control is set and signal sender to stop.
597
+ *
598
+ * This signal is set manually because the flow control logic in the UARTE module
599
+ * only works when the module is receiving and not after an ENDRX event.
600
+ *
601
+ * The RTS signal is kept high until the atomic FIFO is empty. This allow systems
602
+ * with flow control to reduce their FIFO and DMA buffers.
603
+ */
604
+ if ((nordic_nrf5_uart_state [instance ].owner -> hwfc == NRF_UART_HWFC_ENABLED ) &&
605
+ (nordic_nrf5_uart_state [instance ].owner -> rts != NRF_UART_PSEL_DISCONNECTED )) {
606
+
607
+ nrf_gpio_pin_set (nordic_nrf5_uart_state [instance ].owner -> rts );
608
+ }
609
+
596
610
/* Copy data from DMA buffer to FIFO buffer. */
597
611
for (size_t index = 0 ; index < available ; index ++ ) {
598
612
@@ -810,6 +824,7 @@ static void nordic_nrf5_uart_configure_object(serial_t *obj)
810
824
/* Check if pin is set before configuring it. */
811
825
if (uart_object -> rts != NRF_UART_PSEL_DISCONNECTED ) {
812
826
827
+ nrf_gpio_pin_clear (uart_object -> rts );
813
828
nrf_gpio_cfg_output (uart_object -> rts );
814
829
}
815
830
@@ -819,8 +834,9 @@ static void nordic_nrf5_uart_configure_object(serial_t *obj)
819
834
nrf_gpio_cfg_input (uart_object -> cts , NRF_GPIO_PIN_NOPULL );
820
835
}
821
836
837
+ /* Only let UARTE module handle CTS, RTS is handled manually due to buggy UARTE logic. */
822
838
nrf_uarte_hwfc_pins_set (nordic_nrf5_uart_register [uart_object -> instance ],
823
- uart_object -> rts ,
839
+ NRF_UART_PSEL_DISCONNECTED ,
824
840
uart_object -> cts );
825
841
}
826
842
@@ -1429,6 +1445,20 @@ int serial_getc(serial_t *obj)
1429
1445
uint8_t * byte = (uint8_t * ) nrf_atfifo_item_get (fifo , & context );
1430
1446
nrf_atfifo_item_free (fifo , & context );
1431
1447
1448
+ /* Check if hardware flow control is set and the atomic FIFO buffer is empty.
1449
+ *
1450
+ * Receive is halted until the buffer has been completely handled to reduce RAM usage.
1451
+ *
1452
+ * This signal is set manually because the flow control logic in the UARTE module
1453
+ * only works when the module is receiving and not after an ENDRX event.
1454
+ */
1455
+ if ((nordic_nrf5_uart_state [instance ].owner -> hwfc == NRF_UART_HWFC_ENABLED ) &&
1456
+ (nordic_nrf5_uart_state [instance ].owner -> rts != NRF_UART_PSEL_DISCONNECTED ) &&
1457
+ (* head == * tail )) {
1458
+
1459
+ nrf_gpio_pin_clear (nordic_nrf5_uart_state [instance ].owner -> rts );
1460
+ }
1461
+
1432
1462
return * byte ;
1433
1463
}
1434
1464
0 commit comments