-
Notifications
You must be signed in to change notification settings - Fork 3k
NRF52 serial: Fix UART console RX #8046
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
NRF52 serial: Fix UART console RX #8046
Conversation
This change is tested on NRF52_DK with SDK14 with GCC and ARM compilers. |
023922b
to
96eb87b
Compare
This behavior is seen only on NRF52_DK (PCA10040). The test program works correctly on NRF528340_DK (PCA10056). |
This seems like a hack. We now have the mechanism for the target to specify that flow control should be used on the console UART and which pins ( Is this mechanism not working, or are you not using it? |
If the issue is that some programs are using It assumes that the console is on a serial port at all, and usually assumes no flow control. And probably assumes stuff about baud rate and format too. To some extent you can fudge serial settings by picking up the same macros that mbed_retarget.cpp uses to specify console pins and settings, which is what Greentea is doing, but still it's bad - you're double-initialising the serial port if it is a serial port, and failing totally if it isn't. Programs should be using C I'm not very keen on putting a hack into the HAL to ignore the settings it's told to use. |
@@ -822,7 +822,14 @@ static void nordic_nrf5_uart_configure_object(serial_t *obj) | |||
nrf_uarte_hwfc_pins_set(nordic_nrf5_uart_register[uart_object->instance], | |||
uart_object->rts, | |||
uart_object->cts); | |||
} | |||
} else { /* NRF_UART_HWFC_DISABLED */ | |||
/* Check if pin is set before configuring it */ |
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.
Is this comment still relevant?
/* Check if pin is set before configuring it */ | ||
uart_object->cts = NRF_UART_PSEL_DISCONNECTED; | ||
uart_object->rts = NRF_UART_PSEL_DISCONNECTED; | ||
nrf_uarte_hwfc_pins_set(nordic_nrf5_uart_register[uart_object->instance], |
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.
What is the purpose of this addition?
* Even though we set the flow control once here, it gets reset subsequentially. | ||
* This seems necessary until a better fix is found as users can specify RawSerial | ||
* interface with no flow control, resulting in broken RX. | ||
*/ |
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.
So by default UART0 will use flow control connected to the terminal:
- Flow control enabled by default
- Flow control can be explicitly enabled or disabled by user by calling
Serial::set_flow_control
If this is the case it seems reasonable to me.
One possible alternative to changing the uart initialization is to on boot configure |
I was under a misconception here, that In fact they only default to 9600 baud, while the flow and format are left unmodified from however Given that, having the HAL preset the flow mode for that UART so that use of But the HAL does need to assume pins to do that, which is a cheat - activating 2 pins which weren't mentioned in the Maybe that's acceptable, but such magic should be more specific in the code - this isn't really a "NRF52" thing, it's specific to a board (isn't it?), and you want to activate it when configuring a UART against those particular pins you know are connected to the debug port on that particular board. There are a pile of board abstraction layers like It feels like it would be a lot of complication to add magic so that code does what you think it means rather than what it says - making it so that
magically knows to also wiggle pins C and D without ever being told to do so because it makes that code work on a particular board. I tend to agree with @marcuschangarm's abstraction comments on #6891. I'm not sure behind- the-scenes magic is the way to go here. Someone asking for We already have mechanisms to abstract away from such an explicit serial request for the console. If you really need to explicitly reference the console by creating your own (It may be we're still lacking a little in the abstraction area - I note you can find |
That's sounds like a good solution to me. Obviously it means you won't actually have working data flow control on a |
@kjbracey-arm @c1728p9 Should this PR be updated to the proposed solution (CTS driven low for nrf5x ) ? |
While investigating the RX issue on NRF52_DK after SDK 14 updates, it is observed that the RX FIFO doesn't get filled up, when the flow control is disabled. Hence the readable never returns true. If using Serial interface, the stdio file handles (0, 1, 2) get opened. This results in configuring the flow control for STDIO, and it is observed that the RX FIFO gets filled. However, if RawSerial is used, the STDIO file handles don't get opened. During the debug process it was observed that if the flow control is configured once and then set to disabled, RX worked as expected. Alternative to this approach is that user application specifically enables flow control as done in mbed's Greentea test suite. See https://goo.gl/r8nBYH See https://goo.gl/8VB2qg step 14 for _initio's description. See test code to reproduce the issue and test fix here: https://goo.gl/AQU1xG Description The change in behavior with NRF52's UART RX is documented here. ARMmbed#6891 This change is a fix for the above issue.
96eb87b
to
72abe51
Compare
Thanks @c1728p9 I made a modification to the fix in the latest patchset. |
cc @ARMmbed/mbed-os-maintainers @marcuschangarm do we need this change as well for #8292 |
This fix is independent of #8292 |
gpio_t rts; | ||
gpio_init_out(&rts, STDIO_UART_RTS); | ||
/* Set STDIO_UART_RTS as gpio driven low */ | ||
gpio_write(&rts, 0); |
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.
This call will trigger an assert for boards with STDIO_UART_RTS set to NC.
It would be better to wrap everything in an #if
macro.
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.
done
While investigating the RX issue on NRF52_DK after SDK 14 updates, it is observed that the RX FIFO doesn't get filled up, when the flow control is disabled. Hence the readable never returns true. If using Serial interface, the stdio file handles (0, 1, 2) get opened. This results in configuring the flow control for STDIO, and it is observed that the RX FIFO gets filled. However, if RawSerial is used, the STDIO file handles don't get opened. During the debug process it was observed that if the flow control is configured once and then set to disabled, RX worked as expected. Alternative to this approach is that user application specifically enables flow control as done in mbed's Greentea test suite. See https://goo.gl/r8nBYH See https://goo.gl/8VB2qg step 14 for _initio's description. See test code to reproduce the issue and test fix here: https://goo.gl/AQU1xG Description The change in behavior with NRF52's UART RX is documented here. ARMmbed#6891 This change is a fix for the above issue.
/morph build |
Build : SUCCESSBuild number : 3361 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2996 |
IAR network license issue. |
Test : SUCCESSBuild number : 3166 |
The preprocessor based macro check #if evaluates all enums as 0 and hence the code does not get compiled. Since move this to a runtime check where the pin variable can be correctly evaluated. Delete mbed_overrides.c as it has a target specific mbed_sdk_init() to resolve linking problem. This is a follow on patch to: ARMmbed#8046
The preprocessor based macro check #if evaluates all enums as 0 and hence the code does not get compiled. Since move this to a runtime check where the pin variable can be correctly evaluated. Delete mbed_overrides.c as it has a target specific mbed_sdk_init() to resolve linking problem. This is a follow on patch to: #8046
While investigating the RX issue on NRF52_DK after SDK 14 updates,
it is observed that the RX FIFO doesn't get filled up, when the
flow control is disabled. Hence the readable never returns true.
If using Serial interface, the stdio file handles (0, 1, 2) get opened.
This results in configuring the flow control for STDIO, and it is observed
that the RX FIFO gets filled.
However, if RawSerial is used, the STDIO file handles
don't get opened. During the debug process it was observed that if the
flow control is configured once and then set to disabled, RX worked
as expected.
Alternative to this approach is that user application specifically
enables flow control as done in mbed's Greentea test suite. See https://goo.gl/r8nBYH
See https://goo.gl/8VB2qg step 14 for _initio's description.
See test code to reproduce the issue and test fix here: https://goo.gl/AQU1xG
Description
The change in behavior with NRF52's UART RX is documented here. #6891
This change is a fix for the above issue.
Pull request type