AnsweredAssumed Answered

STM32F2xx_StdPeriph_Lib NVIC_Init(): preemption priority, issue with PRIGROUP

Question asked by reich.wolfgang on Jun 7, 2013
Latest reply on Jun 7, 2013 by knik
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] = tmppriority
That 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, IMHO
 tmppriority <<= 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()?

Outcomes