Module stm32f0xx_hal::serial [−][src]
Expand description
API for the integrated USART ports
This only implements the usual asynchronous bidirectional 8-bit transfers.
It’s possible to use a read-only/write-only serial implementation with
usartXrx
/usartXtx
.
Examples
Echo
use stm32f0xx_hal as hal;
use crate::hal::prelude::*;
use crate::hal::serial::Serial;
use crate::hal::pac;
use nb::block;
cortex_m::interrupt::free(|cs| {
let rcc = p.RCC.configure().sysclk(48.mhz()).freeze();
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 {
let received = block!(serial.read()).unwrap();
block!(serial.write(received)).ok();
}
});
Hello World
use stm32f0xx_hal as hal;
use crate::hal::prelude::*;
use crate::hal::serial::Serial;
use crate::hal::pac;
use nb::block;
cortex_m::interrupt::free(|cs| {
let rcc = p.RCC.configure().sysclk(48.mhz()).freeze();
let gpioa = p.GPIOA.split(&mut rcc);
let tx = gpioa.pa9.into_alternate_af1(cs);
let mut serial = Serial::usart1tx(p.USART1, tx, 115_200.bps(), &mut rcc);
loop {
serial.write_str("Hello World!\r\n");
}
});