cancel
Showing results for 
Search instead for 
Did you mean: 

How do I change the priorities for the TIM2?

StephanMair
Senior

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.

13 REPLIES 13

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

JW

TDK
Guru

> 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".

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

JW

Pavel A.
Evangelist III

> 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

>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.

Thank you, that's actually my intention.

I will then use direct manipulation on the registers.

I don't know where to get the SPL.

And thanks for the tip!

First hit for "stm32 spl":
https://www.st.com/en/embedded-software/stm32-standard-peripheral-libraries.html
If you feel a post has answered your question, please click "Accept as Solution".

> 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