Skip to content

Commit 486ee37

Browse files
committed
machine/esp32: default SPI CS pin to NoPin when unset
SPIConfig.CS has a zero value of Pin(0) (GPIO0), but NoPin is Pin(0xff). When the user does not set CS, the SPI driver sees Pin(0) != NoPin and configures GPIO0 as the chip select output, hijacking whatever function that pin was serving such as a button interrupt. Default config.CS to NoPin when it is the zero value, so an omitted CS field correctly means "no hardware CS pin". Applied to both ESP32-S3 and ESP32-C3 SPI drivers. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 944176b commit 486ee37

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/machine/machine_esp32c3_spi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ func (spi *SPI) Configure(config SPIConfig) error {
137137
// configure SPI bus clock
138138
spi.Bus.CLOCK.Set(freqToClockDiv(config.Frequency))
139139

140+
// Default CS to NoPin so that an unset CS field (zero value = GPIO0)
141+
// does not accidentally configure GPIO0 as the chip select output.
142+
if config.CS == 0 {
143+
config.CS = NoPin
144+
}
145+
140146
// configure esp32c3 gpio pin matrix
141147
config.SDI.Configure(PinConfig{Mode: PinInput})
142148
inFunc(FSPIQ_IN_IDX).Set(esp.GPIO_FUNC_IN_SEL_CFG_SEL | uint32(config.SDI))

src/machine/machine_esp32s3_spi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func (spi *SPI) Configure(config SPIConfig) error {
6767
config.Frequency = SPI_DEFAULT_FREQUENCY
6868
}
6969

70+
// Default CS to NoPin so that an unset CS field (zero value = GPIO0)
71+
// does not accidentally configure GPIO0 as the chip select output.
72+
if config.CS == 0 {
73+
config.CS = NoPin
74+
}
75+
7076
switch spi.busID {
7177
case 2: // SPI2 (FSPI)
7278
if config.SCK == 0 {

0 commit comments

Comments
 (0)