fix(st16): mutex usage while FreeRTOS not running prevented firmware boot (#6946)
Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
This commit is contained in:
co-authored by
Peter Feerick
parent
5ac865294f
commit
83a253d687
@@ -35,8 +35,9 @@
|
||||
struct stm32_i2c_device {
|
||||
I2C_HandleTypeDef handle;
|
||||
const stm32_i2c_hw_def_t* hw_def;
|
||||
#if !defined(BOOT) && !defined(RADIO_PA01)
|
||||
#if !defined(BOOT)
|
||||
mutex_handle_t mutex;
|
||||
bool mutex_initialized;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -54,8 +55,16 @@ static I2C_HandleTypeDef* i2c_get_handle(uint8_t bus)
|
||||
return &_i2c_devs[bus].handle;
|
||||
}
|
||||
|
||||
#if !defined(BOOT) && !defined(RADIO_PA01)
|
||||
#define I2CMutex(bus) MutexLock mutexLock = MutexLock::MakeInstance(&i2c_get_device(bus)->mutex)
|
||||
#if !defined(BOOT)
|
||||
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
|
||||
@@ -525,8 +534,8 @@ int stm32_i2c_init(uint8_t bus, uint32_t clock_rate, const stm32_i2c_hw_def_t* h
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOT) && !defined(RADIO_PA01)
|
||||
mutex_create(&dev->mutex);
|
||||
#if !defined(BOOT)
|
||||
dev->mutex_initialized = false;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user