This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LC4357: QS on MPU: What difference between Arm assembly and C in MPU function?

Part Number: TMS570LC4357

Hi all:

    I  am the first time to use ARM assembly and MPU function. In my mind, If I need configure the MPU function, I will set mpu registers in lc4357 datasheet rather than arm assembly.

    In our product, I find that any use or configuration of MPU is realized through arm assembly rather than C.    

    My questions are :

    1. what are differences between assembly and C during configuration of MPU?

    2. Is that necessary to use assembly?

    3. what's the difference between the PSMA regsister "DRBAR" and MPU register "MPUREGBASE"?

Best Wish

Li

  • Hi Li,

    The MPU is configured through CP15 registers using ARM MCR and MRC instructions like enabling MPU with the following code:

    MRC p15, 0, R1, c1, c0, 0

    ; read CP15 register 1

    ORR R1, R1, #0x1

    DSB

    MCR p15, 0, R1, c1, c0, 0 ; enable MPU

    ISB

        2. Is that necessary to use assembly?

    Yes, assembly code is used to config MPU

      3. what's the difference between the PSMA regsister "DRBAR" and MPU register "MPUREGBASE"?

    I don't know PSMA, DRBAR, and MPUREGBASE registers. Can you tell me where you get those names?

    Please refer to ARM TRM: https://developer.arm.com/documentation/ddi0460/d/Memory-Protection-Unit

  • Hi QJ:

    For Q1, I think MPU could be configured through C code instead of arm assembly. is that right?

    For Q3, the  DRBAR is register of PMSA and they are from "ARM® Architecture Reference Manual ARMv7-A and ARMv7-R edition" ,Section B6.1.36, page 1840;

    The DRBAR is Data Region Base Address Register. PMAS is protected memory system architecture.

    Here is the example in assembly:

    To access the DRBAR, software reads or writes the CP15 registers with <opc1> set to 0, <CRn> set to c6, <CRm> set to
    c1, and <opc2> set to 0. For example:
    MRC p15, 0, <Rt>, c6, c1, 0 ; Read DRBAR into Rt
    MCR p15, 0, <Rt>, c6, c1, 0 ; Write Rt to DRBAR

    And in our product, here is the code:

    //=====================================================================
    // Init helper
    // mpuInitRegion
    //=====================================================================
        .global     mpuInitRegion
        .type       mpuInitRegion, function
        .func       mpuInitRegion
        .thumb_func
    mpuInitRegion:  // only for init!
        mov   ip, #0                               // To disable region before manipulation
        mcr    p15, #0, r0, c6, c2, #0     // RGNR, MPU Region Number Register
        mcr    p15, #0, ip, c6, c1, #2     // DRSR, Data Region Size and Enable Register
        mcr    p15, #0, r1, c6, c1, #0    // DRBAR, Data Region Base Address Register
        mcr    p15, #0, r3, c6, c1, #4    // DRACR, Data Region Access Control Register
        mcr    p15, #0, r2, c6, c1, #2    // DRSR, Data Region Size and Enable Register
        bx    lr
        .endfunc
    //=====================================================================

    I think the code above is that DRBAR register is same as the of "MPUREGBASE" register.