Category: General LinuxCNC Questions
Current Situation and Probrem
I am trying to establish stable SPI communication between a Raspberry Pi 4 and an ICE40UP5K FPGA (IceShield) using LinuxCNC and the RIO framework.
While basic SPI communication seems functional outside of LinuxCNC, I am currently encountering unexpected behavior during runtime: the system consistently logs "WRONG DATA" with "HXHP" as the received header.
My goal is to understand what SPI response LinuxCNC expects from the FPGA, and how to configure both ends to ensure correct communication.
Environment
- Raspberry Pi 4
- LinuxCNC version: 2.9.4 (same behavior also observed in 2.9.3 and 2.8.4)
- OS: Official LinuxCNC 2.9.4 Raspberry Pi 4 Bookworm image
- FPGA: ICE40UP5K-SG48I (IceShield)
- Clock source: Since gpio is not available on Bookworm, I use pigpiod to generate a 5 MHz clock on GPIO 4:
#!/bin/bash sudo pigpiod pigs hc 4 5000000
I also modified spiflash.sh to work with pigpiod under Bookworm
FPGA Status
- The Verilog design (rio.v) is written to return the SPI response header "data" (0x64617461)
- The FPGA’s LED is blinking and SPI data is returned via external tools. This suggests the FPGA is operating correctly with the supplied clock.
SPI Test Using Python
To confirm basic SPI functionality outside of LinuxCNC, I used this script:
import spidev
import time
SPI_BUS = 0
SPI_DEVICE = 0
SPI_SPEED_HZ = 25000 # 25 kHz
spi = spidev.SpiDev()
spi.open(SPI_BUS, SPI_DEVICE)
spi.max_speed_hz = SPI_SPEED_HZ
spi.mode = 0b00
try:
print("Sending dummy byte 0x00 to read response...")
result = spi.xfer2([0x00] * 8)
print("Received:", " ".join(f"0x{b:02X}" for b in result))
finally:
spi.close()This consistently returns "data" from the FPGA, suggesting that low-level SPI transport is functioning properly.
Behavior in LinuxCNC
- In the rio_readwrite() function, logging shows the SPI response always begins with "0:02" (0x30 0x3A 0x30 0x32)
- However, the LinuxCNC log reports "WRONG DATA" with the string "HXHP" (0x48 0x58 0x48 0x50)
- I did not find any logic in the Verilog code that would return "HXHP"
- I suspect that "HXHP" is generated internally by LinuxCNC when an unrecognized or malformed header is received
Observations
- SPI communication appears to be working, and the FPGA is returning a response
- However, there may be a mismatch between the header format LinuxCNC expects and what the FPGA sends
- LinuxCNC may be replacing the unrecognized header with "HXHP" as a default or fallback
Questions
- Where in the LinuxCNC source is "HXHP" generated or substituted? Is this a fallback response?
- Is the "0:02" sequence a standard header sent by LinuxCNC under the RIO configuration?
- What header or message structure (e.g. MSGID) is LinuxCNC expecting from the FPGA?
- Are there documented or example SPI response formats compatible with riocomp?
I would appreciate any advice or clarification.
I can provide Verilog and riocomp.c sources if helpful. Thank you.