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.

Using examples SPI (from pdk_am335x_2_00_02_11) and Profinet (sysbios_ind_sdk_2.1.1.2) together

Other Parts Discussed in Thread: AM3359, SYSBIOS

Hi,

my setup:

CCS 6.1.3

AM3359 Industrial Communications Engine v2

pdk_am335x_1_0_2

sysbios_ind_sdk_2.1.1.2

i want to use SPI and Profinet on the AM3359 ICE v2. Therefore i started with the in topic named examples.

Each of them runs well on board . Now i wanted to combine the two examples, copy and paste the code from the "MCSPI_SlaveMode_MasterExample_icev2AM335x_armExample"  into the code of the "profinet_slave_IRT" example.

I also added the include paths from the SPI example to the Profinet example. But when compiling i get an error with the line

masterSpi = SPI_open(BOARD_MCSPI_MASTER_INSTANCE-1, NULL);

The compiler does not know the expression "BOARD_MCSPI_MASTER_INSTANCE". What is the problem ?

Thanks in advance

  • Hi Michael,
    Need to spend some time looking into this and get back to you . Thanks for your patience.

    Lali
  • Hi,

    any solution or hints by now ?
  • Hello Michael,

    This is defined in C:\ti\pdk_am335x_1_0_2\packages\ti\board\src\bbbAM335x\include\board_cfg.h
    #define BOARD_MCSPI_MASTER_INSTANCE (0x2U)

    However combining the two SDKs to implement an SPI slave on the ISDK will be challenging since the Processor SDK has different APIs and as well as a different functional structure.

    The more efficient path may be to create an application which maintains a structure for the desired information to be exchanged information on the C2000 side. This would use the existing master SPI capability in the 2.1.1.2 ISDK to transfer in new inputs and then periodically pick up updates from the C2000. The polling interval to pick up data from the C2000 could be ~1/2 the C2000 control cycle interval or when triggered by GPIO signal etc...

    David
  • Hello and thank you for the answer.
    So "challenging" means it won't be possible, i guess ;-)

    What i need is the AM3359 ICEv2 as a Profinet Slave and as a SPI master. For the Profinet part there is the example in the sysbios ind sdk 2.1.1.2 which i used. This will be my starting point. Now i want to implement the SPI master functionality into the profinet example. Now knowing that it is not possible to combine the two SDKs my question is still:

    1. How to implement SPI into the Profinet example ??? I did not find a documentation and an example for spi in sys bios. A read something about using starterware and implementing starterware code into sys bios but the implementation is nowhere documented. For example in TI RTOS users guide the spi driver is explained with needed #includes and functions. for starterware or sys bios i found no documentation like this.

    So please could you help me implementing SPI into the profinet example ?

    Thanks in advance
    Michael
  • Hi Michael

    We use starterware to control most of our device functions.
    The starterware example provides an overview of the steps we need to take to use the SPI function.
    The example uses APIs like MCSPIChEnable, MCSPICsAssert, MCSPIChStatus, MCSPITransmitData, .... that are contained in the SPI Starterware DAL (Device Abstraction Layer) . This is contained in C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\starterware\dal\mcspi.c

    These same APIs are used by to support the SPI Flash read operations for Profinet.

    Profinet Application
    The Profinet Main
    in C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\examples\profinet_slave\main.c
    calls initSNMP() to enable the SNMP module.
    initSNMP() is contained in C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\examples\profinet_slave\snmp\mib_impl.c
    initSNMP() calls the Board_readFlashStorage .

    SysBIOS Board Support APIs
    Board_readFlashStorage is contained in the sysbios board support packages
    in C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\board\source\board_support.c

    To handle the flash physical organization
    Board_readFlashStorage calls Board_readSpiFlash which calls Board_readSpiFlashPage
    Both of which are in C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\board\source\icev2AM335x\board_spiflash.c

    Which then accesses the board sysBIOS board APIs
    Which calls Board_readMCSPI which only calls Board_MCSPICycle
    In C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\board\source\drivers\board_mcspi.c

    Starterware DAL APIs
    Which calls MCSPIChEnable, MCSPICsAssert, MCSPIChStatus, MCSPITransmitData
    In C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\starterware\dal\mcspi.c

    David
  • Thanks for your detailed answer.

    Now i tried to implement my needed additional SPI into the Profinet_RT_MRP example.
    I want to use SPI1 as a spi-master. I included "board_mcspi.h" into the main.c file. In the project properties i added
    the paths "C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\board\source" and "C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\board\source\drivers".

    Then i tried to initialize the spi in the main section by using the API "Board_initMCSPI(mcspiCfgObj_t *pMcspiObj);"
    I saw the structure of "mcspiCfgObj_t" in the file "board_mcspi.h" and created such an object in my "main.c".
    Not knowing how to set all the parameters (instNum, instAddr,.....) i noticed a default configuration in the file "board_support.c".
    So i copied all the values given there into my configuration. I compiled the code and loaded it onto the ICEv2. But when starting i get an error:

    "CortxA8: Unhandled ADP_Stopped exception 0x20023"

    My questions:

    1. What does this error mean ? Is there some kind of hardware conflict with my init procedure?

    2. Where to get information about which values to set in the config object (instNum, instAddr,...) ?
    Which instNum is for SPI1, which instAddr and so on =?

    3. Is the way i try to implement SPI to the profinet example correct in general or are there important steps missing ?


    Thanks for your patience with me

    Michael
  • Hi Michael

    It looks like you are on the right track.
    This error reports means that the error is not handled by the ARM debugger. It would be good to understand when that error occurs.

    The parameters for the SPI registers are shown in the AM335 TRM www.ti.com/.../spruh73
    The memory map lists SPI1 registers which are also declared as SOC_SPI_1_REGS in
    C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\starterware\include\hw\soc_am335x.h
    as (0x481A0000)

    In C:\ti\sysbios_ind_sdk_2.1.1.2\sdk\examples\profinet_slave_RT_MRP\appl_cnfg.h
    For
    SYS_MMU_ENTRY applMmuEntries[] =
    This address is set to Non bufferable | Non Cacheable instead of bufferable
    This should be {(void *)0x48100000, SYS_MMU_BUFFERABLE},

    if the SPI Flash is included in the build – we should check that we are not reinitializing IPs.

    Some additional information that will help understand how the ISDK information is organized is contained in
    processors.wiki.ti.com/.../Sitara_Indust_SDK_Training
    processors.wiki.ti.com/.../Industrial_SDK_EMAC_Porting_Guide

    David
  • Hi David,

    thanks for the information.
    The error occurs inside the API "Board_initMCSPI" in board_mcspi.c

    .....
    /* Setup SPI peripheral */
    /* Enable the clocks for McSPI1 module.*/
    MCSPIClkConfig(pMcspiObj->instAddr, <<<<<<------- executing this line the error occurs !!!!
    pMcspiObj->channelNum,
    pMcspiObj->inClk,
    pMcspiObj->outClk,
    pMcspiObj->pCfg.clkMode);
    .....



    Board_initMCSPI is called in my main.c at the end of main() just befor the line Bios_start();

    My config object for SPI1 initialisation is:

    mcspiCfgObj_t SPI1config = {
    1, /* instNum.*/
    0x481A0000, /* instAddr.*/
    48000000, /* inClk.*/
    1000000, /* outClk.*/
    0, /* channelNum.*/
    1, /* dataLength.*/
    gTxBuffer, /* pTx.*/
    gRxBuffer, /* rTx.*/
    {
    MCSPI_CH_MULTI, /* channel.*/
    MCSPI_TRANSFER_MODE_TX_RX, /* txRxMode.*/
    MCSPI_DATA_LINE_COMM_MODE_7, /* pinMode. */
    MCSPI_CLK_MODE_2, /* clkMode.*/
    8, /* wordLength.*/
    MCSPI_CS_POL_LOW, /* csPolarity.*/
    TRUE, /* txFifoCfg.*/
    FALSE, /* rxFifoCfg.*/
    MCSPI_INTR_TX_EMPTY(0U) | \
    MCSPI_INTR_RX_FULL(0U) /* interrupt.*/
    },
    {
    INTC_TRIG_HIGH_LEVEL, /* trigType.*/
    0, /* intrLine.*/
    10, /* intrPriority.*/
    FALSE, /* isIntrSecure.*/
    NULL, /* pTxBuf.*/
    NULL, /* pRxBuf.*/
    NULL /* pFnIntrHandler.*/
    },
    {
    TRUE, /* csFlag.*/
    MCSPI_MODE_MASTER, /* modeFlag.*/
    MCSPI_INTERRUPT_MODE /* comFlag.*/
    }
    };

    Questions:

    1. What is the problem ? Are there wrong parameters ?

    2. You mentioned something about "...reinitializing IPs...."
    What does IP in this context mean ?


    Thank you very much

    Michael
  • Hi Michael

    IP is another way of saying SOC peripheral component.

    As a sanity check to see if it is a definition problem you could trythe mcspiCfgObj_t  values that are used in the Profinet example

    David

  • Hello David,

    now i got the init procedure working.
    I traced the init procedure of SPI0 and noticed that before
    initialising the SPI by using "Board_initMCSPI" there was another line of code
    which initialises power and clock to the SPI module. "PRCMModuleEnable(......)"
    I used this command to activate the SPI1 module and then initialised SPI1.
    Now the board starts without error, i have spi clock and chip select but still having no data on the MOSI.
    Even with the config values you posted.

    i created a "uint8_t TxBuffer = 5" variable to test data transmission.
    In my config object i point on it "&TxBuffer". And also when calling
    "Board_writeMCSPI(&SPI1config, &TxBuffer, 1)". In debug mode i see
    that TxBuffer contains the value "5" but when with the program running the "5" turns into "0" and
    stays in that state.

    Is there any problem with the buffers ?
    Do they have to be from a specific data type (char, int,...)

    Thanks a lot

    Michael
  • Hello David,

    it works now !
    It seem like that i just wasn't able to read a "5" on the scope at 9pm.
    Sorry for that. The problem with the TxBuffer variable in debug window i assume it is
    simply not debugable.

    Thanks a lot for your patience and your help.

    Best wishes

    Michael
  • Hi David,
    My purpose is to intergrate SPI1 to ethercat example.

    I modified flash_app_main.c to use SPI1 and setted the interrupt line to 125, SPI1 could be used to connect STM32 device.
    Now I intergrates SPI1 code to ecat_appl project, the project seems to something wrong with interrupt.
    When I enable this function "McspiAppIntrConfig(pCfgMcspi);", the ecat_appl project builds without error but can not runs correctly, because it only print 13 characters "TI Industrial"and seems to be paused.
    When I disable this function "McspiAppIntrConfig(pCfgMcspi);", the ecat_appl project builds without error and  runs correctly.

    So, I doubt the SPI1 interrupt causes this problem. How to do.

    Thank you very much.

    Lyu

  • Hi Lyu

    Please - Could you open this as a new e2e question.
    Please tell us what SDK release and the device that you are using.

    David