Skip to content

Commit 14bde89

Browse files
committed
ST boards: Fix sleep tracing
Prevent singleton lock if the RTOS is not yet ready. lp_ticker is used during the RTOS initialization process. ST lp_ticker implementation calls sleep functions which in turn attempts to print to the console when sleep tracing is enabled. Console initialization attempts to lock the singleton mutex.
1 parent 9a8c9e2 commit 14bde89

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

rtos/source/TARGET_CORTEX/mbed_boot.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@
6464
#include "mbed_error.h"
6565
#include "mbed_mpu_mgmt.h"
6666

67+
6768
int main(void);
6869
static void mbed_cpy_nvic(void);
70+
void mbed_rtos_init_singleton_mutex(void);
6971

7072
/* Stack limits */
7173
unsigned char *mbed_stack_isr_start = 0;
@@ -94,6 +96,7 @@ void mbed_init(void)
9496

9597
void mbed_start(void)
9698
{
99+
mbed_rtos_init_singleton_mutex();
97100
mbed_toolchain_init();
98101
mbed_tfm_init();
99102
mbed_main();

rtos/source/TARGET_CORTEX/mbed_rtos_rtx.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ mbed_rtos_storage_thread_t _main_obj __attribute__((section(".bss.os.thread.cb")
3838

3939
osMutexId_t singleton_mutex_id;
4040
mbed_rtos_storage_mutex_t singleton_mutex_obj;
41-
osMutexAttr_t singleton_mutex_attr;
4241

4342
void mbed_rtos_init()
4443
{
@@ -47,11 +46,6 @@ void mbed_rtos_init()
4746

4847
MBED_NORETURN void mbed_rtos_start()
4948
{
50-
singleton_mutex_attr.name = "singleton_mutex";
51-
singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
52-
singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj);
53-
singleton_mutex_attr.cb_mem = &singleton_mutex_obj;
54-
5549
_main_thread_attr.stack_mem = _main_stack;
5650
_main_thread_attr.stack_size = sizeof(_main_stack);
5751
_main_thread_attr.cb_size = sizeof(_main_obj);
@@ -68,7 +62,6 @@ MBED_NORETURN void mbed_rtos_start()
6862
tfm_ns_lock_init();
6963
#endif // defined(TARGET_TFM) && defined(COMPONENT_NSPE)
7064

71-
singleton_mutex_id = osMutexNew(&singleton_mutex_attr);
7265
osThreadId_t result = osThreadNew((osThreadFunc_t)mbed_start, NULL, &_main_thread_attr);
7366
if ((void *)result == NULL) {
7467
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Pre main thread not created", &_main_thread_attr);
@@ -77,3 +70,14 @@ MBED_NORETURN void mbed_rtos_start()
7770
osKernelStart();
7871
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Failed to start RTOS");
7972
}
73+
74+
void mbed_rtos_init_singleton_mutex(void)
75+
{
76+
const osMutexAttr_t singleton_mutex_attr = {
77+
.name = "singleton_mutex",
78+
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
79+
.cb_size = sizeof(singleton_mutex_obj),
80+
.cb_mem = &singleton_mutex_obj
81+
};
82+
singleton_mutex_id = osMutexNew(&singleton_mutex_attr);
83+
}

0 commit comments

Comments
 (0)