Page 1 of 1

Where to find "SysTick->VAL" is modified ?

Posted: Sat Mar 02, 2024 10:34 am
by r1s8k
Hi,

I just want to learn how things are working, I've been searching about source code which is responsible for setting system clock or function that count millis and micros for the micrcontroller.

I found it in this path:
...\Arduino\hardware\Arduino_Core_STM32-main\libraries\SrcWrapper\src\stm32\clock.c
Which are these two functions:

Code: Select all

#include "backup.h"
#include "clock.h"
#include "lock_resource.h"
#include "otp.h"
#include "stm32yyxx_ll_cortex.h"
#include "stm32yyxx_ll_rcc.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
  * @brief  Function called to read the current micro second
  * @param  None
  * @retval None
  */
uint32_t getCurrentMicros(void)
{
  uint32_t m0 = HAL_GetTick();
  __IO uint32_t u0 = SysTick->VAL;
  uint32_t m1 = HAL_GetTick();
  __IO uint32_t u1 = SysTick->VAL;
  const uint32_t tms = SysTick->LOAD + 1;

  if (m1 != m0) {
    return (m1 * 1000 + ((tms - u1) * 1000) / tms);
  } else {
    return (m0 * 1000 + ((tms - u0) * 1000) / tms);
  }
}

/**
  * @brief  Function called wto read the current millisecond
  * @param  None
  * @retval None
  */
uint32_t getCurrentMillis(void)
{
  return HAL_GetTick();
}
Everything is good, I just want to know where

Code: Select all

SysTick->VAL
is modified.

I opened all the included libraries, but couldn't find it there.

Re: Where to find "SysTick->VAL" is modified ?

Posted: Sat Mar 02, 2024 11:35 am
by GonzoG
You won't find it. It's hardware counter. It's changed by hardware.

Re: Where to find "SysTick->VAL" is modified ?

Posted: Sat Mar 02, 2024 12:03 pm
by r1s8k
OK thanks.