Skip to main content
THA.1
Associate III
December 14, 2021
Solved

(Bug Report) SysTick NVIC priority is incorrectly configured at the initialization code

  • December 14, 2021
  • 2 replies
  • 1463 views

(Environment)

MC_SDK 5.Y.3 + STM32CubeMX 6.3.0 + IAR EWARM 8.5

(Hardware)

NUCLEO-F446RE + X-NUCLEO-IHM08M1 + Low Voltage BLDC motor

(What I found)

  • By CubeMX, SysTick NVIC priority is configured as Priority Group=3bit+1bit, PreemptPriority=4, SubPriority=0
  • At main(), HAL_Init() and SystemClock_Config() implement the above configuration, then I can read the same values for their registers.
  • Right after the above code, however, MX_MotorControl_Init() calls HAL_SYSTICK_Config(), where SysTick priority is set to 15, PreemptPriority=7, SubPriority=1

(Question)

  • Is that a defect or am I doing something wrong in configuration & code generation?
  • If a defect, is it good enough to add HAL_NVIC_SetPriority() for SysTick in MX_MotorContorl_Init()?
  • Or removing NVIC_SetPriority() in SysTick_Config() would be better?

SysTick initialization code looks a little messy.

This topic has been closed for replies.
Best answer by cedric H

Hello @THA.1​ ,

You are right, the MX_MotorControl_Init() overwrites the SysTick priority, and this is a bug.

If you generate with HAL, you could replace the following line in MX_MotorControl_Init(void) :

 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/SYS_TICK_FREQUENCY);

by this one :

HAL_SetTickFreq(HAL_RCC_GetHCLKFreq()/SYS_TICK_FREQUENCY);

Doing this will restore the SYSTick interrupt level set by HAL_Init(), and this is what we want.

Thanks for reporting.

Please note that the strategy for the systick is to be the lowest priority compared to other interrupts. As by default the MX_MotorControl_INIT() reset it to the lowest possible value, we did not catch it.

We advice our users who want to use another interrupt for there own application to set its priority level under the one of Systick, which is not possible due to this bug. We plan to fix it in the next release.

Regards

Cedric

2 replies

cedric H
cedric HBest answer
Technical Moderator
December 15, 2021

Hello @THA.1​ ,

You are right, the MX_MotorControl_Init() overwrites the SysTick priority, and this is a bug.

If you generate with HAL, you could replace the following line in MX_MotorControl_Init(void) :

 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/SYS_TICK_FREQUENCY);

by this one :

HAL_SetTickFreq(HAL_RCC_GetHCLKFreq()/SYS_TICK_FREQUENCY);

Doing this will restore the SYSTick interrupt level set by HAL_Init(), and this is what we want.

Thanks for reporting.

Please note that the strategy for the systick is to be the lowest priority compared to other interrupts. As by default the MX_MotorControl_INIT() reset it to the lowest possible value, we did not catch it.

We advice our users who want to use another interrupt for there own application to set its priority level under the one of Systick, which is not possible due to this bug. We plan to fix it in the next release.

Regards

Cedric

cedric H
Technical Moderator
December 15, 2021

Sorry, I answered to fast,

HAL_SetTickFreq does the job, but the prototype is not the right one.

I come back after additional tests.

Cedric

THA.1
THA.1Author
Associate III
December 16, 2021

Thank you!

I would be able to manage this before the next release :)