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.

AM2434: Using cp14 to operate debug related registers will result in an undefined exception

Part Number: AM2434


I use cp14, which is the instruction of MRC and MCR to operate debug related registers, which will cause an undefined exception. However, the official release manual of armV7r states that cp14 can be used to operate, as shown in the figure, 

So, may I ask how to operate it? If it is method 1, it can be seen that the cp14 interface of V7debug is defined by the manufacturer, so is there a method defined by TI itself? If it is method 2 address mapping, which is also set by TI, please also inform the mapped address area.

  • Hi There,

    We will need to the help from our system architect to answer your questions. It may take a few days for us to come back to you on this thread.

    Best regards,

    Ming

  • Hi Lin,

    Here is the answer from our system architect: 

    1. CP14 is a valid means of accessing V7R debug registers, but there are rules associated with this that are documented in the V7R Architecture Reference Manual.  From the behavior noted in the E2E post I’m guessing that the code was not executed with a privilege level of PL1 or higher (which is required per the ARMv7-R.
    2. TI does support a memory mapped view of the registers, so this can be used as a means of accessing them:

     

    Physical Address

    AM2434 – Arm R5F Core

    APB-AP (32-bit)

    SOC Address Space (36-bit)

    R5F0_0

    0x9D410000

    0x73D410000

    R5F0_1

    0x9D412000

    0x73D412000

    R5F1_0

    0x9D510000

    0x73D510000

    R5F1_1

    0x9D512000

    0x73D512000

    Note that access to the debug resources is also affected by the security state of the device.

    Best regards,

    Ming

  • I have checked that the code was executed in system mode, which is PL1 with a privilege level of PL1. But undefined exception still occurs.

  • Hi Lin,

    Can you provide the code which generates  the undefined exception?

    Best regards, 

    Ming

  •  As the picture shows, when writing DBGDSCRext with MCR , it is in system mode. Once the code is executed, it enters an undefined exception as the following picture shows.

  • Hi Lin,

    I passed your information to our system architects. While waiting for their answer back, can I ask wa=hat is the reason you want to access to the CP14 registers? Are you developing your own debugger?

    Best regards,

    Ming

  • Hi Lin,

    Here are the comments from our system architects:

    ------------------

    I have a few comments—and, again, I am really just reading the arm documentation. If this drags on then we may need to refer customer to ARM support.

    1. The code snippets show debugging of code that is writing to CP14 registers within the context of an active CCS debugger session.  The CCS drivers will be using the same registers to manage the debug session and updating those registers may introduce instability in the debug session and result in undefined behavior. 
      1. Please request information about what the customer is trying to do.
      2. Regarding accesses to DBGSCRext—is there a reason why this is desired over DBGSCRint?
      3. Per the Arm documentation, there are several criteria that must be met (please review v7 Arm Architecture Reference Manual (ARM) documentation for details).  One of those checks is: If DBGPRSR.SPD=1 then access to certain registers becomes undefined (this register should be readable though).  Please check this. 
      4. Per R5 TRM, there is a lock mechanism that will prevent writes to debug registers (see DBGLSR, DBGLAR) that will be relevant if you were to run outside of the CCS context.

    --------------------

    Best regards,

    Ming

  • As your system architect says, I run the code without CCS debugger, but the undefined exception still happens, so I think the undefined exception isn't resulted in by the CCS debugger environment. 

    a. What we are trying to do is to write our own code to implement debugging functions. So we should implement it with the help of some debug registers.

    b. Because DBGDSCRint is RO, and we need write DBGDSCR. Then the DBGDSCRext is RW, so we want to access DBGSCRext.

    c. d   I also find these requirements.  I also want to check the DBGPRSR.SPD and DBGLSR. But as the code in the following picture shows, reading the DBGPRSR and DBGLSR still result in the undefined exception. 

    So I have no idea to deal with this problem. Please tell me how to program in detail instead of guessing based on the manual. Thanks.

  • Hi Lin,

    I did try to read/write to the registers listed in Table C 6-3. Only the read of register 0, 1, 5 worked. I have sent an email out to wider audience for help. It may take a few days to get answer back. Thank you so much for your patience.

    Best regards,

    Ming 

  • Hi Lin,

    We have finally figured out the root cause of this issue. For ARM V7 architecture only a few CP14 registers can be accessed through the CP14 interface:

    The rest of the registers has to be accessed through the Memory Mapped Interface:

     

    Physical Address

    AM2434 – Arm R5F Core

    APB-AP (32-bit)

    SOC Address Space (36-bit)

    R5F0_0

    0x9D410000

    0x73D410000

    R5F0_1

    0x9D412000

    0x73D412000

    R5F1_0

    0x9D510000

    0x73D510000

    R5F1_1

    0x9D512000

    0x73D512000

    Since the CP14 memory mapped base addresses are 36-bit, so you will need to set up the RAT entry for it in syscfg:

    We mapped the 0x73D410000 to 0x10000000 in the RAT entry.

    Here is the code segment for accessing both CP14 interface and the memory mapped interface:

     

    uint32_t *CP14_MMR_region_ptr = (uint32_t *)0x10000000; /// Local address for 0x73D410000
    uint32_t cp14_193 = 0;
    uint32_t cp14_197 = 0;
    void hello_world_main(void *args)
    {
        /* Open drivers to open the UART driver for console */
        Drivers_open();
        Board_driversOpen();

        /// Register access through CP14 Interface
        __asm ("MRC p14, 0, r0, c0, c0, 0"); /// read DBDIDR (register 0)
        __asm ("MRC p14, 0, r0, c0, c1, 0"); /// read DBGDSRCint (register 1)
        __asm ("MRC p14, 0, r0, c0, c5, 0"); /// read DBGDTRRXint (register 5)
        ///__asm ("MCR p14, 0, r0, c0, c5, 0"); /// write DBGDTRTXint

        __asm ("MRC p14, 0, r0, c1, c0, 0"); /// read DBGDRAR (register 128)
        __asm ("MRC p14, 0, r0, c2, c0, 0"); /// read DBGDSAR (register 256)

        /// Register access through Memory Mapped Interface
        cp14_193 = CP14_MMR_region_ptr[193]; /// read DBGOSLSR (register 193)
        cp14_197 = CP14_MMR_region_ptr[197]; /// read DBGPRSR (register 197)

        DebugP_log("Hello World!\r\n");

        ... ...

    }

    I have tested the above code. It worked as expected. 

    Beware of the fact that this code is conflict with the DAP, so you cannot use the CCS memory browser to view the 0x10000000 area.

    Best regards,

    Ming