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

Add on-chip voltage regulator (VREG) voltage setting function #757

Merged
merged 5 commits into from
Feb 28, 2024

Conversation

AkiyukiOkayasu
Copy link
Contributor

Added an on-chip voltage regulator voltage setting function.
Increasing core voltage may be necessary for overclocking. Implemented with reference to hardware_vreg in pico-sdk.

rp2040-hal/src/vreg.rs Outdated Show resolved Hide resolved
@AkiyukiOkayasu
Copy link
Contributor Author

PR sent to rp2040-pac.
When merged, I will again consider having a human-friendly function in HAL.

@AkiyukiOkayasu
Copy link
Contributor Author

The core voltage is now changed using VSEL_A, which was added in pac v0.6.0.
Also added a test for core voltage in on-target-test.

It is a trivial code, but I think it makes sense as a variation of the example and on-target-tests.

}

#[test]
fn change_onchip_regulator_voltage(state: &mut State) {
Copy link
Member

Choose a reason for hiding this comment

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

How do we know that this test works reliably on every device?
The datasheet says: "Note that RP2040 may not operate reliably with its digital core supply (DVDD) at a voltage other than 1.1V."
Perhaps this test should only cover a smaller range of voltages, eg. 1.05 - 1.15V?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my experience, I have set the core voltage to 1.2V on more than 50 RP2040s and have never had a problem. Also, in the thread about overclocking on the RP2040, there is no example of a failure to increase the core voltage.
However, this is not normal usage, there is no guarantee that it will work reliably on all RP2040s.

I noticed that with the default system clock, lowering the core voltage too much can cause problems. It should be a smaller test case range, as you mentioned. Especially in the direction of lowering the core voltage.
1.20V should be fine, so i'll reduce it to 1.05 - 1.20V.
If you are concerned, I would reduce it more. Reducing it is easy:)

Fix doc test for vreg_set_voltage()

Rename vreg_set/get_voltage() to set/get_voltage()
@AkiyukiOkayasu
Copy link
Contributor Author

Reduced test cases and improved documentation comments. And rebased commit log to tidy it up.

Copy link
Member

@ithinuel ithinuel left a comment

Choose a reason for hiding this comment

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

I'm ok with the change on the hal, but I have doubt about the tests.
I'm not sure they add any value. IE what would you expect to possibly fail ?

@AkiyukiOkayasu
Copy link
Contributor Author

As one might expect from the slope of this graph, 0.80V may not work at the default system clock frequency.
Screenshot 2024-02-26 at 16 15 39
https://forums.raspberrypi.com/viewtopic.php?t=301902&start=50#p1820686

However, the RP2040 C/C++ SDK has a minimum voltage of 0.85V, so 0.80V seems like an unusual value.
I tested at the default system clock frequency and 0.80V did not work. The 0.85V did work, but there is no guarantee that it will work with all RP2040s.

@ithinuel
Copy link
Member

What I mean is that the tests as implemented there do not provide anyproof that things are:

  • implemented correctly
  • actually work understress

Writing to and Reading from a register is trivial enough that I don’t think it requires an on-target tests.

For example, if there’s a possibility to actually verify that the voltage is applied as expected that would make a good test case.
EG, if the core voltage is exposed to an external pin that can easily be probed with an ADC, and the tests were to sample that value and check it matches the configuration, that would be great.

@AkiyukiOkayasu
Copy link
Contributor Author

@ithinuel

EG, if the core voltage is exposed to an external pin that can easily be probed with an ADC, and the tests were to sample that value and check it matches the configuration, that would be great.

With the Raspberry Pi Pico, that is impossible.
Unfortunately, it appears that the test has to be removed.

@jannic jannic merged commit deca3a5 into rp-rs:main Feb 28, 2024
6 checks passed
@jannic jannic mentioned this pull request Jun 12, 2024
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.

3 participants