TI中文支持网
TI专业的中文技术问题搜集分享网站

在AWR1642评估板上测试CAN-FD,能发送数据,不能接收数据

在AWR1642评估板上运行mmwave_automotive_toolbox_2_7_1\labs\lab0005_object_data_over_can例程,使用周立功的USB2CAN转换器和上位机软件,基于此例程测试CAN-FD发送和接收数据,能向上位机软件发送数据,但不能接收到上位机软件发送的数据。

软件代码如下:

/*CAN-FD发送接收测试主函数*/

int main (void)
{
Task_Params taskParams;
int32_t errCode;
SOC_Cfg socCfg;

/* Initialize the ESM: */
ESM_init(0U); //dont clear errors as TI RTOS does it

/* Initialize and populate the demo MCB */
memset ((void*)&gMmwMssMCB, 0, sizeof(MmwDemo_MCB));

/* Initialize the SOC confiugration: */
memset ((void *)&socCfg, 0, sizeof(SOC_Cfg));

/* Populate the SOC configuration: */
socCfg.clockCfg = SOC_SysClock_INIT;

/* Initialize the SOC Module: This is done as soon as the application is started
* to ensure that the MPU is correctly configured. */
gMmwMssMCB.socHandle = SOC_init (&socCfg, &errCode);
if (gMmwMssMCB.socHandle == NULL)
{
System_printf ("Error: SOC Module Initialization failed [Error code %d]\n", errCode);
return -1;
}

/* Initialize the DEMO configuration: */
gMmwMssMCB.cfg.sysClockFrequency = MSS_SYS_VCLK;
gMmwMssMCB.cfg.loggingBaudRate = 921600;
gMmwMssMCB.cfg.commandBaudRate = 115200;

/* Check if the SOC is a secure device */
if (SOC_isSecureDevice(gMmwMssMCB.socHandle, &errCode))
{
/* Disable firewall for JTAG and LOGGER (UART) which is needed by the demo */
SOC_controlSecureFirewall(gMmwMssMCB.socHandle, (uint32_t)(SOC_SECURE_FIREWALL_JTAG | SOC_SECURE_FIREWALL_LOGGER),
SOC_SECURE_FIREWALL_DISABLE,
&errCode);
}
/* Debug Message: */
System_printf ("**********************************************\n");
System_printf ("Debug: Launching the Millimeter Wave Demo\n");
System_printf ("**********************************************\n");

/* Initialize the Task Parameters. */

// Task_Params_init(&taskParams);void MmwDemo_mssInitTask(void)
{
int32_t errCode;
MMWave_InitCfg initCfg;
UART_Params uartParams;
Task_Params taskParams;
Semaphore_Params semParams;
Mailbox_Config mboxCfg;
Error_Block eb;

/* Debug Message: */
System_printf("Debug: MMWDemoMSS Launched the Initialization Task\n");

/*****************************************************************************
* Initialize the mmWave SDK components:
*****************************************************************************/
/* Pinmux setting */

/* Setup the PINMUX to bring out the UART-1 */
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINN5_PADBE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR16XX_PINN5_PADBE, SOC_XWR16XX_PINN5_PADBE_MSS_UARTA_TX);
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINN4_PADBD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR16XX_PINN4_PADBD, SOC_XWR16XX_PINN4_PADBD_MSS_UARTA_RX);

/* Setup the PINMUX to bring out the UART-3 */
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR16XX_PINF14_PADAJ, SOC_XWR16XX_PINF14_PADAJ_MSS_UARTB_TX);

/* Setup the PINMUX to bring out the DSS UART */
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINP8_PADBM, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR16XX_PINP8_PADBM, SOC_XWR16XX_PINP8_PADBM_DSS_UART_TX);

Can_Initialize();////CAN接口初始化
#if 1
/* Initialize the UART */
UART_init();

/* Initialize the GPIO */
GPIO_init();
/* Initialize the Mailbox */
Mailbox_init(MAILBOX_TYPE_MSS);

/*****************************************************************************
* Open & configure the drivers:
*****************************************************************************/

/* Setup the default UART Parameters */
UART_Params_init(&uartParams);
uartParams.clockFrequency = gMmwMssMCB.cfg.sysClockFrequency;
uartParams.baudRate = gMmwMssMCB.cfg.commandBaudRate;
uartParams.isPinMuxDone = 1U;

/* Open the UART Instance */
gMmwMssMCB.commandUartHandle = UART_open(0, &uartParams);
if (gMmwMssMCB.commandUartHandle == NULL)
{
System_printf("Error: MMWDemoMSS Unable to open the Command UART Instance\n");
return;
}

/* Setup the default UART Parameters */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.clockFrequency = gMmwMssMCB.cfg.sysClockFrequency;
uartParams.baudRate = gMmwMssMCB.cfg.loggingBaudRate;
uartParams.isPinMuxDone = 1U;

/* Open the Logging UART Instance: */
gMmwMssMCB.loggingUartHandle = UART_open(1, &uartParams);
if (gMmwMssMCB.loggingUartHandle == NULL)
{
System_printf("Error: MMWDemoMSS Unable to open the Logging UART Instance\n");
return;
}

/* Create a binary semaphore which is used to handle GPIO switch interrupt. */
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
gMmwMssMCB.gpioSemHandle = Semaphore_create(0, &semParams, NULL);

/*****************************************************************************
* Creating communication channel between MSS & DSS
*****************************************************************************/

/* Create a binary semaphore which is used to handle mailbox interrupt. */
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
gMmwMssMCB.mboxSemHandle = Semaphore_create(0, &semParams, NULL);

/* Setup the default mailbox configuration */
Mailbox_Config_init(&mboxCfg);

/* Setup the configuration: */
mboxCfg.chType = MAILBOX_CHTYPE_MULTI;
mboxCfg.chId = MAILBOX_CH_ID_0;
mboxCfg.writeMode = MAILBOX_MODE_BLOCKING;
mboxCfg.readMode = MAILBOX_MODE_CALLBACK;
mboxCfg.readCallback = &MmwDemo_mboxCallback;

/* Initialization of Mailbox Virtual Channel */
gMmwMssMCB.peerMailbox = Mailbox_open(MAILBOX_TYPE_DSS, &mboxCfg, &errCode);
if (gMmwMssMCB.peerMailbox == NULL)
{
/* Error: Unable to open the mailbox */
System_printf("Error: Unable to open the Mailbox to the DSS [Error code %d]\n", errCode);
return;
}

/* Create task to handle mailbox messges */
Task_Params_init(&taskParams);
taskParams.stackSize = 16*1024;
#endif
////Task_create(MmwDemo_mboxReadTask, &taskParams, NULL);////20191204 屏蔽掉从mailbox中发送数据
System_printf("WFZHED: MMWDemoMSS Initialization Task is OK\n");
// taskParams.priority = 3;
// taskParams.stackSize = 2*1024;
////Task_create(MmwDemo_mssInitTask, &taskParams, NULL);
MmwDemo_mssInitTask();
////Can_Initialize();////CAN接口初始化
/*循环发送CLASSIC类型数据*/
while(1)
{
if(gRxDoneFlag==1)
{
Can_Transmit_Schedu();

}

}
/* Start BIOS */
BIOS_start();
return 0;
}

}

/*CAN-FD发送接收测试,Can_Initialize函数*/

void Can_Initialize(void)
{
int32_t errCode = 0;
int32_t retVal = 0;
// int32_t j = 0;
//CANFD_OptionTLV optionTLV;
CANFD_MCANInitParams mcanCfgParams;
CANFD_MCANBitTimingParams mcanBitTimingParams;
#if 0
CANFD_MCANMsgObjectStats msgObjStats;
CANFD_MCANErrCntStatus errCounter;
CANFD_MCANProtocolStatus protoStatus;
#endif
CANFD_MCANMsgObjCfgParams rxMsgObjectParams;
CANFD_MsgObjHandle rxMsgObjHandle[2];
gTxDoneFlag = 0;
gRxDoneFlag = 0;

/* Setup the PINMUX to bring out the XWR16xx CAN pins 配置管脚功能*/
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR16XX_PINE14_PADAE, SOC_XWR16XX_PINE14_PADAE_CANFD_TX);

Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR16XX_PIND13_PADAD, SOC_XWR16XX_PIND13_PADAD_CANFD_RX);

/* Configure the divide value for MCAN source clock */
SOC_setPeripheralClock(gMmwMssMCB.socHandle, SOC_MODULE_MCAN, SOC_CLKSOURCE_VCLK, 4U, &errCode);

/* Initialize peripheral memory */
SOC_initPeripheralRam(gMmwMssMCB.socHandle, SOC_MODULE_MCAN, &errCode);
CSL_FINSR(0x43201450, 22, 22, 0x1U);
CSL_FINSR(0x4320140C, 26, 16, 0x23U);
MCANAppInitParams (&mcanCfgParams);///OK

/* Initialize the CANFD driver */
canHandle = CANFD_init(&mcanCfgParams, &errCode);
if (canHandle == NULL)
{
System_printf ("Error: CANFD Module Initialization failed [Error code %d]\n", errCode);
return ;
}

