cortex-m0 instruction cycle count

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

cortex-m0 instruction cycle count

8,873 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Sat Apr 23 02:57:17 MST 2011
Hai
     While debugging with lpc13xx i used to find the elapsed instruction cycles using cycle and cycledelta core registers. I see none of those registers in lpc1114. Probably the cm0 core doesn't have advanced debugging core registers like cm3. Is there a way to find the elapsed time in cm0 using the debugger? or suggest me any other means.
0 Kudos
Reply
10 Replies

7,781 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rmteo on Sun Apr 24 08:43:55 MST 2011
That's too bad.  Sure would make cycle counting so easy just using breakpoints.
0 Kudos
Reply

7,781 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Apr 24 08:20:47 MST 2011
Again: No
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rmteo on Sun Apr 24 08:15:44 MST 2011
OK, does the LPCXpresso IDE have a cycle counter when in debug mode similar to below?
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Apr 24 08:05:42 MST 2011
No, it's LPCXpresso and M0 (not M3).
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rmteo on Sun Apr 24 08:00:13 MST 2011
Does the IDE have a cycle counter when in debug mode similar to below?
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sat Apr 23 12:33:17 MST 2011

Quote: Zero
DWT is used for Core Registers cycle counter.

That's the reason why there's no cycle counter for M0 in LPCXpresso.



Thanks for the tip, I should have looked in LPCXpresso as well.
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Apr 23 12:27:37 MST 2011
DWT is used for Core Registers cycle counter.

That's the reason why there's no cycle counter for M0 in LPCXpresso.
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sat Apr 23 11:09:21 MST 2011
Hi vasanth,

This is something that was posted earlier on another thread:

http://knowledgebase.nxp.com/showpost.php?p=6719&postcount=8

It may be the method you were using with the lpc13xx series but I thought it would be good to post it here for continuity.

fastmappers link is a good one.  I don't know if the LPC1114 has this implemented as fully as the  lpc13xx but look for the DWT in the documentation.

I need more coffee so I hope this made sense.

EDIT: After reading the TRM it appears that the counters are not implemented in the LPC1114 (M0).

EDIT2: I forgot to mention that I like Zero's method.
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Apr 23 08:10:52 MST 2011
A common way to measure times is SysTick timer:

volatile unsigned int timer=0;
void SysTick_Handler(void)                 //SysTick interrupt handler
{
 timer++;
}

unsigned int time;
#define systick_start  SysTick->VAL=10E6;SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;
#define systick_stop   SysTick->CTRL&=~(SysTick_CTRL_ENABLE_Msk);time = 10E6-SysTick->VAL;

//init SysTick
 SysTick_Config(10E6);  // Setup SysTick Timer
 systick_stop;            //and stop it  again  
......  
[COLOR=Red]systick_start;
   //time to measure
[/COLOR][COLOR=Red]systick_stop;
[/COLOR]
1. If you debug your program, SysTick isn't stopping, so don't suspend your program between systick_start and systick_stop.

2. SysTick is working with 24bit values, so don't set its values higher than 33.55E6.

3. A few cycles are needed to stop SysTick, so work relative.
0 Kudos
Reply

7,776 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fastmapper on Sat Apr 23 07:57:37 MST 2011
For short code sequences, you could use the assembly language and the cycle counts for each instruction documented in section 3.3 of the Cortex-M0 Technical Reference Manual (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0432c/index.html).

For longer code sequences, you could use a timer that is not used by your application.  Simply configure the timer with a prescale of 1 and start it counting at the beginning of your application, then read the timer value at the start and end of the code to be timed.  The difference in the counts will tell you how much time elapsed between timer reads.  Since this technique modifies your code, it will not generally provide one cycle precision, but it can get pretty close.
0 Kudos
Reply