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;