Skip to main content
leonardo
Associate III
September 26, 2020
Question

DWT_CYCCNT does not seems to count cycle

  • September 26, 2020
  • 2 replies
  • 2246 views

I'm using follow code:

volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; //address of the register
volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; //address of the register
volatile unsigned int *DWT_LAR = (volatile unsigned int *)0xE0001FB0; //address of the register
volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; //address of the register
 
 *SCB_DEMCR |= 0x01000000;
 *DWT_LAR = 0xC5ACCE55; // unlock
 *DWT_CYCCNT = 0; // reset the counter
 *DWT_CONTROL |= 1 ; // enable the counter
 uint32_t start=0, end=0;
 uint32_t array[100];
 uint32_t idx=0;
 
 *DWT_CYCCNT = 0;
 start = *DWT_CYCCNT;
 idx=1;
 end = *DWT_CYCCNT;
 idx=0;

I put a breackpoint on line 18 and I get:

start=9

end=22

*DWT_CYCCNT = 29

I'm expecting that start could be something like 2 and end something like 4 or 6. Why I get this results?

Is DWT working in an stm32f722?

thank

This topic has been closed for replies.

2 replies

TDK
Super User
September 26, 2020

These are C statements, not assembly. Examine the disassembly to see what instructions are between start and end. Cache and flash wait states can also have an effect.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
September 27, 2020

Time 100 or 1000 iterations of the code to benchmark, subtract out overhead of empty vs test loop

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
leonardo
leonardoAuthor
Associate III
September 28, 2020

The problem I see is a difference between cortex M4 (stm32f411) and M7 (stm32f722)

On M4 I can run the code posted and I get exactly 2 cycle, I can run this other code:

	*DWT_CYCCNT = 0;
	uint_test=1;	// 2 ciclos
	*DWT_CYCCNT = 0;
	float_test=1;	// 2 ciclos
	*DWT_CYCCNT = 0;
	float_test=3.4f * 1.000054f;
	*DWT_CYCCNT = 0;
	float_test=3.4 * float_test;

and get exactly what I expect on debug viewer.

But on M7 I get very wrong values.

I can't find on stm32f722 reference manual the implementation of DWT_CYCCNT. So I'm wondering about the working of this module on M7

In fact, DWT_CYCNT is changing ther values (counting) without code line 6 to 9 on first post. It seems like the DWT is configured and enabled by default? My project is generated using cubemx tool.