cancel
Showing results for 
Search instead for 
Did you mean: 

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

OGhis
Senior

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;

1 ACCEPTED SOLUTION

Accepted Solutions

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

21 REPLIES 21
Imen.D
ST Employee

Hello @OGhis​ ,

Thanks for your contribution and reported issue.

Can you please share your ioc file for check the project settings and configuration. So, that it will be easier for us to reproduce the issue.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
OGhis
Senior

hi,

Generate the code with cubeMx en set a breakpoint on "Error_Handler()" in main.c and start the debugger and you see the issue.

OGhis
Senior

Not yet resolved in HAL lib V 1.2.0 of the STM32G4

OGhis
Senior

for library version 1.2.0 for the STM32G4:

Cannot understand why there is an external decalation of the uint32_t uwTickPrio; ==> there is a function uint32_t HAL_GetTickPrio(void) to get the result of the uwTickPrio.

DarkTaipei
Associate II

I hit the same issue and took me a while to debug. The problem will also show up when you enable -DUSE_FULL_ASSERT on the FreeRTOS, ThreadCreate example.

All stm32**xx_hal_timebase_tim.c will have a line

HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM17_IRQn, TickPriority, 0), where TickPriority = 1 << 4 => 16.

and in the stm32**xx_hal_cortex.c

void HAL_NVIC_SetPriority() function will check

assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)). This line check if the priority is less than 16. and of course, 16 is not less then 16 so it asserted if you enable the assertion.

Still not fixed?

Tony

DarkTaipei
Associate II

I think uwTickPrio is the storage for the HAL library to get the tick priority when necessary. It's a variable initialized with an invalid value (16). Since HAL_INIT is (should be) the first function to call. Inside the HAL_INIT, it will initialized the tick priority according to TICK_INT_PRIO at the stm32_hal_conf.h by calling HAL_InitTick().

The problem here is that the function HAL_InitTick() in stm32**xx_hal_timebase_tim.c, There should add a line

uwTickPrio = TickPriority; after the HAL_NVIC_SetPriority(). so the uwTickPrio will be set to correct value.

Tony

IIRC this was already reported for CubeMX templates in other STM32 family. And fixed.

-- pa

DUlia
Associate II

The issue is still not fixed. CubeMX 6.0.0.

Imen.D
ST Employee

Hello @DUlia​ ,

There is a major issue related to STM32CubeMX 6.0.0: IRQ preemption priorities are set to 0 after project migration.

The correction is ongoing for this issue.

Thank you for your understand.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen