diff options
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 1f1708873..481ea4abc 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -258,7 +258,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 258 | w.set_spe(true); | 258 | w.set_spe(true); |
| 259 | }); | 259 | }); |
| 260 | } | 260 | } |
| 261 | #[cfg(any(spi_v3, spi_v4))] | 261 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 262 | unsafe { | 262 | unsafe { |
| 263 | T::REGS.ifcr().write(|w| w.0 = 0xffff_ffff); | 263 | T::REGS.ifcr().write(|w| w.0 = 0xffff_ffff); |
| 264 | T::REGS.cfg2().modify(|w| { | 264 | T::REGS.cfg2().modify(|w| { |
| @@ -317,7 +317,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 317 | }); | 317 | }); |
| 318 | } | 318 | } |
| 319 | 319 | ||
| 320 | #[cfg(any(spi_v3, spi_v4))] | 320 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 321 | unsafe { | 321 | unsafe { |
| 322 | T::REGS.cfg2().modify(|w| { | 322 | T::REGS.cfg2().modify(|w| { |
| 323 | w.set_cpha(cpha); | 323 | w.set_cpha(cpha); |
| @@ -330,7 +330,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 330 | pub fn get_current_config(&self) -> Config { | 330 | pub fn get_current_config(&self) -> Config { |
| 331 | #[cfg(any(spi_v1, spi_f1, spi_v2))] | 331 | #[cfg(any(spi_v1, spi_f1, spi_v2))] |
| 332 | let cfg = unsafe { T::REGS.cr1().read() }; | 332 | let cfg = unsafe { T::REGS.cr1().read() }; |
| 333 | #[cfg(any(spi_v3, spi_v4))] | 333 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 334 | let cfg = unsafe { T::REGS.cfg2().read() }; | 334 | let cfg = unsafe { T::REGS.cfg2().read() }; |
| 335 | let polarity = if cfg.cpol() == vals::Cpol::IDLELOW { | 335 | let polarity = if cfg.cpol() == vals::Cpol::IDLELOW { |
| 336 | Polarity::IdleLow | 336 | Polarity::IdleLow |
| @@ -383,7 +383,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 383 | w.set_spe(true); | 383 | w.set_spe(true); |
| 384 | }); | 384 | }); |
| 385 | } | 385 | } |
| 386 | #[cfg(any(spi_v3, spi_v4))] | 386 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 387 | unsafe { | 387 | unsafe { |
| 388 | T::REGS.cr1().modify(|w| { | 388 | T::REGS.cr1().modify(|w| { |
| 389 | w.set_csusp(true); | 389 | w.set_csusp(true); |
| @@ -429,7 +429,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 429 | T::REGS.cr1().modify(|w| { | 429 | T::REGS.cr1().modify(|w| { |
| 430 | w.set_spe(true); | 430 | w.set_spe(true); |
| 431 | }); | 431 | }); |
| 432 | #[cfg(any(spi_v3, spi_v4))] | 432 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 433 | T::REGS.cr1().modify(|w| { | 433 | T::REGS.cr1().modify(|w| { |
| 434 | w.set_cstart(true); | 434 | w.set_cstart(true); |
| 435 | }); | 435 | }); |
| @@ -459,7 +459,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | // SPIv3 clears rxfifo on SPE=0 | 461 | // SPIv3 clears rxfifo on SPE=0 |
| 462 | #[cfg(not(any(spi_v3, spi_v4)))] | 462 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 463 | flush_rx_fifo(T::REGS); | 463 | flush_rx_fifo(T::REGS); |
| 464 | 464 | ||
| 465 | set_rxdmaen(T::REGS, true); | 465 | set_rxdmaen(T::REGS, true); |
| @@ -481,7 +481,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 481 | T::REGS.cr1().modify(|w| { | 481 | T::REGS.cr1().modify(|w| { |
| 482 | w.set_spe(true); | 482 | w.set_spe(true); |
| 483 | }); | 483 | }); |
| 484 | #[cfg(any(spi_v3, spi_v4))] | 484 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 485 | T::REGS.cr1().modify(|w| { | 485 | T::REGS.cr1().modify(|w| { |
| 486 | w.set_cstart(true); | 486 | w.set_cstart(true); |
| 487 | }); | 487 | }); |
| @@ -514,7 +514,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | // SPIv3 clears rxfifo on SPE=0 | 516 | // SPIv3 clears rxfifo on SPE=0 |
| 517 | #[cfg(not(any(spi_v3, spi_v4)))] | 517 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 518 | flush_rx_fifo(T::REGS); | 518 | flush_rx_fifo(T::REGS); |
| 519 | 519 | ||
| 520 | set_rxdmaen(T::REGS, true); | 520 | set_rxdmaen(T::REGS, true); |
| @@ -534,7 +534,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 534 | T::REGS.cr1().modify(|w| { | 534 | T::REGS.cr1().modify(|w| { |
| 535 | w.set_spe(true); | 535 | w.set_spe(true); |
| 536 | }); | 536 | }); |
| 537 | #[cfg(any(spi_v3, spi_v4))] | 537 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 538 | T::REGS.cr1().modify(|w| { | 538 | T::REGS.cr1().modify(|w| { |
| 539 | w.set_cstart(true); | 539 | w.set_cstart(true); |
| 540 | }); | 540 | }); |
| @@ -619,9 +619,9 @@ impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { | |||
| 619 | } | 619 | } |
| 620 | } | 620 | } |
| 621 | 621 | ||
| 622 | #[cfg(not(any(spi_v3, spi_v4)))] | 622 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 623 | use vals::Br; | 623 | use vals::Br; |
| 624 | #[cfg(any(spi_v3, spi_v4))] | 624 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 625 | use vals::Mbr as Br; | 625 | use vals::Mbr as Br; |
| 626 | 626 | ||
| 627 | fn compute_baud_rate(clocks: Hertz, freq: Hertz) -> Br { | 627 | fn compute_baud_rate(clocks: Hertz, freq: Hertz) -> Br { |
| @@ -647,17 +647,17 @@ trait RegsExt { | |||
| 647 | 647 | ||
| 648 | impl RegsExt for Regs { | 648 | impl RegsExt for Regs { |
| 649 | fn tx_ptr<W>(&self) -> *mut W { | 649 | fn tx_ptr<W>(&self) -> *mut W { |
| 650 | #[cfg(not(any(spi_v3, spi_v4)))] | 650 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 651 | let dr = self.dr(); | 651 | let dr = self.dr(); |
| 652 | #[cfg(any(spi_v3, spi_v4))] | 652 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 653 | let dr = self.txdr(); | 653 | let dr = self.txdr(); |
| 654 | dr.ptr() as *mut W | 654 | dr.ptr() as *mut W |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | fn rx_ptr<W>(&self) -> *mut W { | 657 | fn rx_ptr<W>(&self) -> *mut W { |
| 658 | #[cfg(not(any(spi_v3, spi_v4)))] | 658 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 659 | let dr = self.dr(); | 659 | let dr = self.dr(); |
| 660 | #[cfg(any(spi_v3, spi_v4))] | 660 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 661 | let dr = self.rxdr(); | 661 | let dr = self.rxdr(); |
| 662 | dr.ptr() as *mut W | 662 | dr.ptr() as *mut W |
| 663 | } | 663 | } |
| @@ -667,22 +667,22 @@ fn check_error_flags(sr: regs::Sr) -> Result<(), Error> { | |||
| 667 | if sr.ovr() { | 667 | if sr.ovr() { |
| 668 | return Err(Error::Overrun); | 668 | return Err(Error::Overrun); |
| 669 | } | 669 | } |
| 670 | #[cfg(not(any(spi_f1, spi_v3, spi_v4)))] | 670 | #[cfg(not(any(spi_f1, spi_v3, spi_v4, spi_v5)))] |
| 671 | if sr.fre() { | 671 | if sr.fre() { |
| 672 | return Err(Error::Framing); | 672 | return Err(Error::Framing); |
| 673 | } | 673 | } |
| 674 | #[cfg(any(spi_v3, spi_v4))] | 674 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 675 | if sr.tifre() { | 675 | if sr.tifre() { |
| 676 | return Err(Error::Framing); | 676 | return Err(Error::Framing); |
| 677 | } | 677 | } |
| 678 | if sr.modf() { | 678 | if sr.modf() { |
| 679 | return Err(Error::ModeFault); | 679 | return Err(Error::ModeFault); |
| 680 | } | 680 | } |
| 681 | #[cfg(not(any(spi_v3, spi_v4)))] | 681 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 682 | if sr.crcerr() { | 682 | if sr.crcerr() { |
| 683 | return Err(Error::Crc); | 683 | return Err(Error::Crc); |
| 684 | } | 684 | } |
| 685 | #[cfg(any(spi_v3, spi_v4))] | 685 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 686 | if sr.crce() { | 686 | if sr.crce() { |
| 687 | return Err(Error::Crc); | 687 | return Err(Error::Crc); |
| 688 | } | 688 | } |
| @@ -696,11 +696,11 @@ fn spin_until_tx_ready(regs: Regs) -> Result<(), Error> { | |||
| 696 | 696 | ||
| 697 | check_error_flags(sr)?; | 697 | check_error_flags(sr)?; |
| 698 | 698 | ||
| 699 | #[cfg(not(any(spi_v3, spi_v4)))] | 699 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 700 | if sr.txe() { | 700 | if sr.txe() { |
| 701 | return Ok(()); | 701 | return Ok(()); |
| 702 | } | 702 | } |
| 703 | #[cfg(any(spi_v3, spi_v4))] | 703 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 704 | if sr.txp() { | 704 | if sr.txp() { |
| 705 | return Ok(()); | 705 | return Ok(()); |
| 706 | } | 706 | } |
| @@ -713,11 +713,11 @@ fn spin_until_rx_ready(regs: Regs) -> Result<(), Error> { | |||
| 713 | 713 | ||
| 714 | check_error_flags(sr)?; | 714 | check_error_flags(sr)?; |
| 715 | 715 | ||
| 716 | #[cfg(not(any(spi_v3, spi_v4)))] | 716 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 717 | if sr.rxne() { | 717 | if sr.rxne() { |
| 718 | return Ok(()); | 718 | return Ok(()); |
| 719 | } | 719 | } |
| 720 | #[cfg(any(spi_v3, spi_v4))] | 720 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 721 | if sr.rxp() { | 721 | if sr.rxp() { |
| 722 | return Ok(()); | 722 | return Ok(()); |
| 723 | } | 723 | } |
| @@ -726,11 +726,11 @@ fn spin_until_rx_ready(regs: Regs) -> Result<(), Error> { | |||
| 726 | 726 | ||
| 727 | fn flush_rx_fifo(regs: Regs) { | 727 | fn flush_rx_fifo(regs: Regs) { |
| 728 | unsafe { | 728 | unsafe { |
| 729 | #[cfg(not(any(spi_v3, spi_v4)))] | 729 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 730 | while regs.sr().read().rxne() { | 730 | while regs.sr().read().rxne() { |
| 731 | let _ = regs.dr().read(); | 731 | let _ = regs.dr().read(); |
| 732 | } | 732 | } |
| 733 | #[cfg(any(spi_v3, spi_v4))] | 733 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 734 | while regs.sr().read().rxp() { | 734 | while regs.sr().read().rxp() { |
| 735 | let _ = regs.rxdr().read(); | 735 | let _ = regs.rxdr().read(); |
| 736 | } | 736 | } |
| @@ -739,11 +739,11 @@ fn flush_rx_fifo(regs: Regs) { | |||
| 739 | 739 | ||
| 740 | fn set_txdmaen(regs: Regs, val: bool) { | 740 | fn set_txdmaen(regs: Regs, val: bool) { |
| 741 | unsafe { | 741 | unsafe { |
| 742 | #[cfg(not(any(spi_v3, spi_v4)))] | 742 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 743 | regs.cr2().modify(|reg| { | 743 | regs.cr2().modify(|reg| { |
| 744 | reg.set_txdmaen(val); | 744 | reg.set_txdmaen(val); |
| 745 | }); | 745 | }); |
| 746 | #[cfg(any(spi_v3, spi_v4))] | 746 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 747 | regs.cfg1().modify(|reg| { | 747 | regs.cfg1().modify(|reg| { |
| 748 | reg.set_txdmaen(val); | 748 | reg.set_txdmaen(val); |
| 749 | }); | 749 | }); |
| @@ -752,11 +752,11 @@ fn set_txdmaen(regs: Regs, val: bool) { | |||
| 752 | 752 | ||
| 753 | fn set_rxdmaen(regs: Regs, val: bool) { | 753 | fn set_rxdmaen(regs: Regs, val: bool) { |
| 754 | unsafe { | 754 | unsafe { |
| 755 | #[cfg(not(any(spi_v3, spi_v4)))] | 755 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 756 | regs.cr2().modify(|reg| { | 756 | regs.cr2().modify(|reg| { |
| 757 | reg.set_rxdmaen(val); | 757 | reg.set_rxdmaen(val); |
| 758 | }); | 758 | }); |
| 759 | #[cfg(any(spi_v3, spi_v4))] | 759 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 760 | regs.cfg1().modify(|reg| { | 760 | regs.cfg1().modify(|reg| { |
| 761 | reg.set_rxdmaen(val); | 761 | reg.set_rxdmaen(val); |
| 762 | }); | 762 | }); |
| @@ -768,9 +768,9 @@ fn finish_dma(regs: Regs) { | |||
| 768 | #[cfg(spi_v2)] | 768 | #[cfg(spi_v2)] |
| 769 | while regs.sr().read().ftlvl() > 0 {} | 769 | while regs.sr().read().ftlvl() > 0 {} |
| 770 | 770 | ||
| 771 | #[cfg(any(spi_v3, spi_v4))] | 771 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 772 | while !regs.sr().read().txc() {} | 772 | while !regs.sr().read().txc() {} |
| 773 | #[cfg(not(any(spi_v3, spi_v4)))] | 773 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 774 | while regs.sr().read().bsy() {} | 774 | while regs.sr().read().bsy() {} |
| 775 | 775 | ||
| 776 | // Disable the spi peripheral | 776 | // Disable the spi peripheral |
| @@ -780,12 +780,12 @@ fn finish_dma(regs: Regs) { | |||
| 780 | 780 | ||
| 781 | // The peripheral automatically disables the DMA stream on completion without error, | 781 | // The peripheral automatically disables the DMA stream on completion without error, |
| 782 | // but it does not clear the RXDMAEN/TXDMAEN flag in CR2. | 782 | // but it does not clear the RXDMAEN/TXDMAEN flag in CR2. |
| 783 | #[cfg(not(any(spi_v3, spi_v4)))] | 783 | #[cfg(not(any(spi_v3, spi_v4, spi_v5)))] |
| 784 | regs.cr2().modify(|reg| { | 784 | regs.cr2().modify(|reg| { |
| 785 | reg.set_txdmaen(false); | 785 | reg.set_txdmaen(false); |
| 786 | reg.set_rxdmaen(false); | 786 | reg.set_rxdmaen(false); |
| 787 | }); | 787 | }); |
| 788 | #[cfg(any(spi_v3, spi_v4))] | 788 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 789 | regs.cfg1().modify(|reg| { | 789 | regs.cfg1().modify(|reg| { |
| 790 | reg.set_txdmaen(false); | 790 | reg.set_txdmaen(false); |
| 791 | reg.set_rxdmaen(false); | 791 | reg.set_rxdmaen(false); |
| @@ -799,7 +799,7 @@ fn transfer_word<W: Word>(regs: Regs, tx_word: W) -> Result<W, Error> { | |||
| 799 | unsafe { | 799 | unsafe { |
| 800 | ptr::write_volatile(regs.tx_ptr(), tx_word); | 800 | ptr::write_volatile(regs.tx_ptr(), tx_word); |
| 801 | 801 | ||
| 802 | #[cfg(any(spi_v3, spi_v4))] | 802 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 803 | regs.cr1().modify(|reg| reg.set_cstart(true)); | 803 | regs.cr1().modify(|reg| reg.set_cstart(true)); |
| 804 | } | 804 | } |
| 805 | 805 | ||
| @@ -970,7 +970,7 @@ pub(crate) mod sealed { | |||
| 970 | } | 970 | } |
| 971 | } | 971 | } |
| 972 | 972 | ||
| 973 | #[cfg(any(spi_v3, spi_v4))] | 973 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 974 | pub fn dsize(&self) -> u8 { | 974 | pub fn dsize(&self) -> u8 { |
| 975 | match self { | 975 | match self { |
| 976 | WordSize::EightBit => 0b0111, | 976 | WordSize::EightBit => 0b0111, |
| @@ -978,7 +978,7 @@ pub(crate) mod sealed { | |||
| 978 | } | 978 | } |
| 979 | } | 979 | } |
| 980 | 980 | ||
| 981 | #[cfg(any(spi_v3, spi_v4))] | 981 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 982 | pub fn _frxth(&self) -> vals::Fthlv { | 982 | pub fn _frxth(&self) -> vals::Fthlv { |
| 983 | match self { | 983 | match self { |
| 984 | WordSize::EightBit => vals::Fthlv::ONEFRAME, | 984 | WordSize::EightBit => vals::Fthlv::ONEFRAME, |
