cancel
Showing results for 
Search instead for 
Did you mean: 

SysTick code generatd by STM32CubeMX, HAL versus LL drivers

Jim Rodrian
Associate III
Posted on October 31, 2017 at 19:18

I'm using STM32CubeMX to generate code for a custom STM32L051R8T6 project.  SysTick functions as expected when HAL drivers are selected.  SysTick does not work if LL drivers are selected.  Is there a reason why STM32CubeMX generated SysTick code only works when HAL drivers are selected for 'RCC'?

#systick #hal-versus-ll-drivers
6 REPLIES 6
Amel NASRI
ST Employee
Posted on November 01, 2017 at 10:26

Hi

Rodrian.Jim

‌,

How exactly are you checking if Systick is working or not?

There should be some missing calls that you need to add. Try to identify what is missing there.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Jim Rodrian
Associate III
Posted on November 02, 2017 at 15:07

SysTick is working when 'void SysTick_Handler(void)' is executed once every millisecond.  The HAL driver code automatically enables execution of the SysTick_Handler function.  The LL driver code does not execute the SysTick_Handler function.  For now, I will stay with the HAL driver code (which requires significantly more code space than the LL driver code.)

Jim

Dan Perrett
Associate
Posted on January 10, 2018 at 13:08

I believe he problem is in this function in stm32f4xx_ll_utils.h:

__STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks)
{
 /* Configure the SysTick to have interrupt in 1ms time base */
 SysTick->LOAD = (uint32_t)((HCLKFrequency / Ticks) - 1UL); /* set reload register */
 SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
 SysTick_CTRL_ENABLE_Msk;�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I think the call to modify the CTRL register shouldbe

 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk
 | SysTick_CTRL_ENABLE_Msk
 | SysTick_CTRL_TICKINT_Msk�?�?�?�?;�?�?�?�?�?�?

EDIT - This didn't work although I'm not sure why - the TICKINT bit remains 0. I manuallyset the bit at the end of setup:

SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk); �?

Posted on January 10, 2018 at 18:51

Probably you need LL_SYSTICK_EnableIT();

because for LL the IT is not enabled (HAL enables it automatically)

Jeanne Joly
Senior III
Posted on February 12, 2018 at 12:00

Hello

Rodrian.Jim

,

Do you try on the current CubeMX release (CubeMX-4.24)?

On this version, when I generate the code for STM32L051R8Tx with RCC set with LL drivers, I obtain this generated code :

int maint(void)

{

LL_Init();

SystemClock_Config();

....

}

void SystemClock_Config(void)

{

....

/* Wait till System clock is ready */

while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI)

{

}

LL_Init1msTick(2097000);

LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);

LL_SetSystemCoreClock(2097000);

/* SysTick_IRQn interrupt configuration */

NVIC_SetPriority(SysTick_IRQn, 0);

}

and LL_SYSTICK_SetClikSource set the bit for the clk source :

/**

* @brief Configures the SysTick clock source

* @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_SetClkSource

* @param Source This parameter can be one of the following values:

* @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8

* @arg @ref LL_SYSTICK_CLKSOURCE_HCLK

* @retval None

*/

__STATIC_INLINE void LL_SYSTICK_SetClkSource(uint32_t Source)

{

if (Source == LL_SYSTICK_CLKSOURCE_HCLK)

{

SET_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);

}

else

{

CLEAR_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);

}

}

Then the SystemCoreClock and the interrupt priority are set.

It should work with this part of code.

Hope it will help you.

BR. Jeanne

Posted on February 12, 2018 at 12:57

Take a look at systick-_config() that's available on most cmsis system. You need to enable the systick isr.

Using libraries allows you to trade one set of problems (steep learning curve on the mcu and it's peripherals) with another set of problems (steep learning curve on the library API and it's bugs). You have to pick the poison, so to speak. For something as simple as systick, going naked is better, I think.