Switch to user mode on K82 with MPU

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switch to user mode on K82 with MPU

Jump to solution
676 Views
EugeneHiihtaja
Senior Contributor I

Hello !

On K82 MPU is always enabled  and Region 0 provisioned with record what give access to whole memore space for all masters in user and privileged mode.

I have start to think how-to port freeRTOS-MPU for K82 is show busFault if task try to drop to user mode by using control register.

/* Set the privilege level to user mode if xRunningPrivileged is false. */
portFORCE_INLINE static void vPortResetPrivilege( BaseType_t xRunningPrivileged )
{
   if( xRunningPrivileged != pdTRUE )
   {
      __asm volatile ( " mrs r0, control \n" \
      " orr r0, #1 \n" \
      " msr control, r0 \n" \
      :::"r0", "memory" );
   }
}

BusFault is enabled and first call of this function cause BusFault even all memory areas accesable in User mode.

If all Tasks created as privileged, this function is not called and no any problems.

Current assumption that K82 require more complicate sequence and may be MPU should be disabled/enabled globally.

But in user mode may be not possible to reenable MPU.

Could you suggest if this sequence is OK for K82 with MPU ?

Regards,

Eugene

0 Kudos
1 Solution
505 Views
EugeneHiihtaja
Senior Contributor I

Hi Xiangjun Rong !

If I completely disable MPU block , it is not problem at all.

But if I disable Master0 in region 0

/* Invalidate Region 0 for Master 0, remove background region with wide access right. */
master0 = prvComposeRegionRightMPU(kSYSMPU_SupervisorEqualToUsermode, kSYSMPU_UserNoAccessRights);
SYSMPU_SetRegionRwxMasterAccessRights(SYSMPU, 0, 0, &master0);

Nothing dosn't work.

So for remove wide access to everything, I have splitted accesses right for master0 for multiple

Regions, e.g Flash, SRAM, etc. separately.

But Region 0 is still have full access right for Master1 ( Debug ) what can't be removed in principle.

Other Masters 2-4 I have disabled as well.

Regards,

Eugene

View solution in original post

0 Kudos
2 Replies
506 Views
EugeneHiihtaja
Senior Contributor I

Hi Xiangjun Rong !

If I completely disable MPU block , it is not problem at all.

But if I disable Master0 in region 0

/* Invalidate Region 0 for Master 0, remove background region with wide access right. */
master0 = prvComposeRegionRightMPU(kSYSMPU_SupervisorEqualToUsermode, kSYSMPU_UserNoAccessRights);
SYSMPU_SetRegionRwxMasterAccessRights(SYSMPU, 0, 0, &master0);

Nothing dosn't work.

So for remove wide access to everything, I have splitted accesses right for master0 for multiple

Regions, e.g Flash, SRAM, etc. separately.

But Region 0 is still have full access right for Master1 ( Debug ) what can't be removed in principle.

Other Masters 2-4 I have disabled as well.

Regards,

Eugene

0 Kudos
505 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Eugene,

If you disable MPU function, do you have issue when you configure to user mode?

BR

Xiangjun Rong

0 Kudos