Skip to content

Commit 59bb79b

Browse files
committed
NRF52 Serial overhaul
Make the following enhancement: -Support serial port use without flow control -Prevent dropped bytes by updating flow control handling -Remove dead code Serial port use without flow control: In the prior implementation there was a window of time between reloading DMA buffers after a timeout where bytes could be dropped. This is because the uart needed to be turned off in order to flush the bytes in the DMA buffer. This change configures the DMA buffer to only receive one byte at a time so there is no need to disable the uart to flush it. After each byte is received the DMA transfer will be over so the transfer will never be partially complete and need flushing. Since the uart is always on it is safe to use it even without flow control. Prevent dropped bytes by updating flow control handling: To prevent dropped bytes due to high latency the flow control handling of the RTS line was configured to be asserted automatically by hardware after each byte. Once the CPU has read the byte and setup the next receive buffer the RTS line is deasserted to the transfer can continue. This ensure that when flow control is enabled data won't be lost due to interrupt latency. Remove dead code: With the above changes there is a lot of dead code, such as the timer handling code. This patch removes the code that is no longer used.
1 parent 21dd8e4 commit 59bb79b

File tree

5 files changed

+87
-301
lines changed

5 files changed

+87
-301
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/README.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,16 @@ The tables must be placed in a C compilation file.
9393

9494
### Serial
9595

96-
The serial implementation uses the UARTE module which works exclusively through EasyDMA and RAM buffers. For optimal performance, each configured instance (NRF52832 has 1, NRF52840 has 2) has three buffers statically assigned:
97-
98-
1. Rx DMA buffer, which EasyDMA is currently writing to.
99-
1. Rx DMA buffer, pre-loaded in EasyDMA for automatic switchover.
100-
1. Rx FIFO buffer, for serving data to the application.
101-
102-
When the first DMA buffer is full or flushed the interrupt handler will automatically copy the DMA buffer to the FIFO buffer. This happens in interrupt context to avoid data loss and with UARTE interrupts set at the highest priority. The FIFO buffer is backed by the Nordic atomic fifo, which can be read and written to safely without disabling interrupts.
96+
The serial implementation uses the UARTE module which works exclusively through EasyDMA and RAM buffers.
97+
To ensure no data is lost a FIFO is used to buffer data received. The FIFO buffer is backed by the Nordic atomic fifo, which can be read and written to safely without disabling interrupts.
10398

10499
#### Customization
105100

106-
All buffers can be resized to fit the application:
101+
The FIFOs can be resized to fit the application:
107102

108103
```
109104
"name": "nordic",
110105
"config": {
111-
"uart_dma_size": {
112-
"help": "UART DMA buffer. 2 buffers per instance. DMA buffer is filled by UARTE",
113-
"value": 8
114-
},
115106
"uart_0_fifo_size": {
116107
"help": "UART0 FIFO buffer. FIFO buffer is filled from DMA buffer.",
117108
"value": 32
@@ -123,7 +114,7 @@ All buffers can be resized to fit the application:
123114
}
124115
```
125116

126-
All DMA buffers are the same size and must be at least 5 bytes due to hardware restrictions. DMA buffers should be sized to handle the worst expected interrupt latency. FIFO buffers can be configured per instance and the size should reflect the largest expected burst data. For example, a serial debug port might receive a line of data at a time, so an 80 byte FIFO buffer would be adequate. A serial port connected to a wifi radio should have a FIFO buffer in the kilo byte range.
117+
FIFO buffers can be configured per instance and the size should reflect the largest expected burst data. For example, a serial debug port might receive a line of data at a time, so an 80 byte FIFO buffer would be adequate. A serial port connected to a wifi radio should have a FIFO buffer in the kilo byte range.
127118

128119
For the NRF52840, UARTE instances are assigned based on pins and calling order. Serial objects with the same pin configurations will go to the same instance. A custom configuration table can be provided by overriding the weakly defined default empty table. In the example below, serial objects using pins `p1` and `p2` for `Tx` and `Rx` will always be assigned to `Instance 1` and serial objects using pins `p3` and `p4` for `Tx` and `Rx` will be assigned to `Instance 0` regardless of calling order. The custom configuration table must always be terminated with a row of `NC`.
129120

@@ -139,12 +130,7 @@ The table must be placed in a C compilation file.
139130

140131
#### Flow Control (RTS/CTS)
141132

142-
When hardware flow control is enabled the DMA and FIFO buffers can be reduced to save RAM. CTS will be disabled when a DMA buffer is copied to the FIFO and enabled again when the FIFO has been emptied. Because of the dual buffering the FIFO buffer must be twice the size of the DMA buffer (less than half and data mmight be lost and more than half will be a waste of RAM).
143-
144-
#### RTC2
145-
146-
Because each DMA buffer must be at least 5 bytes deep, each buffer is automatically flushed after a certain idle period to ensure low latency and correctness. This idle timeout is implemented using 2 of the 4 channels on RTC instance 2. This leaves RTC0 for the SoftDevice and RTC1 for Mbed tickers.
147-
133+
When hardware flow control is enabled the FIFO buffers can be reduced to save RAM. Flow control ensures that bytes cannot be dropped due to poor interrupt latency.
148134

149135
#### SWI0
150136

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@
21582158

21592159

21602160
#ifndef PPI_ENABLED
2161-
#define PPI_ENABLED 0
2161+
#define PPI_ENABLED 1
21622162
#endif
21632163

21642164
// <e> PWM_ENABLED - nrf_drv_pwm - PWM peripheral driver

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/config/sdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@
21582158

21592159

21602160
#ifndef PPI_ENABLED
2161-
#define PPI_ENABLED 0
2161+
#define PPI_ENABLED 1
21622162
#endif
21632163

21642164
// <e> PWM_ENABLED - nrf_drv_pwm - PWM peripheral driver

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/mbed_lib.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
{
22
"name": "nordic",
33
"config": {
4-
"uart_timeout_us": {
5-
"help": "Idle time in micro seconds between characters before buffer is flushed.",
6-
"value": 2000
7-
},
84
"uart_0_fifo_size": {
95
"help": "UART0 FIFO buffer. FIFO buffer is filled from DMA buffer.",
106
"value": 32
117
},
128
"uart_1_fifo_size": {
139
"help": "UART1 FIFO buffer. FIFO buffer is filled from DMA buffer.",
1410
"value": 32
15-
},
16-
"uart_dma_size": {
17-
"help": "UART DMA buffer. 2 buffers per instance. DMA buffer is filled by UARTE",
18-
"value": 8
1911
}
2012
},
2113
"macros": [

0 commit comments

Comments
 (0)