Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 3.6 MPU puzzle?

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Posts
    271

    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\tee nsy3\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 by Bill Greiman; 08-29-2016 at 04:52 PM.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    271
    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 by Bill Greiman; 08-29-2016 at 05:12 PM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,601
    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...

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,346
    Quote Originally Posted by Bill Greiman View Post
    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.
    Bill,
    There was an errata from freescale as mentioned in
    https://forum.pjrc.com/threads/34808...l=1#post107873

    this may explain why everyone disabled MPU

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    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 by Frank B; 08-29-2016 at 08:49 PM.

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    271
    Quote Originally Posted by WMXZ View Post
    Bill,
    There was an errata from freescale as mentioned in
    https://forum.pjrc.com/threads/34808...l=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 by Bill Greiman; 08-29-2016 at 11:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •