How do I change the priorities for the TIM2?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 2: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.
- Labels:
-
STM32WB series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 2:22 AM
Is that SPL? Isn't it open source? Look at what NVIC_Init() does.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 7: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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 7:28 AM
... and then also look at what exactly those three HAL_*** "functions" do.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 9: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 7: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 7:17 PM
Thank you, that's actually my intention.
I will then use direct manipulation on the registers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 7:19 PM
I don't know where to get the SPL.
And thanks for the tip!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-10 7:52 PM
https://www.st.com/en/embedded-software/stm32-standard-peripheral-libraries.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
