This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-AM261: SPI unable to modify the input clock frequency.

Part Number: LP-AM261
Other Parts Discussed in Thread: CCSTUDIO, SYSCONFIG

Device: LP-AM261 Evaluation board
SDK: MCU+ SDK for AM261x 26.0.0.06
CCStudio: 21.0.0.14
SysConfig: 1.27.0

Using the MCSPI Performance 8 Bit example provided by the MCU+ SDK, I'm attempting to transmit at 12 MHz with SPI0, however it will only transmit at 10 MHz.  

The CONFIG_MCSPI0 Channel Configuration 0 has the Clock Frequency set to 12,000,000.  
00_Chanel0Frequency.png

The initial setup of SPI0's clock is to use SYSCLK with SPI0_CLK_GRM_CLKDIV set to 5, to have SPI0_CLK of 50.00MHz.

01_InitialInputClock.png

This generates a Release/syscfg/ti_drivers_config.c gMcspiAttrs with the inputClkFreq set to 50,000,000.  

/* MCSPI atrributes */
static MCSPI_Attrs gMcspiAttrs[CONFIG_MCSPI_NUM_INSTANCES] =
{
    {
        .baseAddr           = CSL_MCSPI0_U_BASE,
        .inputClkFreq       = 50000000U,
        .intrNum            = CSLR_R5FSS0_CORE0_INTR_MCSPI0_INTR,
        .operMode           = MCSPI_OPER_MODE_POLLED,
        .intrPriority       = 4U,
        .chMode             = MCSPI_CH_MODE_SINGLE,
        .pinMode            = MCSPI_PINMODE_4PIN,
        .initDelay          = MCSPI_INITDLY_0,
        .multiWordAccess    = FALSE,
    },
};

However when measured via an oscilloscope the SPI0_CLK signal is only at 10 MHz, which appears to be due to MCU+ SDK McSPI driver's MCSPI_setClkConfig function. 

 

static void MCSPI_setClkConfig(uint32_t baseAddr,
                               uint32_t chNum,
                               uint32_t inputClkFreq,
                               uint32_t bitRate)
{
    uint32_t fRatio;
    uint32_t clkD;
    uint32_t extClk;

    /* Calculate the value of fRatio. */
    fRatio = inputClkFreq / bitRate;
    if(((inputClkFreq % bitRate) != 0U) && (fRatio < MCSPI_MAX_CLK_DIVIDER_SUPPORTED))
    {
        /* use a higher divider value in case the ratio
         * is fractional so that we get a lower SPI clock
         * than requested. This ensures we don't go beyond
         * recommended clock speed for the SPI peripheral */
        fRatio++;
    }

    /* If fRatio is not a power of 2, set granularity of 1 clock cycle */
    if((uint32_t) 0U != (fRatio & (fRatio - 1U)))
    {
        /* Set the clock granularity to 1 clock cycle */
        CSL_REG32_FINS(
            baseAddr + MCSPI_CHCONF(chNum),
            MCSPI_CH0CONF_CLKG,
            CSL_MCSPI_CH0CONF_CLKG_ONECYCLE);

        /* Calculate the ratios clkD and extClk based on fClk */
        extClk = (fRatio - 1U) >> 4U;
        clkD   = (fRatio - 1U) & (uint32_t) MCSPI_CLKD_MASK;

        /* Set the extClk field */
        CSL_REG32_FINS(
            baseAddr + MCSPI_CHCTRL(chNum),
            MCSPI_CH0CTRL_EXTCLK,
            extClk);
    }
    else
    {
        /* Clock granularity of power of 2 */
        CSL_REG32_FINS(
            baseAddr + MCSPI_CHCONF(chNum),
            MCSPI_CH0CONF_CLKG,
            CSL_MCSPI_CH0CONF_CLKG_POWERTWO);

        clkD = 0U;
        while (1U != fRatio)
        {
            fRatio >>= 1U;
            clkD++;
        }
    }

    /* Configure the clkD field */
    CSL_REG32_FINS(baseAddr + MCSPI_CHCONF(chNum), MCSPI_CH0CONF_CLKD, clkD);

    return;
}

