Teensy 3.6 MPU puzzle?

Status
Not open for further replies.

Bill Greiman

Well-known member
Teensy 3.6 MPU puzzle? Memory Protection?

Why is the MPU enabled for Teensy 3.6?

I am writing a new SDHC driver and am looking at various existing SDHC drivers for the K66.

All the SDHC example I look at disable the MPU. In fact there are about 80 examples in the K66 SDK that have this call in main().

Some are for SDHC, some for USB devices, and some for Ethernet.

Code:
    /* Disable MPU. */
    MPU_Enable(MPU, false);

Here is the hex value of MPU_CESR at the start of setup(). The low bit enabling the MPU is set.
Code:
MPU_CESR: 815101

The only code I find in teensy 130b for the MPU is this.

D:\Teensy\teensy130b\hardware\teensy\avr\cores\teensy3\usb_dev.c

line 1111:
Code:
#ifdef HAS_KINETIS_MPU
	MPU_RGDAAC0 |= 0x03000000;
#endif

If I comment this out there are problems.

However If I put this before Serial.begin(9600) and comment out the code in usb_dev.c things seem to work OK.

Code:
  MPU_CESR &= ~MPU_CESR_VLD_MASK;

I don't like putting code to disable the MPU in a SDHC driver.

So why is the MPU enabled in Teensy 3.6?
 
Last edited:
I found the answer. This allows access by the SDHC Bus Master.

Code:
#ifdef HAS_KINETIS_MPU
  MPU_RGDAAC0 |= 0x0C000000;
#endif

Better than disabling the MPU.
 
Last edited:
Oh, I didn't know the MPU could be disabled. It starts enabled after a system reset, but the default setting allows only the first 4 bus masters to access memory.

When starting with these chips I wasted quite a few hours before finally figuring out I needed to add that to the USB code...
 
Might be - still - worth, to set it once (or disable the MPU) in the startup-code..

to disable:
// Switch of MPU unit (maybe bug of silicon)
MPU_CESR &= ~MPU_CESR_VLD_MASK;
 
Last edited:
Bill,
There was an errata from freescale as mentioned in
https://forum.pjrc.com/threads/34808-K66-Beta-Test?p=107873&viewfull=1#post107873

this may explain why everyone disabled MPU

There is no K66 errata for the the VLD bit in MPU_CESR. The K66 starts with VLD set.

The MPU works just as described in the K66 Reference Manual chapter 22 Memory Protection Unit. Check the reset value for MPU_CESR.

I checked reset values for other registers and the SDHC is blocked as stated in the Reference Manual.
 
Last edited:
Status
Not open for further replies.
Back
Top