LPC4370 DWT cycle counter

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

LPC4370 DWT cycle counter

1,774 Views
a_bet
Contributor IV

Hi to you all.
I need to monitor the execution time of some chunks of code and searching on the internet I found that the DWT cycle counter "present on most M3/M4/M7 mcus" is a good way to do that.
Here two blog entries: mcuoneclipse from the forum member BlackNight‌ and this other one on embedded-computing.
The problem is that searching "DWT" or "Data Watchpoint and Trace" in the UM10503 LPC43xx User Manual doesn't lead to anything. No match.
So, is it called in a different way or not present at all?
If so, is there another similar (easy and lite) way I could measure exec time?

Best,
Andrea

Labels (3)
4 Replies

1,595 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Andrea,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
The DWT feature is integrated into the Cortex-M4 core, the LPC43xx is based on Cortex-M4 core, it definitely supports the DWT feature.
You can learn the information about it via The Definitive Guide to ARM Cortex M3 and Cortex M4 Processors.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,595 Views
BlackNight
NXP Employee
NXP Employee

Hi Andrea,

I have to admit that I'm not familiar with the LPC4370, but at least on the M4 of this device I'm very confident that the DWT is implemented. The reason why you don't find anything about the DWT is because this is a ARM core feature and these ARM core things are usually not documented in a vendor implementation.

You could quickly try it with the NXP MCUXpresso IDE as it has a view to show the counter, see Measuring ARM Cortex-M CPU Cycles Spent with the MCUXpresso Eclipse Registers View | MCU on Eclipse 

In version 11 (see New NXP MCUXpresso Eclipse IDE v11.0 | MCU on Eclipse ) it looks like this:

pastedImage_2.png

I hope this helps,

Erich

1,595 Views
a_bet
Contributor IV

Hi Erich,
I'm trying to investigate further.
I simplified my code in order to test only the timer.
Here's what I do:

/*DEBUG Timer Init*/

    uint32_t delta;
    uint32_t max = 0;
    uint32_t min = 0xFFFFFFFF;

    LPC4370_InitCycleCounter(); /*Init DWT HW*/

 while(1)
 {
  LPC4370_ResetCycleCounter(); /* reset cycle counter */

  LPC4370_EnableCycleCounter(); /* start counting */
  LPC_GPIO_PORT->B[DEBUGPIN_PORT][DEBUG_PIN1] = TRUE;
  LPC_GPIO_PORT->B[DEBUGPIN_PORT][DEBUG_PIN1] = FALSE;

  delta = LPC4370_GetCycleCounter();

  if(delta < min)
  {
   min = delta;
  }

  if (max < delta)
  {
      max = delta;
  }
 }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

So, If I run It for a while what I get is:
max = 2450 (~12us if running at 204 MHz)

min = 22 (~100ns if running at 204 MHz).
Here's also a pic of my scope and my setup:

photo_2019-08-30_16-02-36.jpg

photo_2019-08-30_16-03-05.jpg


I noticed that this 2450 value happens just at the very beginning and then no more.
Do you have a hint about why I don't get consistent measurements?
Best,
Andrea

0 Kudos

1,595 Views
a_bet
Contributor IV

Hi Erich,
thanks for the reply. You are right, I was able to perform my first measurement.
The problem is that maybe I use the wrong conversion from cycle counter to time.
I looked at the register before and after a block of code which moves un and down a pin, so that I can compare with a measurement from the scope.
What I do is Elapsed_Time = (DWT_after - DWT_before)*1/f_clk.
In my case f_clk is 204 MHz. 
So looking at DWT I got 50 us whereas the scope says 100 ns. Since we are talking order of magnitude here I suspect something is wrong with my DWT Measurement.

0 Kudos