Skip to content

STM32 CAN: Make data() return correct length slice #4109

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

Merged
merged 3 commits into from
Apr 27, 2025

Conversation

adamgreig
Copy link
Contributor

Currently data() always returns an 8- or 64-byte slice, even though the actual CAN frame contains less data. The remaining bytes will be zero, so the user must check the frame DLC to see how many bytes were actually sent by the remote end. With this change the slice is the same length as was transmitted, with no extra bytes.

Additionally removed the ClassicData::MAX_DATA_LEN constant because almost all instances were using a hardcoded 8 anyway, and the FdData only ever uses 64 and doesn't have an equivalent MAX_DATA_LEN. Happy to make everything use MAX_DATA_LEN instead if that's preferred.

Finally fixed a missing cfg gate on a defmt call that broke the build on G4 without defmt feature.

@Dirbaio Dirbaio added this pull request to the merge queue Apr 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 18, 2025
@Dirbaio
Copy link
Member

Dirbaio commented Apr 18, 2025

seems HIL tests are failing

@adamgreig
Copy link
Contributor Author

Oops, missed that data() was being used internally in a way that assumed it was always 8 bytes long. Fixed.

@cschuhen cschuhen mentioned this pull request Apr 27, 2025
@cschuhen
Copy link

Hi guys, I saw this PR was stuck for a week. I've pushed a fix as #4137 . In it I just make raw_data public.

@github-merge-queue github-merge-queue bot merged commit 17d3ada into embassy-rs:main Apr 27, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants