Hello Minghong,
1. I found a problem in driver about this.
In the function FLEXCAN_DRV_ConfigRemoteResponseMb(), fields of cs are initilized:
/* Initialize transmit mb*/
cs.dataLen = tx_info->data_length;
cs.msgIdType = tx_info->msg_id_type;
cs.code = (uint32_t)FLEXCAN_RX_RANSWER;
#if FEATURE_CAN_HAS_FD
cs.fd_enable = false;
#endif
This function call sub function FLEXCAN_SetTxMsgBuff().
In the function FLEXCAN_SetTxMsgBuff(), fields used in cs are:
cs->enable_brs
cs->dataLen
cs->fd_padding
cs->msgIdType
cs->code
cs->fd_enable
So, there are 2 fields of cs weren't initialized yet: cs->enable_brs and cs->fd_padding, they can be assigned random values, this can lead to wrong result.
I raised a bug for this issue:
https://jira.sw.nxp.com/browse/ASDK-41394
2. As you said, The cast is used for casting a bytes buffer into an words buffer in order to optimize copying data to/from the message buffer.
Example:
const uint32_t * msgData_32 = (const uint32_t *)msgData;
It will copy number of bytes is multiple of 4.
for (databyte = 0; databyte < (cs->dataLen & ~3U); databyte += 4U)
{
FlexcanSwapBytesInWord(msgData_32[databyte >> 2U], flexcan_mb_data_32[databyte >> 2U]);
}
Then, copy number of remaining bytes.
for ( ; databyte < cs->dataLen; databyte++)
{
flexcan_mb_data[FlexcanSwapBytesInWordIndex(databyte)] = msgData[databyte];
}
So, I didn't see problem here.
Best regards,
Nhi