-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Update uart_ll.h - Fixing division by zero (IDFGH-10990) #12179
Conversation
I have faced the division by zero when the baud rate is higher than 1Mbits/s. It happens because the integer division returns zero for sclk_div while slightly below 1.0. I also added 0.5 to improve the roundup process of converting float to integer. With that fix, I can reach 3.125Mbits/s.
Hi @educampos28,
Also I have tried on ESP32S3 with a baud rate of 3.125Mbits/s, the code runs fine without crash. Can you provide more details, such as compile option, sdkconfig, UART source clock selection, baudrate configurations, that would lead to the "division by zero" error? |
@educampos28 Thanks for the debug! Do you want to fix your PR? I guess casting And would you also apply the fix to all other targets? Then we can go through the PR process! |
it will fix. I prefer to use float in this case to guarantee a better result while rounding the number. Also, that function is called once when the user start their system, which the float math won't be a firmware overload for the firmware. Sorry, I don't have time to push this fix to other targets. |
Use uint64_t instead of float to calculate the clock division for the baudrate
sha=3f40c80c06b2d9057fd651db98f6c5b18f64a8b6 |
merged in b0bde58 |
I have faced the division by zero when the baud rate is higher than 1Mbits/s. It happens because the integer division returns zero for sclk_div while slightly below 1.0.
I also added 0.5 to improve the roundup process of converting float to integer.
With that fix, I can reach 3.125Mbits/s.