Merge pull request #4009 from i509VCB/mspm0-gpio-disable-event

mspm0: disable events before clearing gpio RIS
This commit is contained in:
Ulf Lilleengen 2025-03-26 07:50:13 +00:00 committed by GitHub
commit 9edf5b7f04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -935,15 +935,32 @@ impl<'d> InputFuture<'d> {
fn new(pin: PeripheralRef<'d, AnyPin>, polarity: Polarity) -> Self { fn new(pin: PeripheralRef<'d, AnyPin>, polarity: Polarity) -> Self {
let block = pin.block(); let block = pin.block();
// Before clearing any previous edge events, we must disable events.
//
// If we don't do this, it is possible that after we clear the interrupt, the current event
// the hardware is listening for may not be the same event we will configure. This may result
// in RIS being set. Then when interrupts are unmasked and RIS is set, we may get the wrong event
// causing an interrupt.
//
// Selecting which polarity events happen is a RMW operation.
critical_section::with(|_cs| {
if pin.bit_index() >= 16 {
block.polarity31_16().modify(|w| {
w.set_dio(pin.bit_index() - 16, Polarity::DISABLE);
});
} else {
block.polarity15_0().modify(|w| {
w.set_dio(pin.bit_index(), Polarity::DISABLE);
});
};
});
// First clear the bit for this event. Otherwise previous edge events may be recorded. // First clear the bit for this event. Otherwise previous edge events may be recorded.
block.cpu_int().iclr().write(|w| { block.cpu_int().iclr().write(|w| {
w.set_dio(pin.bit_index(), true); w.set_dio(pin.bit_index(), true);
}); });
// Selecting which polarity events happens is a RMW operation. // Selecting which polarity events happen is a RMW operation.
//
// Guard with a critical section in case two different threads try to select events at the
// same time.
critical_section::with(|_cs| { critical_section::with(|_cs| {
// Tell the hardware which pin event we want to receive. // Tell the hardware which pin event we want to receive.
if pin.bit_index() >= 16 { if pin.bit_index() >= 16 {