diff --git a/rtos/source/TARGET_CORTEX/mbed_boot.c b/rtos/source/TARGET_CORTEX/mbed_boot.c index 18f2410badb..495a5ee9a06 100644 --- a/rtos/source/TARGET_CORTEX/mbed_boot.c +++ b/rtos/source/TARGET_CORTEX/mbed_boot.c @@ -94,6 +94,7 @@ void mbed_init(void) void mbed_start(void) { + mbed_rtos_init_singleton_mutex(); mbed_toolchain_init(); mbed_tfm_init(); mbed_main(); diff --git a/rtos/source/TARGET_CORTEX/mbed_boot.h b/rtos/source/TARGET_CORTEX/mbed_boot.h index c963706717b..219168b2cfc 100644 --- a/rtos/source/TARGET_CORTEX/mbed_boot.h +++ b/rtos/source/TARGET_CORTEX/mbed_boot.h @@ -177,6 +177,14 @@ void mbed_tfm_init(void); */ void mbed_main(void); +/** + * Create and Initialize a Singleton Mutex object. + * + * Precondition(s): + * - The RTOS has been started by a call to mbed_rtos_start + */ +void mbed_rtos_init_singleton_mutex(void); + /**@}*/ /**@}*/ diff --git a/rtos/source/TARGET_CORTEX/mbed_rtos_rtx.c b/rtos/source/TARGET_CORTEX/mbed_rtos_rtx.c index 05e17969389..d8413d24d47 100644 --- a/rtos/source/TARGET_CORTEX/mbed_rtos_rtx.c +++ b/rtos/source/TARGET_CORTEX/mbed_rtos_rtx.c @@ -38,7 +38,6 @@ mbed_rtos_storage_thread_t _main_obj __attribute__((section(".bss.os.thread.cb") osMutexId_t singleton_mutex_id; mbed_rtos_storage_mutex_t singleton_mutex_obj; -osMutexAttr_t singleton_mutex_attr; void mbed_rtos_init() { @@ -47,11 +46,6 @@ void mbed_rtos_init() MBED_NORETURN void mbed_rtos_start() { - singleton_mutex_attr.name = "singleton_mutex"; - singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); - singleton_mutex_attr.cb_mem = &singleton_mutex_obj; - _main_thread_attr.stack_mem = _main_stack; _main_thread_attr.stack_size = sizeof(_main_stack); _main_thread_attr.cb_size = sizeof(_main_obj); @@ -68,7 +62,6 @@ MBED_NORETURN void mbed_rtos_start() tfm_ns_lock_init(); #endif // defined(TARGET_TFM) && defined(COMPONENT_NSPE) - singleton_mutex_id = osMutexNew(&singleton_mutex_attr); osThreadId_t result = osThreadNew((osThreadFunc_t)mbed_start, NULL, &_main_thread_attr); if ((void *)result == NULL) { 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() osKernelStart(); MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Failed to start RTOS"); } + +void mbed_rtos_init_singleton_mutex(void) +{ + const osMutexAttr_t singleton_mutex_attr = { + .name = "singleton_mutex", + .attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust, + .cb_size = sizeof(singleton_mutex_obj), + .cb_mem = &singleton_mutex_obj + }; + singleton_mutex_id = osMutexNew(&singleton_mutex_attr); +}