Since the inputClkFreq is 50,000,000 and bitRate is 12,000,000, the ratio is not a power of 2, therefore the Clock ration extension is used.  
This results in EXTCLK of 0, CLKD of 4, which creates a clock ratio of CLKD + 1, resulting in SPI0's clock being 10MHz.  

To have the desired 12 MHz rate, the input clock for SPI0 should be 48 MHz, which should be possible by selecting DPLL_PER_HSDIV0_CLKOUT0 for SPI0_CLK_GCM_CLKSRC_SEL. 

02_InputClock_DPLL_PER_HSDIV0_CLKOUT0.png

 

However this change appears to have no affect on the generated a Release/syscfg/ti_drivers_config.c gMcspiAttrs as the the inputClkFreq set to 50,000,000, which results in the SPI0 clock still being 10MHz.  

In fact attempting any changes to SPI0's clock, via SysConfig's ClockTree tool, such as modifying the SPI0_CLK_GCM_CLKDIV value do not appear to impact the generated Release/syscfg/ti_drivers_config.c gMcspiAttrs's inputClkFreq parameter.


I can confirm when changing the SPI0_CLK_GCM_CLKSRC_SEL to DPLL_PER_HSDIV0_CLKOUT0 the following entry is added to my example.syscfg file.

const mux27       = system.clockTree["SPI0_CLK_GCM_CLKSRC_SEL"];
mux27.inputSelect = "DPLL_PER_HSDIV0_CLKOUT0";

 

Is this a bug within SysConfig/ClockTree/MCU+ SDK or am I missing something?

 

 

 

  • Hi Sean,
    Thanks for the very thorough root-cause analysis — your math and driver trace are correct, and I can add some useful context that points strongly toward this being a SysConfig/MCU+ SDK code-generation defect rather than something you're missing on the configuration side.
    Confirming your clock math
    Per the AM261x TRM (MCSPI clock ratio granularity section), when CLKG=1 (clock granularity = 1 cycle), FRATIO = EXTCLK:CLKD + 1, and the resulting SPICLK = inputClkFreq / FRATIO. With inputClkFreq = 50,000,000 and a target bitRate of 12,000,000, FRATIO rounds up to 5 (not a power of 2), giving exactly the 10 MHz you measured (50 MHz / 5). This is expected behavior of MCSPI_setClkConfig() for a 50 MHz source — 50 MHz simply cannot divide evenly to 12 MHz. Your identification that a 48 MHz source clock is needed to hit exactly 12 MHz (48/4 = 12) is correct.
    On selecting DPLL_PER_HSDIV0_CLKOUT0
    This is a legitimate configuration path — the AM261x TRM's clock mux table explicitly lists SPI0_CLK_MUX with DPLL_PER_HSDIV0_CLKOUT0 as option 3 for MCSPI0_CLK_SRC_SEL, alongside SYS_CLK, EXT_REFCLK, XTALCLK, etc. So functionally, your approach of switching SPI0's clock source away from SYSCLK to reach 48 MHz is sound per the hardware documentation.
    This looks like a known class of SysConfig codegen bug on AM261x
    There is a very similar, previously-confirmed bug on AM261x involving a different peripheral's clock-tree wiring: in that case, the RTI clock source mux address was miscalculated inside the SDK's rti_am261x.syscfg.js (an incorrect address offset, 0x118 instead of 0x140), which caused the RTI to silently fall back to its default 25 MHz clock source instead of the one selected in the ClockTree GUI — even though the SysConfig GUI showed the "correct" configuration and the .syscfg file captured the selection properly. TI confirmed it as an SDK bug, provided a manual .syscfg.js edit as a workaround, and raised an internal fix for the SDK.
    Your symptom matches this pattern closely: the ClockTree mux selection is being correctly written into your example.syscfg (mux27.inputSelect = "DPLL_PER_HSDIV0_CLKOUT0";), but the generated ti_drivers_config.c is not picking up the resolved clock frequency for gMcspiAttrs.inputClkFreq — it stays hardcoded at 50,000,000 regardless of any ClockTree change (mux selection, divider, etc.). That strongly suggests the MCSPI driver's .syscfg.js/template is either not correctly querying the resolved SPI0_CLK_GCM_CLKSRC_SEL → SPI0_CLK_GCM_CLKDIV chain output, or has a stale/incorrect reference (similar to the RTI address bug) when computing the value written into inputClkFreq.
    This is not something you're missing — the SysConfig ClockTree tool is documented as being intended to have exactly this kind of change propagate through to generated code, and your steps (changing clock source in ClockTree, verifying the .syscfg diff, checking the generated C file) are the correct way to diagnose it.
    Recommended next steps
    1. As a workaround, you can bypass the code-gen issue entirely by manually overriding inputClkFreq in gMcspiAttrs after generation (e.g., edit the generated ti_drivers_config.c directly, or override the attribute at runtime before calling MCSPI_open()), setting it to the actual resolved SPI0 input clock frequency (48,000,000 once your DPLL_PER_HSDIV0_CLKOUT0 path is active). This will get you working 12 MHz SPI transfers immediately without waiting on an SDK fix.
    2. I will flag this explicitly as a suspected bug and file an internal ticket — given the precedent above, this looks like it needs a fix in the MCSPI module's .meta/.syscfg.js files (likely in mcu_plus_sdk/source/sysconfig/drivers/.meta/mcspi/... ) to correctly re-resolve inputClkFreq from the ClockTree output rather than using a fixed/default value.
    3. Please also share exact repro steps (SysConfig ClockTree screenshots + resulting .syscfg diff + generated ti_drivers_config.c diff) if you haven't already — this is exactly the level of detail that got the analogous RTI issue root-caused and fixed quickly.
    Let me know if the manual inputClkFreq override workaround gets you unblocked in the meantime.
    Best Regards,
    Zackary Fleenor
  • Hi Zachary,

    As a workaround, you can bypass the code-gen issue entirely by manually overriding inputClkFreq in gMcspiAttrs after generation (e.g., edit the generated ti_drivers_config.c directly, or override the attribute at runtime before calling MCSPI_open()), setting it to the actual resolved SPI0 input clock frequency (48,000,000 once your DPLL_PER_HSDIV0_CLKOUT0 path is active). This will get you working 12 MHz SPI transfers immediately without waiting on an SDK fix.

    When attempt to modify ti_drivers_config.c source, it will be replaced/updated when CCStudio build the project again.  
    Instead I've added the following to the beginning of mcspi_performance_8bit.c example to override as you've suggested. 

    void *mcspi_performance_main(void *args)
    {
        uint32_t            i, j;
        uint32_t            dataLength, dataWidth, bitRate, bufWidthShift;
        uint32_t            baseAddr, chNum;
        uint32_t            chCtrlRegVal, chConfRegVal;
        uint32_t            startTimeInUSec, elapsedTimeInUsecs;
    
        // Workaround for SysConfig bug with setting SPI Input clock to 48MHz
        MCSPI_Attrs MygMcspiAttrs[CONFIG_MCSPI_NUM_INSTANCES] =
        {
            {
                .baseAddr           = CSL_MCSPI0_U_BASE,
                .inputClkFreq       = 48000000U,
                .intrNum            = CSLR_R5FSS0_CORE0_INTR_MCSPI0_INTR,
                .operMode           = MCSPI_OPER_MODE_POLLED,
                .intrPriority       = 4U,
                .chMode             = MCSPI_CH_MODE_SINGLE,
                .pinMode            = MCSPI_PINMODE_4PIN,
                .initDelay          = MCSPI_INITDLY_0,
                .multiWordAccess    = FALSE,
            },
        };
        gMcspiConfig[0].attrs = MygMcspiAttrs;
    
        Drivers_open();


    Via an oscilloscope I can confirm the SPI0_CLK signal is now at 12MHz, and I can proceed, while I wait for an updated SysConfig to address this issue.

    The information provided in my original post is sufficient to recreate this bug.