aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Goll <[email protected]>2024-03-27 00:20:29 +0100
committerSebastian Goll <[email protected]>2024-03-27 00:32:06 +0100
commitb299266cd240d73bf6ec36d6a0710523ce5eb139 (patch)
tree7e885f1db3e94b8bdc0a6601dbe58b2e3fc09cf8
parent2e2986c67b3a7a6a87695a359d630864c9eb6194 (diff)
It is not necessary to enable interrupts before registering waker
-rw-r--r--embassy-stm32/src/i2c/v1.rs28
1 files changed, 7 insertions, 21 deletions
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 1e0eea33c..7c0bb31d6 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -489,7 +489,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
489 489
490 if frame.send_start() { 490 if frame.send_start() {
491 // Send a START condition 491 // Send a START condition
492 Self::enable_interrupts();
493 T::regs().cr1().modify(|reg| { 492 T::regs().cr1().modify(|reg| {
494 reg.set_start(true); 493 reg.set_start(true);
495 }); 494 });
@@ -504,8 +503,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
504 if sr1.start() { 503 if sr1.start() {
505 Poll::Ready(Ok(())) 504 Poll::Ready(Ok(()))
506 } else { 505 } else {
507 // If we need to go around, then re-enable the interrupts, otherwise nothing 506 // When pending, (re-)enable interrupts to wake us up.
508 // can wake us up and we'll hang.
509 Self::enable_interrupts(); 507 Self::enable_interrupts();
510 Poll::Pending 508 Poll::Pending
511 } 509 }
@@ -520,7 +518,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
520 } 518 }
521 519
522 // Set up current address, we're trying to talk to 520 // Set up current address, we're trying to talk to
523 Self::enable_interrupts();
524 T::regs().dr().write(|reg| reg.set_dr(address << 1)); 521 T::regs().dr().write(|reg| reg.set_dr(address << 1));
525 522
526 // Wait for the address to be acknowledged 523 // Wait for the address to be acknowledged
@@ -533,8 +530,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
533 if sr1.addr() { 530 if sr1.addr() {
534 Poll::Ready(Ok(())) 531 Poll::Ready(Ok(()))
535 } else { 532 } else {
536 // If we need to go around, then re-enable the interrupts, otherwise nothing 533 // When pending, (re-)enable interrupts to wake us up.
537 // can wake us up and we'll hang.
538 Self::enable_interrupts(); 534 Self::enable_interrupts();
539 Poll::Pending 535 Poll::Pending
540 } 536 }
@@ -548,7 +544,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
548 } 544 }
549 545
550 // Wait for bytes to be sent, or an error to occur. 546 // Wait for bytes to be sent, or an error to occur.
551 Self::enable_interrupts();
552 let poll_error = poll_fn(|cx| { 547 let poll_error = poll_fn(|cx| {
553 state.waker.register(cx.waker()); 548 state.waker.register(cx.waker());
554 549
@@ -557,8 +552,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
557 // identical poll_fn check_and_clear matches. 552 // identical poll_fn check_and_clear matches.
558 Err(e) => Poll::Ready(Err::<T, Error>(e)), 553 Err(e) => Poll::Ready(Err::<T, Error>(e)),
559 Ok(_) => { 554 Ok(_) => {
560 // If we need to go around, then re-enable the interrupts, otherwise nothing 555 // When pending, (re-)enable interrupts to wake us up.
561 // can wake us up and we'll hang.
562 Self::enable_interrupts(); 556 Self::enable_interrupts();
563 Poll::Pending 557 Poll::Pending
564 } 558 }
@@ -580,7 +574,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
580 574
581 // 18.3.8 “Master transmitter: In the interrupt routine after the EOT interrupt, disable DMA 575 // 18.3.8 “Master transmitter: In the interrupt routine after the EOT interrupt, disable DMA
582 // requests then wait for a BTF event before programming the Stop condition.” 576 // requests then wait for a BTF event before programming the Stop condition.”
583 Self::enable_interrupts();
584 poll_fn(|cx| { 577 poll_fn(|cx| {
585 state.waker.register(cx.waker()); 578 state.waker.register(cx.waker());
586 579
@@ -590,8 +583,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
590 if sr1.btf() { 583 if sr1.btf() {
591 Poll::Ready(Ok(())) 584 Poll::Ready(Ok(()))
592 } else { 585 } else {
593 // If we need to go around, then re-enable the interrupts, otherwise nothing 586 // When pending, (re-)enable interrupts to wake us up.
594 // can wake us up and we'll hang.
595 Self::enable_interrupts(); 587 Self::enable_interrupts();
596 Poll::Pending 588 Poll::Pending
597 } 589 }
@@ -672,7 +664,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
672 664
673 if frame.send_start() { 665 if frame.send_start() {
674 // Send a START condition and set ACK bit 666 // Send a START condition and set ACK bit
675 Self::enable_interrupts();
676 T::regs().cr1().modify(|reg| { 667 T::regs().cr1().modify(|reg| {
677 reg.set_start(true); 668 reg.set_start(true);
678 reg.set_ack(true); 669 reg.set_ack(true);
@@ -688,8 +679,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
688 if sr1.start() { 679 if sr1.start() {
689 Poll::Ready(Ok(())) 680 Poll::Ready(Ok(()))
690 } else { 681 } else {
691 // If we need to go around, then re-enable the interrupts, otherwise nothing 682 // When pending, (re-)enable interrupts to wake us up.
692 // can wake us up and we'll hang.
693 Self::enable_interrupts(); 683 Self::enable_interrupts();
694 Poll::Pending 684 Poll::Pending
695 } 685 }
@@ -704,7 +694,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
704 } 694 }
705 695
706 // Set up current address, we're trying to talk to 696 // Set up current address, we're trying to talk to
707 Self::enable_interrupts();
708 T::regs().dr().write(|reg| reg.set_dr((address << 1) + 1)); 697 T::regs().dr().write(|reg| reg.set_dr((address << 1) + 1));
709 698
710 // Wait for the address to be acknowledged 699 // Wait for the address to be acknowledged
@@ -717,8 +706,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
717 if sr1.addr() { 706 if sr1.addr() {
718 Poll::Ready(Ok(())) 707 Poll::Ready(Ok(()))
719 } else { 708 } else {
720 // If we need to go around, then re-enable the interrupts, otherwise nothing 709 // When pending, (re-)enable interrupts to wake us up.
721 // can wake us up and we'll hang.
722 Self::enable_interrupts(); 710 Self::enable_interrupts();
723 Poll::Pending 711 Poll::Pending
724 } 712 }
@@ -753,15 +741,13 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
753 } 741 }
754 742
755 // Wait for bytes to be received, or an error to occur. 743 // Wait for bytes to be received, or an error to occur.
756 Self::enable_interrupts();
757 let poll_error = poll_fn(|cx| { 744 let poll_error = poll_fn(|cx| {
758 state.waker.register(cx.waker()); 745 state.waker.register(cx.waker());
759 746
760 match Self::check_and_clear_error_flags() { 747 match Self::check_and_clear_error_flags() {
761 Err(e) => Poll::Ready(Err::<T, Error>(e)), 748 Err(e) => Poll::Ready(Err::<T, Error>(e)),
762 _ => { 749 _ => {
763 // If we need to go around, then re-enable the interrupts, otherwise nothing 750 // When pending, (re-)enable interrupts to wake us up.
764 // can wake us up and we'll hang.
765 Self::enable_interrupts(); 751 Self::enable_interrupts();
766 Poll::Pending 752 Poll::Pending
767 } 753 }