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

Fix unexpected ADC behavior due to uninitialized data being sent over SPI #14

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

rtzoeller
Copy link

Zero-initialize the buffer used for ADC reads, as the buffer is always written over the wire as part of the SPI transaction. In unlucky circumstances the uninitialized buffer would encode a valid command, resetting the device or triggering other undesired behavior.

Note that uint8_t buffer[s] = {0}; won't work due to the variable-length of the array.

@rtzoeller
Copy link
Author

I've put this up against the develop branch, but I'm happy to retarget or duplicate it against main if desired.

The conditions for this to cause an issue seem to be fairly application and device specific; I've reliably hit it with an STM32H7 in one application, but never hit it with an STM32L0 in another. It's UB regardless, so it'd be nice to see it fixed.

@nerdyscout
Copy link
Owner

thank you for contributing.

never have seen this issue, but totally agree to fix it.

@nerdyscout nerdyscout closed this Mar 25, 2024
@nerdyscout nerdyscout reopened this Mar 25, 2024
@nerdyscout nerdyscout merged commit 6d937c6 into nerdyscout:develop Mar 25, 2024
5 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants