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

RP2040 spi-baud! doesn't look right #84

Open
pkoning2 opened this issue Jan 8, 2024 · 2 comments
Open

RP2040 spi-baud! doesn't look right #84

pkoning2 opened this issue Jan 8, 2024 · 2 comments

Comments

@pkoning2
Copy link

pkoning2 commented Jan 8, 2024

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.

@tabemann
Copy link
Owner

tabemann commented Jan 8, 2024 via email

@tabemann
Copy link
Owner

tabemann commented Jan 9, 2024

I have fixed this issue, and the fix is now in the devel, master, and editor-devel (as I am working on a text editor named zeptoed, and it relies on SPI as it edits files in FAT32 filesystems on SDHC cards) branches.

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

No branches or pull requests

2 participants