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.

SYSCONFIG: AM62 SPI config in sysconfig

Part Number: SYSCONFIG
Other Parts Discussed in Thread: AM623,

Tool/software:

Hi,
I want to configure the SPI Clock for the AM623. But for some SPI frequencies I get 2 parameters in the ti_driver_open_close.c

What do I wrong? 
Does sysconfig detect wrong SPI clock settings?

Regards, Holger

/*
 *  Copyright (C) 2021-2025 Texas Instruments Incorporated
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Auto generated file
 */

#include "ti_drivers_open_close.h"
#include <kernel/dpl/DebugP.h>

void Drivers_open(void)
{


    Drivers_mcspiOpen();


}

void Drivers_close(void)
{


    Drivers_mcspiClose();

}

/*
 * MCSPI
 */
/* MCSPI Driver handles */
MCSPI_Handle gMcspiHandle[CONFIG_MCSPI_NUM_INSTANCES];
/* MCSPI Driver Open Parameters */
MCSPI_OpenParams gMcspiOpenParams[CONFIG_MCSPI_NUM_INSTANCES] =
{
    {
        .transferMode           = MCSPI_TRANSFER_MODE_BLOCKING,
        .transferTimeout        = SystemP_WAIT_FOREVER,
        .transferCallbackFxn    = NULL,
        .msMode                 = MCSPI_MS_MODE_MASTER,
        .mcspiDmaIndex = -1,
    },
    {
        .transferMode           = MCSPI_TRANSFER_MODE_BLOCKING,
        .transferTimeout        = SystemP_WAIT_FOREVER,
        .transferCallbackFxn    = NULL,
        .msMode                 = MCSPI_MS_MODE_MASTER,
        .mcspiDmaIndex = -1,
    },
};
/* MCSPI Driver Channel Configurations */
MCSPI_ChConfig gConfigMcspi0ChCfg[CONFIG_MCSPI0_NUM_CH] =
{
    {
        .chNum              = MCSPI_CHANNEL_0,
        .frameFormat        = MCSPI_FF_POL0_PHA0,
        .bitRate            = 1600000,
        .csPolarity         = MCSPI_CS_POL_LOW,
        .trMode             = MCSPI_TR_MODE_TX_RX,
        .inputSelect        = MCSPI_IS_D1,
        .dpe0               = MCSPI_DPE_ENABLE,
        .dpe1               = MCSPI_DPE_DISABLE,
        .slvCsSelect        = MCSPI_SLV_CS_SELECT_0,
        .startBitEnable     = FALSE,
        .startBitPolarity   = MCSPI_SB_POL_LOW,
        .csIdleTime         = MCSPI_TCS0_0_CLK,
        .defaultTxData      = 0x0U,
        .txFifoTrigLvl      = 16U,
        .rxFifoTrigLvl      = 16U,
    },
};
MCSPI_ChConfig gConfigMcspi1ChCfg[CONFIG_MCSPI1_NUM_CH] =
{
    {
        .chNum              = MCSPI_CHANNEL_0,
        .frameFormat        = MCSPI_FF_POL0_PHA0,
        .bitRate            = 1780000,
        .csPolarity         = MCSPI_CS_POL_LOW,
        .trMode             = MCSPI_TR_MODE_TX_RX,
        .inputSelect        = MCSPI_IS_D1,
        .dpe0               = MCSPI_DPE_ENABLE,
        .dpe1               = MCSPI_DPE_DISABLE,
        .slvCsSelect        = MCSPI_SLV_CS_SELECT_0,
        .startBitEnable     = FALSE,
        .startBitPolarity   = MCSPI_SB_POL_LOW,
        .csIdleTime         = MCSPI_TCS0_0_CLK,
        .defaultTxData      = 0x0U,
        .txFifoTrigLvl      = 16U,
        .rxFifoTrigLvl      = 16U,
    },
};

#include <drivers/mcspi/v0/dma/mcspi_dma.h>



void Drivers_mcspiOpen(void)
{
    uint32_t instCnt, chCnt;
    int32_t  status = SystemP_SUCCESS;

    for(instCnt = 0U; instCnt < CONFIG_MCSPI_NUM_INSTANCES; instCnt++)
    {
        gMcspiHandle[instCnt] = NULL;   /* Init to NULL so that we can exit gracefully */
    }

    /* Open all instances */
    for(instCnt = 0U; instCnt < CONFIG_MCSPI_NUM_INSTANCES; instCnt++)
    {
        gMcspiHandle[instCnt] = MCSPI_open(instCnt, &gMcspiOpenParams[instCnt]);
        if(NULL == gMcspiHandle[instCnt])
        {
            DebugP_logError("MCSPI open failed for instance %d !!!\r\n", instCnt);
            status = SystemP_FAILURE;
            break;
        }
    }

    /* Channel configuration */
    for(chCnt = 0U; chCnt < CONFIG_MCSPI0_NUM_CH; chCnt++)
    {
        status = MCSPI_chConfig(
                     gMcspiHandle[CONFIG_MCSPI0],
                     &gConfigMcspi0ChCfg[chCnt]);
        if(status != SystemP_SUCCESS)
        {
            DebugP_logError("CONFIG_MCSPI0 channel %d config failed !!!\r\n", chCnt);
            break;
        }
    }
    for(chCnt = 0U; chCnt < CONFIG_MCSPI1_NUM_CH; chCnt++)
    {
        status = MCSPI_chConfig(
                     gMcspiHandle[CONFIG_MCSPI1],
                     &gConfigMcspi1ChCfg[chCnt]);
        if(status != SystemP_SUCCESS)
        {
            DebugP_logError("CONFIG_MCSPI1 channel %d config failed !!!\r\n", chCnt);
            break;
        }
    }

    if(SystemP_FAILURE == status)
    {
        Drivers_mcspiClose();   /* Exit gracefully */
    }

    return;
}

void Drivers_mcspiClose(void)
{
    uint32_t instCnt;
    /* Close all instances that are open */
    for(instCnt = 0U; instCnt < CONFIG_MCSPI_NUM_INSTANCES; instCnt++)
    {
        if(gMcspiHandle[instCnt] != NULL)
        {
            MCSPI_close(gMcspiHandle[instCnt]);
            gMcspiHandle[instCnt] = NULL;
        }
    }

    return;
}

  • Hi,

    The results which I am about to show are based on the latest SDK and SysConfig.

    Upon adding two MCSPI instances, I do not see the frequency difference as you are seeing.

    Please read the MCSPI Integration guide for configuring values and what other parameters mean in SysConfig GUI:  [FAQ] SK-AM64B: MCSPI Integration Guide 

    If you are using a very older SDK, I will recommend you to switch to the latest and this should resolve your problem.

    Regards,

    Vaibhav

  • What do I wrong? 
    Does sysconfig detect wrong SPI clock settings?

    To summarize you have configured two MCSPI Instances in SysConfig, lets suppose SPI1 and SPI2 Controllers, and each of these have different frequencies configured by you, hence you see those exact values reflected in the generated files. Hope this helps clarify your doubt.

  • Hi Vaibhav,
    can you try to change the clock values and see if it is still correct?

    Regards, Holger

  • Hi,

    Just to clarify, the two frequencies which you see, one which is 1600000 and 1780000 are of two different MCSPI instances added by you. And these numbers are configured by you.

    For example, have a look at the following screenshot:

    I have declared:

    1. CONFIG_MCSPI0: For this instance I set frequency as 123456(just to demonstrate, I have written this random number), this number is reflected on the generated file.

    2. CONFIG_MCSPI1: For this instance I set frequency as 178000 and hence you also see this on the generated file.

    In your application you can use lets say MCSPI1, then that would mean you are operating in 178000 frequency and if you use the MCSPI0 in your application that would mean you are operating at 123456 frequency.

    Hope this clarifies your doubt.

    Best,

    Viabhav