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
  • Former Member
    0 Former Member in reply to Serge

    It's not presented in the FSP Stacks as it's the Cortex-M core feature.

    The initialization should be the following

    SysTick_Config(SystemCoreClock / 1000);//1000 is the number of ticks per second
        NVIC_SetPriority(SysTick_IRQn, 0); // Set User configured Priority for Systick Interrupt, 0 is the interrupt priority

    And the usage:

    void SysTick_Handler (void)
    {
        tick ++;
    }

    uint32_t millis (void)
    {
        return tick;
    }

    Kind regards,

    Sergey

    If this response, or one provided by another user, answers your question, please verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    https://en-support.renesas.com/knowledgeBase/

Children