We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
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!