-
Notifications
You must be signed in to change notification settings - Fork 979
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
HardwareSerial hangs in flush() with flow control enabled and no device attached #2122
Comments
Hi @fronders Thanks for this detailed issue. Hard to define in which case we do not need to flush. For me if CTS is not asserted this simply means the device is not ready to receive.
This would need to add a default timeout when the end() called flush(). In that case, no more break. |
Hi @fpistm Yeah, I agree this was a "quick hack" - we're losing data in case device wasn't ready to receive, but in this edge-case we were de-initializing UART by calling |
when called by end(). Default, no timeout (0). When called by end(), default timeout is TX_TIMEOUT which can be redefined if needed. Fixes stm32duino#2122 Signed-off-by: Frederic Pillon <[email protected]>
Hi @fronders |
@fpistm Looks good, but I'll be able to test only late tonight. I'll report back once I have it UPD: do you think we also might need smth similar here? :) Arduino_Core_STM32/cores/arduino/HardwareSerial.cpp Lines 521 to 525 in 0c69f37
|
I don't think, we follow the Arduino API reference: As stated at the end:
|
@fpistm yeap that PR fix works a charm! yes, I agree, but shouldn't there be a reasonable time we give ringbuffer to get out? |
No. Up to you to check if you can send as stated in the api. |
when called by end(). Default, no timeout (0). When called by end(), default timeout is TX_TIMEOUT which can be redefined if needed. Fixes stm32duino#2122 Signed-off-by: Frederic Pillon <[email protected]>
Describe the bug
I'm using Sparkfun's SARA-R5 library - an LTE modem using UART connection.
The init sequence includes autobaud selection - it cycles through different UART baudrates and reinitiailizes the UART like this (original code here):
Then it sends
ATE0
and waits forOK
response on selected baudrate - classic stuff.The problem comes up when
HardwareSerial
has hw flow control enabled and there's no device attached (i.e. CTS not asserted). Theend()
function gets stuck forever because offlush()
waiting for the ringbuffer to become empty (line 499).Arduino_Core_STM32/cores/arduino/HardwareSerial.cpp
Lines 490 to 504 in 0c69f37
But because hw flow control enabled and CTS not asserted (i.e. SARA-R5 not connected) the bytes pending in the ringbuffer never get transmitted (remember it tries to send
ATE0
) so the whole while loop just hangs forever.I've made a "dirty" fix that removes the problem in this specific case - if CTS is enabled and no CTS asserted (UART CTS flag is not set) then simply reset ringbuffer:
But this generally opens a broader issue some of
HardwareSerial
code has infinite loops relying purely on interrupts and no timeout exit:flush()
andwrite()
. Kinda similar to what #1834 brings upDesktop (please complete the following information):
Board (please complete the following information):
Custom PCB using STM32L496RGT6 MCU connected via UART with CTS\RTS to a u-blox SARA-R5 modem
The text was updated successfully, but these errors were encountered: