-
Notifications
You must be signed in to change notification settings - Fork 928
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
[WIP] Separate system clock config for rp2xxx devices #4674
Conversation
Thank you for the PR @cibomahto Can you please run /bin/sh: 1: node: not found
Unformatted:
src/machine/machine_rp2_2040.go
src/machine/machine_rp2_2350.go
make: *** [GNUmakefile:185: fmt-check] Error 1 |
@@ -113,6 +113,19 @@ const ( | |||
fnXIP pinFunc = 0 | |||
) | |||
|
|||
// System clock configuration | |||
const ( | |||
pllSysFreq uint32 = 125 * MHz |
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.
The rp2040 datasheet says that its cores are capable of 133 MHz. A cursory glance at the datasheet didn't mention any downside to that speed, so why is TinyGo running at 125 MHz? Perhaps it's because of non-integer periods that you mention in the PR description for rp2350? If so, this PR might consider rp2040 at 133 MHz for the same reasons you chose 150 MHz for rp2350.
Failing all that, a comment would be nice.
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.
That's a good point, I don't know why it was running at 125 either, but this seems plausible.
Changing out the xoscFreq constant for a package level variable feels off. I also don't understand what we gained from switching out the constant for a xoscFreq field on clockCfg. In any case the constants could remain in each board-level file and the variable be set in a single package level file. |
As is, the xoscFreq constant doesn't work- you need to configure the PLLs to match the xoscFreq setting, and they were hard-coded in the clock configuration routine. Otherwise, you won't get the correct CPU clock speed, or the PLL might not actually start. I guess some other options are:
In C-style apis, it's a common pattern to have default tables that you can pass to init routines, but I haven't been able to find something similar in TinyGo. The closest so far is for instance the SPI or I2C configuration objects (for example), but in this case the defaults are 'secret', and applied when fields are left at 0, which seems a little weird to me. |
Gentle ping from a nobody who looks forward to run my pico2 at 150MHz :) It seems to me dropping |
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.
My main gripe is preserving the clarity of the existing code. From what I can tell the actual changes to the logic of what is happening are:
- pllSysFreq, dependent on rp2350 vs rp2040
- pllSysPostDiv1, dependent on rp2350 vs rp2040
The way we express hardware/board dependent constants in tinygo are using constants guarded by build tags. This gives us clarity of hardware values which are constant throughout the life of the program. Even in the case where their conceptual value may vary we can still choose to express their default/startup value as a constant.
To implement these constants I'd suggest creating two constants inside src/machine/machine_rp2_2040.go and src/machine/machine_rp2_2350.go to express this hardware dependent variation.
// src/machine/machine_rp2_2040.go
const (
pllSysFreq = 125 * MHz
pllSysPostDiv1 = 6
)
// src/machine/machine_rp2_2350.go
const (
pllSysFreq = 150 * MHz
pllSysPostDiv1 = 5
)
And then use these values where they correspond.
Let me know if it is still unclear and I can try my hand at adding a commit here
@soypat That sounds good. Is there a mechanism that allows constants defined in machine-level files to be overridden by a board-level tag? Two notes:
|
No, however those could need to be
Seems reasonable.
That is however possibly a problem, since things like servos would malfunction. |
Note that some code, such as
Is there no way to work around these malfunctions? Does the frequency really have to be runtime configurable to avoid them? |
That's good insight! I'm confused by that code and comment. It seems like the function will work even if CPUFrequency() isn't constant, but just be somewhat inaccurate for short delays. It also seems confusing that it expects a function call to evaluate to a constant.
The scope of this commit is to allow rp2040 and rp2350 to run at different (fixed) clock speeds, and it wasn't intended to be run-time configurable. The PWM timing issue can be corrected by updating the rp2 PWM driver to work with these clock frequencies. |
* Addresses tinygo-org#4673: input oscillator frequency can be changed for an individual board by filling in a custom PLL configuration
586c88e
to
2ca264d
Compare
Note that I'm not familiar enough with the compiler to know, but: it's possible your |
This moves the clock definitions into the 2040 and 2350 machine files, and reverts them to constants. This also addresses tinygo-org#4673
I've checked in an updated version of this pull request, changing the clock configurations back to constants. The PWM generation is still a blocker, and since the performance gain from 125 to 150MHz isn't really significant, I'm no longer sure it's worth rewriting, so I'd be fine with dropping this change set. |
Closing this for now, if someone wants to take over please do. |
Addressed in #4723. |
Here is a first pass at separating the PLL configuration options for the rp2xxx devices, to allow the rp2350 to be configured for 150MHz. I tested (using a logic analyzer) that the UART, USB, I2C, and SPI generate roughly correct speeds.
I moved the configuration into the machine files, but it could be nice to allow a board to override them. If you have a suggestion for how to do that, please let me know.
I know of three issues that should be fixed before submitting the pull request:
cc @soypat @deadprogram