From e6d8308fde19860e4b86c2dfd7a404ff0304a237 Mon Sep 17 00:00:00 2001 From: Tomas Galbicka <151615323+TomasGalbickaNXP@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:36:33 +0200 Subject: [PATCH 1/2] GCC: ARM_CM0: Fix L6286E error on Keil MDK (#1131) Change the .b instruction to .bx with higher range to solve error reported by MDK descibed bellow. Fix: Error: L6286E: Relocation #REL:0 in portasm.o(.text.SVC_Handler) with respect to vPortSVCHandler_C. Value(0x1a04) out of range(-0x800 - 0x7fe) for (R_ARM_THM_JUMP11) Compiler: Keil MDK ARMClang 6.22.0 https://developer.arm.com/documentation/ka002847/latest/ https://developer.arm.com/documentation/dui0496/m/Linker-Errors-and-Warnings/List-of-the-armlink-error-and-warning-messages Signed-off-by: Tomas Galbicka --- portable/GCC/ARM_CM0/portasm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/portable/GCC/ARM_CM0/portasm.c b/portable/GCC/ARM_CM0/portasm.c index be1500ef0..179a71546 100644 --- a/portable/GCC/ARM_CM0/portasm.c +++ b/portable/GCC/ARM_CM0/portasm.c @@ -472,7 +472,8 @@ void vClearInterruptMask( __attribute__( ( unused ) ) uint32_t ulMask ) /* __att " ldr r3, =%1 \n" " cmp r2, r3 \n" " beq system_call_exit \n" - " b vPortSVCHandler_C \n" + " ldr r3, =vPortSVCHandler_C \n" + " bx r3 \n" " \n" " system_call_enter: \n" " push {lr} \n" @@ -508,11 +509,13 @@ void vClearInterruptMask( __attribute__( ( unused ) ) uint32_t ulMask ) /* __att " \n" " stacking_used_psp: \n" " mrs r0, psp \n" - " b vPortSVCHandler_C \n" + " ldr r3, =vPortSVCHandler_C \n" + " bx r3 \n" " \n" " stacking_used_msp: \n" " mrs r0, msp \n" - " b vPortSVCHandler_C \n" + " ldr r3, =vPortSVCHandler_C \n" + " bx r3 \n" " \n" " .align 4 \n" ); From 6dab25ae4e2d4212b76dec01737fcdb2d257af50 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:21:35 +0530 Subject: [PATCH 2/2] Pend a yield in portPRE_TASK_DELETE_HOOK (#1132) When a task deletes itself, it calls portPRE_TASK_DELETE_HOOK which translates to vPortCloseRunningThread on the Windows port. vPortCloseRunningThread never returns and as a result, taskYIELD_WITHIN_API in vTaskDelete does not get called. As a result, the next task is not scheduled when configUSE_PREEMPTION is set to 0. This change records that a yield is pending so that the next tick interrupt switches out the task that was deleted. Signed-off-by: Gaurav Aggarwal --- portable/MSVC-MingW/port.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/portable/MSVC-MingW/port.c b/portable/MSVC-MingW/port.c index 7c34aabd6..c6ee941c8 100644 --- a/portable/MSVC-MingW/port.c +++ b/portable/MSVC-MingW/port.c @@ -547,6 +547,20 @@ void vPortCloseRunningThread( void * pvTaskToDelete, /* This is called from a critical section, which must be exited before the * thread stops. */ taskEXIT_CRITICAL(); + + /* Record that a yield is pending so that the next tick interrupt switches + * out this thread regardless of the value of configUSE_PREEMPTION. This is + * needed when a task deletes itself - the taskYIELD_WITHIN_API within + * vTaskDelete does not get called because this function never returns. If + * we do not pend portINTERRUPT_YIELD here, the next task is not scheduled + * when configUSE_PREEMPTION is set to 0. */ + if( pvInterruptEventMutex != NULL ) + { + WaitForSingleObject( pvInterruptEventMutex, INFINITE ); + ulPendingInterrupts |= ( 1 << portINTERRUPT_YIELD ); + ReleaseMutex( pvInterruptEventMutex ); + } + CloseHandle( pxThreadState->pvYieldEvent ); ExitThread( 0 ); }