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

HardwareSerial Available For Write #9319

Merged
merged 3 commits into from
Mar 5, 2024
Merged

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Mar 1, 2024

Description of Change

When setting RX buffer, the setRxBufferSize() method would fail with values lower than 128 bytes.
Although it seems what IDF requests, it is not the best way to execute it, because the return value would be zero and the buffer size would be kept the same, by default 256. Now it returns the size it has been set, defining a minimum of 128+1 bytes, as required by IDF UART driver.

By other hand, for TX buffer, the setTxBufferSize() method also fails with less than 128 bytes, returning also 0.
With the change, it will return and set it to 128 (minimum), as requeired by IDF.
It also changes availableForWrite() in order to return a value that matches setTxBufferSize() when there is no data to be written, making it possible for applications to better compare and decide when to write to the UART.

Tests scenarios

Tested with ESP32 and ESP32-S3.

void setup() {
  size_t Ts = Serial.setTxBufferSize(100);
  size_t Rs = Serial.setRxBufferSize(100);
  Serial.begin(115200);
  delay(1000);
  
  Serial.printf("TX Buffer (%d) Size is %d\n", Ts, Serial.availableForWrite());
  Serial.printf("RX Buffer Size is %d\n", Rs);
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    Serial.write(c);
  }
}

Related links

Closes #9317

It makes sure that setting TX buffer size will match availableForWrite() response. It also sets the buffer to the minimum instead of doing nothing and returning an error.

For RX Buffer, it sets the minimum and also don't return an error.

This makes the APIs better and easy to understand its results.
This will allow to set TX buffer to a minimum with no error message.
It also makes it works as in the Arduino API specification that is to return the buffer available space. In ESP32 case it will be the minmum the HW TX FIFO size of 128 bytes.
This change will make sure that if no TX Ringbuffer is used, it will return the UART FIFO available space. Otherwise, it will return the Ringbuffer available space, as defined in the Arduino especification.
@SuGlider SuGlider added this to the 3.0.0-RC1 milestone Mar 1, 2024
@SuGlider SuGlider self-assigned this Mar 1, 2024
Copy link
Contributor

github-actions bot commented Mar 1, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "feat(uart): setBufferSize ":
    • body's lines must not be longer than 100 characters
    • summary looks too short
  • the commit message "feat: adjust availableForWrite":
    • body's lines must not be longer than 100 characters
  • the commit message "feat: sets TX buffer ":
    • body's lines must not be longer than 100 characters
    • 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).

⚠️

The source branch "Serial_availableForWrite" incorrect format:

  • contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS).
    Please rename your branch.
Messages
📖 You might consider squashing your 3 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.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- 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 a79e2c7

@P-R-O-C-H-Y P-R-O-C-H-Y added the Status: Pending Merge Pull Request is ready to be merged label Mar 4, 2024
@me-no-dev me-no-dev merged commit 58b9f07 into master Mar 5, 2024
50 checks passed
@me-no-dev me-no-dev deleted the Serial_availableForWrite branch March 5, 2024 08:53
SuGlider added a commit to SuGlider/arduino-esp32 that referenced this pull request Mar 7, 2024
me-no-dev pushed a commit that referenced this pull request Mar 11, 2024
* feat(uart): backports UART pin attachment from 3.0.0 to 2.0.15

* Fix (uart): Fixes additional Serial HardwareSerial errors for 2.0.14

* Update esp32-hal-uart.c

* Update HardwareSerial.h

* Apply suggestions from code review

* Fixes UartAvailableForWrite #9319

* Fixes  (set RX/TX buffer size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Peripheral: UART Status: Pending Merge Pull Request is ready to be merged
Projects
Development

Successfully merging this pull request may close these issues.

Rethink the result of HardwareSerial::availableForWrite() and setTxBufferSize
4 participants