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);
}
}
Hello,
I received following answer from SDK team:
On behalf of the FlexCAN driver developer:
After running multiple tests for FlexCAN FD transmissions, no issue was found on our side.
We identified the following situation in which FLEXCAN_DRV_IRQHandler() is called, but FLEXCAN_DVR_CompleteTransfer() is never reached: the sending node does not receive 'ACK' from the receiving node (nodes are configured with different bitrate, FlexCAN module is not initialized on the receiving node). In this situation state->mbs[mb_idx].state remains FLEXCAN_MB_TX_BUSY as it is set by FLEXCAN_DRV_StartSendData(), but is never changed to FLEXCAN_MB_TX_IDLE as FLEXCAN_DRV_CompleteTransfer() is never called.
In order to further investigate the problem, could you inspect the state of the Error and Status 1 register by calling FLEXCAN_HAL_GetErrStatus() after FLEXCAN_DRV_Send() and let us know the result?
Also, please make sure that all fields from the flexcan_data_info_t structure are correctly set:
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,
.is_remote = false /*!< Specifies if the frame is standard or remote */
};
Also, we are confused related to the following statement:
- did not call 'FLEXCAN_DRV_IRQHandler()' -> call 'FLEXCAN_DRV_CompleteTransfer()'
Is FLEXCAN_DRV_IRQHandler called? If not, how come FLEXCAN_DRV_CompleteTransfer() is called? If FLEXCAN_DRV_IRQHandler is invoked, does it reach FLEXCAN_DRV_CompleteTransfer()?
Hope it helps.
Regards,
Martin
Hello,
I sent your question to SDK application team. I will write you back as soon as I have any information for you.
Regards,
Martin