From c0c3680fe652a1c7ab6ab11738ec32b1f1c4a367 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Tue, 24 Sep 2019 10:23:10 +0200 Subject: [PATCH] Bluetooth detection issue on QX7 (some samples, after bootloader) --- .../common/arm/stm32/bluetooth_driver.cpp | 18 +++++++++++------- .../common/arm/stm32/bootloader/CMakeLists.txt | 7 +++++++ .../common/arm/stm32/bootloader/boot.cpp | 4 ++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp index 2a9e0848b..1d861e1d6 100644 --- a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp +++ b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp @@ -20,6 +20,7 @@ #include "opentx.h" +#if !defined(BOOT) Fifo btTxFifo; Fifo btRxFifo; @@ -42,6 +43,7 @@ enum BluetoothWriteState }; volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE; +#endif void bluetoothInit(uint32_t baudrate, bool enable) { @@ -65,6 +67,7 @@ void bluetoothInit(uint32_t baudrate, bool enable) GPIO_Init(BT_BCTS_GPIO, &GPIO_InitStructure); #endif +#if !defined(BOOT) GPIO_PinAFConfig(BT_USART_GPIO, BT_TX_GPIO_PinSource, BT_GPIO_AF); GPIO_PinAFConfig(BT_USART_GPIO, BT_RX_GPIO_PinSource, BT_GPIO_AF); @@ -90,17 +93,17 @@ void bluetoothInit(uint32_t baudrate, bool enable) bluetoothWriteState = BLUETOOTH_WRITE_IDLE; - if (enable) { - GPIO_ResetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); - } - else { - GPIO_SetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); - } - btRxFifo.clear(); btTxFifo.clear(); +#endif + + if (enable) + GPIO_ResetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); + else + GPIO_SetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); } +#if !defined(BOOT) void bluetoothDisable() { GPIO_SetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // close bluetooth (recent modules will go to bootloader mode) @@ -165,3 +168,4 @@ uint8_t bluetoothIsWriting(void) { return bluetoothWriteState != BLUETOOTH_WRITE_IDLE; } +#endif // !BOOT diff --git a/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt b/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt index 4141a766e..58b6b57f7 100644 --- a/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt +++ b/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt @@ -92,6 +92,13 @@ if(PCB STREQUAL X12S OR PCB STREQUAL X10 OR PCB STREQUAL X9E OR (PCB STREQUAL X9 ) endif() +if(PCB STREQUAL X7 OR PCB STREQUAL XLITE) + set(BOOTLOADER_SRC + ${BOOTLOADER_SRC} + ../../../../../targets/common/arm/stm32/bluetooth_driver.cpp + ) +endif() + if(NOT (PCB STREQUAL X10 OR PCB STREQUAL X12S)) set(BOOTLOADER_SRC ${BOOTLOADER_SRC} diff --git a/radio/src/targets/common/arm/stm32/bootloader/boot.cpp b/radio/src/targets/common/arm/stm32/bootloader/boot.cpp index e5adcd545..762f39253 100644 --- a/radio/src/targets/common/arm/stm32/bootloader/boot.cpp +++ b/radio/src/targets/common/arm/stm32/bootloader/boot.cpp @@ -245,6 +245,10 @@ int main() backlightInit(); backlightEnable(); +#if defined(PCBX7) || defined(PCBXLITE) + bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE, false); +#endif + #if defined(PCBTARANIS) i2cInit(); #endif