Curious about Raspberry Pi 4B SPI speed

More
15 Apr 2024 02:26 #298266 by rdtsc
Hello, looking at the SPI speed between the Pi and a Mesa 7C80 host, Bookworm 12 iso.  The manual has little to say about SPI speed:  www.raspberrypi.com/documentation/comput...erry-pi.html#speed-2

If the `xxd` tool is added, this can be run to see the current speed:  xxd -pd /sys/class/spidev/spidev0.0/device/of_node/spi-max-frequency
In my case it returns 0x07735940 which is 125MHz.  Seems pretty fast already.

Is the SPI speed solely controlled by the app, or can we tweak it somehow?

Please Log in or Create an account to join the conversation.

More
15 Apr 2024 03:06 #298268 by cornholio
The RPi4 spi driver doesn't use the spidev device, it's not quite up to realtime usage. Linuxcnc unloads the driver used by the RPi4 and use it's own driver.

Here's some info
linuxcnc.org/docs/stable/html/man/man9/h...#SPI%20CLOCK%20RATES

Please Log in or Create an account to join the conversation.

More
26 Apr 2024 14:06 #299119 by rdtsc
Interesting, was unaware that drivers could be "shimmed" on-the-fly this way.

Ok so it looks like, to experiment with LinuxCNC SPI speed on Rpi4, something like this could be done to the .hal file:

loadrt hm2_rpspi config="num_encoders=0 num_pwmgens=0 num_stepgens=3" spiclk_rate=31250 spiclk_rate_rd=12500

Where the speeds are out of:
- 62500 - 62.500 MHz
- 41667 - 41.667 MHz
- 31250 - 31.250 MHz
- 25000 - 25.000 MHz
- 20834 - 20.833 MHz
- 17858 - 17.857 MHz
- 15625 - 15.625 MHz
- 13889 - 13.889 MHz
- 12500 - 12.500 MHz
- 11364 - 11.364 MHz
- 10417 - 10.417 MHz
- 9616 - 9.615 MHz

Please Log in or Create an account to join the conversation.

More
26 Apr 2024 14:44 #299121 by cornholio
The config is more to do with allocating the FPGA resources.

There’s actually 2 drivers involved, the hostmot2 driver which handles the “heavy lifting” and the hm2_xxxx driver which handles the physical communication.

With regards to the SPI speed just pick a speed that is reliable. There’s no need to get hung up on it.

It’s amazing what one learns when the docs are read. It’s also useful to read the manual for the card you are using as well.

Please Log in or Create an account to join the conversation.

Time to create page: 0.118 seconds
Powered by Kunena Forum