2021-12-01 10:42 PM
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
Solved! Go to Solution.
2021-12-02 01:11 AM
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
2021-12-02 01:11 AM
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
2021-12-02 02:03 PM
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