SwiftyGPIO icon indicating copy to clipboard operation
SwiftyGPIO copied to clipboard

SPI fails on 32-bit Zero

Open barretpj opened this issue 5 years ago • 2 comments

Board Type

Raspberry Pi Zero W

Operating System

Raspberry Pi OS Lite Linux raspberrypi 5.4.51+ #1327 Thu Jul 23 10:53:06 BST 2020 armv6l GNU/Linux

Swift Version

Pre-built from https://github.com/uraimo/buildSwiftOnARM/releases/download/5.1.5/swift-5.1.5-armv6-RPi01234-RaspbianBuster.tgz

Description

SPI calls fail with "Message too long" regardless of the length of message.

On investigation it's because struct spi_ioc_transfer uses UnsafeMutableRawPointer for tx_buf and rx_buf, but /usr/include/linux/spi/spidev.h defines these pointers as __u64

If I add 32 bits of padding after these 2 members in to struct spi_ioc_transfer the SPI calls succeed.

barretpj avatar Aug 12 '20 15:08 barretpj

From testing various versions, this bugs seem introduced in v 1.1.15. Version. 1.1.14 seems ok.

gestrich avatar Aug 16 '20 15:08 gestrich

Thanks @barretpj @gestrich, exactly, 1.1.15 introduced this change that broke it and the fix is converting to an uint64 via bitpattern (that actually adds a padding at the beginning if necessary), will fix/test it as soon as I can get a hold of a pi.

uraimo avatar Sep 01 '20 20:09 uraimo