-
Notifications
You must be signed in to change notification settings - Fork 13
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
RP2040 spi-baud! doesn't look right #84
Comments
I have confirmed that it indeed does have an integer overflow - thanks for
catching this!
Travis
…On Mon, Jan 8, 2024, 10:17 Paul Koning ***@***.***> wrote:
I was thinking about the RP2040 rules for the SPI clock, and looked at the
logic in spi.fs. It looks strange and doesn't seem to work right.
The natural thing to do would be to divide the system clock by the desired
SPI clock, rounded up, and then use that as the divisor. For slow SPI
clocks that doesn't quite work because there are two dividers (7 and 8 bits
respectively). So I see there is code to calculate the "prescaler" first,
then the second divider from that.
But find-spi-prescaler doesn't work right. If I ask it for the prescaler
for 20 MHz it tells me 4, which is an ok answer. But if I change sysclk to
120 MHz and ask it that same question I should get 2 or 6 but I still get 4
instead, and find-spi-postdiv gives 4 for a SPI clock of 15 MHz rather than
20. It turns out the reason is that find-spi-prescaler gets a 32 bit
overflow so it doesn't find 2 as a valid prescale.
I'm curious why the code works the way it does.
—
Reply to this email directly, view it on GitHub
<#84>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDMC2GLB2EWIQTCVRBQNHLYNQLXZAVCNFSM6AAAAABBRWU5KWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3TANZZGIYDMOI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I have fixed this issue, and the fix is now in the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was thinking about the RP2040 rules for the SPI clock, and looked at the logic in spi.fs. It looks strange and doesn't seem to work right.
The natural thing to do would be to divide the system clock by the desired SPI clock, rounded up, and then use that as the divisor. For slow SPI clocks that doesn't quite work because there are two dividers (7 and 8 bits respectively). So I see there is code to calculate the "prescaler" first, then the second divider from that.
But find-spi-prescaler doesn't work right. If I ask it for the prescaler for 20 MHz it tells me 4, which is an ok answer. But if I change sysclk to 120 MHz and ask it that same question I should get 2 or 6 but I still get 4 instead, and find-spi-postdiv gives 2 for a SPI clock of 15 MHz (120 MHz / 8) rather than 20. It turns out the reason is that find-spi-prescaler gets a 32 bit overflow so it doesn't find 2 as a valid prescale.
I'm curious why the code works the way it does.
The text was updated successfully, but these errors were encountered: