Make UART pins Rx/Tx/etc in addition to USART.
This commit is contained in:
parent
54ada5bae1
commit
0920c0cb1d
@ -1,7 +1,7 @@
|
||||
#![macro_use]
|
||||
|
||||
#[cfg_attr(usart_v1, path = "v1.rs")]
|
||||
#[cfg_attr(usart_v2, path = "v2.rs")]
|
||||
//#[cfg_attr(usart_v1, path = "v1.rs")]
|
||||
//#[cfg_attr(usart_v2, path = "v2.rs")]
|
||||
#[cfg_attr(usart_v3, path = "v3.rs")]
|
||||
mod _version;
|
||||
use crate::peripherals;
|
||||
@ -140,6 +140,9 @@ macro_rules! impl_pin {
|
||||
}
|
||||
|
||||
crate::pac::peripheral_pins!(
|
||||
|
||||
// USART
|
||||
|
||||
($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => {
|
||||
impl_pin!($inst, $pin, TxPin, $af);
|
||||
};
|
||||
@ -159,4 +162,26 @@ crate::pac::peripheral_pins!(
|
||||
($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => {
|
||||
impl_pin!($inst, $pin, CkPin, $af);
|
||||
};
|
||||
|
||||
// UART
|
||||
|
||||
($inst:ident, uart, UART, $pin:ident, TX, $af:expr) => {
|
||||
impl_pin!($inst, $pin, TxPin, $af);
|
||||
};
|
||||
|
||||
($inst:ident, uart, UART, $pin:ident, RX, $af:expr) => {
|
||||
impl_pin!($inst, $pin, RxPin, $af);
|
||||
};
|
||||
|
||||
($inst:ident, uart, UART, $pin:ident, CTS, $af:expr) => {
|
||||
impl_pin!($inst, $pin, CtsPin, $af);
|
||||
};
|
||||
|
||||
($inst:ident, uart, UART, $pin:ident, RTS, $af:expr) => {
|
||||
impl_pin!($inst, $pin, RtsPin, $af);
|
||||
};
|
||||
|
||||
($inst:ident, uart, UART, $pin:ident, CK, $af:expr) => {
|
||||
impl_pin!($inst, $pin, CkPin, $af);
|
||||
};
|
||||
);
|
||||
|
@ -22,7 +22,7 @@ impl<'d, T: Instance> Uart<'d, T> {
|
||||
unborrow!(inner, rx, tx);
|
||||
|
||||
// Uncomment once we find all of the H7's UART clocks.
|
||||
//T::enable();
|
||||
T::enable();
|
||||
let pclk_freq = T::frequency();
|
||||
|
||||
// TODO: better calculation, including error checking and OVER8 if possible.
|
||||
@ -65,7 +65,7 @@ impl<'d, T: Instance> Uart<'d, T> {
|
||||
});
|
||||
}
|
||||
let r = self.inner.regs();
|
||||
let dst = r.dr().ptr() as *mut u8;
|
||||
let dst = r.tdr().ptr() as *mut u8;
|
||||
ch.transfer(buffer, dst).await;
|
||||
Ok(())
|
||||
}
|
||||
|
99
examples/stm32h7/src/bin/usart.rs
Normal file
99
examples/stm32h7/src/bin/usart.rs
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(trait_alias)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use example_common::*;
|
||||
|
||||
use stm32h7xx_hal as hal;
|
||||
use hal::prelude::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use stm32h7::stm32h743 as pac;
|
||||
|
||||
#[embassy::task]
|
||||
async fn main_task() {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
let config = Config::default();
|
||||
let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, config);
|
||||
|
||||
usart.bwrite_all(b"Hello Embassy World!\r\n").unwrap();
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
loop {
|
||||
usart.read(&mut buf).unwrap();
|
||||
usart.bwrite_all(&buf).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
struct ZeroClock;
|
||||
|
||||
impl Clock for ZeroClock {
|
||||
fn now(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let pp = pac::Peripherals::take().unwrap();
|
||||
|
||||
let pwrcfg = pp.PWR.constrain().freeze();
|
||||
|
||||
let rcc = pp.RCC.constrain();
|
||||
|
||||
let ccdr = rcc
|
||||
.sys_ck(96.mhz())
|
||||
.pclk1(48.mhz())
|
||||
.pclk2(48.mhz())
|
||||
.pclk3(48.mhz())
|
||||
.pclk4(48.mhz())
|
||||
.pll1_q_ck(48.mhz())
|
||||
.freeze(pwrcfg, &pp.SYSCFG);
|
||||
|
||||
let pp = unsafe { pac::Peripherals::steal() };
|
||||
|
||||
pp.DBGMCU.cr.modify(|_, w| {
|
||||
w.dbgsleep_d1().set_bit();
|
||||
w.dbgstby_d1().set_bit();
|
||||
w.dbgstop_d1().set_bit();
|
||||
w.d1dbgcken().set_bit();
|
||||
w
|
||||
});
|
||||
|
||||
pp.RCC.ahb4enr.modify(|_, w| {
|
||||
w.gpioaen().set_bit();
|
||||
w.gpioben().set_bit();
|
||||
w.gpiocen().set_bit();
|
||||
w.gpioden().set_bit();
|
||||
w.gpioeen().set_bit();
|
||||
w.gpiofen().set_bit();
|
||||
w
|
||||
});
|
||||
|
||||
|
||||
unsafe { embassy::time::set_clock(&ZeroClock) };
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(main_task()));
|
||||
})
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 424f96eae80015536c4df5ed62c1caad85bb531f
|
||||
Subproject commit 3cc324ef25916ff4d70acfc4e7551109f7d02900
|
Loading…
Reference in New Issue
Block a user