From 7625c72410ebefb18b2b3670c4eba951edd87ca6 Mon Sep 17 00:00:00 2001 From: Jeff Tenney Date: Wed, 26 Aug 2026 09:38:52 -0700 Subject: [PATCH 1/2] Reduce SVCall priority on ARMv7-M with MPU (#1470) Restore the original SVCall priority for the ARMv7-M MPU ports from before #832. This change reduces the SVCall preemption priority from zero (the highest) to a priority just higher than configMAX_SYSCALL_INTERRUPT_PRIORITY (numerically lower). --------- Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> --- portable/GCC/ARM_CM3_MPU/port.c | 11 ++++++----- portable/GCC/ARM_CM4_MPU/port.c | 10 ++++++---- portable/IAR/ARM_CM4F_MPU/port.c | 8 +++++--- portable/RVDS/ARM_CM4_MPU/port.c | 11 ++++++----- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/portable/GCC/ARM_CM3_MPU/port.c b/portable/GCC/ARM_CM3_MPU/port.c index 96d781d96..6b7ed02a0 100644 --- a/portable/GCC/ARM_CM3_MPU/port.c +++ b/portable/GCC/ARM_CM3_MPU/port.c @@ -96,12 +96,14 @@ typedef void ( * portISR_t )( void ); #define portPERIPHERALS_START_ADDRESS 0x40000000UL #define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL -/* Constants required to access and manipulate the SysTick. */ +/* Constants required to access and manipulate the SysTick and other FreeRTOS + * interrupts. */ #define portNVIC_SYSTICK_INT ( 0x00000002UL ) #define portNVIC_SYSTICK_ENABLE ( 0x00000001UL ) #define portMIN_INTERRUPT_PRIORITY ( 255UL ) #define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL ) #define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL ) +#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL ) /* Constants required to set up the initial stack. */ #define portINITIAL_XPSR ( 0x01000000 ) @@ -877,12 +879,11 @@ BaseType_t xPortStartScheduler( void ) } #endif /* configASSERT_DEFINED */ - /* Make PendSV and SysTick the lowest priority interrupts, and make SVCall - * the highest priority. */ + /* Make PendSV and SysTick the lowest priority interrupts, and configure + * SVCall for sufficient preemption priority. */ portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI; portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI; - portNVIC_SHPR2_REG = 0; - + portNVIC_SHPR2_REG = portNVIC_SVC_PRI; /* Configure the regions in the MPU that are common to all tasks. */ prvSetupMPU(); diff --git a/portable/GCC/ARM_CM4_MPU/port.c b/portable/GCC/ARM_CM4_MPU/port.c index 146798c0f..e1a70c511 100644 --- a/portable/GCC/ARM_CM4_MPU/port.c +++ b/portable/GCC/ARM_CM4_MPU/port.c @@ -106,12 +106,14 @@ typedef void ( * portISR_t )( void ); #define portPERIPHERALS_START_ADDRESS 0x40000000UL #define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL -/* Constants required to access and manipulate the SysTick. */ +/* Constants required to access and manipulate the SysTick and other FreeRTOS + * interrupts. */ #define portNVIC_SYSTICK_INT ( 0x00000002UL ) #define portNVIC_SYSTICK_ENABLE ( 0x00000001UL ) #define portMIN_INTERRUPT_PRIORITY ( 255UL ) #define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL ) #define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL ) +#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL ) /* Constants required to manipulate the VFP. */ #define portFPCCR ( ( volatile uint32_t * ) 0xe000ef34UL ) /* Floating point context control register. */ @@ -965,11 +967,11 @@ BaseType_t xPortStartScheduler( void ) } #endif /* configASSERT_DEFINED */ - /* Make PendSV and SysTick the lowest priority interrupts, and make SVCall - * the highest priority. */ + /* Make PendSV and SysTick the lowest priority interrupts, and configure + * SVCall for sufficient preemption priority. */ portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI; portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI; - portNVIC_SHPR2_REG = 0; + portNVIC_SHPR2_REG = portNVIC_SVC_PRI; /* Configure the regions in the MPU that are common to all tasks. */ prvSetupMPU(); diff --git a/portable/IAR/ARM_CM4F_MPU/port.c b/portable/IAR/ARM_CM4F_MPU/port.c index 423d0a777..a3b6517ef 100644 --- a/portable/IAR/ARM_CM4F_MPU/port.c +++ b/portable/IAR/ARM_CM4F_MPU/port.c @@ -120,9 +120,11 @@ typedef void ( * portISR_t )( void ); #define portCORTEX_M7_r0p1_ID ( 0x410FC271UL ) #define portCORTEX_M7_r0p0_ID ( 0x410FC270UL ) +/* Constants to manipulate FreeRTOS interrupt priorities. */ #define portMIN_INTERRUPT_PRIORITY ( 255UL ) #define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL ) #define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL ) +#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL ) /* Constants used to check the installation of the FreeRTOS interrupt handlers. */ #define portSCB_VTOR_REG ( *( ( portISR_t ** ) 0xE000ED08 ) ) @@ -862,11 +864,11 @@ BaseType_t xPortStartScheduler( void ) } #endif /* configASSERT_DEFINED */ - /* Make PendSV and SysTick the lowest priority interrupts, and make SVCall - * the highest priority. */ + /* Make PendSV and SysTick the lowest priority interrupts, and configure + * SVCall for sufficient preemption priority. */ portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI; portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI; - portNVIC_SHPR2_REG = 0; + portNVIC_SHPR2_REG = portNVIC_SVC_PRI; /* Configure the regions in the MPU that are common to all tasks. */ prvSetupMPU(); diff --git a/portable/RVDS/ARM_CM4_MPU/port.c b/portable/RVDS/ARM_CM4_MPU/port.c index 77c497a9b..7cdf3ea87 100644 --- a/portable/RVDS/ARM_CM4_MPU/port.c +++ b/portable/RVDS/ARM_CM4_MPU/port.c @@ -95,13 +95,15 @@ typedef void ( * portISR_t )( void ); #define portPERIPHERALS_START_ADDRESS 0x40000000UL #define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL -/* Constants required to access and manipulate the SysTick. */ +/* Constants required to access and manipulate the SysTick and other FreeRTOS + * interrupts. */ #define portNVIC_SYSTICK_CLK ( 0x00000004UL ) #define portNVIC_SYSTICK_INT ( 0x00000002UL ) #define portNVIC_SYSTICK_ENABLE ( 0x00000001UL ) #define portMIN_INTERRUPT_PRIORITY ( 255UL ) #define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL ) #define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL ) +#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL ) /* Constants required to manipulate the VFP. */ #define portFPCCR ( ( volatile uint32_t * ) 0xe000ef34UL ) /* Floating point context control register. */ @@ -966,12 +968,11 @@ BaseType_t xPortStartScheduler( void ) } #endif /* configASSERT_DEFINED */ - /* Make PendSV and SysTick the same priority as the kernel, and the SVC - * handler highest priority so it can be used to exit a critical section - * (where lower priorities are masked). */ + /* Make PendSV and SysTick the lowest priority interrupts, and configure + * SVCall for sufficient preemption priority. */ portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI; portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI; - portNVIC_SHPR2_REG = 0; + portNVIC_SHPR2_REG = portNVIC_SVC_PRI; /* Configure the regions in the MPU that are common to all tasks. */ prvSetupMPU(); From 8be86d4a24fd4091f8f4192018423ab590f408db Mon Sep 17 00:00:00 2001 From: Ian Thompson <101299961+ianstcdns@users.noreply.github.com> Date: Wed, 26 Aug 2026 10:09:47 -0700 Subject: [PATCH 2/2] Optional PRIVILEGED_DATA wrapper + Partner-Supported-Ports submodule update (#1433) - Instead, when MPU wrappers are not used, allow port to override PRIVILEGED_FUNCTION, PRIVILEGED_DATA, or FREERTOS_SYSTEM_CALL selectively, permitting custom section placement at link-time. - Allows critical data to be placed in port-specific location for improved performance, notably for cache-coherent SMP. - Does not require enabling the full MPU wrappers. --- include/mpu_wrappers.h | 14 +++++++++++--- portable/ThirdParty/Partner-Supported-Ports | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/mpu_wrappers.h b/include/mpu_wrappers.h index ebbd5f940..69e6cbb40 100644 --- a/include/mpu_wrappers.h +++ b/include/mpu_wrappers.h @@ -286,9 +286,17 @@ #else /* portUSING_MPU_WRAPPERS */ - #define PRIVILEGED_FUNCTION - #define PRIVILEGED_DATA - #define FREERTOS_SYSTEM_CALL + #ifndef PRIVILEGED_FUNCTION + #define PRIVILEGED_FUNCTION + #endif + + #ifndef PRIVILEGED_DATA + #define PRIVILEGED_DATA + #endif + + #ifndef FREERTOS_SYSTEM_CALL + #define FREERTOS_SYSTEM_CALL + #endif #endif /* portUSING_MPU_WRAPPERS */ diff --git a/portable/ThirdParty/Partner-Supported-Ports b/portable/ThirdParty/Partner-Supported-Ports index abc22103e..fccbbce9b 160000 --- a/portable/ThirdParty/Partner-Supported-Ports +++ b/portable/ThirdParty/Partner-Supported-Ports @@ -1 +1 @@ -Subproject commit abc22103e1e6634b33457d4127bff1ab62f27f90 +Subproject commit fccbbce9bd7e227ee211b01fdbbcf133dc3a474a