2021-12-08 05:43:39 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use defmt::assert_eq;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2021-12-08 05:43:39 +01:00
|
|
|
use embassy_stm32::dma::NoDma;
|
2022-10-26 18:58:22 +02:00
|
|
|
use embassy_stm32::interrupt;
|
2021-12-08 05:43:39 +01:00
|
|
|
use embassy_stm32::usart::{Config, Uart};
|
|
|
|
use example_common::*;
|
|
|
|
|
2022-08-17 18:49:55 +02:00
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_stm32::init(config());
|
2021-12-08 05:43:39 +01:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
// Arduino pins D0 and D1
|
|
|
|
// They're connected together with a 1K resistor.
|
2022-02-24 00:19:26 +01:00
|
|
|
#[cfg(feature = "stm32f103c8")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PA9, p.PA10, p.USART1, interrupt::take!(USART1));
|
2021-12-08 05:43:39 +01:00
|
|
|
#[cfg(feature = "stm32g491re")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1));
|
2021-12-08 05:43:39 +01:00
|
|
|
#[cfg(feature = "stm32g071rb")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1));
|
2021-12-08 05:43:39 +01:00
|
|
|
#[cfg(feature = "stm32f429zi")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PG14, p.PG9, p.USART6, interrupt::take!(USART6));
|
2021-12-08 05:43:39 +01:00
|
|
|
#[cfg(feature = "stm32wb55rg")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PA2, p.PA3, p.LPUART1, interrupt::take!(LPUART1));
|
2021-12-08 05:43:39 +01:00
|
|
|
#[cfg(feature = "stm32h755zi")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1));
|
2022-04-26 23:57:26 +02:00
|
|
|
#[cfg(feature = "stm32u585ai")]
|
2022-10-26 18:58:22 +02:00
|
|
|
let (tx, rx, usart, irq) = (p.PD8, p.PD9, p.USART3, interrupt::take!(USART3));
|
2023-04-10 15:12:47 +02:00
|
|
|
#[cfg(feature = "stm32h563zi")]
|
|
|
|
let (tx, rx, usart, irq) = (p.PB6, p.PB7, p.LPUART1, interrupt::take!(LPUART1));
|
2021-12-08 05:43:39 +01:00
|
|
|
|
|
|
|
let config = Config::default();
|
2022-10-26 18:58:22 +02:00
|
|
|
let mut usart = Uart::new(usart, rx, tx, irq, NoDma, NoDma, config);
|
2021-12-08 05:43:39 +01:00
|
|
|
|
|
|
|
// We can't send too many bytes, they have to fit in the FIFO.
|
|
|
|
// This is because we aren't sending+receiving at the same time.
|
|
|
|
|
|
|
|
let data = [0xC0, 0xDE];
|
2022-01-14 22:43:40 +01:00
|
|
|
usart.blocking_write(&data).unwrap();
|
2021-12-08 05:43:39 +01:00
|
|
|
|
|
|
|
let mut buf = [0; 2];
|
2022-01-14 22:43:40 +01:00
|
|
|
usart.blocking_read(&mut buf).unwrap();
|
2021-12-08 05:43:39 +01:00
|
|
|
assert_eq!(buf, data);
|
|
|
|
|
|
|
|
info!("Test OK");
|
|
|
|
cortex_m::asm::bkpt();
|
|
|
|
}
|