I am currently experimenting with FreeRTOS with MPU for Cortex M3.
It seems to me that given the settings in FreeRTOSConfig.h, an unprivileged task will never be able to use taskENTER_CRITICAL.
For instance, this is from the CORTEX_MPU_LM3Sxxxx_Rowley port:
... #define configKERNEL_INTERRUPT_PRIORITY (( unsigned char ) 7 << configUNUSED_PRIO_BITS) ... #define configMAX_SYSCALL_INTERRUPT_PRIORITY (( unsigned char ) 5 << configUNUSED_PRIO_BITS) ...
‘KERNEL_INTERRUPT_PRIORITY’ is the priority that is assigned to SysTick, SVC and pendSV Handlers
‘MAX_SYSCALL_INTERRUPT_PRIORITY’ is the priority that is used in ENTER_CRITICAL. Any exception/interrupt with same or below priority will be masked out between ENTER_CRITICAL and EXIT_CRITICAL.
But if KERNEL_INTERRUPT_PRIORITY is lower or same as MAX_SYSCALL_INTERRUPT_PRIORITY, as it is here (bigger or equal numerical value), after ENTER_CRITICAL is called, the task will not be able to execute another SVC (which will have too low a priority now), including calling EXIT_CRITICAL! (because EXIT_CRITICAL calls prvRaisePrivilege, which uses SVC 2).
So I could do one of two things:
- give KERNEL_INTERRUPT_PRIORITY a higher priority than MAX_SYSCALL_INTERRUPT_PRIORITY
- give just the SVC handler a higher priority than MAX_SYSCALL_INTERRUPT_PRIORITY
In both cases a small test application seems to work ok (i.e. a non privileged call can use ENTER_CRITICAL/EXIT CRITICAL) but I am not sure of the ramifications of this.
The priorities seem to be set this way (KERNEL_INTERRUPT_PRIORITY lower than MAX_SYSCALL_INTERRUPT_PRIORITY) for most if not all M3/M4 ports, so I guess there must be a good reason for this.