Skip to content

Conversation

@gagarinlg
Copy link
Member

this fixes the ST16 boot issues and adds a correct fix for the PA01 boot issues we had
This has to go into 2.12 and 3.0

…t a good idea. Locking is now skipped, when FreeRTOS is not yet initilized.
@gagarinlg gagarinlg added this to the 2.12.0 milestone Jan 4, 2026
@pfeerick pfeerick changed the title fix ST16 startup issues fix(st16): mutex usage while FreeRTOS not running prevented firmware boot Jan 5, 2026
@pfeerick pfeerick added the bug/regression ↩️ A new version of EdgeTX broke something label Jan 5, 2026
@pfeerick
Copy link
Member

pfeerick commented Jan 5, 2026

adds a correct fix for the PA01 boot issues we had

The issue from #6793 has been reinstated... the boot time animation thinks the battery is flat, vs nightly which correctly indicates it to be fully charged.

Reinstating this restores expected behaviour.

diff --git a/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp b/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp
index 2a8ae2b569..eb85702313 100644
--- a/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp
+++ b/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp
@@ -35,7 +35,7 @@
 struct stm32_i2c_device {
   I2C_HandleTypeDef handle;
   const stm32_i2c_hw_def_t* hw_def;
-#if !defined(BOOT)
+#if !defined(BOOT) && !defined(RADIO_PA01)
   mutex_handle_t mutex;
 #endif
 };
@@ -54,7 +54,7 @@ static I2C_HandleTypeDef* i2c_get_handle(uint8_t bus)
   return &_i2c_devs[bus].handle;
 }
 
-#if !defined(BOOT)
+#if !defined(BOOT) && !defined(RADIO_PA01)
 #define I2CMutex(bus) MutexLock mutexLock = MutexLock::MakeInstance(&i2c_get_device(bus)->mutex)
 #else
 #define I2CMutex(bus)
@@ -525,7 +525,7 @@ int stm32_i2c_init(uint8_t bus, uint32_t clock_rate, const stm32_i2c_hw_def_t* h
   }
 #endif
 
-#if !defined(BOOT)
+#if !defined(BOOT) && !defined(RADIO_PA01)
   mutex_create(&dev->mutex);
 #endif
   return 1;

@pfeerick
Copy link
Member

pfeerick commented Jan 5, 2026

This seems to work (only tested on ST16 and PA01):

diff --git a/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp b/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp
index 2a8ae2b569..ad4f0e16ac 100644
--- a/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp
+++ b/radio/src/targets/common/arm/stm32/stm32_i2c_driver.cpp
@@ -37,6 +37,7 @@ struct stm32_i2c_device {
   const stm32_i2c_hw_def_t* hw_def;
 #if !defined(BOOT)
   mutex_handle_t mutex;
+  bool mutex_initialized;
 #endif
 };
 
@@ -55,7 +56,15 @@ static I2C_HandleTypeDef* i2c_get_handle(uint8_t bus)
 }
 
 #if !defined(BOOT)
-#define I2CMutex(bus) MutexLock mutexLock = MutexLock::MakeInstance(&i2c_get_device(bus)->mutex)
+static void i2c_ensure_mutex(stm32_i2c_device* dev)
+{
+  if (!dev->mutex_initialized && scheduler_is_running()) {
+    mutex_create(&dev->mutex);
+    dev->mutex_initialized = true;
+  }
+}
+
+#define I2CMutex(bus) i2c_ensure_mutex(i2c_get_device(bus)); MutexLock mutexLock = MutexLock::MakeInstance(&i2c_get_device(bus)->mutex)
 #else
 #define I2CMutex(bus)
 #endif
@@ -526,7 +535,7 @@ int stm32_i2c_init(uint8_t bus, uint32_t clock_rate, const stm32_i2c_hw_def_t* h
 #endif
 
 #if !defined(BOOT)
-  mutex_create(&dev->mutex);
+  dev->mutex_initialized = false;
 #endif
   return 1;
 }

@gagarinlg
Copy link
Member Author

Hmm, mutex creation should be OK at that point in time.
But when your solution works, I am happy with it

@pfeerick
Copy link
Member

pfeerick commented Jan 7, 2026

Booted up ST16 and PA01 with PR firmware, seems ok. TX16S booting normally also ;)

@pfeerick pfeerick merged commit 83a253d into main Jan 7, 2026
48 checks passed
@pfeerick pfeerick deleted the fix_ST16_boot branch January 7, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug/regression ↩️ A new version of EdgeTX broke something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants