stm32/usart: expose all functionality as inherent methods.
This commit is contained in:
parent
98f24bf819
commit
c949519714
@ -129,7 +129,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn write_dma(&mut self, buffer: &[u8]) -> Result<(), Error>
|
pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
TxDma: crate::usart::TxDma<T>,
|
TxDma: crate::usart::TxDma<T>,
|
||||||
{
|
{
|
||||||
@ -146,7 +146,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_dma(&mut self, buffer: &mut [u8]) -> Result<(), Error>
|
pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
RxDma: crate::usart::RxDma<T>,
|
RxDma: crate::usart::RxDma<T>,
|
||||||
{
|
{
|
||||||
@ -163,7 +163,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_blocking(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
|
pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let r = self.inner.regs();
|
let r = self.inner.regs();
|
||||||
for b in buffer {
|
for b in buffer {
|
||||||
@ -190,6 +190,25 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> {
|
||||||
|
unsafe {
|
||||||
|
let r = self.inner.regs();
|
||||||
|
for &b in buffer {
|
||||||
|
while !sr(r).read().txe() {}
|
||||||
|
tdr(r).write_volatile(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn blocking_flush(&mut self) -> Result<(), Error> {
|
||||||
|
unsafe {
|
||||||
|
let r = self.inner.regs();
|
||||||
|
while !sr(r).read().tc() {}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance, TxDma, RxDma> embedded_hal::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> {
|
impl<'d, T: Instance, TxDma, RxDma> embedded_hal::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> {
|
||||||
@ -224,21 +243,10 @@ impl<'d, T: Instance, TxDma, RxDma> embedded_hal::blocking::serial::Write<u8>
|
|||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
|
fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
|
||||||
unsafe {
|
self.blocking_write(buffer)
|
||||||
let r = self.inner.regs();
|
|
||||||
for &b in buffer {
|
|
||||||
while !sr(r).read().txe() {}
|
|
||||||
tdr(r).write_volatile(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
fn bflush(&mut self) -> Result<(), Self::Error> {
|
fn bflush(&mut self) -> Result<(), Self::Error> {
|
||||||
unsafe {
|
self.blocking_flush()
|
||||||
let r = self.inner.regs();
|
|
||||||
while !sr(r).read().tc() {}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +260,7 @@ where
|
|||||||
= impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
|
= impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
|
||||||
|
|
||||||
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
|
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
|
||||||
self.write_dma(buf)
|
self.write(buf)
|
||||||
.map_err(|_| embassy_traits::uart::Error::Other)
|
.map_err(|_| embassy_traits::uart::Error::Other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,7 +275,7 @@ where
|
|||||||
= impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
|
= impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
|
||||||
|
|
||||||
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
|
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
|
||||||
self.read_dma(buf)
|
self.read(buf)
|
||||||
.map_err(|_| embassy_traits::uart::Error::Other)
|
.map_err(|_| embassy_traits::uart::Error::Other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
|||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embassy_traits::uart::Write as _;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
use heapless::String;
|
use heapless::String;
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ mod example_common;
|
|||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embedded_hal::blocking::serial::Write;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
@ -19,12 +18,12 @@ fn main() -> ! {
|
|||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config);
|
let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config);
|
||||||
|
|
||||||
unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n"));
|
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||||
info!("wrote Hello, starting echo");
|
info!("wrote Hello, starting echo");
|
||||||
|
|
||||||
let mut buf = [0u8; 1];
|
let mut buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
unwrap!(usart.read_blocking(&mut buf));
|
unwrap!(usart.blocking_read(&mut buf));
|
||||||
unwrap!(usart.bwrite_all(&buf));
|
unwrap!(usart.blocking_write(&buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
|||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embassy_traits::uart::Write as _;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
use heapless::String;
|
use heapless::String;
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
|||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embassy_traits::uart::Write as _Write;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
use heapless::String;
|
use heapless::String;
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#[path = "../example_common.rs"]
|
#[path = "../example_common.rs"]
|
||||||
mod example_common;
|
mod example_common;
|
||||||
use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
|
|
||||||
use embassy::executor::Executor;
|
use embassy::executor::Executor;
|
||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
@ -20,13 +19,13 @@ async fn main_task() {
|
|||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, NoDma, NoDma, config);
|
let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, NoDma, NoDma, config);
|
||||||
|
|
||||||
unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n"));
|
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||||
info!("wrote Hello, starting echo");
|
info!("wrote Hello, starting echo");
|
||||||
|
|
||||||
let mut buf = [0u8; 1];
|
let mut buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
unwrap!(usart.read_blocking(&mut buf));
|
unwrap!(usart.blocking_read(&mut buf));
|
||||||
unwrap!(usart.bwrite_all(&buf));
|
unwrap!(usart.blocking_write(&buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ use embassy::executor::Executor;
|
|||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_traits::uart::Write as _Write;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
|
@ -10,7 +10,6 @@ use example_common::*;
|
|||||||
use embassy::executor::Spawner;
|
use embassy::executor::Spawner;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embassy_traits::uart::{Read, Write};
|
|
||||||
|
|
||||||
#[embassy::main]
|
#[embassy::main]
|
||||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||||
|
@ -7,7 +7,6 @@ mod example_common;
|
|||||||
|
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embedded_hal::blocking::serial::Write;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
#[cortex_m_rt::entry]
|
#[cortex_m_rt::entry]
|
||||||
@ -19,12 +18,12 @@ fn main() -> ! {
|
|||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config);
|
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config);
|
||||||
|
|
||||||
unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n"));
|
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||||
info!("wrote Hello, starting echo");
|
info!("wrote Hello, starting echo");
|
||||||
|
|
||||||
let mut buf = [0u8; 1];
|
let mut buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
unwrap!(usart.read_blocking(&mut buf));
|
unwrap!(usart.blocking_read(&mut buf));
|
||||||
unwrap!(usart.bwrite_all(&buf));
|
unwrap!(usart.blocking_write(&buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
|||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embassy_traits::uart::Write as _;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
use heapless::String;
|
use heapless::String;
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
|||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embedded_hal::blocking::serial::Write;
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
#[embassy::main(config = "config()")]
|
#[embassy::main(config = "config()")]
|
||||||
@ -42,10 +41,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
// This is because we aren't sending+receiving at the same time.
|
// This is because we aren't sending+receiving at the same time.
|
||||||
|
|
||||||
let data = [0xC0, 0xDE];
|
let data = [0xC0, 0xDE];
|
||||||
usart.bwrite_all(&data).unwrap();
|
usart.blocking_write(&data).unwrap();
|
||||||
|
|
||||||
let mut buf = [0; 2];
|
let mut buf = [0; 2];
|
||||||
usart.read_blocking(&mut buf).unwrap();
|
usart.blocking_read(&mut buf).unwrap();
|
||||||
assert_eq!(buf, data);
|
assert_eq!(buf, data);
|
||||||
|
|
||||||
info!("Test OK");
|
info!("Test OK");
|
||||||
|
@ -8,7 +8,6 @@ use defmt::assert_eq;
|
|||||||
use embassy::executor::Spawner;
|
use embassy::executor::Spawner;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use embassy_traits::uart::{Read, Write};
|
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
#[embassy::main(config = "config()")]
|
#[embassy::main(config = "config()")]
|
||||||
|
12
tests/stm32/teleprobe.sh
Executable file
12
tests/stm32/teleprobe.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
echo Running target=$1 elf=$2
|
||||||
|
STATUSCODE=$(
|
||||||
|
curl \
|
||||||
|
-sS \
|
||||||
|
--output /dev/stderr \
|
||||||
|
--write-out "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $TELEPROBE_TOKEN" \
|
||||||
|
https://teleprobe.embassy.dev/targets/$1/run --data-binary @$2
|
||||||
|
)
|
||||||
|
echo
|
||||||
|
echo HTTP Status code: $STATUSCODE
|
||||||
|
test "$STATUSCODE" -eq 200
|
Loading…
Reference in New Issue
Block a user