Memory protection unit (MPU) FRDM-K22F

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory protection unit (MPU) FRDM-K22F

1,003 Views
coopertrooper
Contributor III

Hello everyone,

 

I would like to test the limitations/functionality of the mpu on my device. Is there some examples/documentations I can refer to to get me started and so some basic experiments? I looked at the API that comes with the KSDK, but I am finding it hard to create an experiment with it.

Labels (1)
0 Kudos
5 Replies

127 Views
yasuhikokoumoto
Senior Contributor I

Hello Christian,

first of all, you should better refer to the "Kinetis Peripheral Module Quick Reference" (http://cache.freescale.com/files/32bit/doc/quick_ref_guide/KQRUG.pdf?fpsp=1).

Best regards,

Yasuhiko Koumoto.

0 Kudos

127 Views
coopertrooper
Contributor III

Thank you very much for your response.

I was reading the documentation the examples look useful, but they are fragmented. It does mention that these example source codes are available online, but it only lists KINETIS512_SC.zip available at www.freescale.com

0 Kudos

127 Views
yasuhikokoumoto
Senior Contributor I

Hi Christian,

I made the MPU demo program on the KSDK V1.1 using FRDM-K64F. I'm sorry but it is not for K22F.

#include <stdio.h> #include <stdlib.h>

#include "fsl_device_registers.h" #include "fsl_uart_driver.h" #include "fsl_clock_manager.h" #include "board.h"

#ifdef DEBUG #include "fsl_debug_console.h" #endif

#define M0_r  ((3<<3)|(4)) #define M0_w  ((3<<3)|(2)) #define M0_x  ((3<<3)|(1))

void HardFault_Handler(void) {     printf("MPU_EAR0=0x%08x\n\r",MPU_EAR0);     printf("MPU_EDR0=0x%08x\n\r",MPU_EDR0);     printf("MPU_EAR1=0x%08x\n\r",MPU_EAR1);     printf("MPU_EDR1=0x%08x\n\r",MPU_EDR1);     printf("MPU_EAR2=0x%08x\n\r",MPU_EAR2);     printf("MPU_EDR2=0x%08x\n\r",MPU_EDR2);     printf("MPU_EAR3=0x%08x\n\r",MPU_EAR3);     printf("MPU_EDR3=0x%08x\n\r",MPU_EDR3);     printf("MPU_EAR4=0x%08x\n\r",MPU_EAR4);     printf("MPU_EDR4=0x%08x\n\r",MPU_EDR4);         if(((int)MPU_EDR3 & 1)==0){ // If the read error causes,

    MPU_RGDAAC4 |= M0_r;    // emable read for the region tempory.     }     MPU_CESR |=  MPU_CESR_SPERR_MASK; // clear interrupts }

void MPU_Setup(void) {   SIM_SCGC7 = SIM_SCGC7_MPU_MASK | SIM_SCGC7_FLEXBUS_MASK;

  MPU_CESR &= ~MPU_CESR_VLD_MASK;  // disable MPU

  MPU_CESR |=  MPU_CESR_SPERR_MASK; // clear interrupts

  MPU_RGD0_WORD2 = 0; // ignore default protection for RGD0

  MPU_RGD1_WORD0 = 0x00000000;// until SRAM area   MPU_RGD1_WORD1 = 0x1FFEFFFF;// Read/Write/Execute   MPU_RGD1_WORD2 = M0_r | M0_w | M0_x;   MPU_RGD1_WORD3 = 0x00000001;

  MPU_RGD2_WORD0 = 0x1FFF0000; // SRAM_L   MPU_RGD2_WORD1 = 0x1FFFFFFF; // Read/Write   MPU_RGD2_WORD2 = M0_r | M0_w;   MPU_RGD2_WORD3 = 0x00000001;

  MPU_RGD3_WORD0 = 0x20000000; // SRAM_U(Part1)   MPU_RGD3_WORD1 = 0x200000FF; // only Read   MPU_RGD3_WORD2 = M0_r ;   MPU_RGD3_WORD3 = 0x00000001;

  MPU_RGD4_WORD0 = 0x20000100; // SRAM_U(part2)   MPU_RGD4_WORD1 = 0x200001FF; // only Write   MPU_RGD4_WORD2 = M0_w;;   MPU_RGD4_WORD3 = 0x00000001;   MPU_RGD5_WORD0 = 0x20000200; // SRAM_U(Part3)   MPU_RGD5_WORD1 = 0x2002FFFF; // Read/Write/Execute   MPU_RGD5_WORD2 = M0_r | M0_w | M0_x;   MPU_RGD5_WORD3 = 0x00000001;

  MPU_RGD6_WORD0 = 0x20030000; // The rest address spaces   MPU_RGD6_WORD1 = 0xFFFFFFFF; // Read/Write/Execute   MPU_RGD6_WORD2 = M0_r | M0_w | M0_x;   MPU_RGD6_WORD3 = 0x00000001;     MPU_CESR |= MPU_CESR_VLD_MASK; // enabe MPU   }

volatile int a; volatile int *p;

int main (void) {   hardware_init();   configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);   dbg_uart_init();     MPU_Setup(); // MPU Setting

  // Tests of the protection errors   p = (int*)0x20000080;   a = *p;   printf("Passed - 1\n\r");   *p = a;   printf("Passed - 2\n\r");   p = (int*)0x20000100;   a= *p;   printf("Passed - 3\n\r");   *p = a;   printf("Passed - 4\n\r"); }

Does this help you?

Basically returning from the protection fault (i.e. Hard Fault) has no meaning and OS should abort the task. In the sample program the store error can recover form the exception because the error PC pointed after the store instruction due to the store buffer. However, the read error causes repeatedly because the error PC pointed to the load instruction.

Best ergards,

Yasuhiko Koumoto.

0 Kudos

127 Views
coopertrooper
Contributor III

Hello Yasuhiko,

Thank you very much for the example code you have provided. I know it is not for the K22F, but I think I can modify it to suit my needs. Really appreciate the help. I will give it a try soon and will let you know if I get it to work or not.

0 Kudos

127 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Christian,

just note that the device in FRDM-K22F120M does not provide MPU. Please refer to the following document. Kinetis K22_120 MHz devices

Regards,

Carlos

0 Kudos