-
Notifications
You must be signed in to change notification settings - Fork 3k
[feature-nrf528xx] Serial re-implementation for the NRF52 series #6435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature-nrf528xx] Serial re-implementation for the NRF52 series #6435
Conversation
/morph build |
Build : FAILUREBuild number : 1544 |
Serial implementation uses UARTE instead of UART peripheral: * EasyDMA is used for reading and writing data. * Triple buffering for receiving data. See README for full description.
/morph build |
Build : SUCCESSBuild number : 1547 Triggering tests/morph test |
Exporter Build : FAILUREBuild number : 1186 |
Test : SUCCESSBuild number : 1326 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 1195 |
{ | ||
"name": "nordic", | ||
"config": { | ||
"uart-hwfc": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcuschangarm @0xc0170 Would having uart declared in both mbed_lib.json and targets.json cause any issues when overriding it in custom_targets.json?
I'm using a custom_targets.json which is intended to disable flow control, but the mbed_config.h always ends up containing the following:
#define MBED_CONF_NORDIC_UART_HWFC 1 // set by target:MCU_NRF52840
#define MBED_CONF_NORDIC_UART_HWFC 1 // set by library:nordic
Since I'm not using hardware flow control this results in my printf's hanging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might have missed my response here: https://os.mbed.com/forum/upcoming-features/topic/29477/?page=1#comment-56395
In any case, targets.json has been cleaned up and a new PR is in the pipeline: #6547
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcuschangarm
I believe the recommendation did not work due to @vergil-SI overriding uart-hwfc and uart_hwfc in custom_targets.json.
#6547 does seems to address this issue by doing target specific target_overrides in mbed_lib.json.
From the README:
Description
Serial
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:
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.
Customization
All buffers can be resized to fit the application:
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.
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
andp2
forTx
andRx
will always be assigned toInstance 1
and serial objects using pinsp3
andp4
forTx
andRx
will be assigned toInstance 0
regardless of calling order. The custom configuration table must always be terminated with a row ofNC
.The table must be placed in a C compilation file.
RTC2
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.
The RTC2 ISR is set at the lowest interrupt priority to ensure that UARTE interrupts take precedence. The last 2 of the 4 RTC channels are used for decoupling UARTE ISR context from Mbed IRQ events. This ensures that any user code will only delay other user callbacks and idle flushing and puts an upper bound on the interrupt handling time for the UARTE ISR.
Limitations
Pull request type
[x ] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change