doceme / py-spidev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"error return without exception set" then try to set cshigh to False.

oosavu opened this issue · comments

Raspberry PI Zero W.

Works good on Linux raspberrypi 4.19.75+ #1270 Tue Sep 24 18:38:54 BST 2019

Fails on Raspberry Pi OS (32-bit) Lite May 2020 (Release date:2020-05-27)

import spidev spi = spidev.SpiDev() spi.open(0, 1) spi.cshigh = False
image

I think the problem is here:

py-spidev/spidev_module.c

Lines 904 to 906 in a5d82b8

if (test != mode) {
return -1;
}

__spidev_set_mode returns -1 without calling PyErr_Set*, which is then returned by SpiDev_set_cshigh.

Running this test code:

#!/usr/bin/env python3
import spidev

spi = spidev.SpiDev()
spi.open(0, 0)

spi.cshigh = False

I see only these relevant syscalls in strace:

openat(AT_FDCWD, "/dev/spidev0.0", O_RDWR|O_LARGEFILE) = 3
ioctl(3, SPI_IOC_RD_MODE, 0xbea7c23f)   = 0
ioctl(3, SPI_IOC_RD_BITS_PER_WORD, 0xbea7c23f) = 0
ioctl(3, SPI_IOC_RD_MAX_SPEED_HZ, 0xbea7c248) = 0
ioctl(3, SPI_IOC_WR_MODE, 0xbea7d1d7)   = 0
ioctl(3, SPI_IOC_RD_MODE, 0xbea7d1db)   = 0

So because none of the ioctl calls fail, I have to assume that the attempt to set the SPI_CS_HIGH bit was refused by the kernel driver. So test, the readback value, didn't match mode, the value attempted to be set.

cshigh in fact is True by default because if you print(device.cshigh) you'll get a True, however I'm having a low-active behavior:

DS0003

Why is this?

The SPI standard is that chip select should default to active-low. There are however a handful of chips that use active-high, so a general driver has to support that possibility.

Isn't this a 1-line fix? Why is it still open?