Created
March 29, 2019 21:09
-
-
Save skammer/f3138a575f530d239ec55779701a5899 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_main] | |
#![no_std] | |
#[allow(unused)] | |
extern crate stm32f1xx_hal; | |
extern crate cortex_m_rt; | |
extern crate cortex_m_semihosting; | |
extern crate panic_semihosting; | |
extern crate cortex_m; | |
extern crate nb; | |
use cortex_m_semihosting::{hprintln}; | |
use stm32f1xx_hal::{ | |
prelude::*, | |
pac, | |
rtc::Rtc, | |
spi::Spi, | |
spi::Mode, | |
spi::Phase, | |
spi::Polarity, | |
timer, | |
}; | |
use nb::block; | |
use cortex_m_rt::entry; | |
#[entry] | |
fn main() -> ! { | |
let dp = pac::Peripherals::take().unwrap(); | |
let mut pwr = dp.PWR; | |
let mut rcc = dp.RCC.constrain(); | |
let mut afio = dp.AFIO.constrain(&mut rcc.apb2); | |
let mut flash = dp.FLASH.constrain(); | |
let clocks = rcc | |
.cfgr | |
.use_hse(8.mhz()) | |
.hclk(72.mhz()) | |
.sysclk(72.mhz()) | |
.pclk1(36.mhz()) | |
.pclk2(72.mhz()) | |
.freeze(&mut flash.acr); | |
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2); | |
let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); | |
let gpiob = dp.GPIOB.split(&mut rcc.apb2); | |
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); | |
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 spi_mode = Mode { | |
polarity: Polarity::IdleLow, | |
phase: Phase::CaptureOnFirstTransition, | |
}; | |
let mut spi = Spi::spi1( | |
dp.SPI1, | |
(sck, miso, mosi), | |
&mut afio.mapr, | |
spi_mode, | |
18.mhz(), | |
clocks, | |
&mut rcc.apb2, | |
); | |
let mut cp = cortex_m::Peripherals::take().unwrap(); | |
cp.DCB.enable_trace(); | |
cp.DWT.enable_cycle_counter(); | |
let mut led_on = false; | |
loop { | |
block!(spi.send(0xf1)).map_err(|_| ()); | |
block!(spi.read()).map_err(|_| ()); | |
// if led_on { | |
// led.set_low(); | |
// led_on = false; | |
// } | |
// else { | |
// led.set_high(); | |
// led_on = true; | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment