From b00a04a5aff78f026a3d8b1e7bd61608c8fe2ba8 Mon Sep 17 00:00:00 2001 From: bkleiner Date: Sat, 28 Oct 2023 18:24:14 +0200 Subject: [PATCH] spi: only check for dshot if we want dma --- src/driver/at32/spi.c | 4 ++-- src/driver/spi.c | 22 ++++++++++++---------- src/driver/stm32/spi.c | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/driver/at32/spi.c b/src/driver/at32/spi.c index 9874af702..a3b257c1f 100644 --- a/src/driver/at32/spi.c +++ b/src/driver/at32/spi.c @@ -8,7 +8,7 @@ extern void spi_enable_rcc(spi_ports_t port); extern void spi_csn_enable(spi_bus_device_t *bus); extern void spi_csn_disable(spi_bus_device_t *bus); -extern bool spi_txn_can_send(spi_bus_device_t *bus); +extern bool spi_txn_can_send(spi_bus_device_t *bus, bool dma); extern void spi_txn_finish(spi_bus_device_t *bus); const spi_port_def_t spi_port_defs[SPI_PORT_MAX] = { @@ -289,7 +289,7 @@ void spi_bus_device_init(spi_bus_device_t *bus) { void spi_seg_submit_wait_ex(spi_bus_device_t *bus, const spi_txn_segment_t *segs, const uint32_t count) { spi_txn_wait(bus); - while (!spi_txn_can_send(bus)) + while (!spi_txn_can_send(bus, true)) ; const spi_ports_t port = bus->port; diff --git a/src/driver/spi.c b/src/driver/spi.c index 83d5dbbe3..ff8fb4c74 100644 --- a/src/driver/spi.c +++ b/src/driver/spi.c @@ -31,14 +31,6 @@ void spi_bus_device_reconfigure(spi_bus_device_t *bus, spi_mode_t mode, uint32_t } uint8_t spi_dma_is_ready(spi_ports_t port) { -#if defined(STM32F4) && defined(USE_MOTOR_DSHOT) - if (target.brushless && port == SPI_PORT1) { - extern volatile int dshot_dma_phase; - if (dshot_dma_phase != 0) { - return 0; - } - } -#endif return dma_transfer_done[port]; } @@ -59,11 +51,21 @@ bool spi_txn_ready(spi_bus_device_t *bus) { return bus->txn_head == bus->txn_tail; } -bool spi_txn_can_send(spi_bus_device_t *bus) { +bool spi_txn_can_send(spi_bus_device_t *bus, bool dma) { if (!spi_dma_is_ready(bus->port)) { return false; } +#if defined(STM32F4) && defined(USE_MOTOR_DSHOT) + extern volatile int dshot_dma_phase; + if (dma && + target.brushless && + bus->port == SPI_PORT1 && + dshot_dma_phase != 0) { + return false; + } +#endif + volatile spi_port_config_t *config = &spi_port_config[bus->port]; if (config->active_device != NULL && config->active_device != bus) { return false; @@ -82,7 +84,7 @@ void spi_txn_continue(spi_bus_device_t *bus) { return; } - if (!spi_txn_can_send(bus)) { + if (!spi_txn_can_send(bus, true)) { return; } diff --git a/src/driver/stm32/spi.c b/src/driver/stm32/spi.c index 67edf2e64..76050a2ee 100644 --- a/src/driver/stm32/spi.c +++ b/src/driver/stm32/spi.c @@ -8,7 +8,7 @@ extern void spi_enable_rcc(spi_ports_t port); extern void spi_csn_enable(spi_bus_device_t *bus); extern void spi_csn_disable(spi_bus_device_t *bus); -extern bool spi_txn_can_send(spi_bus_device_t *bus); +extern bool spi_txn_can_send(spi_bus_device_t *bus, bool dma); extern void spi_txn_finish(spi_bus_device_t *bus); const spi_port_def_t spi_port_defs[SPI_PORT_MAX] = { @@ -324,7 +324,7 @@ void spi_bus_device_init(spi_bus_device_t *bus) { void spi_seg_submit_wait_ex(spi_bus_device_t *bus, const spi_txn_segment_t *segs, const uint32_t count) { spi_txn_wait(bus); - while (!spi_txn_can_send(bus)) + while (!spi_txn_can_send(bus, false)) ; const spi_ports_t port = bus->port;