Skip to content

Commit 6d4a0cd

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 6d4a0cd

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
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: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ osThreadAttr_t _main_thread_attr;
3636
MBED_ALIGN(8) char _main_stack[MBED_CONF_APP_MAIN_STACK_SIZE];
3737
mbed_rtos_storage_thread_t _main_obj __attribute__((section(".bss.os.thread.cb")));
3838

39-
osMutexId_t singleton_mutex_id;
39+
osMutexId_t singleton_mutex_id;
4040
mbed_rtos_storage_mutex_t singleton_mutex_obj;
41-
osMutexAttr_t singleton_mutex_attr;
41+
const osMutexAttr_t singleton_mutex_attr = {
42+
.name = "singleton_mutex",
43+
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
44+
.cb_size = sizeof(singleton_mutex_obj),
45+
.cb_mem = &singleton_mutex_obj
46+
};
4247

4348
void mbed_rtos_init()
4449
{
@@ -47,11 +52,6 @@ void mbed_rtos_init()
4752

4853
MBED_NORETURN void mbed_rtos_start()
4954
{
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-
5555
_main_thread_attr.stack_mem = _main_stack;
5656
_main_thread_attr.stack_size = sizeof(_main_stack);
5757
_main_thread_attr.cb_size = sizeof(_main_obj);
@@ -68,7 +68,6 @@ MBED_NORETURN void mbed_rtos_start()
6868
tfm_ns_lock_init();
6969
#endif // defined(TARGET_TFM) && defined(COMPONENT_NSPE)
7070

71-
singleton_mutex_id = osMutexNew(&singleton_mutex_attr);
7271
osThreadId_t result = osThreadNew((osThreadFunc_t)mbed_start, NULL, &_main_thread_attr);
7372
if ((void *)result == NULL) {
7473
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Pre main thread not created", &_main_thread_attr);
@@ -77,3 +76,8 @@ MBED_NORETURN void mbed_rtos_start()
7776
osKernelStart();
7877
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Failed to start RTOS");
7978
}
79+
80+
void mbed_rtos_init_singleton_mutex(void)
81+
{
82+
singleton_mutex_id = osMutexNew(&singleton_mutex_attr);
83+
}

0 commit comments

Comments
 (0)