STM32: Timer Interrupt: Löschen des Pending Flags

Gast #3388353
Lesenswert?

Hallo zusammen,

ich habe ein seltsame Beobachtung mit meinem STM32 und einem 
Timer-Interrupt gemacht:

Wenn ich das Pending Flag erst ganz zum Schluß der ISR lösche
1
void TIM6_IRQHandler()
2
{
3
  (...)
4
  TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
5
}
wird die ISR immer zweimal ausgeführt.
Es sieht so aus, als ob das Löschen zu spät erfolgt und daher die ISR 
nochmal ausgeführt wird.

Wenn ich das Pending Flag direkt zu Beginn ISR lösche
1
void TIM6_IRQHandler()
2
{
3
  TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
4
  (...)
5
}
ist alles okay.

Kann mir jemand sagen
- woran das liegt
- wo ich das hätte in den Manuals erkennen sollen?
#3389448
Lesenswert?

Ich bastel gerade mit einem TI-Launchpad rum und dabei ist mir ein 
interessanter Hinweis in den LIB-Sourcen über den Weg gelaufen. Hier ein 
Beispiel für eine Funktion zum Löschen des Timer IRQ flags. Man beachte 
die NOTE section:


1
//*****************************************************************************
2
//
3
//! Clears timer interrupt sources.
4
//!
5
//! \param ulBase is the base address of the timer module.
6
//! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
7
//!
8
//! The specified timer interrupt sources are cleared, so that they no longer
9
//! assert.  This function must be called in the interrupt handler to keep the
10
//! interrupt from being triggered again immediately upon exit.
11
//!
12
//! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
13
//! parameter to TimerIntEnable().
14
//!
15
//! \note Because there is a write buffer in the Cortex-M processor, it may
16
//! take several clock cycles before the interrupt source is actually cleared.
17
//! Therefore, it is recommended that the interrupt source be cleared early in
18
//! the interrupt handler (as opposed to the very last action) to avoid
19
//! returning from the interrupt handler before the interrupt source is
20
//! actually cleared.  Failure to do so may result in the interrupt handler
21
//! being immediately reentered (because the interrupt controller still sees
22
//! the interrupt source asserted).
23
//!
24
//! \return None.
25
//
26
//*****************************************************************************
27
void
28
TimerIntClear(unsigned long ulBase, unsigned long ulIntFlags)
29
{
30
    //
31
    // Check the arguments.
32
    //
33
    ASSERT(TimerBaseValid(ulBase));
34

35
    //
36
    // Clear the requested interrupt sources.
37
    //
38
    HWREG(ulBase + TIMER_O_ICR) = ulIntFlags;
39
}


Dieser Hinweis findet sich bei ziemlich allen IRQ clear functions in den 
TI libs. Bei STM32 habe ich solche Tipps nicht gefunden.

PS

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren