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

UART: fixes begin() after a previous begin() :: deleting previous RX/TX buffers and its data #9095

Merged
merged 8 commits into from
Jan 16, 2024

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Jan 12, 2024

Description of Change

HardwareSerial::begin() has a bug that by always restaring the IDF UART driver, the currently running UART driver will release all the RX and TX ringbuffers causing it to drop all data waiting to be read.

This is very easy to verify by cross connecting RX/TX running begin(), write(byte) and then begin() + read(). No data is read.

The second issue is relatet to changing the RX Pin using begin() or setPins().
This causes a BREAK in the line and stops the driver, unless it is caught.

Both issues are corrected in this PR.

HardwareSerial::end(bool) has been changed to the standard HardwareSerial::end()

Important note:

No data is lost when changing the Arduino standard parameters, such as baud rate, uart frame format and pins.
But if the user changes IDF driver internal settings, like Line Inverting, RX/TX buffer size or RX FIFO IRQ Threshold, the driver must be restarted and it will cause the RX/TX buffer to be released with its data.

Tests scenarios

Tested with ESP32-S3 using UART0, UART1 and UART3

//https://wokwi.com/projects/384481453752614913 attached for easy viewing
// pins 3 and 38 are connected (RX1-TX1) || pins 47 and 21 are connected (RX2-TX2)

void setup() {
  Serial.begin(115200);                
  Serial2.begin(115200, SERIAL_8N1, 11, 10);
  Serial1.begin(115200, SERIAL_8N1, 38, 1);
}

void loop() {
  // Check if Serial1 has received any data
  if (Serial1.available()) {
    char byteReceived1 = Serial1.read();
    Serial.print("Byte received on Serial1: ");
    Serial.println(byteReceived1);
  }

  // Check if Serial2 has received any data
  if (Serial2.available()) {
    char byteReceived2 = Serial2.read();
    Serial.print("Byte received on Serial2: ");
    Serial.println(byteReceived2);
  }

  // Call the functions to send "H" and "I"
  sendHOverSerial1();
  sendIOverSerial2(); // Stops sendHOverSerial1() working
}

void sendHOverSerial1() {
  Serial1.begin(115200, SERIAL_8N1, 38, 3); // Re-initialize Serial1 with different pins
  Serial1.write("H"); 
  delay(1000); 
 Serial1.begin(115200, SERIAL_8N1, 38, 1); // Initialize Serial1 back to stock pins <---- causes data loss
}

void sendIOverSerial2() {
  Serial2.begin(115200, SERIAL_8N1, 47, 21);  // Initialize Serial2 with pin swap 
  Serial2.write("I"); 
  delay(1000); 
  // Serial2.begin(115200, SERIAL_8N1, 11, 10); // <------- causes BREAK
}

Related links

#9020

@SuGlider SuGlider added this to the 3.0.0-RC1 milestone Jan 12, 2024
@SuGlider SuGlider self-assigned this Jan 12, 2024
Copy link
Contributor

github-actions bot commented Jan 12, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Typo: fixes typos and some testing left over":
    • type/action should start with a lowercase letter
    • type/action should be one of [change, ci, docs, feat, fix, refactor, remove, revert, test]
  • the commit message "UART: fixes begin()":
    • summary looks too short
    • type/action should start with a lowercase letter
    • type/action should be one of [change, ci, docs, feat, fix, refactor, remove, revert, test]
  • the commit message "feat: fixes end()":
    • summary looks too short

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

⚠️ Please consider squashing your 8 commits (simplifying branch history).

👋 Hello SuGlider, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 7331a42

@lucasssvaz lucasssvaz added the hil_test Run Hardware Tests label Jan 13, 2024
 [HardwareSerial]: Changes CI to match new HardwareSerial begin() and end()
[uart]: fixes end(void) instead of end(bool)
@SuGlider
Copy link
Collaborator Author

@me-no-dev | @lucasssvaz - It seems that HIL isn't working... CI is faling due to some Python failure.

@SuGlider SuGlider removed the hil_test Run Hardware Tests label Jan 13, 2024
[fix]: adjust commentary of the copyright year
@me-no-dev me-no-dev merged commit 60395ed into espressif:master Jan 16, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants