-
Notifications
You must be signed in to change notification settings - Fork 241
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
Turn off input_enable for ADC capable pins #755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the HW starts with this enabled by default, I’d keep it enabled for pins that are assumed digital by default.
We have a newtype wrapper for ADC pins that does turn of input enable & output disable.
That being said, the main thing I’m not fond of with this solution is that it makes a few pins behave differently "by default" which will cause surprise for sure.
So making all pins to turn off input-enabled and changing that when switching function seems acceptable to me too.
That doesn't solve the core issue: The ADC pins should have the input disabled by default. (See erratum RP2040-E6 in the datasheet.) Both the boot rom (since version RP2040B2) and the C SDK work around it by disabling input enable as soon as possible in the boot process. For pins actually configured as ADC pins, we already unset input enable.
That would be a valid alternative. Did anybody check what bootrom v2 and SDK do? |
So both clear input enable for pins 26-29 only. I agree with @ithinuel that it would be nice if all pins had the same startup config. But there's probably a reason that Raspberry only applied the workaround to these pins. Probably to minimize the probability of breaking changes. Does the same argument count for rp2040-hal? Most rust programs won't notice the difference as long as we implicitly set input enable when selecting a non-adc function on the pin. The C SDK can't be so sure as in C it's more likely that firmware accesses registers directly, without using helper functions. But it's still possible to break existing software, even if it uses the methods provided by rp2040-hal: For example, PIO can read all pins independent of pin function settings. So it is possible that a firmware (intentionally or unintentionally) doesn't assign a pin to the PIO peripheral, but still reads the input value from a PIO state machine. |
@ithinuel @jonathanpallant How shall we progress with this pull request? As I understand it, switching the ADC pins to "input disabled" early in the boot process is desirable for stability reasons, otherwise they wouldn't have made that change in the C SDK. The open question is if we should apply that change to the ADC pins only (which minimizes impact on existing users which may somehow rely on the previous behavior), or if we prefer consistency and apply the change to all input pins, as @ithinuel suggested. I would agree with both approaches, so if both of you agree that it should be applied to all pins, I'll update the pull request accordingly. |
I would make the change to all pins, add a clear note to the CHANGELOG, and make it a breaking change. |
I just wrote a small on-target-test, checking that the inputs are really disabled on boot. |
ee34974
to
6279f2b
Compare
Looks good but had no time to actually test it. |
This is meant to fix #754.
Not yet tested at all!Tested using on-target-tests.