This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using GPIO for timing execution of functions

I have a need to measure the execution time of certain functions using an oscilloscope. When I enter the function I toggle a pin high, and before exiting the function I toggle the pin low.

I'm using an STM32F7 (Cortex M7) processor and using armcc in Keil.

I noticed that sometimes, even if the function takes a while to execute, I wouldn't see the pins toggling on the oscilloscope. I also noticed some weird things like if did a pin toggle (using STMicro's low level libraries) versus explicitly setting the pin high and low, I would get different behaviors.

It is my understanding that the compiler can re-order certain instructions. The read/write order to volatile locations will keep its order with respect to other read/writes to volatile locations, but other code can be moved around.

Do I need to be using some of the memory barrier intrinsics, like __dsb(), __dmb(), or __isb?

I found a reference here: http://www.keil.com/support/man/docs/armcc/armcc_chr1359124212159.htm but I am still a little bit confused.

  • The compiler will not re-order around function calls. Thus if your pin set/reset function is called and not inlined there is no re-ordering. Also, on a CM7, I doubt there is much re-ordering the compiler will do.
    Anyway, you can simply check by disassembling the entry and exit code. Make sure, you have only a single exit!
    Also, I suggest to make a tight loop setting/reseting a pin to measure the overhead!