Skip to content
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

feat(serial): add timeout support to flush() #2124

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Sep 8, 2023

when called by end().
Default, no timeout (0). When called by end(), default timeout is
TX_TIMEOUT which can be redefined if needed.

Fixes #2122.

Tested with below sketch on a Nucleo-WL55JC1.
Serial1 is instantiate with CTS/RTS. With original code, it wait forever while with this PR it continue after TIMEOUT_TX expiration.

HardwareSerial Serial1(PB7, PB6, PB3, PB4);
uint32_t baud_val[] = {
  1200,
  2400,
  4800,
  9600,
  115200,
  250000
};
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  for (uint8_t idx = 0; idx < 6; idx++) {
    Serial1.end();
    Serial.printf("Test %u\n", baud_val[idx]);
    Serial1.begin(baud_val[idx]);
    Serial1.println("ATE0");
  }
  delay(100);
}
Output
09:20:52.421 -> Test 1200
09:20:53.419 -> Test 2400
09:20:54.384 -> Test 4800
09:20:55.383 -> Test 9600
09:20:56.380 -> Test 115200
09:20:57.379 -> Test 250000
09:20:58.473 -> Test 1200
09:20:59.471 -> Test 2400
09:21:00.470 -> Test 4800
09:21:01.465 -> Test 9600

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]>
@fpistm fpistm added enhancement New feature or request fix 🩹 Bug fix labels Sep 8, 2023
@fpistm fpistm added this to the 2.7.0 milestone Sep 8, 2023
@fpistm fpistm merged commit 6f39b41 into stm32duino:main Sep 11, 2023
22 checks passed
@fpistm fpistm deleted the Serial_flush_timeout branch September 11, 2023 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix 🩹 Bug fix
Projects
Development

Successfully merging this pull request may close these issues.

HardwareSerial hangs in flush() with flow control enabled and no device attached
1 participant