How to make S32K146 M4 Core user mode and supervisor mode switching?

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

How to make S32K146 M4 Core user mode and supervisor mode switching?

2,829 Views
paulzhou
Contributor II

Dear Sir 

      How to make S32K146 M4 Core user mode and supervisor mode switching?

      Do you have demo code for this case? or reference application document ?

      Do S32K146 MCAL must do user mode and supervisor mode switching to meets functional security?

     Thank you!

Labels (1)
2 Replies

2,373 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,
If you need to switch to User mode, just set the nPRIV bit in CONTROL register

// switch to User (unprivileged) mode
 __asm__("mov r0, #0x01");
 __asm__("msr control, r0"); // nPRIV = 1


And to switch it back, you need to do it in SVC handler

// make a supervisor call (SVC) to transfer control to privileged software
 __asm__("svc #0x00");

void SVC_Handler(void){
 // switch to Supervisor (privileged) mode
 __asm__("mov r0, #0x00");
 __asm__("msr control, r0"); // nPRIV = 0
}

Unfortunately, I’m not familiar with MCAL.
Could you please create a service ticket?

https://community.nxp.com/docs/DOC-329745 

Regards,
Daniel

2,374 Views
paulzhou
Contributor II

Dear Daniel
     Thank you for your help and this problem is solved

0 Kudos
Reply