2021-06-10 02:07 AM
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.
2021-06-10 02:22 AM
Is that SPL? Isn't it open source? Look at what NVIC_Init() does.
JW
2021-06-10 07:19 AM
> 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);
2021-06-10 07:28 AM
... and then also look at what exactly those three HAL_*** "functions" do.
JW
2021-06-10 09:40 AM
> 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
2021-06-10 07:17 PM
>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.
2021-06-10 07:17 PM
Thank you, that's actually my intention.
I will then use direct manipulation on the registers.
2021-06-10 07:19 PM
I don't know where to get the SPL.
And thanks for the tip!
2021-06-10 07:52 PM
2021-06-10 10:04 PM
> 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