/* Configuring 1Mbps and 5Mbps as nominal and data bit-rate respectively
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: 2
Ph seg 1: 2
Ph Seg2 : 3
Sync jump: 1
BRP(Baud rate Prescaler): 1

Nominal Bit rate = (40)/(((2+2+3)+1)*BRP) = 5Mhz
*/
#if 1
/*1000Kbps NomBitRate: (40)/(((8+6+5)+1)*2)*/
mcanBitTimingParams.nomBrp = 0x2U;
mcanBitTimingParams.nomPropSeg = 0x8U;
mcanBitTimingParams.nomPseg1 = 0x6U;
mcanBitTimingParams.nomPseg2 = 0x5U;
mcanBitTimingParams.nomSjw = 0x1U;
#else
/*500Kbps NomBitRate: (40)/(((6+5+4)+1)*5)*/
mcanBitTimingParams.nomBrp = 0x5U;
mcanBitTimingParams.nomPropSeg = 0x6U;
mcanBitTimingParams.nomPseg1 = 0x5U;
mcanBitTimingParams.nomPseg2 = 0x4U;
mcanBitTimingParams.nomSjw = 0x1U;
#endif

#if 1 //1 Mbps
mcanBitTimingParams.dataBrp = 0x2U;//0x1U;
mcanBitTimingParams.dataPropSeg = 0x8U;//0x2U;
mcanBitTimingParams.dataPseg1 = 0x6U;//0x2U;
mcanBitTimingParams.dataPseg2 = 0x5U;//0x3U;
mcanBitTimingParams.dataSjw = 0x1U;
#else //5 Mbps
mcanBitTimingParams.dataBrp = 0x1U;
mcanBitTimingParams.dataPropSeg = 0x2U;
mcanBitTimingParams.dataPseg1 = 0x2U;
mcanBitTimingParams.dataPseg2 = 0x3U;
mcanBitTimingParams.dataSjw = 0x1U;

#endif
/* Configure the CAN driver */
retVal = CANFD_configBitTime (canHandle, &mcanBitTimingParams, &errCode);
if (retVal < 0)
{
System_printf ("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_11_BIT;////CANFD_MCANXidType_29_BIT;
txMsgObjectParams.msgIdentifier = 0xD1;

txMsgObjHandle = CANFD_createMsgObject (canHandle, &txMsgObjectParams, &errCode);
if (txMsgObjHandle == NULL)
{
System_printf ("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_11_BIT;//CANFD_MCANXidType_29_BIT;
rxMsgObjectParams.msgIdentifier = 0xFF;

rxMsgObjHandle[0] = CANFD_createMsgObject (canHandle, &rxMsgObjectParams, &errCode);
if (rxMsgObjHandle[0] == NULL)
{
System_printf ("Error: CANFD create Rx message object failed [Error code %d]\n", errCode);
return ;
}
/*
rxMsgObjectParams.direction = CANFD_Direction_RX;
rxMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
rxMsgObjectParams.msgIdentifier = 0xA2;

rxMsgObjHandle[1] = CANFD_createMsgObject (canHandle, &rxMsgObjectParams, &errCode);
if (rxMsgObjHandle[1] == NULL)
{
System_printf ("Error: CANFD create Rx message object failed [Error code %d]\n", errCode);
return ;
}
*/
System_printf ("wfzhed: Can_Initialize IS OK\n");
}

/*CAN-FD发送接收测试,MCANAppInitParams函数*/
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;
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;
mcanCfgParams->filterConfig.rrfe = 0x1U;
mcanCfgParams->filterConfig.rrfs = 0x1U;
mcanCfgParams->filterConfig.anfe = 0x1U;
mcanCfgParams->filterConfig.anfs = 0x1U;
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;
mcanCfgParams->msgRAMConfig.rxFIFO0size = 0U;
mcanCfgParams->msgRAMConfig.rxFIFO0OpMode = 0U;
mcanCfgParams->msgRAMConfig.rxFIFO0waterMark = 0U;
mcanCfgParams->msgRAMConfig.rxFIFO1size = 64U;
mcanCfgParams->msgRAMConfig.rxFIFO1waterMark = 64U;////20191206
mcanCfgParams->msgRAMConfig.rxFIFO1OpMode = 1U;////20191206

mcanCfgParams->eccConfig.enable = 1;
mcanCfgParams->eccConfig.enableChk = 1;
mcanCfgParams->eccConfig.enableRdModWr = 1;

mcanCfgParams->errInterruptEnable = 1U;
mcanCfgParams->dataInterruptEnable = 1U;
mcanCfgParams->appErrCallBack = MCANAppErrStatusCallback;
mcanCfgParams->appDataCallBack = MCANAppCallback;
}

WFZHED2019:

此测试是在CAN-FD上跑普通的CAN协议,使用CAN-FD的软件驱动,设置为普通的CAN工作模式。

Annie Liu:

回复 WFZHED2019:

为更加有效地解决您的问题,我们建议您将问题发布在E2E英文技术论坛上https://e2e.ti.com/support/sensors/f/1023,将由资深的工程师为您提供帮助。我们的E2E英文社区有TI专家进行回复,并得到全球各地工程师的支持,分享他们的知识和经验。

赞(0)
未经允许不得转载:TI中文支持网 » 在AWR1642评估板上测试CAN-FD,能发送数据,不能接收数据
分享到: 更多 (0)