cancel
Showing results for 
Search instead for 
Did you mean: 

EXTI->PR Manual vs Snippets

skoe
Associate II
Posted on October 22, 2015 at 21:54

The STML0 (and L1) manual says following about the register EXTI_PR:

''1: The selected trigger request occurred. This bit is set when the selected edge event arrives on the interrupt line. This bit is cleared by writing it to 1 or by changing the sensitivity of the edge detector.''

The bits are of type rc_w1, which corresponds to the description.

But the Code Snippets (e.g., stm32snippetsl0\STM32L0xx_Snippets_Package_V1.1.1/Projects/RTC/02_ProgrammingTheWakeUpTimer/main.c) use following code:

EXTI->PR |= EXTI_PR_PR20; /* clear exti line 20 flag */

This does ''Take all bits that are set in this register, set one more (even though it is usually set already at this place) and write it back''. And that translates to ''Clear all pending EXTI lines'', which is not the intention. It may clear additional, unwanted lines.

Shouldn't the line be as follows, considering rc_w1?

EXTI->PR = EXTI_PR_PR20; /* clear exti line 20 flag */

#clear-exti-pr
4 REPLIES 4
matic
Associate III
Posted on October 22, 2015 at 23:10

In first case: EXTI->PR |= EXTI_PR_PR20; you mask only that bit and write 1 to it. That would clear it.

In second case: EXTI->PR = EXTI_PR_PR20; you write also zeros to all other bits, but that doesn't do anything whether there is 1 or 0. 

I think in both cases the result will be the same -> cleared only EXTI_PR_PR20.

skoe
Associate II
Posted on October 22, 2015 at 23:43

> In first case: EXTI->PR |= EXTI_PR_PR20; you mask only that bit and write 1 to it.

> That would clear it.

Thanks for your response but unfortunately I think that's not correct. That's an ''or'', not an ''and''. Let's assume that line 0 and 1 are set, so EXTI->PR reads:

val = EXTI->PR; // val is now 3

we want to clear line 0 only, the first case would:

val |= 1; // val is still 3 - note that's ''or''

this is written back:

EXTI->PR = val; // This writes 3 and thus clears line 0 *and* line 1

Right?

matic
Associate III
Posted on October 23, 2015 at 06:21

I'm not sure but I think in this case it isn't important if there is OR or AND. You only have to write 1 to the line you want to clear. if you write 1 to any of zeros, this will stay 0. If you write 0 to any of zeros, it will stay 0 too. And if you write 0 to any of 1, it will stay 1.

Not 100% sure, but 99... 🙂

Posted on October 23, 2015 at 12:19

> Shouldn't the line be as follows, considering rc_w1?

> EXTI->PR = EXTI_PR_PR20; /* clear exti line 20 flag */

Yes, you are right.

I have heard from ST that they are working on it and it will be corrected in the next version of manual and the Snippets.

Thanks for reporting this.

JW