Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send and receive CAN FD Frames with more than 8 Bytes of data. #71

Open
abauske opened this issue Jan 5, 2024 · 0 comments
Open

Comments

@abauske
Copy link

abauske commented Jan 5, 2024

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:

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant