Forum: Mikrocontroller und Digitale Elektronik STM32 IRQ Pre-Emption fehlerhaft?


von Florian M. (micro-flo)


Lesenswert?

Hallo zusammen,
Ich benutze in meinem STM32 Programm mehrere Interrupts.
Einer soll dabei die geringste Priorität kriegen, die anderen also nicht 
unterbrechen.
1
// Configure the NVIC Preemption Priority Bits
2
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
3
4
NVIC_InitTypeDef NVIC_InitStruct;
5
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
6
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
7
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
8
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
9
NVIC_Init(&NVIC_InitStruct);
10
11
12
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
13
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
14
NVIC_InitStruct.NVIC_IRQChannel = WWDG_IRQn;
15
NVIC_Init(&NVIC_InitStruct);

Zum Testen benutze ich einen leeren Interrupt, lösche also das IRQ Bit 
nicht, wodurch der Interrupt permanent anliegt.
1
extern "C" void EXTI9_5_IRQHandler(void) {
2
}


Mit NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); lege ich fest, dass 
2 Bits für Pre-Emption verwendet werden.
Also wenn ich den Watchdog auf
1
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1; oder
2
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2; oder
3
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 3;
setze, darf er den EXTI nicht unterbrechen.
Es klappt aber nur mit 2 und 3, nicht mit 1!
Gleiches Spiel, wenn NVIC_PriorityGroup_3 oder NVIC_PriorityGroup_4 
setze.
Nur wenn das oberste Bit im Prioritätsregister gesetzt ist, unterbricht 
der Watchdog den EXTI nicht.

Ich will nur wissen, ob ich einen Fehler mache oder der STM32 einen hat.

Danke :)

von (prx) A. K. (prx)


Lesenswert?

Welche Lib verwendest du? Die Funktion NVIC_PriorityGroupConfig finde 
ich nur in der alten StdPeriphLib V2, nicht aber in der CMSIS Lib.

von Florian M. (micro-flo)


Lesenswert?

Hi,
Ich benutze Version 3.4

STM32F10x_StdPeriph_Driver_V3_4
misc.c
1
/**
2
  * @brief  Configures the priority grouping: pre-emption priority and subpriority.
3
  * @param  NVIC_PriorityGroup: specifies the priority grouping bits length. 
4
  *   This parameter can be one of the following values:
5
  *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
6
  *                                4 bits for subpriority
7
  *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
8
  *                                3 bits for subpriority
9
  *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
10
  *                                2 bits for subpriority
11
  *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
12
  *                                1 bits for subpriority
13
  *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
14
  *                                0 bits for subpriority
15
  * @retval None
16
  */
17
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
18
{
19
  /* Check the parameters */
20
  assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
21
  
22
  /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
23
  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
24
}

von (prx) A. K. (prx)


Lesenswert?

Ach dahin hatte ST diesen Zombie verschoben. Der NVIC wird als 
Bestandteil des Cores von der CMSIS Lib abgedeckt, das Pendant in der 
StdPeriphLib ist nur noch zur Kompatibilität mit Libs vor V3 drin.

Es könnte sein, dass ein Interrupt nur durchkommt, wenn sein Bit im IABR 
nicht gesetzt ist. Und das wird evtl. zusammen mit dem Pending Bit 
gelöscht. Besonders tiefschürfend ist ARMs Doku allerdings nicht.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.