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

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
r1s8k
Posts: 15
Joined: Tue Mar 10, 2020 7:14 pm
Answers: 1

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

Post 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.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

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

Post by GonzoG »

You won't find it. It's hardware counter. It's changed by hardware.
r1s8k
Posts: 15
Joined: Tue Mar 10, 2020 7:14 pm
Answers: 1

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

Post by r1s8k »

OK thanks.
Post Reply

Return to “General discussion”