← index #11082Issue #7404
Related · high · value 2.385
QUERY · ISSUE

RP2 SPI: Instantiating with spi=None does not behave sensibly.

openby peterhinchopened 2023-03-20updated 2024-09-02
bugport-rp2

The constructor accepts None as an arg to miso, but still instantiates the default pin.

The clear intent is to create an output-only interface. Either it should reject the arg or (preferably) it should not instantiate a pin. Current behaviour can lead to unexpected pin conflicts.

This should also apply to mosi.

CANDIDATE · ISSUE

esp32: Hardware SPI class initialiser doesn't support None for unused signals

closedby jonathanhoggopened 2021-06-16updated 2021-06-17
port-esp32

I'm using hardware SPI on ESP32 without the sck or miso signals (both interfaces). When initialising the peripheral, this is an error:

spi = SPI(1, baudrate=1000000, sck=None, mosi=Pin(12), miso=None)

because you're not allowed to specify None for the sck and miso parameters.

However this is A-OK:

spi = SPI(1)
spi.init(baudrate=1000000, sck=None, mosi=Pin(12), miso=None)

and does exactly what I want: internally the None is translated to a -1 signal specification for the spi_bus_config_t structure to indicate that the signal is not used.

The problem with the latter is that it grabs and initialises the default pins first before reconfiguring. I would prefer that SPI left these pins alone as I need them for other purposes and this forces me into a careful initialisation order dance to make sure my pins are all correct at the end.

It doesn't look like a big fix, so I'm happy to put in my own PR if there's agreement on aligning these APIs.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied