Hello Cortex M3 experts,
I have a FreeRTOS task that runs in Thread/unprivileged mode. When that task tries to execute a SVC instruction, I get a hard fault. But if the task is launched in privileged mode, that does not happen. The strange thing is that it happens in this code:
__asm portBASE_TYPE portRaisePrivilege( void ) { mrs r0, control tst r0, #1 ; Is the task running privileged? */ itte ne movne r0, #0 ; CONTROL[0]!=0, return false. */ svcne #portSVC_RAISE_PRIVILEGE ; Switch to privileged. */ moveq r0, #1 ; CONTROL[0]==0, return true. */ bx lr }
which is invoked by these calls:
void vPortExitCritical( void ) { portBASE_TYPE xRunningPrivileged = portRaisePrivilege() ; uxCriticalNesting--; if( uxCriticalNesting == 0 ) { portENABLE_INTERRUPTS(); } portRESET_PRIVILEGE( xRunningPrivileged ) ; }
and
void vPortEnterCritical( void ) { portBASE_TYPE xRunningPrivileged = portRaisePrivilege() ; portDISABLE_INTERRUPTS(); uxCriticalNesting++; portRESET_PRIVILEGE( xRunningPrivileged ) ; }
If I call the functions like this:
vPortEnterCritical() ; vPortExitCritical() ;
the hard fault will occur during the call to "vPortExitCritical". Any ideas?
I believe this forum is a appropriate for such a question.
FWIW so do I. I was just being my normal facetious self ;)