When miso=None is set, the default miso pin changed state.
Port, board and/or hardware
Raspberry Pi Pico W
MicroPython version
MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico W with RP2040
Reproduction
RS = Pin(16, Pin.OUT)
spi = SPI(0,
baudrate=400000,
polarity=0,
phase=0,
bits=8,
firstbit=SPI.MSB,
sck=Pin(18),
mosi=Pin(19),
miso=None)
RS.value(0)
time.sleep_ms(1)
RS.value(1)
Expected behaviour
Expected to set up SPI without MISO, set the RS pin value to 0, and after 1 ms, set the RS pin value to 1.
Observed behaviour
The SPI was set up correctly, but the RS pin's value never changed.
Additional Information
If I set up the pin after initializing SPI, it works as expected, the used pin 16 is default pin for miso. I think this bug is on other types of RPIs Pico.
Code of Conduct
Yes, I agree
Default SPI pins incorrect according to SDK and datasheets for pico and pico w
When creating a default SPI0 instance, the default MOSI, MISO, and SCK pins do not reflect any datasheets nor the C/C++ SDK for the pico and pico w.
I'm new to embedded development, but not to software development in general. Embarrassingly, it took me longer than it should have to figure out why machine.SPI(0) was not communicating on the GPIOs specified in the datasheet.
Observation:
>>> import machine
>>> machine.SPI(0)
SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=6, mosi=7, miso=4)
SDKs v1.4.0:
Both clearly outline default SPI0 as SCK=18, MOSI=19, and MISO=16
pico SDK permalink: pico-sdk/src/boards/include/boards/pico.h
pico w SDK permalink: pico-sdk/src/boards/include/boards/pico_w.h
Documentations:
Raspberry Pi Pico Datasheet
Raspberry Pi Pico W Datasheet
Issue:
The issue arises from the hardcoded pin values here: https://github.com/micropython/micropython/blob/6f4d424f461bede1afb69637763f4fce5f27cd90/ports/rp2/machine_spi.c#L42-L46
Suggested fix
Possibly move default pins into board configuration files:
https://github.com/micropython/micropython/blob/6f4d424f461bede1afb69637763f4fce5f27cd90/ports/rp2/boards/PICO/mpconfigboard.h
https://github.com/micropython/micropython/blob/6f4d424f461bede1afb69637763f4fce5f27cd90/ports/rp2/boards/PICO_W/mpconfigboard.h
Firmware:
Using UF2: unstable-v1.19.1-240 nightly build from https://micropython.org/download/rp2-pico-w/
From REPL: MicroPython v1.19.1 on 2022-08-05; Raspberry Pi Pico W with RP2040