title: The right way to clear an interrupt flag on STM32
body: <p>I'm developping a bare-metal project on a STM32L4 and I'm starting from an existing code base.</p>
  
  <p>The ISRs have been implemented the following way:</p>
  
  <ol>
  <li>read interrupt status in the peripheral to know what event(s) provoked the interrupt</li>
  <li>do something</li>
  <li>clear the flags that have read at the beginning.</li>
  </ol>
  
  <p>Is it the right way to clear the flag ? Shouldn't the flags be cleared at the very beginning of the ISR ? My understanding is that, if the same peripheral event is happening a second time during step 2, it will not provoke a second IRQ so it would be lost. On the other hand if you clear the flag as soon as you can, this second event would pulse the interrupt whose state in the CPU would change to "pending and active": a second IRQ would happen.</p>
  
  <p>PS: From STM32 Processor Programming Manual I read: "STM32 interrupts are both level-sensitive and pulse-sensitive". </p>