diff --git a/src/main/drivers/accgyro/accgyro_mpu.c b/src/main/drivers/accgyro/accgyro_mpu.c index 66ec254b8..bc9da88be 100644 --- a/src/main/drivers/accgyro/accgyro_mpu.c +++ b/src/main/drivers/accgyro/accgyro_mpu.c @@ -228,6 +228,12 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro, const gyro gyro->bus.bustype = BUSTYPE_SPI; spiBusSetInstance(&gyro->bus, spiInstanceByDevice(SPI_CFG_TO_DEV(config->spiBus))); + + // SPI instance may be NULL if the bus is non-existent + if (!gyro->bus.busdev_u.spi.instance) { + return false; + } + gyro->bus.busdev_u.spi.csnPin = IOGetByTag(config->csnTag); IOInit(gyro->bus.busdev_u.spi.csnPin, OWNER_GYRO_CS, RESOURCE_INDEX(config->index)); IOConfigGPIO(gyro->bus.busdev_u.spi.csnPin, SPI_IO_CS_CFG); diff --git a/src/main/drivers/bus_spi.c b/src/main/drivers/bus_spi.c index 4645d8e3b..d93f2bc19 100644 --- a/src/main/drivers/bus_spi.c +++ b/src/main/drivers/bus_spi.c @@ -62,7 +62,7 @@ SPIDevice spiDeviceByInstance(SPI_TypeDef *instance) SPI_TypeDef *spiInstanceByDevice(SPIDevice device) { - if (device >= SPIDEV_COUNT) { + if (device == SPIINVALID || device >= SPIDEV_COUNT) { return NULL; } diff --git a/src/main/drivers/bus_spi_ll.c b/src/main/drivers/bus_spi_ll.c index 41cf4579b..99c4db819 100644 --- a/src/main/drivers/bus_spi_ll.c +++ b/src/main/drivers/bus_spi_ll.c @@ -76,6 +76,10 @@ void spiInitDevice(SPIDevice device) { spiDevice_t *spi = &(spiDevice[device]); + if (!spi->dev) { + return; + } + #ifdef SDCARD_SPI_INSTANCE if (spi->dev == SDCARD_SPI_INSTANCE) { spi->leadingEdge = true; diff --git a/src/main/drivers/bus_spi_stdperiph.c b/src/main/drivers/bus_spi_stdperiph.c index 86bdb86e5..f2626a854 100644 --- a/src/main/drivers/bus_spi_stdperiph.c +++ b/src/main/drivers/bus_spi_stdperiph.c @@ -37,6 +37,10 @@ void spiInitDevice(SPIDevice device) { spiDevice_t *spi = &(spiDevice[device]); + if (!spi->dev) { + return; + } + #ifdef SDCARD_SPI_INSTANCE if (spi->dev == SDCARD_SPI_INSTANCE) { spi->leadingEdge = true; diff --git a/src/main/target/STM32F7X2/target.h b/src/main/target/STM32F7X2/target.h index b1415742d..82d055089 100644 --- a/src/main/target/STM32F7X2/target.h +++ b/src/main/target/STM32F7X2/target.h @@ -45,13 +45,13 @@ #define USE_GYRO_SPI_MPU6500 // Other USE_ACCs and USE_GYROs should follow -#define GYRO_1_SPI_INSTANCE SPI1 +#define GYRO_1_SPI_INSTANCE NULL #define GYRO_1_CS_PIN NONE #define GYRO_1_ALIGN ALIGN_DEFAULT #define ACC_1_ALIGN ALIGN_DEFAULT #define GYRO_1_EXTI_PIN PB15 // XXX Should be gone -#define GYRO_2_SPI_INSTANCE SPI1 +#define GYRO_2_SPI_INSTANCE NULL #define GYRO_2_CS_PIN NONE #define GYRO_2_ALIGN ALIGN_DEFAULT #define ACC_2_ALIGN ALIGN_DEFAULT