-
Notifications
You must be signed in to change notification settings - Fork 7.7k
fix(uart): always applies the user selected UART Clock Source #11747
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
Conversation
The problem affects more often SoC that supports REF_TICK UART Clock source (ESP32 and ESP32-S2). The implementation has an issue retated to when the user doesn't set any specific UART source clock and the UART changes its baudrate from lower than 250,000 to higher (ESP32/ESP32-S2). The bug is about not changing the clock source to something faster (APB) in order to get correct clock resolution in order to reach closer enough to the new baudrate selection. The new behaviour (which was working before) is that is the application doesn't set any specific UART clock rate, it shall follow a rule: ESP32/ESP32-S2 will use REF_TICK whenever baudrate is lower than 250,000. Other SoC will use XTAL. ESP32/ESP32-S2 will change UART Clock Source to APB when baudrate is higher than 250,000 for a better final result. If the user application explicitaly changes the UART Clock Source using `setClockSource()`, this new clock source will be used always, independently from the target SoC and selected baudrate (overriding the rule above).
👋 Hello SuGlider, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Test Results 76 files 76 suites 13m 12s ⏱️ Results for commit 3f3e4a6. ♻️ This comment has been updated with latest results. |
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the ESP32 UART driver where the clock source wasn't properly applied when changing baud rates. The issue specifically affected ESP32 and ESP32-S2 SoCs when switching from low to high baud rates without explicit clock source configuration.
Key changes:
- Removes automatic clock source tracking that was overriding user-defined settings
- Ensures user-selected clock sources are always respected regardless of baud rate changes
- Fixes condition check to properly handle user-defined clock sources (>= 0 instead of > 0)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Description of Change
The problem affects more often SoC that supports REF_TICK UART Clock source (ESP32 and ESP32-S2).
The implementation has an issue retated to when the user doesn't set any specific UART source clock and the UART changes its baudrate from lower than 250,000 to higher (ESP32/ESP32-S2).
The bug is about not changing the clock source to something faster (APB) in order to get correct clock resolution in order to reach closer enough to the new baudrate selection.
The new behaviour (which was working before) is that is the application doesn't set any specific UART clock rate, it shall follow a rule:
ESP32/ESP32-S2 will use REF_TICK whenever baudrate is lower than 250,000. Other SoC will use XTAL. ESP32/ESP32-S2 will change UART Clock Source to APB when baudrate is higher than 250,000 for a better final result.
If the user application explicitaly changes the UART Clock Source using
setClockSource()
, this new clock source will be used always, independently from the target SoC and selected baudrate (overriding the rule above).Test Scenarios
Using ESP32 / ESP32-S2 and setting Debug Level to Verbose - Checking the logs about UART_1 Clock Source.
Tested also with ESP32-C3 and ESP32-S3 to check if it uses XTAL for all baudrates by default and later it changes to APB.
PR Verbose Output:
ESP32 - UART Clock Sources are REF_TICK (11) or APB (4)
If baudrate < 250,000 ESP32/S2 shall use REF_TICK as UART Clock Source unless it is explicitally set by the user with, for instance:
setClockSource(UART_CLK_SRC_APB); // VALID ONLY FOR ESP32/ESP32-S2
Related links
Closes #11721