Skip to content

Commit 7625c72

Browse files
jefftenneyaggarg
andauthored
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>
1 parent 92bfb86 commit 7625c72

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

portable/GCC/ARM_CM3_MPU/port.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ typedef void ( * portISR_t )( void );
9696
#define portPERIPHERALS_START_ADDRESS 0x40000000UL
9797
#define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL
9898

99-
/* Constants required to access and manipulate the SysTick. */
99+
/* Constants required to access and manipulate the SysTick and other FreeRTOS
100+
* interrupts. */
100101
#define portNVIC_SYSTICK_INT ( 0x00000002UL )
101102
#define portNVIC_SYSTICK_ENABLE ( 0x00000001UL )
102103
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
103104
#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL )
104105
#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL )
106+
#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL )
105107

106108
/* Constants required to set up the initial stack. */
107109
#define portINITIAL_XPSR ( 0x01000000 )
@@ -877,12 +879,11 @@ BaseType_t xPortStartScheduler( void )
877879
}
878880
#endif /* configASSERT_DEFINED */
879881

880-
/* Make PendSV and SysTick the lowest priority interrupts, and make SVCall
881-
* the highest priority. */
882+
/* Make PendSV and SysTick the lowest priority interrupts, and configure
883+
* SVCall for sufficient preemption priority. */
882884
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
883885
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
884-
portNVIC_SHPR2_REG = 0;
885-
886+
portNVIC_SHPR2_REG = portNVIC_SVC_PRI;
886887

887888
/* Configure the regions in the MPU that are common to all tasks. */
888889
prvSetupMPU();

portable/GCC/ARM_CM4_MPU/port.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ typedef void ( * portISR_t )( void );
106106
#define portPERIPHERALS_START_ADDRESS 0x40000000UL
107107
#define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL
108108

109-
/* Constants required to access and manipulate the SysTick. */
109+
/* Constants required to access and manipulate the SysTick and other FreeRTOS
110+
* interrupts. */
110111
#define portNVIC_SYSTICK_INT ( 0x00000002UL )
111112
#define portNVIC_SYSTICK_ENABLE ( 0x00000001UL )
112113
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
113114
#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL )
114115
#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL )
116+
#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL )
115117

116118
/* Constants required to manipulate the VFP. */
117119
#define portFPCCR ( ( volatile uint32_t * ) 0xe000ef34UL ) /* Floating point context control register. */
@@ -965,11 +967,11 @@ BaseType_t xPortStartScheduler( void )
965967
}
966968
#endif /* configASSERT_DEFINED */
967969

968-
/* Make PendSV and SysTick the lowest priority interrupts, and make SVCall
969-
* the highest priority. */
970+
/* Make PendSV and SysTick the lowest priority interrupts, and configure
971+
* SVCall for sufficient preemption priority. */
970972
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
971973
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
972-
portNVIC_SHPR2_REG = 0;
974+
portNVIC_SHPR2_REG = portNVIC_SVC_PRI;
973975

974976
/* Configure the regions in the MPU that are common to all tasks. */
975977
prvSetupMPU();

portable/IAR/ARM_CM4F_MPU/port.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ typedef void ( * portISR_t )( void );
120120
#define portCORTEX_M7_r0p1_ID ( 0x410FC271UL )
121121
#define portCORTEX_M7_r0p0_ID ( 0x410FC270UL )
122122

123+
/* Constants to manipulate FreeRTOS interrupt priorities. */
123124
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
124125
#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL )
125126
#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL )
127+
#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL )
126128

127129
/* Constants used to check the installation of the FreeRTOS interrupt handlers. */
128130
#define portSCB_VTOR_REG ( *( ( portISR_t ** ) 0xE000ED08 ) )
@@ -862,11 +864,11 @@ BaseType_t xPortStartScheduler( void )
862864
}
863865
#endif /* configASSERT_DEFINED */
864866

865-
/* Make PendSV and SysTick the lowest priority interrupts, and make SVCall
866-
* the highest priority. */
867+
/* Make PendSV and SysTick the lowest priority interrupts, and configure
868+
* SVCall for sufficient preemption priority. */
867869
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
868870
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
869-
portNVIC_SHPR2_REG = 0;
871+
portNVIC_SHPR2_REG = portNVIC_SVC_PRI;
870872

871873
/* Configure the regions in the MPU that are common to all tasks. */
872874
prvSetupMPU();

portable/RVDS/ARM_CM4_MPU/port.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ typedef void ( * portISR_t )( void );
9595
#define portPERIPHERALS_START_ADDRESS 0x40000000UL
9696
#define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL
9797

98-
/* Constants required to access and manipulate the SysTick. */
98+
/* Constants required to access and manipulate the SysTick and other FreeRTOS
99+
* interrupts. */
99100
#define portNVIC_SYSTICK_CLK ( 0x00000004UL )
100101
#define portNVIC_SYSTICK_INT ( 0x00000002UL )
101102
#define portNVIC_SYSTICK_ENABLE ( 0x00000001UL )
102103
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
103104
#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL )
104105
#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL )
106+
#define portNVIC_SVC_PRI ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL )
105107

106108
/* Constants required to manipulate the VFP. */
107109
#define portFPCCR ( ( volatile uint32_t * ) 0xe000ef34UL ) /* Floating point context control register. */
@@ -966,12 +968,11 @@ BaseType_t xPortStartScheduler( void )
966968
}
967969
#endif /* configASSERT_DEFINED */
968970

969-
/* Make PendSV and SysTick the same priority as the kernel, and the SVC
970-
* handler highest priority so it can be used to exit a critical section
971-
* (where lower priorities are masked). */
971+
/* Make PendSV and SysTick the lowest priority interrupts, and configure
972+
* SVCall for sufficient preemption priority. */
972973
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
973974
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
974-
portNVIC_SHPR2_REG = 0;
975+
portNVIC_SHPR2_REG = portNVIC_SVC_PRI;
975976

976977
/* Configure the regions in the MPU that are common to all tasks. */
977978
prvSetupMPU();

0 commit comments

Comments
 (0)