Skip to content

Fix always zero AnalogIn on nordic #9114

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 2 commits into from
Apr 1, 2024

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Mar 29, 2024

This is quite mysterious. The underlying code hasn't changed in quite a while. nordic AnalogIn.value was always returning zero on 9.x.x builds, including some early betas. The problem starts appearing when gcc13 starts being used. Compiling with gcc10 or gcc12 causes the problem to go away.

While debugging, I added a printf which also caused the problem to go away. Adding tiny delay calls almost anywhere also helped. Eventually I realized it may have been due to these calls acting as an optimization memory fence. Adding asm volatile("": : : "memory"); had the same effect. I'm not sure whether this is a compiler bug or something else, but the fix works.

Also removed the logic to start with value = -1, which didn't seem necessary.

@dhalbert dhalbert force-pushed the fix-nordic-analogin branch from d7df835 to 1821a7a Compare March 29, 2024 02:10
@dhalbert dhalbert force-pushed the fix-nordic-analogin branch from 1821a7a to 453c82c Compare March 29, 2024 02:26
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question

@dhalbert dhalbert requested a review from tannewt March 30, 2024 21:07
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

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