drivers: spi: spi_rpi_pico_pio: Byte order is incorrect #72954
Labels
area: SPI
SPI bus
bug
The issue is a bug, or the PR is fixing a bug
platform: Raspberry Pi Pico
Raspberry Pi Pico (RPi Pico)
priority: low
Low impact/importance bug
Describe the bug
The PIO-based SPI driver for the Raspberry Pi Pico (and the RP2040 in general) sends data out the SPI bus in the wrong byte order when SPI_WORD_SET() is 16 or 32 bits, and reverses the byte order of the input data. Data is passed to the SPI driver (tx buffer) in the byte order intended for transmission. However, the little-endian PIO SPI driver treats the data as 16- or 32-bit integers, loading the data into the transmit FIFO in the reverse of the correct order and not correcting the reversed data in the receive FIFO.
To Reproduce
Steps to reproduce the behavior:
west build -p auto -b rpi_pico
Observed behavior
The command to read the TEST_CONFIG register should be 0x8F000008, but is sent on the bus as 0x08 0x00 0x00 0x8F. The input line receives 0xE0 0x00 0x00 0x8B, but the status message delivered to the application is 0x8B0000E0. The TMAG5170 driver repeats the attempt to read the TEST_CONFIG register, never leaving the driver's init function.
Expected behavior
The data should be transmitted in the order provided, regardless of the CPU byte order: 0x8F 0x00 0x00 0x08, and the received data should be placed in the rx buffer in the order expected: 0xE0 0x00 0x00 0x8B.
Impact
The PIO SPI driver cannot operate correctly in either SPI_WORD_SET(16) or SPI_WORD_SET(32) configurations.
Logs and console output
Data as exchanged on the SPI bus (first two 32-bit exchanges):
Environment (please complete the following information):
Additional context
boards/rpi_pico.overlay used to build sample:
TMAG5170 connections to RPI Pico:
The text was updated successfully, but these errors were encountered: