KE18F MPU

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

KE18F MPU

1,923 Views
sean_dvorscak
Contributor III

I was wondering if someone could explain to me what I might be missing when trying to configure the MPU to restrict access from the core, DMA, and debugger from a section of FlashNVM on the KE18F MCU.

 

I am trying to get a better understanding on how to use the MPU by doing a small experiment where I restrict (or at least I think I do) access to FlashNVM region 0x14000180-0x140001FF.  After I initialize the MPU and the RGD, I set up a write to a spot in the region.  I can see in the memory window that the write was able to happen, and I am not sure why.

 

CODE SNIPPET:

// Going to do some testing on the FlashNVM section that is still free
#define MPU_FLASHNVM_WORD      SYSMPU->WORD[2]
#define MPU_FLASHNVM_RGDAAC  SYSMPU->RGDAAC[2]
#define MPU_FLASHNVM_START      0x14000180U
#define MPU_FLASHNVM_END          0x140001FFU

static void Init_MPU(void)
{
// Enable Clock
EnableClock(CLOCK_Sysmpu0);

// Test on the FlashNVM/FlexRAM
MPU_FLASHNVM_WORD[0] = MPU_FLASHNVM_START & SYSMPU_WORD_SRTADDR_MASK;
MPU_FLASHNVM_WORD[1] = MPU_FLASHNVM_END & SYSMPU_WORD_ENDADDR_MASK;
MPU_FLASHNVM_WORD[2] = SYSMPU_WORD_M0SM_MASK | SYSMPU_WORD_M1SM_MASK
| SYSMPU_WORD_M2SM_MASK | SYSMPU_WORD_M3SM_MASK;
MPU_FLASHNVM_WORD[3] = SYSMPU_WORD_VLD_MASK;

// Enable MPU
SYSMPU->CESR = SYSMPU_CESR_VLD_MASK;
}

(*(uint32_t *)0x14000180U) = 0xDEADBEEFU; // This write still gets through

Labels (1)
0 Kudos
11 Replies

1,916 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You can download the sdk in this link -- mcuxpresso.nxp.com. The sdk has the example about mpu. You can refer it.

 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,899 Views
sean_dvorscak
Contributor III

Hello,

I already had the SDK and looked at the examples for the MPU.  The code in there seems to be the same as the code I am doing.  So I am still not sure what I am doing wrong/misunderstanding.

0 Kudos

1,891 Views
nxf56274
NXP Employee
NXP Employee

Hi,

I use the sdk to make a simple test.

I set the address you mentioned.

1.PNG

Then I test the address.At first, the address can be accessed. Then I modify the rights. 

2.PNG

You can see the result. We can print '12'. But we can't print '13'. Because the mcu goes to bus fault.

3.PNG

 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,885 Views
sean_dvorscak
Contributor III

So was the write of 13 to location 0x14000180 able to go through?  Or did you only set the access for writes and executes allowed, reads not allowed?

 

The community website is behaving really odd right for me, and I cannot quite see those pictures that well.  I can only see the second picture, not the top one.

0 Kudos

1,863 Views
nxf56274
NXP Employee
NXP Employee

Hi,

At first, read and write rights. We can write and read. Then the rights is read and no writing. So we can't give '13' to address. You can use this example and change the address. You will get the results very soon.

 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,852 Views
sean_dvorscak
Contributor III

Yeah I am still not getting the expected results.  I cannot see that picture that you sent of the code.  Can you paste the code to the reply please?

 

Is there a certain way that I am supposed to configure the address?  I am just writing the address as SYSMPU->WORD[2][0] = 0x14000180U.  Is there else I am supposed to do to it?  I tried using the SYSMPU_WORD_SRTADDR() macro in the MKE18F.h file.  Still didn't work.

 

I am getting faults when I try to read from any FlashNVM region.  I want to only get faults when it is in the range 0x14000180-0x140001FF.  However, I get faults even reading 0x14000000.  I am also only get these faults when I give the program free run.  If I single step, I don't get any faults.  Is there something with the single stepping that is making the faults not happen for some reason?

 

Also, I set the User access to no read, write, or execute by setting Bus Masters 0-3 User Accesses to be 0.  I set the supervisor access to be the same as the User Accesses.  However, I can still write to the locations.  Why can I still write, but not read?

 

I attached a file with how I am setting things up.  Does anything look wrong?

0 Kudos

1,828 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Sorry, I delete that project. Do you use our example and change the region address to run ? If not, please do it. Whatever, we should understand the sdk example then we can develop our own project. 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,816 Views
sean_dvorscak
Contributor III

Not sure what you mean by change the region address to run?

 

So it seems like I am doing some things right, but I am missing something.  It seems like I am setting up the address wrong, because I am getting faults when I try to read location 0x14000000.  I want to protect 0x14000180-0x14000200.  That region is protected and I do get faults when I try to read that area as well.  Not sure why other locations are giving me faults.

 

The other thing that I am not sure about is why I can write to the location that I thought was protected.  When I do (*(uint8_t *)0x14000181U) = 0xF8, the write goes through.  Is this not a core write?  I thought by setting the M0UM field to 0x0, and the M0SM field to 0x3, that I would disable any writes, reads, and executions.  Am I understanding that wrong?  I also set the M1UM, M2UM, M3UM, M1SM, M2SM, and M3SM to match the M0UM and M0SM respectively.  So I thought I was not giving any access to any of the bus masters.

0 Kudos

1,797 Views
nxf56274
NXP Employee
NXP Employee

Hi,

1 the rights relationship between different region descriptor is OR.

2 the region0 is special. If you do not set it. Its start address is 0 and end address is 0xFFFF_FFFF. 

 region0's WORD2 has a different initial value. M0SM = '11', M0UM = '111'. So we have the read ,write and execute access in whole memory.

3 If your region only has read access(r--), considering the region 0 has all access(rwx), the rights for your region is r--|rwx= rwx. So your region still has the write access. You have to remove the region 0's write access. Then your setting will effect. In the sdk example , use SYSMPU_SetRegionRwxMasterAccessRights to modify the region0 rights. You would better not modify the region0's word2 directly.

 

 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,791 Views
sean_dvorscak
Contributor III

Hello,

So you mention that the accesses are OR'd, but if the RGD0 gives access rights to read, write, and execute for the entire memory.  Based off that, wouldn't I have read, write, and execute accesses for the entire memory?

This isn't what I observe.  When I try to read any memory location, I am thrown in to the HardFault_Handler.

// This gives a fault

uint8_t Tester = (*(uint8_t *)0x14000000U;

Even when I set the RGD[0] to give access to everything, M0-M7, I still get faults.  I can still write, but I cannot read.  Not sure why I can't read any location, but I can write, even when I gave the entire memory access to everything.

Is there also a way to make the region 0 not valid?  I don't want to restrict access to the entire 4GB memory region, and I don't want to have issues when with the ORing of right accesses.

0 Kudos

1,783 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You can refer the attachment. Modify the TESTADDR to test. 

1.PNG

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos