-
-
Notifications
You must be signed in to change notification settings - Fork 457
fix(st16): mutex usage while FreeRTOS not running prevented firmware boot #6946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…t a good idea. Locking is now skipped, when FreeRTOS is not yet initilized.
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; |
|
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;
} |
|
Hmm, mutex creation should be OK at that point in time. |
|
Booted up ST16 and PA01 with PR firmware, seems ok. TX16S booting normally also ;) |
…boot (#6946) Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
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