Rust edition bumped & UART implementation
- Also adds UART example
This commit is contained in:
@ -72,7 +72,9 @@ fn main() -> ! {
|
||||
}
|
||||
TestCase::TestPullup => {
|
||||
// Tie PORTA[0] to PORTA[1] for these tests!
|
||||
let input = porta.pa1.into_pull_up_input(&mut dp.IOCONFIG);
|
||||
let input = porta
|
||||
.pa1
|
||||
.into_pull_up_input(&mut dp.IOCONFIG, &mut dp.PORTA);
|
||||
assert!(input.is_high().unwrap());
|
||||
let mut out = porta
|
||||
.pa0
|
||||
|
44
examples/uart.rs
Normal file
44
examples/uart.rs
Normal file
@ -0,0 +1,44 @@
|
||||
//! UART example application. Sends a test string over a UART and then enters
|
||||
//! echo mode
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use core::fmt::Write;
|
||||
use cortex_m_rt::entry;
|
||||
use panic_rtt_target as _;
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use va108xx_hal::{pac, prelude::*, uart};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
rtt_init_print!();
|
||||
rprintln!("-- VA108xx UART test application--");
|
||||
|
||||
let mut dp = pac::Peripherals::take().unwrap();
|
||||
|
||||
let gpiob = dp.PORTB.split(&mut dp.SYSCONFIG).unwrap();
|
||||
let tx = gpiob.pb21.into_funsel_1(&mut dp.IOCONFIG);
|
||||
let rx = gpiob.pb20.into_funsel_1(&mut dp.IOCONFIG);
|
||||
|
||||
let uartb = uart::Uart::uartb(
|
||||
dp.UARTB,
|
||||
(tx, rx),
|
||||
115200.bps(),
|
||||
&mut dp.SYSCONFIG,
|
||||
50.mhz().into(),
|
||||
);
|
||||
let (mut tx, mut rx) = uartb.split();
|
||||
writeln!(tx, "Hello World\r").unwrap();
|
||||
loop {
|
||||
// Echo what is received on the serial link.
|
||||
match rx.read() {
|
||||
Ok(recv) => {
|
||||
nb::block!(tx.write(recv)).expect("TX send error");
|
||||
}
|
||||
Err(nb::Error::WouldBlock) => (),
|
||||
Err(nb::Error::Other(uart_error)) => {
|
||||
rprintln!("UART receive error {:?}", uart_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user