#![deny(unsafe_code)] #![no_std] #![no_main] use cortex_m_rt::entry; use panic_halt as _; use embedded_hal::spi::{Mode, Phase, Polarity}; pub const MODE: Mode = Mode { phase: Phase::CaptureOnSecondTransition, polarity: Polarity::IdleHigh, }; use stm32f1xx_hal::{ gpio::gpioa::PA4, gpio::{Output, PushPull}, pac::{Peripherals, SPI1}, prelude::*, spi::{Pins, Spi, Spi1NoRemap}, }; fn setup() -> ( Spi, u8>, PA4>, ) { let dp = Peripherals::take().unwrap(); let mut flash = dp.FLASH.constrain(); let mut rcc = dp.RCC.constrain(); let clocks = rcc.cfgr.freeze(&mut flash.acr); let mut afio = dp.AFIO.constrain(&mut rcc.apb2); let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); // SPI1 let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); let miso = gpioa.pa6; let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); let cs = gpioa.pa4.into_push_pull_output(&mut gpioa.crl); let spi = Spi::spi1( dp.SPI1, (sck, miso, mosi), &mut afio.mapr, MODE, 1_u32.mhz(), clocks, &mut rcc.apb2, ); (spi, cs) } #[entry] fn main() -> ! { let (_spi, _cs) = setup(); loop {} }