Resolve a set of critical bugs in SERCOM and unify SPI/UART/I2C baudrate calculations
#381
+77
−45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR supersedes #737, which can be closed.
There are a series of bugs relating to:
GCLK->PCHCTRL[clk_id].reg = GCLK_PCHCTRL_GEN_GCLK1_Val | (1 << GCLK_PCHCTRL_CHEN_Pos)to values that exceeded Table 54-6 (see also Table 14-9) values forclk_id =3(FDPLL0 and FDPLL1 Reference clock frequency) by 3,750%. The code had originally missed in the datasheet where theCOREclock controls the SERCOM frequency, Section 36.5.3:The calculation of baudrates particularly
I2CM.BAUD.bit.BAUDandI2CM.BAUD.bit.HSBAUDthat were not in accordance Section 36.6.4.2.1.1 and 36.6.4.2.1.2 for the SAM D5x/E5x and Section 28.6.2.4.1.1 and 28.6.4.2.1.2 for the SAM D21/DA1 chips.It the clock of a SAM D5x/E5x was set during runtime from the default 48 MHz, there was a situation where the
BAUDsetting for UART and I2C was not set correctly and could have as much as 100% error between actual and desired bus baudrates.There is an overflow condition in the calculation of
BAUDandHSBAUDsettings, recommend adding the following pseudo code to clamp I2C baudrates ininitMasterWire(baudtate). With low enoughbaudrateit is possible to generate an overflow condition where theBAUDwould be very low, e.g.0x01generating a baudrate that exceeds the maximum specified value.