From 8560c1f6bf7961d8560c5e852dd7d9a7e336a476 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Mar 2023 03:07:56 +0200 Subject: [PATCH] fix: x10 Express boot freeze and bluetooth lockup (#3349) * Fix attempt for boot issue * fix: reset BT usart context after de-init --- radio/src/opentx.cpp | 2 ++ radio/src/storage/storage_common.cpp | 14 ++++++++++++-- .../targets/common/arm/stm32/bluetooth_driver.cpp | 1 + radio/src/tasks/mixer_task.cpp | 7 +++++++ radio/src/tasks/mixer_task.h | 4 ++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index c2d6e1536..e0780f05e 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1694,6 +1694,8 @@ int main() #endif boardInit(); + + modulePortInit(); pulsesInit(); checkValidMCU(); diff --git a/radio/src/storage/storage_common.cpp b/radio/src/storage/storage_common.cpp index b2ffc1e17..5ad366ea9 100644 --- a/radio/src/storage/storage_common.cpp +++ b/radio/src/storage/storage_common.cpp @@ -21,6 +21,7 @@ #include "opentx.h" #include "timers_driver.h" +#include "tasks/mixer_task.h" #if defined(USBJ_EX) #include "usb_joystick.h" @@ -60,7 +61,10 @@ void preModelLoad() logsClose(); #endif - pulsesStop(); + if (mixerTaskStarted()) { + pulsesStop(); + } + stopTrainer(); #if defined(COLORLCD) deleteCustomScreens(); @@ -182,7 +186,13 @@ void postModelLoad(bool alarms) PLAY_MODEL_NAME(); } #endif - pulsesStart(); + + // Mixer should only be restarted + // if we are switching between models, + // not on first boot (started later on) + if (mixerTaskStarted()) { + pulsesStart(); + } #if defined(SDCARD) referenceModelAudioFiles(); diff --git a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp index 8500d5142..8e1f44815 100644 --- a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp +++ b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp @@ -97,6 +97,7 @@ void bluetoothDisable() LL_GPIO_SetOutputPin(BT_EN_GPIO, BT_EN_GPIO_PIN); if (_bt_usart_ctx) { STM32SerialDriver.deinit(_bt_usart_ctx); + _bt_usart_ctx = nullptr; } } diff --git a/radio/src/tasks/mixer_task.cpp b/radio/src/tasks/mixer_task.cpp index 663428433..330e44977 100644 --- a/radio/src/tasks/mixer_task.cpp +++ b/radio/src/tasks/mixer_task.cpp @@ -35,6 +35,7 @@ static RTOS_MUTEX_HANDLE mixerMutex; // The mixer will start in 'paused' mode // and start working properly once // mixerTaskStart() has been called. +static bool _mixer_started = false; static bool _mixer_running = false; static bool _mixer_exit = false; @@ -61,8 +62,14 @@ void mixerTaskInit() MIXER_STACK_SIZE, MIXER_TASK_PRIO); } +bool mixerTaskStarted() +{ + return _mixer_started; +} + void mixerTaskStart() { + _mixer_started = true; _mixer_running = true; } diff --git a/radio/src/tasks/mixer_task.h b/radio/src/tasks/mixer_task.h index e371c6744..65c4e67b4 100644 --- a/radio/src/tasks/mixer_task.h +++ b/radio/src/tasks/mixer_task.h @@ -30,6 +30,10 @@ TASK_FUNCTION(mixerTask); // init, create and start the OS task itself void mixerTaskInit(); +// return true if the mixer has +// already started at least once since boot +bool mixerTaskStarted(); + // start the main computations // and pushing channels out //