You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stm32f0xx-hal/examples/serial_echo.rs

41 lines
1005 B
Rust

#![no_main]
#![no_std]
#[allow(unused)]
use panic_halt;
use stm32f0xx_hal as hal;
use crate::hal::{prelude::*, serial::Serial, stm32};
use cortex_m_rt::entry;
#[entry]
fn main() -> ! {
if let Some(p) = stm32::Peripherals::take() {
cortex_m::interrupt::free(move |cs| {
let mut flash = p.FLASH;
let mut rcc = p.RCC.configure().sysclk(48.mhz()).freeze(&mut flash);
let gpioa = p.GPIOA.split(&mut rcc);
let tx = gpioa.pa9.into_alternate_af1(cs);
let rx = gpioa.pa10.into_alternate_af1(cs);
let mut serial = Serial::usart1(p.USART1, (tx, rx), 115_200.bps(), &mut rcc);
loop {
// Wait for reception of a single byte
let received = nb::block!(serial.read()).unwrap();
// Send back previously received byte and wait for completion
nb::block!(serial.write(received)).ok();
}
});
}
loop {
continue;
}
}