1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 22:35:23 +03:00

New SPI API supporting DMA

Call targetConfiguration() once before config is loaded and again afterwards in case the config needs to be changed to load from SD card etc

Drop SPI clock during binding

Remove debug

Add per device SPI DMA enable

Fix sdioPinConfigure() declaration warning

Reduce clock speed during SPI RX initialisation
This commit is contained in:
Steve Evans 2021-04-20 19:45:56 +01:00 committed by Michael Keller
parent 6d286e25f1
commit 87c8847c13
136 changed files with 3585 additions and 2721 deletions

View file

@ -208,40 +208,6 @@ static IO_t busSwitchResetPin = IO_NONE;
}
#endif
bool requiresSpiLeadingEdge(SPIDevice device)
{
#if defined(CONFIG_IN_SDCARD) || defined(CONFIG_IN_EXTERNAL_FLASH)
#if !defined(SDCARD_SPI_INSTANCE) && !defined(RX_SPI_INSTANCE)
UNUSED(device);
#endif
#if defined(SDCARD_SPI_INSTANCE)
if (device == spiDeviceByInstance(SDCARD_SPI_INSTANCE)) {
return true;
}
#endif
#if defined(RX_SPI_INSTANCE)
if (device == spiDeviceByInstance(RX_SPI_INSTANCE)) {
return true;
}
#endif
#else
#if !defined(USE_SDCARD) && !defined(USE_RX_SPI)
UNUSED(device);
#endif
#if defined(USE_SDCARD)
if (device == SPI_CFG_TO_DEV(sdcardConfig()->device)) {
return true;
}
#endif
#if defined(USE_RX_SPI)
if (device == SPI_CFG_TO_DEV(rxSpiConfig()->spibus)) {
return true;
}
#endif
#endif // CONFIG_IN_SDCARD || CONFIG_IN_EXTERNAL_FLASH
return false;
}
static void configureSPIAndQuadSPI(void)
{
@ -255,22 +221,22 @@ static void configureSPIAndQuadSPI(void)
spiPreinit();
#ifdef USE_SPI_DEVICE_1
spiInit(SPIDEV_1, requiresSpiLeadingEdge(SPIDEV_1));
spiInit(SPIDEV_1);
#endif
#ifdef USE_SPI_DEVICE_2
spiInit(SPIDEV_2, requiresSpiLeadingEdge(SPIDEV_2));
spiInit(SPIDEV_2);
#endif
#ifdef USE_SPI_DEVICE_3
spiInit(SPIDEV_3, requiresSpiLeadingEdge(SPIDEV_3));
spiInit(SPIDEV_3);
#endif
#ifdef USE_SPI_DEVICE_4
spiInit(SPIDEV_4, requiresSpiLeadingEdge(SPIDEV_4));
spiInit(SPIDEV_4);
#endif
#ifdef USE_SPI_DEVICE_5
spiInit(SPIDEV_5, requiresSpiLeadingEdge(SPIDEV_5));
spiInit(SPIDEV_5);
#endif
#ifdef USE_SPI_DEVICE_6
spiInit(SPIDEV_6, requiresSpiLeadingEdge(SPIDEV_6));
spiInit(SPIDEV_6);
#endif
#endif // USE_SPI
@ -318,6 +284,11 @@ void init(void)
detectHardwareRevision();
#endif
#if defined(USE_TARGET_CONFIG)
// Call once before the config is loaded for any target specific configuration required to support loading the config
targetConfiguration();
#endif
#ifdef USE_BRUSHED_ESC_AUTODETECT
// Opportunistically use the first motor pin of the default configuration for detection.
// We are doing this as with some boards, timing seems to be important, and the later detection will fail.
@ -362,10 +333,6 @@ void init(void)
pgResetAll();
#if defined(STM32H7) && defined(USE_SDCARD_SDIO) // H7 only for now, likely should be applied to F4/F7 too
sdioPinConfigure();
SDIO_GPIO_Init();
#endif
#ifdef USE_SDCARD_SPI
configureSPIAndQuadSPI();
initFlags |= SPI_AND_QSPI_INIT_ATTEMPTED;
@ -656,6 +623,10 @@ void init(void)
if (blackboxConfig()->device == BLACKBOX_DEVICE_FLASH) {
emfat_init_files();
}
#endif
// There's no more initialisation to be done, so enable DMA where possible for SPI
#ifdef USE_SPI
spiInitBusDMA();
#endif
if (mscStart() == 0) {
mscWaitForButton();
@ -1020,6 +991,11 @@ void init(void)
motorEnable();
#endif
#ifdef USE_SPI
// Attempt to enable DMA on all SPI busses
spiInitBusDMA();
#endif
swdPinsInit();
unusedPinsInit();