title: How to write a time difference function to STM32F4
body: <p>i am working on STM32F4 and pretty new at it. I know basics of C but with more than 1 day research, i still not found a solution of this.</p>
  
  <p>I simply want to make a delay function myself, processor runs at 168MHz ( HCLK ). So my intuition says that it produces 168x10^6 clock cycles at each seconds. So the method should be something like that,</p>
  
  <p>1-Store current clock count to a variable</p>
  
  <p>2-Time diff = (  clock value at any time -  stored starting clock value ) / 168000000</p>
  
  <p>This flow should give me time difference in terms of seconds and then i can use it to convert whatever i want.</p>
  
  <p>But, unfortunately, despite it seems so easy, I just cant implement any methods to MCU. </p>
  
  <p>I tried time.h but it did not work properly. For ex, clock() gave same result over and over, and time( the one returns seconds since 1970 ) gave hexadecimal 0xFFFFFFFF ( -1, I guess means error ) .</p>
  
  <p>Thanks.</p>
  
  <p>Edit : While writing i assumed that some func like clock() will return total clock count since the start of program flow, but now i think after 4Billion/168Million secs it will overflow uint32_t size. I am really confused.</p>