cancel
Showing results for 
Search instead for 
Did you mean: 

Creating delay using __asm__("nop")

MGado.1
Associate

How to measure the time from __asm__("nop") on STM32F730 using 216 MHz clock? I did try to check it using osciloscope without success. The time is bigger than 1/216 MHz.

3 REPLIES 3
TDK
Guru

DWT->CYCCNT will measure ticks. You'll need to figure out and subtract off the overhead for accessing it.

https://community.arm.com/developer/ip-products/processors/f/cortex-m-forum/8952/where-to-find-the-execution-cycles-of-cortex-m7-instruction

The Cortex-M7 pipeline is not as straightforward as it is for Cortex-M4. NOP instruction isn't guaranteed to take any time at all.

If you feel a post has answered your question, please click "Accept as Solution".

Why would you do it this way? Seems highly prone to caching and superscalar issues, not to mention interrupts.

Can't you use a 32-bit TIM to account for passage of time, or use the DWT_CYCCNT to count cycles?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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, finish, delta;

start = *DWT_CYCCNT;

...

finish = *DWT_CYCCNT;

delta = (finish - start);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..