diff options
| author | Ralf <[email protected]> | 2023-02-05 20:17:53 +0100 |
|---|---|---|
| committer | Ralf <[email protected]> | 2023-02-06 13:23:35 +0100 |
| commit | e3174d7a998ead0fbe5ddadf59914cc16a561a44 (patch) | |
| tree | ddea9c6c143a24c9767fb41741a4c860d15c5b60 | |
| parent | 7d8e6649b7d3364d363cacf9696bd9f40f6881a8 (diff) | |
STM32 SPI: Set clk-pin pull-up/-down to match spi clock polarity
RM0394:
40.4.6
Communication formats
...
The idle state of SCK must correspond to the polarity selected in the SPIx_CR1 register (by
pulling up SCK if CPOL=1 or pulling down SCK if CPOL=0).
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 5b81c791a..e5ba746e4 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -10,7 +10,7 @@ pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MO | |||
| 10 | use self::sealed::WordSize; | 10 | use self::sealed::WordSize; |
| 11 | use crate::dma::{slice_ptr_parts, Transfer}; | 11 | use crate::dma::{slice_ptr_parts, Transfer}; |
| 12 | use crate::gpio::sealed::{AFType, Pin as _}; | 12 | use crate::gpio::sealed::{AFType, Pin as _}; |
| 13 | use crate::gpio::AnyPin; | 13 | use crate::gpio::{AnyPin, Pull}; |
| 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; | 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; |
| 15 | use crate::rcc::RccPeripheral; | 15 | use crate::rcc::RccPeripheral; |
| 16 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| @@ -93,8 +93,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 93 | config: Config, | 93 | config: Config, |
| 94 | ) -> Self { | 94 | ) -> Self { |
| 95 | into_ref!(peri, sck, mosi, miso); | 95 | into_ref!(peri, sck, mosi, miso); |
| 96 | |||
| 97 | let sck_pull_mode = match config.mode.polarity { | ||
| 98 | Polarity::IdleLow => Pull::Down, | ||
| 99 | Polarity::IdleHigh => Pull::Up, | ||
| 100 | }; | ||
| 101 | |||
| 96 | unsafe { | 102 | unsafe { |
| 97 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 103 | sck.set_as_af_pull(sck.af_num(), AFType::OutputPushPull, sck_pull_mode); |
| 98 | sck.set_speed(crate::gpio::Speed::VeryHigh); | 104 | sck.set_speed(crate::gpio::Speed::VeryHigh); |
| 99 | mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull); | 105 | mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull); |
| 100 | mosi.set_speed(crate::gpio::Speed::VeryHigh); | 106 | mosi.set_speed(crate::gpio::Speed::VeryHigh); |
