You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More drastically in https://github.com/Microchip-MPLAB-Harmony/csp/blob/f6814f5b3f60f7743dad711b866c929169dc0037/peripheral/can_u2003/templates/plib_can.c.ftl#L238C14-L238C14 we copy data from register buffer to rx buffer object. Let's assume in MCC we configured FiFo size to hold the maximum of 64 Data Bytes (there is a dropdown for that for Rx and Tx Fifos in MCC). In that case MCC declares macro #define CAN0_RX_FIFO0_ELEMENT_SIZE 72U (which sounds reasonable for 4 Byte Id + 4 Bytes Misc + 64 Bytes Data; too lazy to check with datasheet, as this is not the point I am making) which means we copy 72 Bytes of data in a struct that is only 16 Bytes of size, causing overflow and therefore undefined behaviour.
Possible ways forward:
Increase data length to constant 64 Bytes --> wastes memory for all of us that only want to use 8 Byte maximum, but easily implemented
Configure data length according to user selection in MCC --> probably most elegant solution
Keep in mind I might have overlook some consequences.
The text was updated successfully, but these errors were encountered:
Title states the problem. We can only send and receive data using
bool CAN0_MessageTransmitFifo(uint8_t numberOfMessage, CAN_TX_BUFFER *txBuffer);
or
bool CAN0_MessageReceiveFifo(CAN_RX_FIFO_NUM rxFifoNum, uint8_t numberOfMessage, CAN_RX_BUFFER *rxBuffer);
respectively. However in https://github.com/Microchip-MPLAB-Harmony/csp/blob/f6814f5b3f60f7743dad711b866c929169dc0037/peripheral/can_u2003/templates/plib_can_common.h.ftl#L370C3-L370C3 it is hardcoded that both rx and tx buffer objects only contain a maximum of 8 data bytes.
More drastically in https://github.com/Microchip-MPLAB-Harmony/csp/blob/f6814f5b3f60f7743dad711b866c929169dc0037/peripheral/can_u2003/templates/plib_can.c.ftl#L238C14-L238C14 we copy data from register buffer to rx buffer object. Let's assume in MCC we configured FiFo size to hold the maximum of 64 Data Bytes (there is a dropdown for that for Rx and Tx Fifos in MCC). In that case MCC declares macro
#define CAN0_RX_FIFO0_ELEMENT_SIZE 72U
(which sounds reasonable for 4 Byte Id + 4 Bytes Misc + 64 Bytes Data; too lazy to check with datasheet, as this is not the point I am making) which means we copy 72 Bytes of data in a struct that is only 16 Bytes of size, causing overflow and therefore undefined behaviour.Possible ways forward:
Keep in mind I might have overlook some consequences.
The text was updated successfully, but these errors were encountered: