[][src]Module stm32l0x1_hal::serial

USART(s) and LPUART

This is an implementation of RS232 USART(s) and LPUART. The interface for the LPUART and USARTs is largely the same, though their interaction with various power modes is different (see the Reference Manual).

extern crate stm32l0x1_hal;

use stm32l0x1_hal::common::Constrain;

let d = stm32l0x1_hal::stm32l0x1::Peripherals::take().unwrap();

let mut rcc = d.RCC.constrain();
let mut flash = d.FLASH.constrain();

rcc.freeze(&mut flash, &mut pwr);
let clk_ctx = rcc.cfgr.context().unwrap();

let mut gpiob = gpio::B::new(d.GPIOB, &mut rcc.iop);

// VCP USART
let vcp_rx = gpioa.PA15.into_output::<PushPull, Floating>().into_alt_fun::<AF4>();
vcp_rx.set_pin_speed(PinSpeed::VeryHigh);

let vcp_tx = gpioa.PA2.into_output::<PushPull, Floating>().into_alt_fun::<AF4>();
vcp_tx.set_pin_speed(PinSpeed::VeryHigh);

let vcp_serial = Serial::usart2(
    d.USART2,
    (vcp_tx, vcp_rx),
    Bps(115200),
    clocking::USARTClkSource::HSI16,
    &clk_ctx,
    &mut rcc.apb1,
    &mut rcc.ccipr);

let (mut tx, mut rx) = vcp_serial.split();

loop {
    block!(tx.write(block!(rx.read()).unwrap())).unwrap();
}

Modules

lpuart1

LPUART1 module

usart2

USART module

Structs

RtsDe

Serial RS232 RTS / RS485 DE channel

Rx

Serial receiver channel

Serial

Serial abstraction

Tx

Serial transmitter channel

Enums

Error

Serial errors

Event

UART interrupt event sources

SleepError

Errors relating to wake-from-sleep