Skip to content

Add ring buffer for serial TX #95

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

Merged
merged 12 commits into from
Dec 3, 2019
Merged

Add ring buffer for serial TX #95

merged 12 commits into from
Dec 3, 2019

Conversation

nseidle
Copy link
Member

@nseidle nseidle commented Dec 2, 2019

This PR makes Serial TX writes and prints interrupt driven rather than a blocking serial transfer one byte at a time. The _tx_buffer was there, I just implemented it. This reduces the time spent on Serial.prints significantly.

Here is example output running at 9600bps without this PR:

image

And here is example output with this PR:

image

Note the 66ms is because the TX ring buffer is 256bytes and myString is 293 so we have to wait for the UART to open up. If we increase the size of the ring buffer, this value goes to 0.

Also availableForWrite() method is now implemented.

Also in this PR is a patch for the HAL to make am_hal_uart_flags_get() work.

Here is my test sketch:

void setup() {
  Serial.begin(9600);
  delay(10);
  Serial.println("Serial buffer testing");

  String myString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget ligula laoreet, faucibus felis sit amet, cursus mi. Praesent congue tristique congue. Pellentesque feugiat diam volutpat eros consectetur dapibus. Nullam lobortis enim at rutrum maximus. Sed lobortis purus in sagittis.";

  long myTimer = millis();
  Serial.println(myString);
  long delta = millis() - myTimer;
  
  Serial.println("Length: " + (String)myString.length());
  Serial.println("Time to send myString: " + (String)delta);
  Serial.println("Time to send with blocking method (calculated): " + (String)(myString.length() * (1000.0/960)));
  Serial.print("Available space in TX buffer: ");
  Serial.println(Serial.availableForWrite());
}

void loop() {

}

@oclyke
Copy link
Contributor

oclyke commented Dec 3, 2019

Nice! Thanks for the excellent work. I just modified whitespace to make the changes to the HAL more obvious in the combined diff.

@oclyke oclyke merged commit 40e8e7c into master Dec 3, 2019
@oclyke oclyke deleted the serialTXBuffer branch December 3, 2019 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants