Skip to content

Conversation

@crabel99
Copy link

There are a series of bugs relating to:

  1. Setting of 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 for clk_id =3 (FDPLL0 and FDPLL1 Reference clock frequency) by 3,750%. The code had originally missed in the datasheet where the CORE clock controls the SERCOM frequency, Section 36.5.3:
Two generic clocks are used by `SERCOM: GCLK_SERCOMx_CORE` and `GCLK_SERCOM_SLOW`. The core clock (`GCLK_SERCOMx_CORE`) can clock the I2C when working as a host. The slow clock (`GCLK_SERCOM_SLOW`) is required only for certain functions, e.g. SMBus timing. These two clocks must be configured and enabled in the Generic Clock Controller (`GCLK`) before using the I2C.
  1. The calculation of baudrates particularly I2CM.BAUD.bit.BAUD and I2CM.BAUD.bit.HSBAUD that 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.

  2. It the clock of a SAM D5x/E5x was set during runtime from the default 48 MHz, there was a situation where the BAUD setting for UART and I2C was not set correctly and could have as much as 100% error between actual and desired bus baudrates.

  3. Not Addressed: There is an overflow condition in the calculation of BAUD and HSBAUD settings, recommend adding the following pseudo code to clamp I2C baudrates in initMasterWire(baudtate). With low enough baudrate it is possible to generate an overflow condition where the BAUD would be very low, e.g. 0x01 generating a baudrate that exceeds the maximum specified value.

void SERCOM::initMasterWIRE(uint32_t baudrate)
{
    ...
    // Enable all interrupts
    // sercom->I2CM.INTENSET.reg = SERCOM_I2CM_INTENSET_MB | SERCOM_I2CM_INTENSET_SB | SERCOM_I2CM_INTENSET_ERROR ;
  
    uint8_t speedBit = sercom->I2CM.CTRLA.bit.SPEED;
    uint32_t topSpeeds[3] = {400000, 1000000, 3400000}; // {(sm/fm), (fm+), (hs)}
    const uint32_t minBaudrate = freqRef / 512;       // BAUD = 255: SAMD51 ~195kHz, SAMD21 ~94kHz
    const uint32_t maxBaudrate = topSpeeds[speedBit];
    baudrate = max(minBaudrate, min(baudrate, maxBaudrate));

    if (speedBit == 0x2)
        sercom->I2CM.BAUD.bit.HSBAUD = freqRef / (2 * baudrate) - 1;
    else
        sercom->I2CM.BAUD.bit.BAUD = freqRef / (2 * baudrate) - 5 - freqRef * WIRE_RISE_TIME_NANOSECONDS / (2 * 1e9f);
}

ladyada and others added 30 commits July 25, 2020 17:21
In order to use IRLibRecvPCI class from IRLib2 with Adafruit pIRKey, it's necessary to allow interrupts on this pin.
Enable Interrupt adafruit#8 on Pin PORTA28 (GPIO2)
Improve build script & fix more warnings
Removing _dacResolution for __SAMD51__ is not defined (variable not used)
- make Tone_Handler() a strong symbol
BlitzCityDIY and others added 25 commits June 25, 2024 18:59
This reverts commit 3044845, reversing
changes made to e7a9d6d.
without the suffix, the value is erroneously being shifted twice, which happens to be harmless in these particular instances because the shift is by zero
Add .ramfunc attribute to flash_with_bootloader.ld to enable keeping functions in RAM
Fix hangs when transfer errors occur
Adding analog support to the 3-pin JST A6.
…t-name

fix variant folder name case for trrstrinkey_m0
add missing _Val suffix on arguments to GCLK_GENCTRL_SRC()
fix tone with low frequency e.g 25 hz
…nels

same51g19a: Fix missing ETC channel definitions in WVariant
Revert a part of ccfc7db. It breaks
I2C communcation.
Sercom: partially revert error handling change
@CLAassistant
Copy link

CLAassistant commented Jan 13, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 12 committers have signed the CLA.

✅ ladyada
✅ hathach
✅ crabel99
❌ BlitzCityDIY
❌ Richard Campbell
❌ jepler
❌ nerdyscout
❌ kaysievers
❌ EllaFoxo
❌ mikeysklar
❌ DennisErnst
❌ rcross-lc


Richard Campbell seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@crabel99
Copy link
Author

Superseded by PR #381.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.