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;
}

Parents Reply Children
No Data