File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -1454,12 +1454,18 @@ macro_rules! halUsartImpl {
14541454 let ( over8, div) = if ( pclk_freq / 16 ) >= baud {
14551455 // We have the ability to oversample to 16 bits, take
14561456 // advantage of it.
1457- let div = pclk_freq / baud;
1457+ //
1458+ // We also add `baud / 2` to the `pclk_freq` to ensure
1459+ // rounding of values to the closest scale, rather than the
1460+ // floored behavior of normal integer division.
1461+ let div = ( pclk_freq + ( baud / 2 ) ) / baud;
14581462 ( false , div)
14591463 } else if ( pclk_freq / 8 ) >= baud {
14601464 // We are close enough to pclk where we can only
14611465 // oversample 8.
1462- let div = ( pclk_freq * 2 ) / baud;
1466+ //
1467+ // See note above regarding `baud` and rounding.
1468+ let div = ( ( pclk_freq * 2 ) + ( baud / 2 ) ) / baud;
14631469
14641470 // Ensure the the fractional bits (only 3) are
14651471 // right-aligned.
You can’t perform that action at this time.
0 commit comments