AnsweredAssumed Answered

How to send CAN-FD message

Question asked by Kim JungHyun on Mar 9, 2017
Latest reply on Jan 7, 2018 by ye xie

Hi.

 

I have been trying to send CAN-FD message.

First, I made CAN message to be sent. I confirmed this on the CANoe.

But I could not send CAN FD message.

What should I do?

 

I found the difference between CAN(to be sent) and CAN-FD(not to be sent) through debug

 

■ CAN : state was changed to 'FLEXCAN_MB_IDLE'

- call 'FLEXCAN_DRV_IRQHandler()' -> call 'FLEXCAN_DVR_CompleteTransfer()' -> state->mbs[mb_idx].state = FLEXCAN_MB_IDLE

 

■ CAN-FD : state was always 'FLEXCAN_MB_TX_BUSY'

- did not call 'FLEXCAN_DRV_IRQHandler()' -> call 'FLEXCAN_DVR_CompleteTransfer()'

- CAN FD state->mbs[mb_idx].state = FLEXCAN_MB_TX_BUSY 

 

■ CAN-FD related Component Inspector

 - Device : CAN0

 - Enable FD : checked

 - CAN 0 selected

 

■ Code

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "pin_mux.h"
#include "clockMan1.h"
#include "lpit1.h"
#include "canCom1.h"
#include "dmaController1.h"
#include "osif1.h"
#include "canCom2.h"

  volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#define TX_MB (0UL)
#define TX_MSG_ID (354UL)
#define TX_MB_FD (4UL)
#define TX_MSG_ID_FD (77UL)
#define RX_MB (1UL)
#define RX_MSG_ID (300UL)


uint32_t tick =0;
void LPIT_ISR(void)
{
 LPIT_DRV_ClearInterruptFlagTimerChannels(LPIT0, (1<<0));
 GPIO_HAL_TogglePins(PTC, (1<<1));
 tick++;
}
/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
  /* Write your local variable definition here */
 flexcan_data_info_t dataInfo =
 {
 .data_length = 1U,
 .msg_id_type = FLEXCAN_MSG_ID_STD,
 .enable_brs = false,
 .fd_enable = false,
 .fd_padding = 0U
 };
 uint8_t toggleLED = 0x55;
 
 flexcan_data_info_t dataInfo_FD =
 {
 .data_length = 1U,
 .msg_id_type = FLEXCAN_MSG_ID_STD,
 .enable_brs = true,
 .fd_enable = true,
 .fd_padding = 0U
 };
 uint8_t toggleLED_fd = 0x77;

/* Receive a frame in the recvBuff variable */
flexcan_msgbuff_t recvBuff; 


  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  #ifdef PEX_RTOS_INIT
    PEX_RTOS_INIT();                   /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of Processor Expert internal initialization.                    ***/

 

  /* Write your code here */
  /* For example: for(;;) { } */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr,  CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

 

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

 

LPIT_DRV_Init(INST_LPIT1, &lpit1_InitConfig);
LPIT_DRV_InitChannel(INST_LPIT1, 0, &lpit1_ChnConfig0);
INT_SYS_InstallHandler(LPIT0_Ch0_IRQn, &LPIT_ISR, (isr_t *)0);

 

/* HSCAN : CAN1 */
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, TX_MB, &dataInfo, TX_MSG_ID);
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MB, &dataInfo, RX_MSG_ID);

 

/* CANFD : CAN0 */
FLEXCAN_DRV_Init(INST_CANCOM2, &canCom2_State, &canCom2_InitConfig0);
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM2, TX_MB_FD, &dataInfo_FD, TX_MSG_ID_FD);

 

LPIT_DRV_StartTimerChannels(LPIT0, (1<<0));


for(;;)
{
    if(tick>1000)
    {
        tick = 0;
        GPIO_HAL_ClearPins(PTC,1<<0);
        FLEXCAN_DRV_Send(INST_CANCOM1,TX_MB, &dataInfo, TX_MSG_ID, &toggleLED);
        FLEXCAN_DRV_Send(INST_CANCOM2, TX_MB_FD, &dataInfo_FD, TX_MSG_ID_FD, &toggleLED_fd);

 

    }
    else
    {
        GPIO_HAL_SetPins(PTC,1<<0);
    }
}

Outcomes