Skip to main content
StephanMair
Associate III
June 10, 2021
Question

How do I change the priorities for the TIM2?

  • June 10, 2021
  • 6 replies
  • 2772 views

Hi, I'm using STM32WB55x series mcu, I wanna know how I should configure/change the relevant priority for the TIM2?

In the old days we use this:

void NVIC_Configuration(void) 
 
{
 
	NVIC_InitTypeDef NVIC_InitStructure;
 
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
 
	 
 
	NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; 
 
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; 
 
	NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; 
 
	NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; 
 
	
 
	NVIC_Init(&NVIC_InitStructure);
 
}

I don't know what we should do now given it's the day and age of HAL and CubeMX.

What should I do? If there's a register manipulating solution, it would be better.

This topic has been closed for replies.

6 replies

waclawek.jan
Super User
June 10, 2021

Is that SPL? Isn't it open source? Look at what NVIC_Init() does.

JW

TDK
Super User
June 10, 2021

> I don't know what we should do now given it's the day and age of HAL and CubeMX.

If you have old code, it will still work. You can simply keep using it if you want.

> What should I do?

For example:

HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
 
HAL_NVIC_SetPriority(PVD_PVM_IRQn, 0, 0);
 
HAL_NVIC_EnableIRQ(PVD_PVM_IRQn);
 

"If you feel a post has answered your question, please click ""Accept as Solution""."
StephanMair
Associate III
June 11, 2021

>If you have old code, it will still work. You can simply keep using it if you want.

Well the thing is, SPL doesn't appear to be a part of the keil's "pack", and I don't know where to obtain the relevant SPL source code, and I don't know which header file to include.

TDK
Super User
June 11, 2021
"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
June 10, 2021

... and then also look at what exactly those three HAL_*** "functions" do.

JW

StephanMair
Associate III
June 11, 2021

Thank you, that's actually my intention.

I will then use direct manipulation on the registers.

Pavel A.
Super User
June 10, 2021

> In the old days we use this:

> NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

> NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;

So these days, as TDK wrote, the "HAL" library uses NVIC_PRIORITYGROUP_4.

Do not use sub-priorities, unless there's a strong requirement.

--pa

StephanMair
Associate III
June 11, 2021

I don't know where to get the SPL.

And thanks for the tip!

waclawek.jan
Super User
June 11, 2021

> I don't know where to get the SPL.

ST ceased to port SPL to newer families once Cube/HAL was around, but NVIC is part of the processor core, so you can use SPL of any product using the same Cortex-M core for this purpose.

But you don't need to look at SPL, see below.

> I will then use direct manipulation on the registers.

That's what SPL does. But I don't recommend you to do that. As NVIC is part of the core, once you use the standard CMSIS-mandated headers (which you do by #include "stm32fxxxx" where xxxx is the STM32 model you are using; you may include this indirectly if you use any "library") so use the standard CMSIS functions for NVIC. That's what Cube/HAL does, anyway.

 NVIC_SetPriorityGrouping(3); // SCB_AIRCR.PRIGROUP == 0b011 for 4 bit (maximum) group priority in STM32 with Cortex-M4 core
 NVIC_SetPriority(PVD_PVM_IRQn, 0); // 0 - highest, 15 - lowest
 NVIC_EnableIRQ(PVD_PVM_IRQn);

Read NVIC design hints and tips and Binary point subchapters in PM0214.

JW

Piranha
Principal III
June 13, 2021

As I've said it previously, NVIC is already set to a maximum group priorities after reset. Therefore for a typical usage there is no reason in calling NVIC_SetPriorityGrouping() at all.

https://community.st.com/s/question/0D53W00000XHZKb/nested-interrupts-stm32l4

waclawek.jan
Super User
June 18, 2021

You can go direc the most useful settingtly for the registers but in this particular case it's counterproductive. The NVIC register are part of the processor core and the functions to access them are provided by ARM and are well established.

Piranha also says that you don't need to change the priority grouping as they are set to the most useful setting by reset.

JW