cancel
Showing results for 
Search instead for 
Did you mean: 

Hal_gettick equivalent in LL

JCuna.1
Senior

I almost migrated all my code from Hal to LL and I am really happy for the execution improvent and better size footprint of the code.

However, I can not find a way to make/get a equivalent function as hal_gettick provide me. Usually I use state machine and I control the execution time with a elapsed time from times tick.

Is there a equivalent code in LL, or there is a way to make my own implementation. At the moment I am only generating Hal for RCC in order to no disable the HAL library :D :D​

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

AFAIK you have to roll your own.

First, get the SysTick running in main:

SysTick_Config(SystemCoreClock/1000); // will generate an overflow interrupt every ms.

Second: Define a global variable wich you increment in the SysTick interrupt handler

volatile uint32_t SysTick_counter;
 
void SysTick_Handler(void)
{
 /* USER CODE BEGIN SysTick_IRQn 0 */
   SysTick_counter++;
 /* USER CODE END SysTick_IRQn 0 */
 
 /* USER CODE BEGIN SysTick_IRQn 1 */
 
 /* USER CODE END SysTick_IRQn 1 */
}

Now you can access that variable or wrap it with you own getter.

See HAL_Delay implementation for an example.

hth

KnarfB

View solution in original post

2 REPLIES 2
KnarfB
Principal III

AFAIK you have to roll your own.

First, get the SysTick running in main:

SysTick_Config(SystemCoreClock/1000); // will generate an overflow interrupt every ms.

Second: Define a global variable wich you increment in the SysTick interrupt handler

volatile uint32_t SysTick_counter;
 
void SysTick_Handler(void)
{
 /* USER CODE BEGIN SysTick_IRQn 0 */
   SysTick_counter++;
 /* USER CODE END SysTick_IRQn 0 */
 
 /* USER CODE BEGIN SysTick_IRQn 1 */
 
 /* USER CODE END SysTick_IRQn 1 */
}

Now you can access that variable or wrap it with you own getter.

See HAL_Delay implementation for an example.

hth

KnarfB

JCuna.1
Senior

This is my workaround:

time_stick.h

#ifndef TIME_STICK_H
#define TIME_STICK_H
 
#include "main.h"
 
uint32_t time_stick_get(void);
void time_stick_inc(void);
 
 
#endif /* TIME_STICK_H */

time_stick.c

#include "time_stick.h"
 
__IO uint32_t uwTick;
uint32_t uwTickFreq = 1;
 
uint32_t time_stick_get(void)
{
  return uwTick;
}
 
void time_stick_inc(void)
{
  uwTick += (uint32_t)uwTickFreq;
}

In main.h I add #include "time_stick.h"

In stm32g0xx_it.c I add ime_stick_inc();

void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */
	time_stick_inc();
  /* USER CODE END SysTick_IRQn 0 */
 
  /* USER CODE BEGIN SysTick_IRQn 1 */
 
  /* USER CODE END SysTick_IRQn 1 */
}

and now I can use time_stick_get() as HAL_GetTick()

Don't forget to add LL_SYSTICK_EnableIT(); after mx initialization