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).
This commit is contained in:
parent
7d8e6649b7
commit
e3174d7a99
1 changed files with 8 additions and 2 deletions
|
@ -10,7 +10,7 @@ pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MO
|
||||||
use self::sealed::WordSize;
|
use self::sealed::WordSize;
|
||||||
use crate::dma::{slice_ptr_parts, Transfer};
|
use crate::dma::{slice_ptr_parts, Transfer};
|
||||||
use crate::gpio::sealed::{AFType, Pin as _};
|
use crate::gpio::sealed::{AFType, Pin as _};
|
||||||
use crate::gpio::AnyPin;
|
use crate::gpio::{AnyPin, Pull};
|
||||||
use crate::pac::spi::{regs, vals, Spi as Regs};
|
use crate::pac::spi::{regs, vals, Spi as Regs};
|
||||||
use crate::rcc::RccPeripheral;
|
use crate::rcc::RccPeripheral;
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
|
@ -93,8 +93,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(peri, sck, mosi, miso);
|
into_ref!(peri, sck, mosi, miso);
|
||||||
|
|
||||||
|
let sck_pull_mode = match config.mode.polarity {
|
||||||
|
Polarity::IdleLow => Pull::Down,
|
||||||
|
Polarity::IdleHigh => Pull::Up,
|
||||||
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
|
sck.set_as_af_pull(sck.af_num(), AFType::OutputPushPull, sck_pull_mode);
|
||||||
sck.set_speed(crate::gpio::Speed::VeryHigh);
|
sck.set_speed(crate::gpio::Speed::VeryHigh);
|
||||||
mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull);
|
mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull);
|
||||||
mosi.set_speed(crate::gpio::Speed::VeryHigh);
|
mosi.set_speed(crate::gpio::Speed::VeryHigh);
|
||||||
|
|
Loading…
Reference in a new issue