openpilot icon indicating copy to clipboard operation
openpilot copied to clipboard

comma 3X: switch to kernel driver for low level SPI comms

Open adeebshihadeh opened this issue 1 year ago • 4 comments

The comma 3X talks to its internal panda over SPI using the spidev driver. We want to move the low-level SPI transactions into the kernel for better performance and efficiency.

I already started this a while ago at panda/drivers/spi/.

Minimum requirements for this bounty:

  • Switch to the kernel driver for the panda Python library (panda/python/)
  • Make it interrupt driven (no busy waiting!)
  • Good auto loading + updating the driver
  • Better throughput than the existing panda SPI stack
    • for bonus points, you can patch the kernel to fix the SPI overhead. apparently tracking the "SPI stats" has a ton of overhead in our kernel version, and this was fixed in newer kernels.
  • Performance needs to be good enough to support https://github.com/commaai/openpilot/pull/34711
    • since the easiest way to validate may end up being to finish that move, there's an extra $250 on this bounty ($1k total) for finishing that up and merging it together

We'll be switching pandad in openpilot to Python soon, so no need to implement this for the C++ panda library (just the one in panda/python/).

adeebshihadeh avatar Feb 28 '25 19:02 adeebshihadeh

You cant use a comma 3(tici) for this I assume?

robin-reckmann avatar Mar 06 '25 11:03 robin-reckmann

You need a C3X, C3 has the panda connected via USB:

$ lsusb
Bus 001 Device 010: ID 3801:ddcc comma.ai panda

andiradulescu avatar Mar 06 '25 11:03 andiradulescu

You need a C3X, C3 has the panda connected via USB:

$ lsusb
Bus 001 Device 010: ID 3801:ddcc comma.ai panda

It's also connected over SPI actually, if you compile it with ENABLE_SPI=1 it should also be possible on tici

Beware that this hasn't been extensively tested for stability, so it's possible that you won't be able to hit the same clock speed reliably on a C3

robbederks avatar Mar 13 '25 11:03 robbederks

@robbederks Yep, I could confirm that SPI works on my C3, but only for frequencies below 33MHz.

robin-reckmann avatar Apr 08 '25 14:04 robin-reckmann

Thinking about doing this.

  • [ ] Kernel SPI protocol driver that handles low level async communication.
  • [ ] Update panda spi userspace code to eliminate the need for busy looping

jakethesnake420 avatar Aug 06 '25 11:08 jakethesnake420