diff --git a/libraries/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c b/libraries/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c index a5e63bcc30..19d48caaa4 100644 --- a/libraries/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c +++ b/libraries/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c @@ -547,18 +547,19 @@ osThreadId svcThreadCreate (osThreadDef_t *thread_def, void *argument) { U8 priority = thread_def->tpriority - osPriorityIdle + 1; P_TCB task_context = &thread_def->tcb; - /* If "size != 0" use a private user provided stack. */ + /* Utilize the user provided stack. */ task_context->stack = (U32*)thread_def->stack_pointer; task_context->priv_stack = thread_def->stacksize; - /* Pass parameter 'argv' to 'rt_init_context' */ - task_context->msg = argument; - /* For 'size == 0' system allocates the user stack from the memory pool. */ - rt_init_context (task_context, priority, (FUNCP)thread_def->pthread); - /* Find a free entry in 'os_active_TCB' table. */ OS_TID tsk = rt_get_TID (); os_active_TCB[tsk-1] = task_context; task_context->task_id = tsk; + /* Pass parameter 'argv' to 'rt_init_context' */ + task_context->msg = argument; + /* Initialize thread context structure, including the thread's stack. */ + rt_init_context (task_context, priority, (FUNCP)thread_def->pthread); + + /* Dispatch this task to the scheduler for execution. */ DBG_TASK_NOTIFY(task_context, __TRUE); rt_dispatch (task_context);