Tool/software:
Hello,
I'm working on integrating the CAN-FD driver to work on D3's RS-6843AOP based on IWR6843AOP.
With support from D3 engineering, this forum and documentation I got a single device on CAN bus to transmit TLV messages.
The firmware is based on the Out-Of-The-Box DEMO with modifications to utilize CAN-FD insead of UART, it also uses the Hard Coded CLI configuration.
My aim for the next step is to be able to send configuration over CAN bus using the CAN-FD protocol.
I encountred an issue on getting the CAN-FD recieve to work, as soon as I set the RX pin with the pinmux commands, the resulting binary halts on transmitting messages with:
Error: CANFD instance 0 transmit data failed [Error code -3502]
(I'm debugging over UART using CLI_write commands for printing messages to CLI console)
If I set another RX pin, resulting binary transmits CAN-FD messages with no issues.
Unforyunately, I couldn't find in docs and the forum any solution for this behaviour, also reffered to BOSCH MCAN user manual.
Here is my CAN configurations which make the TX not to work and halts the whole program:
/**************************************************************************
******************** CAN Parameters initialize Function *****************
**************************************************************************/
static void MCANAppInitParams(CANFD_MCANInitParams* mcanCfgParams)
{
/*Intialize MCAN Config Params*/
memset (mcanCfgParams, sizeof (CANFD_MCANInitParams), 0);
mcanCfgParams->fdMode = 0x1U;
mcanCfgParams->brsEnable = 0x1U;
mcanCfgParams->txpEnable = 0x0U;
mcanCfgParams->efbi = 0x0U;
mcanCfgParams->pxhddisable = 0x0U;
// Disable auto-retransmission
mcanCfgParams->darEnable = 0x1U;
mcanCfgParams->wkupReqEnable = 0x1U;
mcanCfgParams->autoWkupEnable = 0x1U;
mcanCfgParams->emulationEnable = 0x0U;
mcanCfgParams->emulationFAck = 0x0U;
mcanCfgParams->clkStopFAck = 0x0U;
mcanCfgParams->wdcPreload = 0x0U;
mcanCfgParams->tdcEnable = 0x1U;
mcanCfgParams->tdcConfig.tdcf = 0U;
mcanCfgParams->tdcConfig.tdco = 8U;
mcanCfgParams->monEnable = 0x0U;
mcanCfgParams->asmEnable = 0x0U;
mcanCfgParams->tsPrescalar = 0x0U;
mcanCfgParams->tsSelect = 0x0U;
mcanCfgParams->timeoutSelect = CANFD_MCANTimeOutSelect_CONT;
mcanCfgParams->timeoutPreload = 0x0U;
mcanCfgParams->timeoutCntEnable= 0x0U;
// Reject all remote frames:
// A remote frame is a frame that does not carry data,
// but instead requests data from another node
// CAN-FD does not support remote frames
mcanCfgParams->filterConfig.rrfe = 0x1U;
mcanCfgParams->filterConfig.rrfs = 0x1U;
// Reject Non-matching frames
// Non-matching frames are frames that do not match the
// filter configuration of the receiver
mcanCfgParams->filterConfig.anfe = 0x0U;
mcanCfgParams->filterConfig.anfs = 0x3U;
mcanCfgParams->msgRAMConfig.lss = 127U;
mcanCfgParams->msgRAMConfig.lse = 64U;
mcanCfgParams->msgRAMConfig.txBufNum = 32U;
mcanCfgParams->msgRAMConfig.txFIFOSize = 0U;
mcanCfgParams->msgRAMConfig.txBufMode = 0U;
mcanCfgParams->msgRAMConfig.txEventFIFOSize = 0U;
mcanCfgParams->msgRAMConfig.txEventFIFOWaterMark = 0U;
// FIFO0 and FIFO1 are not used
mcanCfgParams->msgRAMConfig.rxFIFO0size = 64U;
mcanCfgParams->msgRAMConfig.rxFIFO0OpMode = 0U;
mcanCfgParams->msgRAMConfig.rxFIFO0waterMark = 0U;
mcanCfgParams->msgRAMConfig.rxFIFO1size = 64U;
mcanCfgParams->msgRAMConfig.rxFIFO1waterMark = 0U;
mcanCfgParams->msgRAMConfig.rxFIFO1OpMode = 0U;
mcanCfgParams->eccConfig.enable = 1U;
mcanCfgParams->eccConfig.enableChk = 1U;
mcanCfgParams->eccConfig.enableRdModWr = 1U;
/*
Simplify Interrupts for Debug:
Temporarily set mcanCfgParams->errInterruptEnable = 0U; while debugging reception.
Re-enable it later and ensure MCANAppErrStatusCallback handles errors correctly (clears flags).*/
mcanCfgParams->errInterruptEnable = 1U;
mcanCfgParams->dataInterruptEnable = 1U;
mcanCfgParams->appErrCallBack = MCANAppErrStatusCallback;
mcanCfgParams->appDataCallBack = MCANAppCallback;
}
/**************************************************************************
*************************** CAN Driver Initialize Function ***********************
**************************************************************************/
void Can_Initialize(void)
{
int32_t errCode = 0;
int32_t retVal = 0;
CANFD_MCANInitParams mcanCfgParams;
CANFD_MCANBitTimingParams mcanBitTimingParams;
gTxDoneFlag = 0;
gRxDoneFlag = 0;
/* Setup the PINMUX to bring out the XWR68xx CANFD pins. */
//Enable CAN transciever AOP
// D3 RS-6843AOPC: There is an enable signal on the CAN transceiver that is connected to ball C2 on the IWR6843AOP.
// * PINE15_PADAG functionality
// * Equivalent to PINC2_PADAG on XWR68XXAOP Device
Pinmux_Set_Pull(SOC_XWR68XX_PINE15_PADAG, PINMUX_PULLDOWN_EN);
// Set TX pin
// D3 RS-6843AOPC: CAN TX is on ball D1 of the IWR6843AOP.
// * PINE14_PADAE functionality
// * Equivalent to PIND1_PADAE on XWR68XXAOP Device
Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR68XX_PINE14_PADAE, SOC_XWR68XX_PINE14_PADAE_CANFD_TX);
// Set RX pin
// D3 RS-6843AOPC: RX is on E2.
// * PINF14_PADAJ functionality
// * Equivalent to PINE2_PADAJ on XWR68XXAOP Device
Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR68XX_PINF14_PADAJ, SOC_XWR68XX_PINF14_PADAJ_CANFD_RX);
/* Configure the divide value for MCAN source clock */
SOC_setPeripheralClock(gMmwMCB.socHandle, SOC_MODULE_MCAN, SOC_CLKSOURCE_VCLK, 4U, &errCode);
/* Initialize peripheral memory */
SOC_initPeripheralRam(gMmwMCB.socHandle, SOC_MODULE_MCAN, &errCode);
CSL_FINSR(0x43201450, 22, 22, 0x1U);
CSL_FINSR(0x4320140C, 26, 16, 0x23U);
MCANAppInitParams (&mcanCfgParams);
/* Initialize the CANFD 0 driver */
canHandle = CANFD_init(0, &mcanCfgParams, &errCode);
if (canHandle == NULL)
{
CLI_write ("Error: CANFD Module Initialization failed [Error code %d]\n", errCode);
return;
}
/* Configuring 1Mbps and 1Mbps as nominal and data bit-rate respectively
* Bit Rate = CAN_CLK / (k(PHSEG1 + PROPSEG + PHSEG2 + 1) * BRP)
Prop seg: 8
Ph seg 1: 6
Ph Seg2 : 5
Sync jump: 1
BRP(Baud rate Prescaler): 2
Nominal Bit rate = (40)/(((8+6+5)+1)*BRP) = 1Mhz
Timing Params for Data Bit rate:
Prop seg: 1
Ph seg 1: 1
Ph Seg2 : 1
Sync jump: 1
BRP(Baud rate Prescaler): 2
Data Bit rate = (40)/(((1+1+1)+1)*BRP) = 5Mhz
*/
mcanBitTimingParams.nomBrp = 0x2U;
mcanBitTimingParams.nomPropSeg = 0x8U;
mcanBitTimingParams.nomPseg1 = 0x6U;
mcanBitTimingParams.nomPseg2 = 0x5U;
mcanBitTimingParams.nomSjw = 0x1U;
mcanBitTimingParams.dataBrp = 0x2U;
mcanBitTimingParams.dataPropSeg = 0x1U;
mcanBitTimingParams.dataPseg1 = 0x1U;
mcanBitTimingParams.dataPseg2 = 0x1U;
mcanBitTimingParams.dataSjw = 0x1U;
/* Configure the CAN driver */
retVal = CANFD_configBitTime (canHandle, &mcanBitTimingParams, &errCode);
if (retVal < 0)
{
CLI_write ("Error: CANFD Module configure bit time failed [Error code %d]\n", errCode);
return ;
}
/* Setup the transmit message object */
txMsgObjectParams.direction = CANFD_Direction_TX;
txMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
txMsgObjectParams.msgIdentifier = 0xD1;
txMsgObjHandle = CANFD_createMsgObject (canHandle, &txMsgObjectParams, &errCode);
if (txMsgObjHandle == NULL)
{
CLI_write ("Error: CANFD create Tx message object failed [Error code %d]\n", errCode);
return ;
}
/* Setup the receive message object */
rxMsgObjectParams.direction = CANFD_Direction_RX;
rxMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
rxMsgObjectParams.msgIdentifier = 0xA1;
rxMsgObjHandle = CANFD_createMsgObject (canHandle, &rxMsgObjectParams, &errCode);
if (rxMsgObjHandle == NULL)
{
CLI_write ("Error: CANFD create Rx message object failed [Error code %d]\n", errCode);
return ;
}
CLI_write("Debug: CANFD Instance 0 Initialization was successful\n");
}It would be very useful to have assistence on investigating this issue OR to get a working example of CAN-FD TX and RX for the EVM or another.
Thank you