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

Looking function returns number of milliseconds since restart. Similar to millis() in Arduino world.

Hello all,

I am looking the way to make function returns number of milliseconds since restart, same functionality as millis() in Arduino world.

Using e2 Studio, micro is R7FA6T1AD3CFM.

I have tried such function, see below, but it works only under debugger, otherwise (DWT->CYCCNT) returns constant so whole function also returns constant.

Are there any solution?

uint32_t millis()
{
  uint32_t res = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKD);  //get system clock in Nz
  res = res / BSP_DELAY_UNITS_MILLISECONDS;  //convert to kHz
  res = (DWT->CYCCNT) / res; //get #of cycles and convert to mS
  return res;
}




[locked by: Sai (SWF) at 11:41 (GMT 0) on 5 Jan 2023]
Parents Reply Children