/*############################################################# Program Name : ex1_timer_startstop Author : Grant Phillips Date Modified : 16/01/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example program to demonstrate the use of the Timer class to measure the time delay between starting the timer and stopping the timer. Requirements : * STM32F4-Discovery Board Circuit : * A wire link between PB3 and pin6 of the SWD connector (CN2) as explained in the SWV examples section ##############################################################*/ #include "mbed.h" #include "SWO.h" SWO_Channel SWO; //create SWO object to communicate via ST-Link programmer Timer t; //create a timer object int main() { while(1) { t.start(); //start the timer SWO.printf("Start task!\n"); //do the task(s) here t.stop(); //stop the timer SWO.printf("It took %f seconds to finish the task\n", t.read()); //read the timer value // OR //SWO.printf("It took %d ms to finish the task\n", t.read_ms()); // OR //SWO.printf("It took %d us to finish the task\n", t.read_us()); t.reset(); //reset the timer to 0 wait(1); } }