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?
__dsb()
I found a reference here: http://www.keil.com/support/man/docs/armcc/armcc_chr1359124212159.htm but I am still a little bit confused.