123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #![deny(unsafe_code)]
- #![deny(warnings)]
- #![no_main]
- #![no_std]
- #[macro_use]
- extern crate cortex_m;
- extern crate cortex_m_rt as rt;
- extern crate mfrc522;
- extern crate panic_itm;
- extern crate stm32f1xx_hal as hal;
- use hal::prelude::*;
- use hal::spi::Spi;
- use hal::stm32f103xx;
- use mfrc522::Mfrc522;
- use rt::{entry, exception, ExceptionFrame};
- #[entry]
- fn main() -> ! {
- let mut cp = cortex_m::Peripherals::take().unwrap();
- let dp = stm32f103xx::Peripherals::take().unwrap();
- let _stim = &mut cp.ITM.stim[0];
- let mut rcc = dp.RCC.constrain();
- let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
- let mut flash = dp.FLASH.constrain();
- let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
- let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
- let clocks = rcc.cfgr.freeze(&mut flash.acr);
- 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 = Spi::spi1(
- dp.SPI1,
- (sck, miso, mosi),
- &mut afio.mapr,
- mfrc522::MODE,
- 1.mhz(),
- clocks,
- &mut rcc.apb2,
- );
- let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
- let mut mfrc522 = Mfrc522::new(spi, nss).unwrap();
- let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
- led.set_high();
- loop {
- if let Ok(atqa) = mfrc522.reqa() {
- if let Ok(uid) = mfrc522.select(&atqa) {
- iprintln!(_stim, "* {:?}", uid);
- }
- }
- }
- }
- #[exception]
- fn HardFault(ef: &ExceptionFrame) -> ! {
- panic!("{:#?}", ef);
- }
- #[exception]
- fn DefaultHandler(irqn: i16) {
- panic!("Unhandled exception (IRQn = {})", irqn);
- }
|