Cortex-A9 , Arm Compiler 5 (DS built int) , Read CNTFRQ register

104 Views Asked by At

I try to read CNTFRQ register with inline assembly code. I use the following:

  1. Arria V soc evaluation board
  2. Bare-Metal app
  3. Arm Compiler 5 (DS built in)

I encountered two issues:

  1. I tried to use "regular" syntax which I saw in other places as well and it didn't work.

     static uint32_t freq = 0;
     __asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (freq));
    

I don't know what is wrong with this syntax:

  1. I tried another syntax:

    __asm
    {
        mrc p15, 0, freq, c14, c0, 0
    }
    

Now the code compiles but I have two problems:

  • There is no volatile statement

  • When I execute this asm code via debugger it halts when it reaches the asm code and that's it (I don't see the print value and can't continue to next step or running the debugger)

2

There are 2 best solutions below

1
Martin Rosenau On BEST ANSWER

Although many compilers use GNU's inline assembly syntax (what you call "regular syntax"), the syntax of inline assembly is not standardized and many compilers use a different syntax.

Obviously, your compiler is one of them.

There is no volatile statement

You must check the compiler manual for the correct syntax of inline assembly. Maybe the compiler always treats inline assembly the way GNU C/C++ would treat __asm volatile.

When I execute this asm code via debugger it halts when it reaches the asm code and that's it

The CNTFRQ register is not mentioned in the Cortex-A9 manual. Are you sure that this register exists on your CPU?

3
hutcruchi On

Thank you for your help. It turns out that the cortex-A9 doesn't have the CNTFRQ register. So that's the answer for my original question.

Maybe you know how I can get the CPU freq in cortex-A9? which register I can read?

Thanks