123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //! Serial interface loopback test
- //!
- //! You have to short the TX and RX pins to make this program work
- #![deny(unsafe_code)]
- #![deny(warnings)]
- #![no_main]
- #![no_std]
- extern crate panic_halt;
- use cortex_m::asm;
- use nb::block;
- use stm32f1xx_hal::{
- prelude::*,
- pac,
- serial::Serial,
- };
- use cortex_m_rt::entry;
- #[entry]
- fn main() -> ! {
- let p = pac::Peripherals::take().unwrap();
- let mut flash = p.FLASH.constrain();
- let mut rcc = p.RCC.constrain();
- let clocks = rcc.cfgr.freeze(&mut flash.acr);
- let mut afio = p.AFIO.constrain(&mut rcc.apb2);
- // let mut gpioa = p.GPIOA.split(&mut rcc.apb2);
- let mut gpiob = p.GPIOB.split(&mut rcc.apb2);
- // USART1
- // let tx = gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh);
- // let rx = gpioa.pa10;
- // USART1
- // let tx = gpiob.pb6.into_alternate_push_pull(&mut gpiob.crl);
- // let rx = gpiob.pb7;
- // USART2
- // let tx = gpioa.pa2.into_alternate_push_pull(&mut gpioa.crl);
- // let rx = gpioa.pa3;
- // USART3
- let tx = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
- let rx = gpiob.pb11;
- let serial = Serial::usart3(
- p.USART3,
- (tx, rx),
- &mut afio.mapr,
- 9_600.bps(),
- clocks,
- &mut rcc.apb1,
- );
- let (mut tx, mut rx) = serial.split();
- let sent = b'X';
- block!(tx.write(sent)).ok();
- let received = block!(rx.read()).unwrap();
- assert_eq!(received, sent);
- asm::bkpt();
- loop {}
- }
|