From 829ca3333b26e57cc3a0db38f7c65d8623155220 Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Thu, 14 Apr 2016 14:26:06 +0100 Subject: [PATCH] RTX: Actively switch to the idle thread Prevent a switch to a NULL target thread by setting the new task to run to be the idle task. Otherwise, we get nasty usage fault because we would be returning from the rt_sys_init SVC with a PSP of 0x20. --- rtos/rtx/TARGET_CORTEX_M/rt_Task.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rtos/rtx/TARGET_CORTEX_M/rt_Task.c b/rtos/rtx/TARGET_CORTEX_M/rt_Task.c index 0162305d2e..3179a5192f 100644 --- a/rtos/rtx/TARGET_CORTEX_M/rt_Task.c +++ b/rtos/rtx/TARGET_CORTEX_M/rt_Task.c @@ -406,6 +406,10 @@ void rt_sys_init (FUNCP first_task, U32 prio_stksz, void *stk) { os_tsk.run = &os_idle_TCB; os_tsk.run->state = RUNNING; + /* Set the current thread to idle, so that on exit from this SVCall we do not + * de-reference a NULL TCB. */ + rt_switch_req(&os_idle_TCB); + /* Initialize ps queue */ os_psq->first = 0U; os_psq->last = 0U;