2013-06-07 02:56 AM
STM32F2xx_StdPeriph_Lib_V1.1.0
NVIC_Init()
inmisc.c has problems with AIRCR.PRIGROUP< 0b011.
After reset, SCB->AIRCR.PRIGROUP ==0b000
Calculation is then asfollows:tmppriority=
(
7 - PRIGROUP) ==> 7- 0b00 ==> 7
tmppre = 4- tmppriority
==> (uint_8)(-3) ==> 0xFD
tmpsub = 0x0F >> tmppriority ==> 0x0F >> 7 ==>0x00
tmppriority =
PreemptionPriority
<<tmppre ==> (0..F) << 0xFD ==> 0x00 // always zero, independentlyof
PreemptionPriority
tmppriority |=SubPriority
& tmpsub==> (0..F) & 0x00 ==> 0x00 // alwayszero, independently of
SubPriority
tmppriority <<= 4
==> 0x00 // always zero, independently of
PreemptionPriority
or
SubPriority
NVIC->
IP
[
IRQChannel
]
= tmppriorityThat is: given Preemption- orSubPriority has no effect, all interrupts get programmed with IP==0x00,thus having the same group priority(0).
Result: nopreemption.
WithPRIGROUP == 0b011:
tmppriority=
(
7 - PRIGROUP) ==> 7 - 0b011 ==>4
tmppre = 4- tmppriority
==> 0
tmpsub = 0x0F >> tmppriority ==> 0x0F >> 0 ==>0x0F
tmppriority =
PreemptionPriority
<< tmppre ==> (0..F)<< 0 ==>PreemptionPriority
(0..F)tmppriority |=SubPriority
&tmpsub==> (0..F) & 0x0F ==>
PreemptionPriority | SubPriority
(0..F) // this makes no sense, IMHOtmppriority <<= 4 ==>0x00..0xF0
NVIC->IP[IRQChannel]
= tmppriority
Is this behaviour by design?What is the recommended procedure to set IRQ preemption priority using NVIC_Init()? #stm32-nvic-peripheral-library2013-06-07 03:11 AM
misc.c:
How to configure Interrupts using driver 1. Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig() JW2013-06-07 03:18 AM
This sets only SCR->AIRCR.PRIGROUP, but does not solve the issue mentioned.
2013-06-07 03:47 AM
Is this behaviour by design?
What is the recommended procedure to set IRQ preemption priority using NVIC_Init()?
I think you are right, NVIC_Init() is likely to be buggy. Note that you don't really need the stm32 library, you are free to set priority registers as you like.You can include core_cm3.h alone, it contains everything you need to access those registers and it also has some nice functions to set priorities and groups.
2013-06-07 05:04 AM
> This sets only SCR->AIRCR.PRIGROUP, but does not solve the issue mentioned.
Yes, it does, if you follow the instructions, i.e. use first NVIC_PriorityGroupConfig() with one of the NVIC_PriorityGroup_x - note how they are defined in misc.h. I don't say it can't be improved, but as Knik said above, you might be better off not using it, if it does not fit your style. JW2013-06-07 09:29 AM
Sure, actually I'd even prefer to not use the STM32 peripheral library at all, but there are forces beyond my control that drive me to use it ;)
Anyway, programming SCR->AIRCR.PRIGROUP either directly or via NVIC_PriorityGroupConfig() still does not solve the problem that NVIC_Init() a) fails for PRIGROUP < 0b011, andb) with PRIGROUP == 0b011 ORs PreemptionPriority and SubPriority together, leading to unexpected results.Because of b), NVIC_Init() only works as expected if PreemptionPriority == SubPriority, or SubPriority == 0.2013-06-07 09:47 AM
I think I know what's the actual problem, stm32 only has 16 priority levels so setting grouping below 0b011 doesn't make sense.
Edit:If you set grouping to 0b011 subpriority has to be zero.