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.

CCS/PROCESSOR-SDK-AM437X: How to set privileged mode

Part Number: PROCESSOR-SDK-AM437X

Tool/software: Code Composer Studio

Hi,

Note: For writing to the control module registers, the MPU will need to be in privileged mode of operation and writes will not work from user mode.

SDK:ti-processor-sdk-rtos-am437x-evm-06.00.00.07

How to set privileged mode?

Can it be implemented by calling void CPUSwitchToPrivilegedMode(void)?
ti-processor-sdk-rtos-am437x-evm-06.00.00.07-Windows\pdk_am437x_1_0_15\packages\ti\starterware\soc\armv7a\gcc\cpu.c

  • Hi,

    Nancy Wang said:
    Note: For writing to the control module registers, the MPU will need to be in privileged mode of operation and writes will not work from user mode.

    Can you point me to the location of this note the the SDK documentation? I'd like to better understand the context.

    Nancy Wang said:
    Can it be implemented by calling void CPUSwitchToPrivilegedMode(void)?
    ti-processor-sdk-rtos-am437x-evm-06.00.00.07-Windows\pdk_am437x_1_0_15\packages\ti\starterware\soc\armv7a\gcc\cpu.c

    Yes, provided your application is using the Starterware library that includes this code. 

    I notice what might be a bug in the Starterware.

    Please see pdk_am437x_1_0_17\packages\ti\starterware\soc\armv7a\gcc\cpu.c:

                void CPUSwitchToPrivilegedMode(void)
                {
                    /* The constant passed here should match the constant used for checking in 
                     * svc_handler (in exceptionhandler.S) 
                     */
                    asm("    SWI   1");
                }
    

    Please see pdk_am437x_1_0_17\packages\ti\starterware\soc\armv7a\gcc\exceptionhandler.S:

                @
                @ The SVC Handler switches to system mode if the SVC number is 1. If the
                @ SVC number is different, no mode switching will be done. No other SVC are 
                @ handled here
                @
                SVC_Handler:
                        STMFD     r13!, {r0-r1, r14}       @ Save context in SVC stack
                        SUB       r13, r13, #0x4           @ Adjust the stack pointer
                        LDR       r0, [r14, #-4]           @ R0 points to SWI instruction
                        BIC       r0, r0, #MASK_SVC_NUM    @ Get the SWI number
                        CMP       r0, #458752
                        MRSEQ     r1, spsr                 @ Copy SPSR  
                        ORREQ     r1, r1, #0x1F            @ Change the mode to System
                        MSREQ     spsr_cf, r1              @ Restore SPSR
                        ADD       r13, r13, #0x4           @ Adjust the stack pointer
                        LDMFD     r13!, {r0-r1, pc}^       @ Restore registers from IRQ stack  

    It appears CPUSwitchToPrivilegedMode() executes the SWI w/ constant value 1, but the SVC_Handler function looks for the constant 458752 before switching to System (priviledged) mode. I suggest you experiment with this by:

    • adding a call to CPUSwitchToPrivilegedMode() in your code
    • placing a breakpoint in the SVC vector in the exception vector table
    • seeing if the SVC vector calls the SVC_Handler
    • stepping (asm single step) through the handler to see if the switch to System mode is skipped

    If the code is skipped, then I suggest updating CPUSwitchToPrivilegedMode() to call the SWI w/ constant value 458752. Then repeat the same experiment outlined above.

    Let me know how it goes..

    Regards,
    Frank

  • Hi,

    The location is section 7.1 in AM437x TRM.

    Customer tried to configure pinmux, but he found Pad Control Registers cannot be modified.

  • Hi,

    I ran some experiments which seem to confirm my suspicion that there are bugs in the Starterware.

    <PDK>\packages\ti\starterware\soc\armv7a\gcc\exceptionhandler.S:

    #1: Change .equ MASK_SVC_NUM, 0x1 to .equ MASK_SVC_NUM, 0xFF000000

    Otherwise the BIC instruction in SVC_Handler clears the SWI constant.

    #2: SVC_Handler:

    Change CMP r0, #458752 to CMP r0, #1

    Otherwise SWI constant isn't detected in instruction.

    I added call to CPUSwitchToPrivilegedMode() at the start of the main() of a simple test program.

    While stepping through SVC_Handler, I noticed the CPU is already in System mode. After executing this instruction:

    MRSEQ     r1, spsr                 @ Copy SPSR  

    I observe R1=0x200001DF. 

    Please see DDI0406C_C_arm_architecture_reference_manual.pdf. The LS 5 bits of this value are the M field. This indicates the processor is in System mode (which has PL1) after executing the Starterware startup code. 

    Can you try a similar experiment?

    Regards,
    Frank

  • Hi,

    which starterware library should be added?

  • Hi Nancy,

    <PDK>/packages/ti/starterware/binary/soc/lib/am43xx-evm/a9/<PROFILE>/gcc/libsoc.a, where PROFILE is debug or release

    Regards,
    Frank

  • Hi,

    Thanks for your patient!

    When i add the library, there are many errors occurred, could you please send me your project?

  • Hi Nancy,

    I just created used the Starterware gpio_app_led_blink example. This example includes the soc (libsoc.a) library.

    To build this example:

    • setup the PDK build environment
    • from the Starterware folder, issue: gmake -s gpio_app_led_blink PLATFORM=am43xx-evm PROFILE=debug KW_BUILD=no

    Regards,
    Frank