fix: CC1101 init hangs the ESP32-S3 when the radio is enabled

Init() starts the SPI bus and resets the chip, then every register write
calls SpiStart() again while the bus is still up.  SpiStart() ran pinMode()
on SCK, MOSI and MISO.  On Arduino 3.x that takes the pins from the SPI bus,
which stops it (spiStopBus) while SPIClass still holds the handle, so the
following SPI.begin() returns early and the bus stays down.

On the S3 the stopped bus also has clk_gate cleared, so spiTransferByte()
waits on cmd.usr forever and the task watchdog aborts async_tcp when the
radio settings are saved.  On the ESP32 the transfer completes on detached
pins, so the first register write (FSCTRL1) is silently lost.

SPI.begin() attaches and configures the bus pins itself, so on ESP32
targets SpiStart() now only sets SS, which the driver drives by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-24 20:53:10 +02:00
parent ea973809e2
commit 642cfd0c94

View file

@ -104,10 +104,19 @@ uint8_t PA_TABLE_915[10] {0x03,0x0E,0x1E,0x27,0x38,0x8E,0x84,0xCC,0xC3,0xC0,};
void ELECHOUSE_CC1101::SpiStart(void) void ELECHOUSE_CC1101::SpiStart(void)
{ {
// initialize the SPI pins // initialize the SPI pins
#ifdef ESP32
// ESPSomfy-RTS: SPI.begin() sets the bus pins up itself. Init() calls this
// again while the bus is running, and on Arduino 3.x a pinMode() on a pin
// the bus owns stops the bus while SPI.begin() still thinks it is up. The
// next transfer is lost on the ESP32 and hangs forever on the S3, whose
// stopped bus has no clock. SS is driven by hand, so it still needs one.
pinMode(SS_PIN, OUTPUT);
#else
pinMode(SCK_PIN, OUTPUT); pinMode(SCK_PIN, OUTPUT);
pinMode(MOSI_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT); pinMode(MISO_PIN, INPUT);
pinMode(SS_PIN, OUTPUT); pinMode(SS_PIN, OUTPUT);
#endif
// enable SPI // enable SPI
#ifdef ESP32 #ifdef ESP32