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.

TMS570LC4357: How to configure CANFD in TMS570LC4357

Part Number: TMS570LC4357
Other Parts Discussed in Thread: TIDEP-01014, TCAN4550, TMS570LS1224, HALCOGEN

Hi Team, 

How to configure CANFD in TMS570LC4357

Couldn't increase a DLC more than 8. For CANFD I need 64 byte.

Please share me if you have any CANFD example code for TMS570 MCU.

Thanks in advance.

  • Hi Santhosh,

    TMS570LC43x doesn't support CANFD. It supports the classical CAN only.

  • Yes QJ Wang, Thanks for your feedback. 

    We have planned to use TCAN4550 SPI to CANFD for communication. I have tired the code "TIDEP-01014 - Node1 and Node2" but it is interrupt method. 

    Can you help me the polling method of TCAN4550 CANFD code for TMS570LC4357 MCU.

    Transmit and receiver code for CANFD configuration.

    Thank you.

  • Hi Santhosh,

    You can use TX and RX status in Rx FIFO Status Register and Tx Event FIFO Status.  

    The RX FIFO status register tells how many new messages are in the FIFO, and what index to start reading at. 

    A FIFO which stores CAN message transmit event messages. These elements are generated by the TCAN4x5x when transmitting a message, and are for the microcontroller to read to see the status of a sent message. 

  • HI QJ Wang,

    I have tried the TMS570LS1224 Launchpad with TCAN4550 SPI to CANFD it is working fine, but the issue in TMS570LC4357 Launchpad

    TMS570LS1224

    SPI.c

    uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint8 * srcbuff)

    uint32 spiTransmitAndReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint8 * srcbuff, uint8 * destbuff)

    TMS570LC4357 

    HL_SPI.c  

    uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff)

    uint32 spiTransmitAndReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff)

    spi.c has uint8 for srcbuff and destbuff but in uint16 for LC43x library. 

    So How to modify in TMS570_TCAN45x.c file

    AHB_READ_B_FL_32 API calls spiTransmitData and spiTransmitAndReceiveData ?

    In that case how to make this array?

    txData[0] = AHB_READ_B_FL_OPCODE;
    txData[1] = (address & 0xFF00) >> 0x8;
    txData[2] = (address & 0x00FF) >> 0x0;
    txData[3] = DataLength;
    txData[4] = 0x00;
    txData[5] = 0x00;
    txData[6] = 0x00;
    txData[7] = 0x00;

    Please guide me in this array formation. 

    Thanks in advance.

  • Please modify the HALCOGen generated functions in tm,s570lc43x spi.c:

    uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint8 * srcbuff)

    uint32 spiTransmitAndReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint8 * srcbuff, uint8 * destbuff)

    For the example code used in TMS570LS1224, I modified the  spiTransmitData() and spiTransmitAndReceiveData() manually.

  • Hi QJ Wang,

    Yes, It is worked now. 

    I have some queries in the SPI to CANFD code 

    1. I need to modify my Interrupt based CANFD to Polling method. 

    2.TCAN45x_devConfig  is this API is needed for polling method of CANFD communication ?

    these are the Pin are going to use in my code.

    nINT  -- N2HET1[23]

    CAN_RST -- N2HET1[11]

    SPI3_NCS0

    SPI3_SIMO

    SPI3_SOMI

    SPI3_CLK

    I have modified the TCAN45x_Reset API for my custom board.

    void TCAN45x_Reset()
    {
        static volatile unsigned int delayval;
        delayval = 10000;   //1ms
    
        //reset TCAN4550 device. GIOB[3] is connected to nRST of TCAN4550 device
        hetREG1->PULDIS |= (0x00000800); //gioPORTB->PULDIS |= (0x1<<3);
        gioSetDirection(hetPORT1, (0x00000800)); //gioSetDirection(gioPORTB, 0x1 << 3);
        //gioSetBit(gioPORTB, 3, 1);
        gioSetBit(hetPORT1,11,1);
        while(delayval--);
        //release the TCAN4550 nRST
        //gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ 0x00000000);
        //gioSetBit(gioPORTB, 3, 0);
        gioSetBit(hetPORT1,11,0);
        delayval = 10000;
        while(delayval--);          //is requires. otherwise it doesn't work. QJ 2019
    }

    Please support me for the modification of TCAN45x_devConfig API.

    void TCAN45x_devConfig()
    {
        gioPORTA->DIR     = (uint32)((uint32)0U << 0U);     /* Bit 0/1/2/7 */
        gioPORTB->DIR     = (uint32)((uint32)0xFB);         /* Bit 2 as input */
        gioREG->POL       = (uint32)((uint32)0x0U << 0U);   /* Bit 0/1, falling edge */
        gioREG->LVLSET    = (uint32)((uint32)(0x13U | 0x400));   /* GIOA Bit 0/1/2/7, GIOB Bit 2, high priority interrupt */
        gioPORTA->PULDIS  = 0x87; /* Bit 0/1/2/7, disable the pull */
        gioPORTB->PULDIS  = 0x04; /* Bit 2, disable the pull */
        gioEnableNotification(gioPORTA, 0x87); //enable the INT on GIOA0,GIOA1,GIOA2,GIOA7
        gioEnableNotification(gioPORTB, 0x04); //enable the INT on GIOB2, user button input
    }

    Thanks in advance.

  • Hi,

    Don't you connect TCAN45x CAN_GPIO1 and CAN_GPIO2 to TMS570 MCU pins?

  • Hi QJ Wang,

    I didn't connect the  TCAN45x CAN_GPIO1 and CAN_GPIO2 to TMS570 MCU pins. Is it most?

    I am looking for polling method for Tx and Rx . 

    while(1)
    	{
    	        MCAN_WriteTXFIFO(0, &header, &g_ucADC1Data[g_ucCurrentAdcDataIndex][0]);    
    			// This function actually writes the header and data payload to the specified TX Fifo number. It returns the bit necessary to write to TXBAR,
                //retVal = MCAN_WriteTXFIFO(0, &header, &td[0]);    // This function actually writes the header and data payload to the specified TX Fifo number. It returns the bit necessary to write to TXBAR,
                // This line writes the data and header to TX FIFO 1 and it will write the return value (corresponding to the
                // FIFO bit number in TX BAR
    	        MCAN_WriteTXFIFO(1, &header1, &g_ucADC1Data[g_ucCurrentAdcDataIndex][0]);
    	        MCAN_WriteTXFIFO(2, &header2, &g_ucADC1Data[g_ucCurrentAdcDataIndex][0]);
    	        MCAN_WriteTXFIFO(3, &header3, &g_ucADC1Data[g_ucCurrentAdcDataIndex][0]);
    	        MCAN_WriteTXFIFO(4, &header4, &g_ucADC1Data[g_ucCurrentAdcDataIndex][0]);
    
                AHB_WRITE_B_FL_32(M_CAN_TXBAR, 0x0000001F);     // Now we can send the TX FIFO element 1 data that we had queued up earlier but didn't send.
               // TCAN45x0_CAN_Interrupt_Register MCAN_IR = {0};  // Setup a new MCAN IR object for easy interrupt checking
               // MCAN_ReadInterruptRegister(&MCAN_IR);           // Read the interrupt register
    			//if (MCAN_IR.RF0N) {                     // If a new message in RX FIFO 0
                    TCAN45x0_RX_HEADER MsgHeader = {0}; // Initialize to 0 or you'll get garbage
                    uint8_t numBytes = 0;
                    uint8_t dataPayload[64] = {0};
    				numBytes = MCAN_ReadNextFIFO( RXFIFO0, &MsgHeader, dataPayload);    // This will read the next element in the RX FIFO 0
    
                    //Toggle NHET pin to check how long tit takes to receive the CAN-FD data
                    //gioSetBit(hetPORT1, 9, 1);
    
                    //for(i=0; i<numBytes/2; i++){
                    //   receivedAdcData = dataPayload[i] << 8 | dataPayload[i+1];
                    //}
                    //cmpB = (etpwmREG6->TBPRD * receivedAdcData*2/numBytes)/0xFFF;
                    //etpwmSetCmpB(etpwmREG6, cmpB);
                    if (MsgHeader.ID == 0x55C) {     // #1 board use 0x158, #2 board use 0x128
                       // Do something
                       TMS570_DEBUGF(("Received CAN-FD Data: 0x%x bytes\n", numBytes));
                       for(i=0; i<numBytes; i++){
                           TMS570_DEBUGF(("  0x%X     ", dataPayload[i]));
                       }
                       TMS570_DEBUGF(("  \n\n "));
                    }
              //  }
    
    	
    	}

    Tx is works fine when the without Rx input signals.

    RX Reception message got only in first time is it because of RXFIFO0 - RxFIFO0 is only 0th buffer is reading ?

    Please guide me in polling method of 5 Tx FIFO messages and similarly for 5 Rx FIFO messages with interrupt method.

    AHB_WRITE_B_FL_32(M_CAN_TXBAR, 0x0000001F); 

    Is this address 0x0000001F is indicate the total messages in FIFO buffer ? 

    because I have used 5 FIFO, So I have mentioned as 0x0000001F.

    Similarly I need it for Reception API called and how to use it. 

    Thank you in advance.

  • HI QJ Wang,

    SPI3 Data Formats is Baudrate(KHz) = 8000

    Charlen is 8 ? only 1st Data format is 8 or it should be for all data format?

    Any other setting I need to check for Configuration ?

    Thanks in advance.

  • The CAN_GPIO1 and CAN_GPIO2 are used to interrupt MCU when message is transmitted or FIFOx receives new message. The CAN_GPIO1/2 are connected to MCU GPIO pins which support external interrupt.

    The procedure for configuring the interrupt:

    1. GPIO1_GPO_CONFIG: MCAN_INT 1 (01), for interrupt line m_can_int0

        GPIO2_GPO_CONFIG: MCAN_INT 0 (01), for interrupt line m_can_int1

    2. Enable interrupt: RF0NE -- RX FIFO 0 new message interrupt

                                    TCE -- Transmission complete interrupt

    3. Select the interrupt line: TCL = 0  -- Transmission complete interrupt uses line 0: m_can_int0 --> GPIO1

                                               RF0NL = 1 --  Rx FIFO 0 New Message Interrupt uses line 1: m_can_int1--> GPIO2

    For other TCAN configuration, please check with TCAN team.

  • Yes, the char length is 8 bit.

  • Hi QJ Wang,

    In my case I am not using CAN_GPIO1_INT and CAN_GPIO2_INT. So I need to configure the reception using polling method without interrupt.

       --- CAN_nINT-- N2HET1[23], CAN_RST -- N2HET1[11], SPI3_NCS0, SPI3_SIMO, SPI3_SOMI, SPI3_CLK

    How to read the reception CAN ID without Interrupt from MCAN_ReadNextFIFO or MCAN_ReadRXBuffer, MCAN_ReadTXFIFO

    Thanks in advance

  • Hi Santhosh,

    Since CAN_GPIO1_IN and CAN_GPIO2_IN are not used, I am not sure when to read the MCAN RX buffer. Would you please check with TCAN4550 expert from the interface forum?

    https://e2e.ti.com/support/interface-group/interface/f/interface-forum/

  • Hi QJ Wang,

    I have three interrupt pin from MCU as  GIOA0, GIOA1 and GIOB6 which I can use it with CAN_GPIO1_IN , CAN_GPIO2_IN  and nINT in TCAN4550. Please guide me with the TCAN45x_devConfig API

    How to configure this LVLSET register GIOA 0 and GIOA 1 which is 0x03 and GIOB6 is 0x4000

       gioREG->LVLSET    = (uint32)((uint32)(0x03|0x4000));   /* GIOA Bit 0/1, GIOB Bit 6, high priority interrupt */

    But in example, only CAN_GPIO1_IN is configured for interrupt for RX reception and only RXFIFO0 is used to receive the CAN signals. 

    How to configure to receive the CAN signals in RXFIFO1 and RX Buffer. because I have configured the SFD Filter for RXFIFO 0 and RXFIFO 1 but I couldn't receive any CAN signals from RF1N as 1 and only I receive in RF0N as 1 and receiving CAN signals.

    How to configure this MRAM Configuration is it SID and XID is used for both transmit and receive CAN signals ?

    Rx0NumElements is used to recieve the number of CAN signals. 

    Rx0ElementSize is 48 byte is it possible to allocate the 1st CAN signal starts from this 0 location of Rx0ElementSize and 2nd CAN signal starts from this 8th location of Rx0ElementSize?

    similarly in RxBufNumElements to configure.

    No update RF1N in RXFIFO1 buffer 

    Please share me the configuration for RXFIFO1 buffer to update ?

    Is it possible to configure both RXFIFO and RXbuffer ?

    Please guide me in this above doubts. 

  • Hi Santhosh,

    It's my pleasure to answer any questions regarding the hercules devices. But I am not an expert of TCAN45x device, please get more help from TCAN45x team. Thanks

    https://e2e.ti.com/support/interface-group/interface/f/interface-forum/