cancel
Showing results for 
Search instead for 
Did you mean: 

how to make a delay on STM32

maryuriy
Associate II
Posted on March 07, 2013 at 15:01

Hello!

how to make a delay of N clock cycles? (without timers)

I realized asm(NOP) is not working
5 REPLIES 5
Posted on March 07, 2013 at 15:40

I would use DWT_CYCCNT to get loops with some semblance of predictability, or to benchmark other constructs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 07, 2013 at 16:23

> I realized asm(NOP) is not working

In what whay it wouldn't work (if properly spelled of course)?

JW

maryuriy
Associate II
Posted on March 08, 2013 at 15:16

To clive1:

Asfar as I know, with this method is not accurate in

1

cycle

or at least in a few

cycles

.

To maclawek.jan:

I mean - it will work, but not as it should. And I have to get a delay in

N

clock cycles.

Document PM0056, page 103

:

NOP does nothing. NOP is not necessarily a time-consuming NOP. The processor might

remove it from the pipeline before it reaches the execution stage.

Maybe I'm wrong to understand something?

Posted on March 08, 2013 at 15:42

To clive1:

As far as I know, with this method is not accurate in

1

cycle

or at least in a few

cycles

.

 

Like I said you can use it for benching code sequences that give you specific delays. It's should be good for sub 10 cycle accuracy in a timing loop, so would clearly spank a timer/interrupt implementation.

You're simply not going to achieve the granularity you suggest, people who do this professionally use hardware to enforce signal placement.

In software you've got flash, cache mechanisms, structural alignment, prefetch, write buffers, memory contention and branch prediction in the way of getting single cycle predictability. I'd wager the spread in flash is closer to 4-5 cycles of potential variability for hard coded instruction sequences. I'd have to go dig for the thread with some specific measurements.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
maryuriy
Associate II
Posted on March 11, 2013 at 14:07

Thank you for reply. I like this thought, but hoped that a solution exists.