Merge pull request #1718 from copterust/stm32-spi-set-freq-in-config
Move frequency to SPI config
This commit is contained in:
commit
105aa8f452
@ -165,7 +165,9 @@ impl<'d, T: Instance, Tx, Rx> I2S<'d, T, Tx, Rx> {
|
|||||||
mck.set_as_af(mck.af_num(), AFType::OutputPushPull);
|
mck.set_as_af(mck.af_num(), AFType::OutputPushPull);
|
||||||
mck.set_speed(crate::gpio::Speed::VeryHigh);
|
mck.set_speed(crate::gpio::Speed::VeryHigh);
|
||||||
|
|
||||||
let spi = Spi::new_internal(peri, txdma, rxdma, freq, SpiConfig::default());
|
let mut spi_cfg = SpiConfig::default();
|
||||||
|
spi_cfg.frequency = freq;
|
||||||
|
let spi = Spi::new_internal(peri, txdma, rxdma, spi_cfg);
|
||||||
|
|
||||||
#[cfg(all(rcc_f4, not(stm32f410)))]
|
#[cfg(all(rcc_f4, not(stm32f410)))]
|
||||||
let pclk = unsafe { get_freqs() }.plli2s.unwrap();
|
let pclk = unsafe { get_freqs() }.plli2s.unwrap();
|
||||||
|
@ -36,6 +36,7 @@ pub enum BitOrder {
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
pub bit_order: BitOrder,
|
pub bit_order: BitOrder,
|
||||||
|
pub frequency: Hertz,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
@ -43,6 +44,7 @@ impl Default for Config {
|
|||||||
Self {
|
Self {
|
||||||
mode: MODE_0,
|
mode: MODE_0,
|
||||||
bit_order: BitOrder::MsbFirst,
|
bit_order: BitOrder::MsbFirst,
|
||||||
|
frequency: Hertz(1_000_000),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +90,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
|
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
|
||||||
txdma: impl Peripheral<P = Tx> + 'd,
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
rxdma: impl Peripheral<P = Rx> + 'd,
|
rxdma: impl Peripheral<P = Rx> + 'd,
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(peri, sck, mosi, miso);
|
into_ref!(peri, sck, mosi, miso);
|
||||||
@ -112,7 +113,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
Some(miso.map_into()),
|
Some(miso.map_into()),
|
||||||
txdma,
|
txdma,
|
||||||
rxdma,
|
rxdma,
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -123,7 +123,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
|
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
|
||||||
txdma: impl Peripheral<P = Tx> + 'd, // TODO remove
|
txdma: impl Peripheral<P = Tx> + 'd, // TODO remove
|
||||||
rxdma: impl Peripheral<P = Rx> + 'd,
|
rxdma: impl Peripheral<P = Rx> + 'd,
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(sck, miso);
|
into_ref!(sck, miso);
|
||||||
@ -139,7 +138,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
Some(miso.map_into()),
|
Some(miso.map_into()),
|
||||||
txdma,
|
txdma,
|
||||||
rxdma,
|
rxdma,
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -150,7 +148,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
|
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
|
||||||
txdma: impl Peripheral<P = Tx> + 'd,
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
rxdma: impl Peripheral<P = Rx> + 'd, // TODO remove
|
rxdma: impl Peripheral<P = Rx> + 'd, // TODO remove
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(sck, mosi);
|
into_ref!(sck, mosi);
|
||||||
@ -166,7 +163,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
None,
|
None,
|
||||||
txdma,
|
txdma,
|
||||||
rxdma,
|
rxdma,
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -176,14 +172,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
|
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
|
||||||
txdma: impl Peripheral<P = Tx> + 'd,
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
rxdma: impl Peripheral<P = Rx> + 'd, // TODO: remove
|
rxdma: impl Peripheral<P = Rx> + 'd, // TODO: remove
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(mosi);
|
into_ref!(mosi);
|
||||||
mosi.set_as_af_pull(mosi.af_num(), AFType::OutputPushPull, Pull::Down);
|
mosi.set_as_af_pull(mosi.af_num(), AFType::OutputPushPull, Pull::Down);
|
||||||
mosi.set_speed(crate::gpio::Speed::Medium);
|
mosi.set_speed(crate::gpio::Speed::Medium);
|
||||||
|
|
||||||
Self::new_inner(peri, None, Some(mosi.map_into()), None, txdma, rxdma, freq, config)
|
Self::new_inner(peri, None, Some(mosi.map_into()), None, txdma, rxdma, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(stm32wl)]
|
#[cfg(stm32wl)]
|
||||||
@ -201,7 +196,8 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.mode = MODE_0;
|
config.mode = MODE_0;
|
||||||
config.bit_order = BitOrder::MsbFirst;
|
config.bit_order = BitOrder::MsbFirst;
|
||||||
Self::new_inner(peri, None, None, None, txdma, rxdma, freq, config)
|
config.frequency = freq;
|
||||||
|
Self::new_inner(peri, None, None, None, txdma, rxdma, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -209,10 +205,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
peri: impl Peripheral<P = T> + 'd,
|
peri: impl Peripheral<P = T> + 'd,
|
||||||
txdma: impl Peripheral<P = Tx> + 'd,
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
rxdma: impl Peripheral<P = Rx> + 'd,
|
rxdma: impl Peripheral<P = Rx> + 'd,
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_inner(peri, None, None, None, txdma, rxdma, freq, config)
|
Self::new_inner(peri, None, None, None, txdma, rxdma, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_inner(
|
fn new_inner(
|
||||||
@ -222,12 +217,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
miso: Option<PeripheralRef<'d, AnyPin>>,
|
miso: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
txdma: impl Peripheral<P = Tx> + 'd,
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
rxdma: impl Peripheral<P = Rx> + 'd,
|
rxdma: impl Peripheral<P = Rx> + 'd,
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(peri, txdma, rxdma);
|
into_ref!(peri, txdma, rxdma);
|
||||||
|
|
||||||
let pclk = T::frequency();
|
let pclk = T::frequency();
|
||||||
|
let freq = config.frequency;
|
||||||
let br = compute_baud_rate(pclk, freq.into());
|
let br = compute_baud_rate(pclk, freq.into());
|
||||||
|
|
||||||
let cpha = config.raw_phase();
|
let cpha = config.raw_phase();
|
||||||
@ -334,19 +329,29 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
|
|
||||||
let lsbfirst = config.raw_byte_order();
|
let lsbfirst = config.raw_byte_order();
|
||||||
|
|
||||||
|
let pclk = T::frequency();
|
||||||
|
let freq = config.frequency;
|
||||||
|
let br = compute_baud_rate(pclk, freq.into());
|
||||||
|
|
||||||
#[cfg(any(spi_v1, spi_f1, spi_v2))]
|
#[cfg(any(spi_v1, spi_f1, spi_v2))]
|
||||||
T::REGS.cr1().modify(|w| {
|
T::REGS.cr1().modify(|w| {
|
||||||
w.set_cpha(cpha);
|
w.set_cpha(cpha);
|
||||||
w.set_cpol(cpol);
|
w.set_cpol(cpol);
|
||||||
|
w.set_br(br);
|
||||||
w.set_lsbfirst(lsbfirst);
|
w.set_lsbfirst(lsbfirst);
|
||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
||||||
T::REGS.cfg2().modify(|w| {
|
{
|
||||||
w.set_cpha(cpha);
|
T::REGS.cfg2().modify(|w| {
|
||||||
w.set_cpol(cpol);
|
w.set_cpha(cpha);
|
||||||
w.set_lsbfirst(lsbfirst);
|
w.set_cpol(cpol);
|
||||||
});
|
w.set_lsbfirst(lsbfirst);
|
||||||
|
});
|
||||||
|
T::REGS.cfg1().modify(|w| {
|
||||||
|
w.set_mbr(br);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_config(&self) -> Config {
|
pub fn get_current_config(&self) -> Config {
|
||||||
@ -354,6 +359,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
let cfg = T::REGS.cr1().read();
|
let cfg = T::REGS.cr1().read();
|
||||||
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
||||||
let cfg = T::REGS.cfg2().read();
|
let cfg = T::REGS.cfg2().read();
|
||||||
|
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
||||||
|
let cfg1 = T::REGS.cfg1().read();
|
||||||
|
|
||||||
let polarity = if cfg.cpol() == vals::Cpol::IDLELOW {
|
let polarity = if cfg.cpol() == vals::Cpol::IDLELOW {
|
||||||
Polarity::IdleLow
|
Polarity::IdleLow
|
||||||
} else {
|
} else {
|
||||||
@ -371,9 +379,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
BitOrder::MsbFirst
|
BitOrder::MsbFirst
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(any(spi_v1, spi_f1, spi_v2))]
|
||||||
|
let br = cfg.br();
|
||||||
|
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
||||||
|
let br = cfg1.mbr();
|
||||||
|
|
||||||
|
let pclk = T::frequency();
|
||||||
|
let frequency = compute_frequency(pclk, br);
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
mode: Mode { polarity, phase },
|
mode: Mode { polarity, phase },
|
||||||
bit_order,
|
bit_order,
|
||||||
|
frequency,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,6 +670,21 @@ fn compute_baud_rate(clocks: Hertz, freq: Hertz) -> Br {
|
|||||||
Br::from_bits(val)
|
Br::from_bits(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compute_frequency(clocks: Hertz, br: Br) -> Hertz {
|
||||||
|
let div: u16 = match br {
|
||||||
|
Br::DIV2 => 2,
|
||||||
|
Br::DIV4 => 4,
|
||||||
|
Br::DIV8 => 8,
|
||||||
|
Br::DIV16 => 16,
|
||||||
|
Br::DIV32 => 32,
|
||||||
|
Br::DIV64 => 64,
|
||||||
|
Br::DIV128 => 128,
|
||||||
|
Br::DIV256 => 256,
|
||||||
|
};
|
||||||
|
|
||||||
|
clocks / div
|
||||||
|
}
|
||||||
|
|
||||||
trait RegsExt {
|
trait RegsExt {
|
||||||
fn tx_ptr<W>(&self) -> *mut W;
|
fn tx_ptr<W>(&self) -> *mut W;
|
||||||
fn rx_ptr<W>(&self) -> *mut W;
|
fn rx_ptr<W>(&self) -> *mut W;
|
||||||
|
@ -17,16 +17,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI1,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PB3,
|
|
||||||
p.PB5,
|
let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
||||||
p.PB4,
|
|
||||||
p.DMA1_CH3,
|
|
||||||
p.DMA1_CH2,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
for n in 0u32.. {
|
for n in 0u32.. {
|
||||||
let mut write: String<128> = String::new();
|
let mut write: String<128> = String::new();
|
||||||
|
@ -16,16 +16,10 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI3,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PC10,
|
|
||||||
p.PC12,
|
let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
|
||||||
p.PC11,
|
|
||||||
NoDma,
|
|
||||||
NoDma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
|
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
|
||||||
|
|
||||||
|
@ -17,16 +17,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI1,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PB3,
|
|
||||||
p.PB5,
|
let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA2_CH3, p.DMA2_CH2, spi_config);
|
||||||
p.PB4,
|
|
||||||
p.DMA2_CH3,
|
|
||||||
p.DMA2_CH2,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
for n in 0u32.. {
|
for n in 0u32.. {
|
||||||
let mut write: String<128> = String::new();
|
let mut write: String<128> = String::new();
|
||||||
|
@ -76,7 +76,9 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Start test using spi as neopixel driver");
|
info!("Start test using spi as neopixel driver");
|
||||||
|
|
||||||
let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, NoDma, Hertz(4_000_000), Config::default());
|
let mut config = Config::default();
|
||||||
|
config.frequency = Hertz(4_000_000);
|
||||||
|
let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, NoDma, config);
|
||||||
|
|
||||||
let mut neopixels = Ws2812::new();
|
let mut neopixels = Ws2812::new();
|
||||||
|
|
||||||
|
@ -43,16 +43,10 @@ fn main() -> ! {
|
|||||||
config.rcc.pll1.q_ck = Some(mhz(100));
|
config.rcc.pll1.q_ck = Some(mhz(100));
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
let spi = spi::Spi::new(
|
let mut spi_config = spi::Config::default();
|
||||||
p.SPI3,
|
spi_config.frequency = mhz(1);
|
||||||
p.PB3,
|
|
||||||
p.PB5,
|
let spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, NoDma, NoDma, spi_config);
|
||||||
p.PB4,
|
|
||||||
NoDma,
|
|
||||||
NoDma,
|
|
||||||
mhz(1),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let executor = EXECUTOR.init(Executor::new());
|
let executor = EXECUTOR.init(Executor::new());
|
||||||
|
|
||||||
|
@ -39,16 +39,10 @@ fn main() -> ! {
|
|||||||
config.rcc.pll1.q_ck = Some(mhz(100));
|
config.rcc.pll1.q_ck = Some(mhz(100));
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
let spi = spi::Spi::new(
|
let mut spi_config = spi::Config::default();
|
||||||
p.SPI3,
|
spi_config.frequency = mhz(1);
|
||||||
p.PB3,
|
|
||||||
p.PB5,
|
let spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH4, spi_config);
|
||||||
p.PB4,
|
|
||||||
p.DMA1_CH3,
|
|
||||||
p.DMA1_CH4,
|
|
||||||
mhz(1),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let executor = EXECUTOR.init(Executor::new());
|
let executor = EXECUTOR.init(Executor::new());
|
||||||
|
|
||||||
|
@ -27,17 +27,11 @@ async fn main(_spawner: Spawner) {
|
|||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
let mut spi_config = spi::Config::default();
|
||||||
|
spi_config.frequency = khz(200);
|
||||||
|
|
||||||
// SPI for sx1276
|
// SPI for sx1276
|
||||||
let spi = spi::Spi::new(
|
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
||||||
p.SPI1,
|
|
||||||
p.PB3,
|
|
||||||
p.PA7,
|
|
||||||
p.PA6,
|
|
||||||
p.DMA1_CH3,
|
|
||||||
p.DMA1_CH2,
|
|
||||||
khz(200),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
||||||
|
@ -32,17 +32,11 @@ async fn main(_spawner: Spawner) {
|
|||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
let mut spi_config = spi::Config::default();
|
||||||
|
spi_config.frequency = khz(200);
|
||||||
|
|
||||||
// SPI for sx1276
|
// SPI for sx1276
|
||||||
let spi = spi::Spi::new(
|
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
||||||
p.SPI1,
|
|
||||||
p.PB3,
|
|
||||||
p.PA7,
|
|
||||||
p.PA6,
|
|
||||||
p.DMA1_CH3,
|
|
||||||
p.DMA1_CH2,
|
|
||||||
khz(200),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
||||||
|
@ -27,17 +27,11 @@ async fn main(_spawner: Spawner) {
|
|||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
let mut spi_config = spi::Config::default();
|
||||||
|
spi_config.frequency = khz(200);
|
||||||
|
|
||||||
// SPI for sx1276
|
// SPI for sx1276
|
||||||
let spi = spi::Spi::new(
|
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
||||||
p.SPI1,
|
|
||||||
p.PB3,
|
|
||||||
p.PA7,
|
|
||||||
p.PA6,
|
|
||||||
p.DMA1_CH3,
|
|
||||||
p.DMA1_CH2,
|
|
||||||
khz(200),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
||||||
|
@ -27,17 +27,11 @@ async fn main(_spawner: Spawner) {
|
|||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
let mut spi_config = spi::Config::default();
|
||||||
|
spi_config.frequency = khz(200);
|
||||||
|
|
||||||
// SPI for sx1276
|
// SPI for sx1276
|
||||||
let spi = spi::Spi::new(
|
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
||||||
p.SPI1,
|
|
||||||
p.PB3,
|
|
||||||
p.PA7,
|
|
||||||
p.PA6,
|
|
||||||
p.DMA1_CH3,
|
|
||||||
p.DMA1_CH2,
|
|
||||||
khz(200),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
||||||
|
@ -15,16 +15,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Hello World, folks!");
|
info!("Hello World, folks!");
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI1,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PB3,
|
|
||||||
p.PA7,
|
let mut spi = Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, NoDma, NoDma, spi_config);
|
||||||
p.PA6,
|
|
||||||
NoDma,
|
|
||||||
NoDma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut cs = Output::new(p.PA15, Level::High, Speed::VeryHigh);
|
let mut cs = Output::new(p.PA15, Level::High, Speed::VeryHigh);
|
||||||
|
|
||||||
|
@ -15,16 +15,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Hello World, folks!");
|
info!("Hello World, folks!");
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI1,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PA5,
|
|
||||||
p.PA7,
|
let mut spi = Spi::new(p.SPI1, p.PA5, p.PA7, p.PA6, NoDma, NoDma, spi_config);
|
||||||
p.PA6,
|
|
||||||
NoDma,
|
|
||||||
NoDma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh);
|
let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh);
|
||||||
|
|
||||||
|
@ -15,16 +15,10 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI3,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PC10,
|
|
||||||
p.PC12,
|
let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
|
||||||
p.PC11,
|
|
||||||
NoDma,
|
|
||||||
NoDma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
|
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
|
||||||
|
|
||||||
|
@ -17,16 +17,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
let spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI3,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PC10,
|
|
||||||
p.PC12,
|
let spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
|
||||||
p.PC11,
|
|
||||||
NoDma,
|
|
||||||
NoDma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut spi = BlockingAsync::new(spi);
|
let mut spi = BlockingAsync::new(spi);
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_stm32::init(Default::default());
|
let p = embassy_stm32::init(Default::default());
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi_config = Config::default();
|
||||||
p.SPI3,
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
p.PC10,
|
|
||||||
p.PC12,
|
let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, p.DMA1_CH1, p.DMA1_CH2, spi_config);
|
||||||
p.PC11,
|
|
||||||
p.DMA1_CH1,
|
|
||||||
p.DMA1_CH2,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
Config::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// These are the pins for the Inventek eS-Wifi SPI Wifi Adapter.
|
// These are the pins for the Inventek eS-Wifi SPI Wifi Adapter.
|
||||||
|
|
||||||
|
@ -35,15 +35,14 @@ async fn main(_spawner: Spawner) {
|
|||||||
#[cfg(feature = "stm32c031c6")]
|
#[cfg(feature = "stm32c031c6")]
|
||||||
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
|
||||||
|
|
||||||
|
let mut spi_config = spi::Config::default();
|
||||||
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi = Spi::new(
|
||||||
spi,
|
spi, sck, // Arduino D13
|
||||||
sck, // Arduino D13
|
|
||||||
mosi, // Arduino D11
|
mosi, // Arduino D11
|
||||||
miso, // Arduino D12
|
miso, // Arduino D12
|
||||||
NoDma,
|
NoDma, NoDma, spi_config,
|
||||||
NoDma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];
|
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];
|
||||||
|
@ -34,15 +34,14 @@ async fn main(_spawner: Spawner) {
|
|||||||
#[cfg(feature = "stm32c031c6")]
|
#[cfg(feature = "stm32c031c6")]
|
||||||
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
|
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
|
||||||
|
|
||||||
|
let mut spi_config = spi::Config::default();
|
||||||
|
spi_config.frequency = Hertz(1_000_000);
|
||||||
|
|
||||||
let mut spi = Spi::new(
|
let mut spi = Spi::new(
|
||||||
spi,
|
spi, sck, // Arduino D13
|
||||||
sck, // Arduino D13
|
|
||||||
mosi, // Arduino D11
|
mosi, // Arduino D11
|
||||||
miso, // Arduino D12
|
miso, // Arduino D12
|
||||||
tx_dma,
|
tx_dma, rx_dma, spi_config,
|
||||||
rx_dma,
|
|
||||||
Hertz(1_000_000),
|
|
||||||
spi::Config::default(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];
|
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];
|
||||||
|
Loading…
Reference in New Issue
Block a user