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.

AM6442: Why does calling __MRC(15,0, 9, 13, 0) crash the processor, and is there another way to get cycle count on R5F?

Part Number: AM6442

Tool/software:

From what I understand the standard way to count clock cycles on the ARM R5F (or pretty much any ARM processor) is to read the cycle count register (PMCCNTR).

See ARM documentation

https://developer.arm.com/documentation/ddi0460/d/Events-and-Performance-Monitor/Performance-monitoring-registers/c9--Cycle-Count-Register

The ARM Optimizing C/C++ Compiler v20.2.0.LTS reference manual SPNU151V February 2020 (page 124) shows built in functions (__MRC) for using the ARM MRC instruction which can be used to read the cycle count.

https://www.ti.com/lit/ug/spnu151v/spnu151v.pdf?ts=1719238978311&ref_url=https%253A%252F%252Fwww.google.com%252F

But when I try to read the cycle count it appears that the CPU throws an exception/interrupt.

Here is my code...

uint32_t count1 =  __MRC(15,0, 9, 13, 0);

Which disassembles to...

0xEE19CF1D            MRC        p15, #0, r12, c9, c13, #0

What could be the problem here?  I was thinking it was security permissions, but this seems to happen whether or not SYSFW is loaded.

I see multiple other examples of other people doing exactly the same thing.  So why is it broken in my case?  There is an enable register for the count register, but writing the enable register also causes an exception.

https://www.iar.com/knowledge/learn/debugging/monitor-performance-in-arm-cortex-a-from-your-code2/

Or if I can't use this instruction on the AM6442, is there another lightweight way to get a count of clock cycles?