Skip to main content
OGhis
Senior
February 10, 2020
Solved

HAL_NVIC_SetPriority assert issue and incorrect Preempt Priority value for the STM32F4 / STM32G4 /...

i had used used cubemx 5.5 and in 'System Core' => 'SYS' configurated the 'Time Source' as TIM7 and enabled the option 'Enable Full Assert'

On running the project a had an assert that fails over the Preempt Priority value for the timer (TIM7)

The PreemptPriority value for the HAL_NVIC_SetPriority variate from 0-15, but when the HAL_RCC_ClockConfig function is called is this value 16. (max 4 bits long) .

The reason comes from the File STM32F4xx_hal.c where uwTickPrio is defined as follow:

uint32_t uwTickPrio  = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */

In main.c with the function HAL_Init() is the PreemptPrioity value correct but with the SystemClock_Config() function is the PreemptPrioity value overridden by the uwTickPrio  value.

The issue comes from the WEAK function HAL_InitTick in the weak function is the uwTickPrio  initialized, but the HAL_InitTick is overridden in the stm32f4xx_hal_timebase_tim.c

So the only possible solution i had found is to add the following code before HAL_NVIC_SetPriority(TIM7_IRQn, TickPriority ,0); in the HAL_InitTick of the file stm32f4xx_hal_timebase_tim.c that was generated by cubemx.

uwTickPrio = TickPriority;

This topic has been closed for replies.
Imen.DBest answer
ST Technical Moderator
November 4, 2020

Hello @Simon Sq​ ,

The proposal fix is to add the following code "uwTickPrio = TickPriority;" in stm32f4xx_hal_timebase_tim.c file before this line:

HAL_NVIC_SetPriority(TIM7_IRQn, TickPriority ,0); under /*Configure the TIM7 IRQ priority */

I'm checking with the development team on the status of this issue.

Our apologies for the delay.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks

21 replies

AKana.1
Visitor II
June 11, 2021

The code

uwTickPrio = TICK_INT_PRIORITY;

is just copied from __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)

Seems like generated new HAL_InitTick just miss the same default initialization

FJahn.3
Visitor II
October 21, 2021

Still an issue in version 1.7.0, but inserting "uwTickPrio = TickPriority;" as suggested above works for me

OR Insert the below in the autogenerated main.c file.

 /* USER CODE BEGIN Init */

 uwTickPrio = TICK_INT_PRIORITY; /// Work-around for when "Enable Full Assert" in CUBEMX

 /* USER CODE END Init */

MGall.8
Visitor II
March 31, 2022

The sad thing is that after more than two years (with CubeMx 6.5.0 and STM32G0 firmware package 1.5.0) this bug is still not fixed...