From 009e1896bfe457e1b15156a2624284b385a53e27 Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 30 Mar 2021 10:05:52 -0500 Subject: stm32: consolidate crates --- .github/workflows/rust.yml | 12 +- embassy-stm32-examples/.cargo/config | 28 ++ embassy-stm32-examples/Cargo.toml | 54 ++++ embassy-stm32-examples/build.rs | 31 +++ embassy-stm32-examples/memory.x | 5 + embassy-stm32-examples/src/bin/can.rs | 57 ++++ embassy-stm32-examples/src/bin/exti.rs | 58 ++++ embassy-stm32-examples/src/bin/hello.rs | 42 +++ embassy-stm32-examples/src/bin/rtc_async.rs | 39 +++ embassy-stm32-examples/src/bin/serial.rs | 79 ++++++ embassy-stm32-examples/src/bin/usb_serial.rs | 117 ++++++++ embassy-stm32-examples/src/example_common.rs | 17 ++ embassy-stm32/Cargo.toml | 3 +- embassy-stm32/src/f4/mod.rs | 2 + embassy-stm32/src/f4/qei.rs | 91 +++++++ embassy-stm32/src/f4/serial.rs | 364 +++++++++++++++++++++++++ embassy-stm32/src/lib.rs | 40 ++- embassy-stm32f4-examples/.cargo/config | 28 -- embassy-stm32f4-examples/Cargo.toml | 55 ---- embassy-stm32f4-examples/build.rs | 31 --- embassy-stm32f4-examples/memory.x | 5 - embassy-stm32f4-examples/src/bin/can.rs | 57 ---- embassy-stm32f4-examples/src/bin/exti.rs | 58 ---- embassy-stm32f4-examples/src/bin/hello.rs | 42 --- embassy-stm32f4-examples/src/bin/rtc_async.rs | 39 --- embassy-stm32f4-examples/src/bin/serial.rs | 79 ------ embassy-stm32f4-examples/src/bin/usb_serial.rs | 117 -------- embassy-stm32f4-examples/src/example_common.rs | 17 -- embassy-stm32f4/Cargo.toml | 45 --- embassy-stm32f4/src/lib.rs | 317 --------------------- embassy-stm32f4/src/qei.rs | 91 ------- embassy-stm32f4/src/serial.rs | 364 ------------------------- embassy-stm32l0/Cargo.toml | 28 -- embassy-stm32l0/src/lib.rs | 22 -- embassy/src/util/signal.rs | 2 +- 35 files changed, 1031 insertions(+), 1405 deletions(-) create mode 100644 embassy-stm32-examples/.cargo/config create mode 100644 embassy-stm32-examples/Cargo.toml create mode 100644 embassy-stm32-examples/build.rs create mode 100644 embassy-stm32-examples/memory.x create mode 100644 embassy-stm32-examples/src/bin/can.rs create mode 100644 embassy-stm32-examples/src/bin/exti.rs create mode 100644 embassy-stm32-examples/src/bin/hello.rs create mode 100644 embassy-stm32-examples/src/bin/rtc_async.rs create mode 100644 embassy-stm32-examples/src/bin/serial.rs create mode 100644 embassy-stm32-examples/src/bin/usb_serial.rs create mode 100644 embassy-stm32-examples/src/example_common.rs create mode 100644 embassy-stm32/src/f4/mod.rs create mode 100644 embassy-stm32/src/f4/qei.rs create mode 100644 embassy-stm32/src/f4/serial.rs delete mode 100644 embassy-stm32f4-examples/.cargo/config delete mode 100644 embassy-stm32f4-examples/Cargo.toml delete mode 100644 embassy-stm32f4-examples/build.rs delete mode 100644 embassy-stm32f4-examples/memory.x delete mode 100644 embassy-stm32f4-examples/src/bin/can.rs delete mode 100644 embassy-stm32f4-examples/src/bin/exti.rs delete mode 100644 embassy-stm32f4-examples/src/bin/hello.rs delete mode 100644 embassy-stm32f4-examples/src/bin/rtc_async.rs delete mode 100644 embassy-stm32f4-examples/src/bin/serial.rs delete mode 100644 embassy-stm32f4-examples/src/bin/usb_serial.rs delete mode 100644 embassy-stm32f4-examples/src/example_common.rs delete mode 100644 embassy-stm32f4/Cargo.toml delete mode 100644 embassy-stm32f4/src/lib.rs delete mode 100644 embassy-stm32f4/src/qei.rs delete mode 100644 embassy-stm32f4/src/serial.rs delete mode 100644 embassy-stm32l0/Cargo.toml delete mode 100644 embassy-stm32l0/src/lib.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7b04a9947..d7b427e04 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,22 +46,22 @@ jobs: - package: embassy-nrf target: thumbv7em-none-eabi features: 52840,defmt - - package: embassy-stm32f4-examples + - package: embassy-stm32-examples target: thumbv7em-none-eabi features: stm32f405 - - package: embassy-stm32f4 + - package: embassy-stm32 target: thumbv7em-none-eabi features: stm32f405 - - package: embassy-stm32f4 + - package: embassy-stm32 target: thumbv7em-none-eabi features: stm32f446 - - package: embassy-stm32f4 + - package: embassy-stm32 target: thumbv7em-none-eabi features: stm32f405,defmt - - package: embassy-stm32l0 + - package: embassy-stm32 target: thumbv6m-none-eabi features: stm32l0x2 - - package: embassy-stm32l0 + - package: embassy-stm32 target: thumbv6m-none-eabi features: stm32l0x2,defmt - package: embassy-rp-examples diff --git a/embassy-stm32-examples/.cargo/config b/embassy-stm32-examples/.cargo/config new file mode 100644 index 000000000..7c1d4dfb6 --- /dev/null +++ b/embassy-stm32-examples/.cargo/config @@ -0,0 +1,28 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +runner = "probe-run --chip STM32F401CCUx" + +rustflags = [ + # LLD (shipped with the Rust toolchain) is used as the default linker + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tdefmt.x", + + # if you run into problems with LLD switch to the GNU linker by commenting out + # this line + # "-C", "linker=arm-none-eabi-ld", + + # if you need to link to pre-compiled C libraries provided by a C toolchain + # use GCC as the linker by commenting out both lines above and then + # uncommenting the three lines below + # "-C", "linker=arm-none-eabi-gcc", + # "-C", "link-arg=-Wl,-Tlink.x", + # "-C", "link-arg=-nostartfiles", + + # Code-size optimizations. + "-Z", "trap-unreachable=no", + "-C", "inline-threshold=5", + "-C", "no-vectorize-loops", +] + +[build] +target = "thumbv7em-none-eabihf" diff --git a/embassy-stm32-examples/Cargo.toml b/embassy-stm32-examples/Cargo.toml new file mode 100644 index 000000000..52446db32 --- /dev/null +++ b/embassy-stm32-examples/Cargo.toml @@ -0,0 +1,54 @@ +[package] +authors = ["Dario Nieuwenhuis "] +edition = "2018" +name = "embassy-stm32f4-examples" +version = "0.1.0" + +[features] +default = [ + "defmt-default", +] +defmt-default = [] +defmt-trace = [] +defmt-debug = [] +defmt-info = [] +defmt-warn = [] +defmt-error = [] + +stm32f401 = ["stm32f4xx-hal/stm32f401", "embassy-stm32/stm32f401"] +stm32f405 = ["stm32f4xx-hal/stm32f405", "embassy-stm32/stm32f405"] +stm32f407 = ["stm32f4xx-hal/stm32f407", "embassy-stm32/stm32f407"] +stm32f410 = ["stm32f4xx-hal/stm32f410", "embassy-stm32/stm32f410"] +stm32f411 = ["stm32f4xx-hal/stm32f411", "embassy-stm32/stm32f411"] +stm32f412 = ["stm32f4xx-hal/stm32f412", "embassy-stm32/stm32f412"] +stm32f413 = ["stm32f4xx-hal/stm32f413", "embassy-stm32/stm32f413"] +stm32f415 = ["stm32f4xx-hal/stm32f405", "embassy-stm32/stm32f405"] +stm32f417 = ["stm32f4xx-hal/stm32f407", "embassy-stm32/stm32f407"] +stm32f423 = ["stm32f4xx-hal/stm32f413", "embassy-stm32/stm32f413"] +stm32f427 = ["stm32f4xx-hal/stm32f427", "embassy-stm32/stm32f427"] +stm32f429 = ["stm32f4xx-hal/stm32f429", "embassy-stm32/stm32f429"] +stm32f437 = ["stm32f4xx-hal/stm32f427", "embassy-stm32/stm32f427"] +stm32f439 = ["stm32f4xx-hal/stm32f429", "embassy-stm32/stm32f429"] +stm32f446 = ["stm32f4xx-hal/stm32f446", "embassy-stm32/stm32f446"] +stm32f469 = ["stm32f4xx-hal/stm32f469", "embassy-stm32/stm32f469"] +stm32f479 = ["stm32f4xx-hal/stm32f469", "embassy-stm32/stm32f469"] + + +[dependencies] +embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } +embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } +embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32" } +embassy-extras = {version = "0.1.0", path = "../embassy-extras" } + +defmt = "0.2.0" +defmt-rtt = "0.2.0" + +cortex-m = "0.7.1" +cortex-m-rt = "0.6.13" +embedded-hal = { version = "0.2.4" } +panic-probe = "0.1.0" +stm32f4xx-hal = { version = "0.8.3", features = ["rt", "usb_fs"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"} +futures = { version = "0.3.8", default-features = false, features = ["async-await"] } +rtt-target = { version = "0.3", features = ["cortex-m"] } +bxcan = "0.5.0" +usb-device = "0.2.7" diff --git a/embassy-stm32-examples/build.rs b/embassy-stm32-examples/build.rs new file mode 100644 index 000000000..d534cc3df --- /dev/null +++ b/embassy-stm32-examples/build.rs @@ -0,0 +1,31 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/embassy-stm32-examples/memory.x b/embassy-stm32-examples/memory.x new file mode 100644 index 000000000..efa700b8a --- /dev/null +++ b/embassy-stm32-examples/memory.x @@ -0,0 +1,5 @@ +MEMORY +{ + FLASH : ORIGIN = 0x08000000, LENGTH = 64K + RAM : ORIGIN = 0x20000000, LENGTH = 32K +} diff --git a/embassy-stm32-examples/src/bin/can.rs b/embassy-stm32-examples/src/bin/can.rs new file mode 100644 index 000000000..4923d399d --- /dev/null +++ b/embassy-stm32-examples/src/bin/can.rs @@ -0,0 +1,57 @@ +#![no_std] +#![no_main] +#![feature(trait_alias)] +#![feature(type_alias_impl_trait)] +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::{panic, *}; + +use bxcan::filter::Mask32; +use cortex_m_rt::entry; +use embassy::executor::Executor; +use embassy::util::Forever; +use embassy_stm32::{can, interrupt}; +use stm32f4xx_hal::prelude::*; +use stm32f4xx_hal::{can::Can, stm32}; + +#[embassy::task] +async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { + let gpioa = dp.GPIOA.split(); + + let rx = gpioa.pa11.into_alternate_af9(); + let tx = gpioa.pa12.into_alternate_af9(); + let mut can = bxcan::Can::new(Can::new(dp.CAN1, (tx, rx))); + + // APB1 (PCLK1): 24MHz, Bit rate: 20kBit/s, Sample Point 87.5% + // Value was calculated with http://www.bittiming.can-wiki.info/ + can.modify_config().set_bit_timing(0x001c_004a); + // Configure filters so that can frames can be received. + can.modify_filters().enable_bank(0, Mask32::accept_all()); + + let mut can = can::Can::new(can, interrupt::take!(CAN1_TX), interrupt::take!(CAN1_RX0)); + + let _frame = can.receive().await; +} + +static EXECUTOR: Forever = Forever::new(); + +#[entry] +fn main() -> ! { + let dp = stm32::Peripherals::take().unwrap(); + let cp = cortex_m::peripheral::Peripherals::take().unwrap(); + + dp.DBGMCU.cr.modify(|_, w| { + w.dbg_sleep().set_bit(); + w.dbg_standby().set_bit(); + w.dbg_stop().set_bit() + }); + dp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); + + let executor = EXECUTOR.put(Executor::new()); + executor.run(|spawner| { + unwrap!(spawner.spawn(run(dp, cp))); + }); +} diff --git a/embassy-stm32-examples/src/bin/exti.rs b/embassy-stm32-examples/src/bin/exti.rs new file mode 100644 index 000000000..6c08e6898 --- /dev/null +++ b/embassy-stm32-examples/src/bin/exti.rs @@ -0,0 +1,58 @@ +#![no_std] +#![no_main] +#![feature(trait_alias)] +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::{panic, *}; + +use cortex_m_rt::entry; +use embassy::executor::Executor; +use embassy::traits::gpio::*; +use embassy::util::Forever; +use embassy_stm32::exti::ExtiPin; +use embassy_stm32::interrupt; +use futures::pin_mut; +use stm32f4xx_hal::prelude::*; +use stm32f4xx_hal::stm32; + +#[embassy::task] +async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { + let gpioa = dp.GPIOA.split(); + + let button = gpioa.pa0.into_pull_up_input(); + let mut syscfg = dp.SYSCFG.constrain(); + + let pin = ExtiPin::new(button, interrupt::take!(EXTI0), &mut syscfg); + pin_mut!(pin); + + info!("Starting loop"); + + loop { + pin.as_mut().wait_for_rising_edge().await; + info!("edge detected!"); + } +} + +static EXECUTOR: Forever = Forever::new(); + +#[entry] +fn main() -> ! { + let dp = stm32::Peripherals::take().unwrap(); + let cp = cortex_m::peripheral::Peripherals::take().unwrap(); + + dp.DBGMCU.cr.modify(|_, w| { + w.dbg_sleep().set_bit(); + w.dbg_standby().set_bit(); + w.dbg_stop().set_bit() + }); + dp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); + + let executor = EXECUTOR.put(Executor::new()); + executor.run(|spawner| { + unwrap!(spawner.spawn(run(dp, cp))); + }); +} diff --git a/embassy-stm32-examples/src/bin/hello.rs b/embassy-stm32-examples/src/bin/hello.rs new file mode 100644 index 000000000..8a6654146 --- /dev/null +++ b/embassy-stm32-examples/src/bin/hello.rs @@ -0,0 +1,42 @@ +#![no_std] +#![no_main] +#![feature(trait_alias)] +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::*; + +use cortex_m_rt::entry; +use stm32f4xx_hal::prelude::*; + +#[entry] +fn main() -> ! { + info!("Hello World!"); + + let p = stm32f4xx_hal::stm32::Peripherals::take().unwrap(); + + p.DBGMCU.cr.modify(|_, w| { + w.dbg_sleep().set_bit(); + w.dbg_standby().set_bit(); + w.dbg_stop().set_bit() + }); + p.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); + + let gpioa = p.GPIOA.split(); + let gpioc = p.GPIOC.split(); + + let mut led = gpioc.pc13.into_push_pull_output(); + let button = gpioa.pa0.into_pull_up_input(); + led.set_low().unwrap(); + + loop { + if button.is_high().unwrap() { + led.set_low().unwrap(); + } else { + led.set_high().unwrap(); + } + } +} diff --git a/embassy-stm32-examples/src/bin/rtc_async.rs b/embassy-stm32-examples/src/bin/rtc_async.rs new file mode 100644 index 000000000..ea54a2a94 --- /dev/null +++ b/embassy-stm32-examples/src/bin/rtc_async.rs @@ -0,0 +1,39 @@ +#![no_std] +#![no_main] +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::*; + +use defmt::panic; +use embassy; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32; +use embassy_stm32::hal; + +#[embassy::task] +async fn run1() { + loop { + info!("BIG INFREQUENT TICK"); + Timer::after(Duration::from_ticks(32768 * 2 as u64)).await; + } +} + +#[embassy::task] +async fn run2() { + loop { + info!("tick"); + Timer::after(Duration::from_ticks(13000 as u64)).await; + } +} + +#[embassy::main(use_hse = 16)] +async fn main(spawner: Spawner) { + let (dp, clocks) = embassy_stm32::Peripherals::take().unwrap(); + + spawner.spawn(run1()).unwrap(); +} diff --git a/embassy-stm32-examples/src/bin/serial.rs b/embassy-stm32-examples/src/bin/serial.rs new file mode 100644 index 000000000..c10f74a36 --- /dev/null +++ b/embassy-stm32-examples/src/bin/serial.rs @@ -0,0 +1,79 @@ +#![no_std] +#![no_main] +#![feature(trait_alias)] +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::{panic, *}; + +use cortex_m::singleton; +use cortex_m_rt::entry; +use embassy::executor::{Executor, Spawner}; +use embassy::traits::uart::{Read, Write}; +use embassy::util::Forever; +use embassy_stm32::interrupt; +use embassy_stm32::serial; +use futures::pin_mut; +use stm32f4xx_hal::dma::StreamsTuple; +use stm32f4xx_hal::prelude::*; +use stm32f4xx_hal::serial::config::Config; +use stm32f4xx_hal::stm32; + +#[embassy::main(use_hse = 16, sysclk = 48, pclk1 = 24)] +async fn main(spawner: Spawner) { + let (dp, clocks) = embassy_stm32::Peripherals::take().unwrap(); + let cp = cortex_m::peripheral::Peripherals::take().unwrap(); + + dp.DBGMCU.cr.modify(|_, w| { + w.dbg_sleep().set_bit(); + w.dbg_standby().set_bit(); + w.dbg_stop().set_bit() + }); + + // https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1 + let gpioa = dp.GPIOA.split(); + let streams = StreamsTuple::new(dp.DMA2); + + let _serial = unsafe { + serial::Serial::new( + dp.USART1, + (streams.7, streams.2), + ( + gpioa.pa9.into_alternate_af7(), + gpioa.pa10.into_alternate_af7(), + ), + interrupt::take!(DMA2_STREAM7), + interrupt::take!(DMA2_STREAM2), + interrupt::take!(USART1), + Config::default().baudrate(9600.bps()), + clocks, + ) + }; + + let streams = StreamsTuple::new(dp.DMA1); + + let mut serial = unsafe { + serial::Serial::new( + dp.USART2, + (streams.6, streams.5), + ( + gpioa.pa2.into_alternate_af7(), + gpioa.pa3.into_alternate_af7(), + ), + interrupt::take!(DMA1_STREAM6), + interrupt::take!(DMA1_STREAM5), + interrupt::take!(USART2), + Config::default().baudrate(9600.bps()), + clocks, + ) + }; + pin_mut!(serial); + + let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); + + buf[5] = 0x01; + serial.write(buf).await.unwrap(); +} diff --git a/embassy-stm32-examples/src/bin/usb_serial.rs b/embassy-stm32-examples/src/bin/usb_serial.rs new file mode 100644 index 000000000..7e95f1221 --- /dev/null +++ b/embassy-stm32-examples/src/bin/usb_serial.rs @@ -0,0 +1,117 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] + +#[path = "../example_common.rs"] +mod example_common; +use example_common::*; + +use cortex_m_rt::entry; +use defmt::panic; +use embassy::executor::{Executor, Spawner}; +use embassy::interrupt::InterruptExt; +use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; +use embassy::time::{Duration, Timer}; +use embassy::util::Forever; +use embassy_extras::usb::usb_serial::UsbSerial; +use embassy_extras::usb::Usb; +use embassy_stm32::{interrupt, pac, rtc}; +use futures::future::{select, Either}; +use futures::pin_mut; +use stm32f4xx_hal::otg_fs::{UsbBus, USB}; +use stm32f4xx_hal::prelude::*; +use usb_device::bus::UsbBusAllocator; +use usb_device::prelude::*; + +#[embassy::task] +async fn run1(bus: &'static mut UsbBusAllocator>) { + info!("Async task"); + + let mut read_buf = [0u8; 128]; + let mut write_buf = [0u8; 128]; + let serial = UsbSerial::new(bus, &mut read_buf, &mut write_buf); + + let device = UsbDeviceBuilder::new(bus, UsbVidPid(0x16c0, 0x27dd)) + .manufacturer("Fake company") + .product("Serial port") + .serial_number("TEST") + .device_class(0x02) + .build(); + + let irq = interrupt::take!(OTG_FS); + irq.set_priority(interrupt::Priority::Level3); + + let usb = Usb::new(device, serial, irq); + pin_mut!(usb); + usb.as_mut().start(); + + let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0(); + + let mut buf = [0u8; 64]; + loop { + let mut n = 0; + let left = { + let recv_fut = async { + loop { + let byte = unwrap!(read_interface.read_byte().await); + unwrap!(write_interface.write_byte(byte).await); + buf[n] = byte; + + n += 1; + if byte == b'\n' || byte == b'\r' || n == buf.len() { + break; + } + } + }; + pin_mut!(recv_fut); + + let timeout = Timer::after(Duration::from_ticks(32768 * 10)); + + match select(recv_fut, timeout).await { + Either::Left(_) => true, + Either::Right(_) => false, + } + }; + + if left { + for c in buf[..n].iter_mut() { + if 0x61 <= *c && *c <= 0x7a { + *c &= !0x20; + } + } + unwrap!(write_interface.write_byte(b'\n').await); + unwrap!(write_interface.write_all(&buf[..n]).await); + unwrap!(write_interface.write_byte(b'\n').await); + } else { + unwrap!(write_interface.write_all(b"\r\nSend something\r\n").await); + } + } +} + +static USB_BUS: Forever>> = Forever::new(); + +#[embassy::main(use_hse = 25, sysclk = 48, require_pll48clk)] +async fn main(spawner: Spawner) -> ! { + static mut EP_MEMORY: [u32; 1024] = [0; 1024]; + + info!("Hello World!"); + + let (p, clocks) = embassy_stm32::Peripherals::take().unwrap(); + + let gpioa = p.GPIOA.split(); + let usb = USB { + usb_global: p.OTG_FS_GLOBAL, + usb_device: p.OTG_FS_DEVICE, + usb_pwrclk: p.OTG_FS_PWRCLK, + pin_dm: gpioa.pa11.into_alternate_af10(), + pin_dp: gpioa.pa12.into_alternate_af10(), + hclk: clocks.hclk(), + }; + // Rust analyzer isn't recognizing the static ref magic `cortex-m` does + #[allow(unused_unsafe)] + let usb_bus = USB_BUS.put(UsbBus::new(usb, unsafe { &mut EP_MEMORY })); + + spawner.spawn(run1(usb_bus)).unwrap(); +} diff --git a/embassy-stm32-examples/src/example_common.rs b/embassy-stm32-examples/src/example_common.rs new file mode 100644 index 000000000..54d633837 --- /dev/null +++ b/embassy-stm32-examples/src/example_common.rs @@ -0,0 +1,17 @@ +#![macro_use] + +use defmt_rtt as _; // global logger +use panic_probe as _; + +pub use defmt::*; + +use core::sync::atomic::{AtomicUsize, Ordering}; + +defmt::timestamp! {"{=u64}", { + static COUNT: AtomicUsize = AtomicUsize::new(0); + // NOTE(no-CAS) `timestamps` runs with interrupts disabled + let n = COUNT.load(Ordering::Relaxed); + COUNT.store(n + 1, Ordering::Relaxed); + n as u64 + } +} diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 28d9e7fe3..237eaa014 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -47,4 +47,5 @@ embedded-dma = { version = "0.1.2" } bxcan = "0.5.0" nb = "*" stm32f4xx-hal = { version = "0.8.3", features = ["rt", "can"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git", optional = true } -stm32l0xx-hal = { version = "0.7.0", features = ["rt"], optional = true } \ No newline at end of file +stm32l0xx-hal = { version = "0.7.0", features = ["rt"], optional = true } +futures = { version = "0.3.5", default-features = false, features = ["async-await"] } \ No newline at end of file diff --git a/embassy-stm32/src/f4/mod.rs b/embassy-stm32/src/f4/mod.rs new file mode 100644 index 000000000..a80d640dc --- /dev/null +++ b/embassy-stm32/src/f4/mod.rs @@ -0,0 +1,2 @@ +pub mod qei; +pub mod serial; diff --git a/embassy-stm32/src/f4/qei.rs b/embassy-stm32/src/f4/qei.rs new file mode 100644 index 000000000..5973e62d9 --- /dev/null +++ b/embassy-stm32/src/f4/qei.rs @@ -0,0 +1,91 @@ +use crate::interrupt; +use core::future::Future; +use core::pin::Pin; +use embassy::traits::qei::WaitForRotate; +use embedded_hal::Direction; +use stm32f4xx_hal::pac::TIM2; +use stm32f4xx_hal::{qei, qei::Pins}; + +pub struct Qei { + _qei: qei::Qei, + int: T::Interrupt, +} + +impl> Qei { + pub fn tim2(tim: TIM2, pins: PINS, interrupt: interrupt::TIM2) -> Self { + let qei = qei::Qei::tim2(tim, pins); + + let tim = unsafe { + &mut *(stm32f4xx_hal::stm32::TIM2::ptr() + as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) + }; + /* + enable qei interrupt + */ + tim.dier.write(|w| w.uie().set_bit()); + + Qei { + _qei: qei, + int: interrupt, + } + } +} + +impl + 'static> WaitForRotate for Qei { + type RotateFuture<'a> = impl Future + 'a; + + fn wait_for_rotate<'a>( + self: Pin<&'a mut Self>, + count_down: u16, + count_up: u16, + ) -> Self::RotateFuture<'a> { + let s = unsafe { self.get_unchecked_mut() }; + + let tim = unsafe { + &mut *(stm32f4xx_hal::stm32::TIM2::ptr() + as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) + }; + + /* + the interrupt will be reached at zero or the max count + write the total range to the qei. + */ + tim.arr + .write(|w| unsafe { w.bits((count_down + count_up) as u32) }); + + /* + set timer to the correct value in the range + */ + tim.cnt.write(|w| unsafe { w.bits(count_down as u32) }); + + /* + clear interrupt flag + */ + tim.sr.write(|w| w.uif().clear_bit()); + + async move { + embassy::util::InterruptFuture::new(&mut s.int).await; + + if tim.cnt.read().bits() == 0 { + Direction::Downcounting + } else if tim.cnt.read() == count_down + count_up { + Direction::Upcounting + } else { + panic!("unexpected value") + } + } + } +} + +mod sealed { + pub trait Sealed {} +} + +pub trait Instance: sealed::Sealed { + type Interrupt: interrupt::Interrupt; +} + +impl sealed::Sealed for TIM2 {} +impl Instance for TIM2 { + type Interrupt = interrupt::TIM2; +} diff --git a/embassy-stm32/src/f4/serial.rs b/embassy-stm32/src/f4/serial.rs new file mode 100644 index 000000000..7539abf51 --- /dev/null +++ b/embassy-stm32/src/f4/serial.rs @@ -0,0 +1,364 @@ +//! Async Serial. + +use core::future::Future; +use core::marker::PhantomData; +use core::pin::Pin; +use embassy::interrupt::Interrupt; +use embassy::traits::uart::{Error, Read, ReadUntilIdle, Write}; +use embassy::util::InterruptFuture; +use futures::{select_biased, FutureExt}; + +use crate::hal::{ + dma, + dma::config::DmaConfig, + dma::traits::{Channel, DMASet, PeriAddress, Stream}, + dma::{MemoryToPeripheral, PeripheralToMemory, Transfer}, + rcc::Clocks, + serial, + serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig}, + serial::{Event as SerialEvent, Pins}, +}; +use crate::interrupt; +use crate::pac; + +/// Interface to the Serial peripheral +pub struct Serial< + USART: PeriAddress + WithInterrupt, + TSTREAM: Stream + WithInterrupt, + RSTREAM: Stream + WithInterrupt, + CHANNEL: Channel, +> { + tx_stream: Option, + rx_stream: Option, + usart: Option, + tx_int: TSTREAM::Interrupt, + rx_int: RSTREAM::Interrupt, + usart_int: USART::Interrupt, + channel: PhantomData, +} + +// static mut INSTANCE: *const Serial, Stream2> = ptr::null_mut(); + +impl Serial +where + USART: serial::Instance + + PeriAddress + + DMASet + + DMASet + + WithInterrupt, + TSTREAM: Stream + WithInterrupt, + RSTREAM: Stream + WithInterrupt, + CHANNEL: Channel, +{ + // Leaking futures is forbidden! + pub unsafe fn new( + usart: USART, + streams: (TSTREAM, RSTREAM), + pins: PINS, + tx_int: TSTREAM::Interrupt, + rx_int: RSTREAM::Interrupt, + usart_int: USART::Interrupt, + mut config: SerialConfig, + clocks: Clocks, + ) -> Self + where + PINS: Pins, + { + config.dma = SerialDmaConfig::TxRx; + + let (usart, _) = serial::Serial::new(usart, pins, config, clocks) + .unwrap() + .release(); + + let (tx_stream, rx_stream) = streams; + + Serial { + tx_stream: Some(tx_stream), + rx_stream: Some(rx_stream), + usart: Some(usart), + tx_int: tx_int, + rx_int: rx_int, + usart_int: usart_int, + channel: PhantomData, + } + } +} + +impl Read for Serial +where + USART: serial::Instance + + PeriAddress + + DMASet + + DMASet + + WithInterrupt + + 'static, + TSTREAM: Stream + WithInterrupt + 'static, + RSTREAM: Stream + WithInterrupt + 'static, + CHANNEL: Channel + 'static, +{ + type ReadFuture<'a> = impl Future> + 'a; + + /// Receives serial data. + /// + /// The future is pending until the buffer is completely filled. + fn read<'a>(self: Pin<&'a mut Self>, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { + let this = unsafe { self.get_unchecked_mut() }; + let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) }; + + async move { + let rx_stream = this.rx_stream.take().unwrap(); + let usart = this.usart.take().unwrap(); + + let mut rx_transfer = Transfer::init( + rx_stream, + usart, + static_buf, + None, + DmaConfig::default() + .transfer_complete_interrupt(true) + .memory_increment(true) + .double_buffer(false), + ); + + let fut = InterruptFuture::new(&mut this.rx_int); + rx_transfer.start(|_usart| {}); + fut.await; + + let (rx_stream, usart, _, _) = rx_transfer.free(); + this.rx_stream.replace(rx_stream); + this.usart.replace(usart); + + Ok(()) + } + } +} + +impl Write for Serial +where + USART: serial::Instance + + PeriAddress + + DMASet + + DMASet + + WithInterrupt + + 'static, + TSTREAM: Stream + WithInterrupt + 'static, + RSTREAM: Stream + WithInterrupt + 'static, + CHANNEL: Channel + 'static, +{ + type WriteFuture<'a> = impl Future> + 'a; + + /// Sends serial data. + fn write<'a>(self: Pin<&'a mut Self>, buf: &'a [u8]) -> Self::WriteFuture<'a> { + let this = unsafe { self.get_unchecked_mut() }; + #[allow(mutable_transmutes)] + let static_buf = unsafe { core::mem::transmute::<&'a [u8], &'static mut [u8]>(buf) }; + + async move { + let tx_stream = this.tx_stream.take().unwrap(); + let usart = this.usart.take().unwrap(); + + let mut tx_transfer = Transfer::init( + tx_stream, + usart, + static_buf, + None, + DmaConfig::default() + .transfer_complete_interrupt(true) + .memory_increment(true) + .double_buffer(false), + ); + + let fut = InterruptFuture::new(&mut this.tx_int); + + tx_transfer.start(|_usart| {}); + fut.await; + + let (tx_stream, usart, _buf, _) = tx_transfer.free(); + + this.tx_stream.replace(tx_stream); + this.usart.replace(usart); + + Ok(()) + } + } +} + +impl ReadUntilIdle for Serial +where + USART: serial::Instance + + PeriAddress + + DMASet + + DMASet + + WithInterrupt + + 'static, + TSTREAM: Stream + WithInterrupt + 'static, + RSTREAM: Stream + WithInterrupt + 'static, + CHANNEL: Channel + 'static, +{ + type ReadUntilIdleFuture<'a> = impl Future> + 'a; + + /// Receives serial data. + /// + /// The future is pending until either the buffer is completely full, or the RX line falls idle after receiving some data. + /// + /// Returns the number of bytes read. + fn read_until_idle<'a>( + self: Pin<&'a mut Self>, + buf: &'a mut [u8], + ) -> Self::ReadUntilIdleFuture<'a> { + let this = unsafe { self.get_unchecked_mut() }; + let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) }; + + async move { + let rx_stream = this.rx_stream.take().unwrap(); + let usart = this.usart.take().unwrap(); + + unsafe { + /* __HAL_UART_ENABLE_IT(&uart->UartHandle, UART_IT_IDLE); */ + (*USART::ptr()).cr1.modify(|_, w| w.idleie().set_bit()); + + /* __HAL_UART_CLEAR_IDLEFLAG(&uart->UartHandle); */ + (*USART::ptr()).sr.read(); + (*USART::ptr()).dr.read(); + }; + + let mut rx_transfer = Transfer::init( + rx_stream, + usart, + static_buf, + None, + DmaConfig::default() + .transfer_complete_interrupt(true) + .memory_increment(true) + .double_buffer(false), + ); + + let total_bytes = RSTREAM::get_number_of_transfers() as usize; + + let fut = InterruptFuture::new(&mut this.rx_int); + let fut_idle = InterruptFuture::new(&mut this.usart_int); + + rx_transfer.start(|_usart| {}); + + futures::future::select(fut, fut_idle).await; + + let (rx_stream, usart, _, _) = rx_transfer.free(); + + let remaining_bytes = RSTREAM::get_number_of_transfers() as usize; + + unsafe { + (*USART::ptr()).cr1.modify(|_, w| w.idleie().clear_bit()); + } + this.rx_stream.replace(rx_stream); + this.usart.replace(usart); + + Ok(total_bytes - remaining_bytes) + } + } +} + +mod private { + pub trait Sealed {} +} + +pub trait WithInterrupt: private::Sealed { + type Interrupt: Interrupt; +} + +macro_rules! dma { + ($($PER:ident => ($dma:ident, $stream:ident),)+) => { + $( + impl private::Sealed for dma::$stream {} + impl WithInterrupt for dma::$stream { + type Interrupt = interrupt::$PER; + } + )+ + } + } + +macro_rules! usart { + ($($PER:ident => ($usart:ident),)+) => { + $( + impl private::Sealed for pac::$usart {} + impl WithInterrupt for pac::$usart { + type Interrupt = interrupt::$PER; + } + )+ + } +} + +dma! { + DMA2_STREAM0 => (DMA2, Stream0), + DMA2_STREAM1 => (DMA2, Stream1), + DMA2_STREAM2 => (DMA2, Stream2), + DMA2_STREAM3 => (DMA2, Stream3), + DMA2_STREAM4 => (DMA2, Stream4), + DMA2_STREAM5 => (DMA2, Stream5), + DMA2_STREAM6 => (DMA2, Stream6), + DMA2_STREAM7 => (DMA2, Stream7), + DMA1_STREAM0 => (DMA1, Stream0), + DMA1_STREAM1 => (DMA1, Stream1), + DMA1_STREAM2 => (DMA1, Stream2), + DMA1_STREAM3 => (DMA1, Stream3), + DMA1_STREAM4 => (DMA1, Stream4), + DMA1_STREAM5 => (DMA1, Stream5), + DMA1_STREAM6 => (DMA1, Stream6), +} + +#[cfg(any(feature = "stm32f401", feature = "stm32f410", feature = "stm32f411",))] +usart! { + USART1 => (USART1), + USART2 => (USART2), + USART6 => (USART6), +} + +#[cfg(any(feature = "stm32f405", feature = "stm32f407"))] +usart! { + USART1 => (USART1), + USART2 => (USART2), + USART3 => (USART3), + USART6 => (USART6), + + UART4 => (UART4), + UART5 => (UART5), +} + +#[cfg(feature = "stm32f412")] +usart! { + USART1 => (USART1), + USART2 => (USART2), + USART3 => (USART3), + USART6 => (USART6), +} + +#[cfg(feature = "stm32f413")] +usart! { + USART1 => (USART1), + USART2 => (USART2), + USART3 => (USART3), + USART6 => (USART6), + USART7 => (USART7), + USART8 => (USART8), + + UART5 => (UART5), + UART9 => (UART9), + UART10 => (UART10), +} + +#[cfg(any( + feature = "stm32f427", + feature = "stm32f429", + feature = "stm32f446", + feature = "stm32f469" +))] +usart! { + USART1 => (USART1), + USART2 => (USART2), + USART3 => (USART3), + USART6 => (USART6), + + UART4 => (UART4), + UART5 => (UART5), +// UART7 => (UART7), +// UART8 => (UART8), +} diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 3cef287c3..a60c3192b 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -25,6 +25,25 @@ feature = "stm32f469", feature = "stm32f479", ))] +mod f4; + +#[cfg(any( + feature = "stm32f401", + feature = "stm32f405", + feature = "stm32f407", + feature = "stm32f412", + feature = "stm32f413", + feature = "stm32f415", + feature = "stm32f417", + feature = "stm32f423", + feature = "stm32f427", + feature = "stm32f429", + feature = "stm32f437", + feature = "stm32f439", + feature = "stm32f446", + feature = "stm32f469", + feature = "stm32f479", +))] pub use {stm32f4xx_hal as hal, stm32f4xx_hal::stm32 as pac}; #[cfg(any(feature = "stm32l0x1", feature = "stm32l0x2", feature = "stm32l0x3",))] @@ -58,8 +77,6 @@ pub mod can; feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", - feature = "stm32f410", - feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", @@ -75,6 +92,25 @@ pub mod can; ))] pub mod rtc; +#[cfg(any( + feature = "stm32f401", + feature = "stm32f405", + feature = "stm32f407", + feature = "stm32f412", + feature = "stm32f413", + feature = "stm32f415", + feature = "stm32f417", + feature = "stm32f423", + feature = "stm32f427", + feature = "stm32f429", + feature = "stm32f437", + feature = "stm32f439", + feature = "stm32f446", + feature = "stm32f469", + feature = "stm32f479", +))] +pub use f4::{qei, serial}; + #[cfg(any( feature = "stm32f401", feature = "stm32f405", diff --git a/embassy-stm32f4-examples/.cargo/config b/embassy-stm32f4-examples/.cargo/config deleted file mode 100644 index 7c1d4dfb6..000000000 --- a/embassy-stm32f4-examples/.cargo/config +++ /dev/null @@ -1,28 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "probe-run --chip STM32F401CCUx" - -rustflags = [ - # LLD (shipped with the Rust toolchain) is used as the default linker - "-C", "link-arg=--nmagic", - "-C", "link-arg=-Tlink.x", - "-C", "link-arg=-Tdefmt.x", - - # if you run into problems with LLD switch to the GNU linker by commenting out - # this line - # "-C", "linker=arm-none-eabi-ld", - - # if you need to link to pre-compiled C libraries provided by a C toolchain - # use GCC as the linker by commenting out both lines above and then - # uncommenting the three lines below - # "-C", "linker=arm-none-eabi-gcc", - # "-C", "link-arg=-Wl,-Tlink.x", - # "-C", "link-arg=-nostartfiles", - - # Code-size optimizations. - "-Z", "trap-unreachable=no", - "-C", "inline-threshold=5", - "-C", "no-vectorize-loops", -] - -[build] -target = "thumbv7em-none-eabihf" diff --git a/embassy-stm32f4-examples/Cargo.toml b/embassy-stm32f4-examples/Cargo.toml deleted file mode 100644 index c6ef98973..000000000 --- a/embassy-stm32f4-examples/Cargo.toml +++ /dev/null @@ -1,55 +0,0 @@ -[package] -authors = ["Dario Nieuwenhuis "] -edition = "2018" -name = "embassy-stm32f4-examples" -version = "0.1.0" - -[features] -default = [ - "defmt-default", -] -defmt-default = [] -defmt-trace = [] -defmt-debug = [] -defmt-info = [] -defmt-warn = [] -defmt-error = [] - -stm32f401 = ["stm32f4xx-hal/stm32f401", "embassy-stm32f4/stm32f401"] -stm32f405 = ["stm32f4xx-hal/stm32f405", "embassy-stm32f4/stm32f405"] -stm32f407 = ["stm32f4xx-hal/stm32f407", "embassy-stm32f4/stm32f407"] -stm32f410 = ["stm32f4xx-hal/stm32f410", "embassy-stm32f4/stm32f410"] -stm32f411 = ["stm32f4xx-hal/stm32f411", "embassy-stm32f4/stm32f411"] -stm32f412 = ["stm32f4xx-hal/stm32f412", "embassy-stm32f4/stm32f412"] -stm32f413 = ["stm32f4xx-hal/stm32f413", "embassy-stm32f4/stm32f413"] -stm32f415 = ["stm32f4xx-hal/stm32f405", "embassy-stm32f4/stm32f405"] -stm32f417 = ["stm32f4xx-hal/stm32f407", "embassy-stm32f4/stm32f407"] -stm32f423 = ["stm32f4xx-hal/stm32f413", "embassy-stm32f4/stm32f413"] -stm32f427 = ["stm32f4xx-hal/stm32f427", "embassy-stm32f4/stm32f427"] -stm32f429 = ["stm32f4xx-hal/stm32f429", "embassy-stm32f4/stm32f429"] -stm32f437 = ["stm32f4xx-hal/stm32f427", "embassy-stm32f4/stm32f427"] -stm32f439 = ["stm32f4xx-hal/stm32f429", "embassy-stm32f4/stm32f429"] -stm32f446 = ["stm32f4xx-hal/stm32f446", "embassy-stm32f4/stm32f446"] -stm32f469 = ["stm32f4xx-hal/stm32f469", "embassy-stm32f4/stm32f469"] -stm32f479 = ["stm32f4xx-hal/stm32f469", "embassy-stm32f4/stm32f469"] - - -[dependencies] -embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } -embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } -embassy-stm32f4 = { version = "*", path = "../embassy-stm32f4" } -embassy-stm32 = { version = "*", path = "../embassy-stm32" } -embassy-extras = {version = "0.1.0", path = "../embassy-extras" } - -defmt = "0.2.0" -defmt-rtt = "0.2.0" - -cortex-m = "0.7.1" -cortex-m-rt = "0.6.13" -embedded-hal = { version = "0.2.4" } -panic-probe = "0.1.0" -stm32f4xx-hal = { version = "0.8.3", features = ["rt", "usb_fs"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"} -futures = { version = "0.3.8", default-features = false, features = ["async-await"] } -rtt-target = { version = "0.3", features = ["cortex-m"] } -bxcan = "0.5.0" -usb-device = "0.2.7" diff --git a/embassy-stm32f4-examples/build.rs b/embassy-stm32f4-examples/build.rs deleted file mode 100644 index d534cc3df..000000000 --- a/embassy-stm32f4-examples/build.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); -} diff --git a/embassy-stm32f4-examples/memory.x b/embassy-stm32f4-examples/memory.x deleted file mode 100644 index efa700b8a..000000000 --- a/embassy-stm32f4-examples/memory.x +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - FLASH : ORIGIN = 0x08000000, LENGTH = 64K - RAM : ORIGIN = 0x20000000, LENGTH = 32K -} diff --git a/embassy-stm32f4-examples/src/bin/can.rs b/embassy-stm32f4-examples/src/bin/can.rs deleted file mode 100644 index c34c0a2a4..000000000 --- a/embassy-stm32f4-examples/src/bin/can.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![no_std] -#![no_main] -#![feature(trait_alias)] -#![feature(type_alias_impl_trait)] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] - -#[path = "../example_common.rs"] -mod example_common; -use example_common::{panic, *}; - -use bxcan::filter::Mask32; -use cortex_m_rt::entry; -use embassy::executor::Executor; -use embassy::util::Forever; -use embassy_stm32f4::{can, interrupt}; -use stm32f4xx_hal::prelude::*; -use stm32f4xx_hal::{can::Can, stm32}; - -#[embassy::task] -async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { - let gpioa = dp.GPIOA.split(); - - let rx = gpioa.pa11.into_alternate_af9(); - let tx = gpioa.pa12.into_alternate_af9(); - let mut can = bxcan::Can::new(Can::new(dp.CAN1, (tx, rx))); - - // APB1 (PCLK1): 24MHz, Bit rate: 20kBit/s, Sample Point 87.5% - // Value was calculated with http://www.bittiming.can-wiki.info/ - can.modify_config().set_bit_timing(0x001c_004a); - // Configure filters so that can frames can be received. - can.modify_filters().enable_bank(0, Mask32::accept_all()); - - let mut can = can::Can::new(can, interrupt::take!(CAN1_TX), interrupt::take!(CAN1_RX0)); - - let _frame = can.receive().await; -} - -static EXECUTOR: Forever = Forever::new(); - -#[entry] -fn main() -> ! { - let dp = stm32::Peripherals::take().unwrap(); - let cp = cortex_m::peripheral::Peripherals::take().unwrap(); - - dp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - dp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); - - let executor = EXECUTOR.put(Executor::new()); - executor.run(|spawner| { - unwrap!(spawner.spawn(run(dp, cp))); - }); -} diff --git a/embassy-stm32f4-examples/src/bin/exti.rs b/embassy-stm32f4-examples/src/bin/exti.rs deleted file mode 100644 index 9879de408..000000000 --- a/embassy-stm32f4-examples/src/bin/exti.rs +++ /dev/null @@ -1,58 +0,0 @@ -#![no_std] -#![no_main] -#![feature(trait_alias)] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] -#![feature(type_alias_impl_trait)] - -#[path = "../example_common.rs"] -mod example_common; -use example_common::{panic, *}; - -use cortex_m_rt::entry; -use embassy::executor::Executor; -use embassy::traits::gpio::*; -use embassy::util::Forever; -use embassy_stm32f4::exti::ExtiPin; -use embassy_stm32f4::interrupt; -use futures::pin_mut; -use stm32f4xx_hal::prelude::*; -use stm32f4xx_hal::stm32; - -#[embassy::task] -async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { - let gpioa = dp.GPIOA.split(); - - let button = gpioa.pa0.into_pull_up_input(); - let mut syscfg = dp.SYSCFG.constrain(); - - let pin = ExtiPin::new(button, interrupt::take!(EXTI0), &mut syscfg); - pin_mut!(pin); - - info!("Starting loop"); - - loop { - pin.as_mut().wait_for_rising_edge().await; - info!("edge detected!"); - } -} - -static EXECUTOR: Forever = Forever::new(); - -#[entry] -fn main() -> ! { - let dp = stm32::Peripherals::take().unwrap(); - let cp = cortex_m::peripheral::Peripherals::take().unwrap(); - - dp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - dp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); - - let executor = EXECUTOR.put(Executor::new()); - executor.run(|spawner| { - unwrap!(spawner.spawn(run(dp, cp))); - }); -} diff --git a/embassy-stm32f4-examples/src/bin/hello.rs b/embassy-stm32f4-examples/src/bin/hello.rs deleted file mode 100644 index 8a6654146..000000000 --- a/embassy-stm32f4-examples/src/bin/hello.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![no_std] -#![no_main] -#![feature(trait_alias)] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] -#![feature(type_alias_impl_trait)] - -#[path = "../example_common.rs"] -mod example_common; -use example_common::*; - -use cortex_m_rt::entry; -use stm32f4xx_hal::prelude::*; - -#[entry] -fn main() -> ! { - info!("Hello World!"); - - let p = stm32f4xx_hal::stm32::Peripherals::take().unwrap(); - - p.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - p.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); - - let gpioa = p.GPIOA.split(); - let gpioc = p.GPIOC.split(); - - let mut led = gpioc.pc13.into_push_pull_output(); - let button = gpioa.pa0.into_pull_up_input(); - led.set_low().unwrap(); - - loop { - if button.is_high().unwrap() { - led.set_low().unwrap(); - } else { - led.set_high().unwrap(); - } - } -} diff --git a/embassy-stm32f4-examples/src/bin/rtc_async.rs b/embassy-stm32f4-examples/src/bin/rtc_async.rs deleted file mode 100644 index f2757294d..000000000 --- a/embassy-stm32f4-examples/src/bin/rtc_async.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![no_std] -#![no_main] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] -#![feature(type_alias_impl_trait)] - -#[path = "../example_common.rs"] -mod example_common; -use example_common::*; - -use defmt::panic; -use embassy; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32f4; -use embassy_stm32f4::hal; - -#[embassy::task] -async fn run1() { - loop { - info!("BIG INFREQUENT TICK"); - Timer::after(Duration::from_ticks(32768 * 2 as u64)).await; - } -} - -#[embassy::task] -async fn run2() { - loop { - info!("tick"); - Timer::after(Duration::from_ticks(13000 as u64)).await; - } -} - -#[embassy::main(use_hse = 16)] -async fn main(spawner: Spawner) { - let (dp, clocks) = embassy_stm32::Peripherals::take().unwrap(); - - spawner.spawn(run1()).unwrap(); -} diff --git a/embassy-stm32f4-examples/src/bin/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs deleted file mode 100644 index 1717cadb9..000000000 --- a/embassy-stm32f4-examples/src/bin/serial.rs +++ /dev/null @@ -1,79 +0,0 @@ -#![no_std] -#![no_main] -#![feature(trait_alias)] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] -#![feature(type_alias_impl_trait)] - -#[path = "../example_common.rs"] -mod example_common; -use example_common::{panic, *}; - -use cortex_m::singleton; -use cortex_m_rt::entry; -use embassy::executor::{Executor, Spawner}; -use embassy::traits::uart::{Read, Write}; -use embassy::util::Forever; -use embassy_stm32f4::interrupt; -use embassy_stm32f4::serial; -use futures::pin_mut; -use stm32f4xx_hal::dma::StreamsTuple; -use stm32f4xx_hal::prelude::*; -use stm32f4xx_hal::serial::config::Config; -use stm32f4xx_hal::stm32; - -#[embassy::main(use_hse = 16, sysclk = 48, pclk1 = 24)] -async fn main(spawner: Spawner) { - let (dp, clocks) = embassy_stm32::Peripherals::take().unwrap(); - let cp = cortex_m::peripheral::Peripherals::take().unwrap(); - - dp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - - // https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1 - let gpioa = dp.GPIOA.split(); - let streams = StreamsTuple::new(dp.DMA2); - - let _serial = unsafe { - serial::Serial::new( - dp.USART1, - (streams.7, streams.2), - ( - gpioa.pa9.into_alternate_af7(), - gpioa.pa10.into_alternate_af7(), - ), - interrupt::take!(DMA2_STREAM7), - interrupt::take!(DMA2_STREAM2), - interrupt::take!(USART1), - Config::default().baudrate(9600.bps()), - clocks, - ) - }; - - let streams = StreamsTuple::new(dp.DMA1); - - let mut serial = unsafe { - serial::Serial::new( - dp.USART2, - (streams.6, streams.5), - ( - gpioa.pa2.into_alternate_af7(), - gpioa.pa3.into_alternate_af7(), - ), - interrupt::take!(DMA1_STREAM6), - interrupt::take!(DMA1_STREAM5), - interrupt::take!(USART2), - Config::default().baudrate(9600.bps()), - clocks, - ) - }; - pin_mut!(serial); - - let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); - - buf[5] = 0x01; - serial.write(buf).await.unwrap(); -} diff --git a/embassy-stm32f4-examples/src/bin/usb_serial.rs b/embassy-stm32f4-examples/src/bin/usb_serial.rs deleted file mode 100644 index 669d187d4..000000000 --- a/embassy-stm32f4-examples/src/bin/usb_serial.rs +++ /dev/null @@ -1,117 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] - -#[path = "../example_common.rs"] -mod example_common; -use example_common::*; - -use cortex_m_rt::entry; -use defmt::panic; -use embassy::executor::{Executor, Spawner}; -use embassy::interrupt::InterruptExt; -use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; -use embassy::time::{Duration, Timer}; -use embassy::util::Forever; -use embassy_extras::usb::usb_serial::UsbSerial; -use embassy_extras::usb::Usb; -use embassy_stm32f4::{interrupt, pac, rtc}; -use futures::future::{select, Either}; -use futures::pin_mut; -use stm32f4xx_hal::otg_fs::{UsbBus, USB}; -use stm32f4xx_hal::prelude::*; -use usb_device::bus::UsbBusAllocator; -use usb_device::prelude::*; - -#[embassy::task] -async fn run1(bus: &'static mut UsbBusAllocator>) { - info!("Async task"); - - let mut read_buf = [0u8; 128]; - let mut write_buf = [0u8; 128]; - let serial = UsbSerial::new(bus, &mut read_buf, &mut write_buf); - - let device = UsbDeviceBuilder::new(bus, UsbVidPid(0x16c0, 0x27dd)) - .manufacturer("Fake company") - .product("Serial port") - .serial_number("TEST") - .device_class(0x02) - .build(); - - let irq = interrupt::take!(OTG_FS); - irq.set_priority(interrupt::Priority::Level3); - - let usb = Usb::new(device, serial, irq); - pin_mut!(usb); - usb.as_mut().start(); - - let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0(); - - let mut buf = [0u8; 64]; - loop { - let mut n = 0; - let left = { - let recv_fut = async { - loop { - let byte = unwrap!(read_interface.read_byte().await); - unwrap!(write_interface.write_byte(byte).await); - buf[n] = byte; - - n += 1; - if byte == b'\n' || byte == b'\r' || n == buf.len() { - break; - } - } - }; - pin_mut!(recv_fut); - - let timeout = Timer::after(Duration::from_ticks(32768 * 10)); - - match select(recv_fut, timeout).await { - Either::Left(_) => true, - Either::Right(_) => false, - } - }; - - if left { - for c in buf[..n].iter_mut() { - if 0x61 <= *c && *c <= 0x7a { - *c &= !0x20; - } - } - unwrap!(write_interface.write_byte(b'\n').await); - unwrap!(write_interface.write_all(&buf[..n]).await); - unwrap!(write_interface.write_byte(b'\n').await); - } else { - unwrap!(write_interface.write_all(b"\r\nSend something\r\n").await); - } - } -} - -static USB_BUS: Forever>> = Forever::new(); - -#[embassy::main(use_hse = 25, sysclk = 48, require_pll48clk)] -async fn main(spawner: Spawner) -> ! { - static mut EP_MEMORY: [u32; 1024] = [0; 1024]; - - info!("Hello World!"); - - let (p, clocks) = embassy_stm32::Peripherals::take().unwrap(); - - let gpioa = p.GPIOA.split(); - let usb = USB { - usb_global: p.OTG_FS_GLOBAL, - usb_device: p.OTG_FS_DEVICE, - usb_pwrclk: p.OTG_FS_PWRCLK, - pin_dm: gpioa.pa11.into_alternate_af10(), - pin_dp: gpioa.pa12.into_alternate_af10(), - hclk: clocks.hclk(), - }; - // Rust analyzer isn't recognizing the static ref magic `cortex-m` does - #[allow(unused_unsafe)] - let usb_bus = USB_BUS.put(UsbBus::new(usb, unsafe { &mut EP_MEMORY })); - - spawner.spawn(run1(usb_bus)).unwrap(); -} diff --git a/embassy-stm32f4-examples/src/example_common.rs b/embassy-stm32f4-examples/src/example_common.rs deleted file mode 100644 index 54d633837..000000000 --- a/embassy-stm32f4-examples/src/example_common.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![macro_use] - -use defmt_rtt as _; // global logger -use panic_probe as _; - -pub use defmt::*; - -use core::sync::atomic::{AtomicUsize, Ordering}; - -defmt::timestamp! {"{=u64}", { - static COUNT: AtomicUsize = AtomicUsize::new(0); - // NOTE(no-CAS) `timestamps` runs with interrupts disabled - let n = COUNT.load(Ordering::Relaxed); - COUNT.store(n + 1, Ordering::Relaxed); - n as u64 - } -} diff --git a/embassy-stm32f4/Cargo.toml b/embassy-stm32f4/Cargo.toml deleted file mode 100644 index 8e9b14f03..000000000 --- a/embassy-stm32f4/Cargo.toml +++ /dev/null @@ -1,45 +0,0 @@ -[package] -name = "embassy-stm32f4" -version = "0.1.0" -authors = ["Dario Nieuwenhuis "] -edition = "2018" - -[features] -defmt-trace = [ ] -defmt-debug = [ ] -defmt-info = [ ] -defmt-warn = [ ] -defmt-error = [ ] - -stm32f401 = ["stm32f4xx-hal/stm32f401", "embassy-stm32/stm32f401"] -stm32f405 = ["stm32f4xx-hal/stm32f405", "embassy-stm32/stm32f405"] -stm32f407 = ["stm32f4xx-hal/stm32f407", "embassy-stm32/stm32f407"] -stm32f410 = ["stm32f4xx-hal/stm32f410", "embassy-stm32/stm32f410"] -stm32f411 = ["stm32f4xx-hal/stm32f411", "embassy-stm32/stm32f411"] -stm32f412 = ["stm32f4xx-hal/stm32f412", "embassy-stm32/stm32f412"] -stm32f413 = ["stm32f4xx-hal/stm32f413", "embassy-stm32/stm32f413"] -stm32f415 = ["stm32f4xx-hal/stm32f405", "embassy-stm32/stm32f415"] -stm32f417 = ["stm32f4xx-hal/stm32f407", "embassy-stm32/stm32f417"] -stm32f423 = ["stm32f4xx-hal/stm32f413", "embassy-stm32/stm32f423"] -stm32f427 = ["stm32f4xx-hal/stm32f427", "embassy-stm32/stm32f427"] -stm32f429 = ["stm32f4xx-hal/stm32f429", "embassy-stm32/stm32f429"] -stm32f437 = ["stm32f4xx-hal/stm32f427", "embassy-stm32/stm32f437"] -stm32f439 = ["stm32f4xx-hal/stm32f429", "embassy-stm32/stm32f439"] -stm32f446 = ["stm32f4xx-hal/stm32f446", "embassy-stm32/stm32f446"] -stm32f469 = ["stm32f4xx-hal/stm32f469", "embassy-stm32/stm32f469"] -stm32f479 = ["stm32f4xx-hal/stm32f469", "embassy-stm32/stm32f479"] - -[dependencies] -embassy = { version = "0.1.0", path = "../embassy" } -embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32" } - -defmt = { version = "0.2.0", optional = true } -log = { version = "0.4.11", optional = true } -cortex-m-rt = "0.6.13" -cortex-m = "0.7.1" -futures = { version = "0.3.5", default-features = false, features = ["async-await"] } -embedded-hal = { version = "0.2.4" } -embedded-dma = { version = "0.1.2" } -stm32f4xx-hal = { version = "0.8.3", features = ["rt", "can"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"} -bxcan = "0.5.0" -nb = "*" diff --git a/embassy-stm32f4/src/lib.rs b/embassy-stm32f4/src/lib.rs deleted file mode 100644 index eb6f04f88..000000000 --- a/embassy-stm32f4/src/lib.rs +++ /dev/null @@ -1,317 +0,0 @@ -#![no_std] -#![feature(generic_associated_types)] -#![feature(asm)] -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] -#![feature(type_alias_impl_trait)] -#![allow(incomplete_features)] - -#[cfg(not(any( - feature = "stm32f401", - feature = "stm32f405", - feature = "stm32f407", - feature = "stm32f410", - feature = "stm32f411", - feature = "stm32f412", - feature = "stm32f413", - feature = "stm32f415", - feature = "stm32f417", - feature = "stm32f423", - feature = "stm32f427", - feature = "stm32f429", - feature = "stm32f437", - feature = "stm32f439", - feature = "stm32f446", - feature = "stm32f469", - feature = "stm32f479", -)))] -compile_error!( - "No chip feature activated. You must activate exactly one of the following features: " -); - -#[cfg(any( - all(feature = "stm32f401", feature = "stm32f405"), - all(feature = "stm32f401", feature = "stm32f407"), - all(feature = "stm32f401", feature = "stm32f410"), - all(feature = "stm32f401", feature = "stm32f411"), - all(feature = "stm32f401", feature = "stm32f412"), - all(feature = "stm32f401", feature = "stm32f413"), - all(feature = "stm32f401", feature = "stm32f415"), - all(feature = "stm32f401", feature = "stm32f417"), - all(feature = "stm32f401", feature = "stm32f423"), - all(feature = "stm32f401", feature = "stm32f427"), - all(feature = "stm32f401", feature = "stm32f429"), - all(feature = "stm32f401", feature = "stm32f437"), - all(feature = "stm32f401", feature = "stm32f439"), - all(feature = "stm32f401", feature = "stm32f446"), - all(feature = "stm32f401", feature = "stm32f469"), - all(feature = "stm32f401", feature = "stm32f479"), - all(feature = "stm32f405", feature = "stm32f401"), - all(feature = "stm32f405", feature = "stm32f407"), - all(feature = "stm32f405", feature = "stm32f410"), - all(feature = "stm32f405", feature = "stm32f411"), - all(feature = "stm32f405", feature = "stm32f412"), - all(feature = "stm32f405", feature = "stm32f413"), - all(feature = "stm32f405", feature = "stm32f415"), - all(feature = "stm32f405", feature = "stm32f417"), - all(feature = "stm32f405", feature = "stm32f423"), - all(feature = "stm32f405", feature = "stm32f427"), - all(feature = "stm32f405", feature = "stm32f429"), - all(feature = "stm32f405", feature = "stm32f437"), - all(feature = "stm32f405", feature = "stm32f439"), - all(feature = "stm32f405", feature = "stm32f446"), - all(feature = "stm32f405", feature = "stm32f469"), - all(feature = "stm32f405", feature = "stm32f479"), - all(feature = "stm32f407", feature = "stm32f401"), - all(feature = "stm32f407", feature = "stm32f405"), - all(feature = "stm32f407", feature = "stm32f410"), - all(feature = "stm32f407", feature = "stm32f411"), - all(feature = "stm32f407", feature = "stm32f412"), - all(feature = "stm32f407", feature = "stm32f413"), - all(feature = "stm32f407", feature = "stm32f415"), - all(feature = "stm32f407", feature = "stm32f417"), - all(feature = "stm32f407", feature = "stm32f423"), - all(feature = "stm32f407", feature = "stm32f427"), - all(feature = "stm32f407", feature = "stm32f429"), - all(feature = "stm32f407", feature = "stm32f437"), - all(feature = "stm32f407", feature = "stm32f439"), - all(feature = "stm32f407", feature = "stm32f446"), - all(feature = "stm32f407", feature = "stm32f469"), - all(feature = "stm32f407", feature = "stm32f479"), - all(feature = "stm32f410", feature = "stm32f401"), - all(feature = "stm32f410", feature = "stm32f405"), - all(feature = "stm32f410", feature = "stm32f407"), - all(feature = "stm32f410", feature = "stm32f411"), - all(feature = "stm32f410", feature = "stm32f412"), - all(feature = "stm32f410", feature = "stm32f413"), - all(feature = "stm32f410", feature = "stm32f415"), - all(feature = "stm32f410", feature = "stm32f417"), - all(feature = "stm32f410", feature = "stm32f423"), - all(feature = "stm32f410", feature = "stm32f427"), - all(feature = "stm32f410", feature = "stm32f429"), - all(feature = "stm32f410", feature = "stm32f437"), - all(feature = "stm32f410", feature = "stm32f439"), - all(feature = "stm32f410", feature = "stm32f446"), - all(feature = "stm32f410", feature = "stm32f469"), - all(feature = "stm32f410", feature = "stm32f479"), - all(feature = "stm32f411", feature = "stm32f401"), - all(feature = "stm32f411", feature = "stm32f405"), - all(feature = "stm32f411", feature = "stm32f407"), - all(feature = "stm32f411", feature = "stm32f410"), - all(feature = "stm32f411", feature = "stm32f412"), - all(feature = "stm32f411", feature = "stm32f413"), - all(feature = "stm32f411", feature = "stm32f415"), - all(feature = "stm32f411", feature = "stm32f417"), - all(feature = "stm32f411", feature = "stm32f423"), - all(feature = "stm32f411", feature = "stm32f427"), - all(feature = "stm32f411", feature = "stm32f429"), - all(feature = "stm32f411", feature = "stm32f437"), - all(feature = "stm32f411", feature = "stm32f439"), - all(feature = "stm32f411", feature = "stm32f446"), - all(feature = "stm32f411", feature = "stm32f469"), - all(feature = "stm32f411", feature = "stm32f479"), - all(feature = "stm32f412", feature = "stm32f401"), - all(feature = "stm32f412", feature = "stm32f405"), - all(feature = "stm32f412", feature = "stm32f407"), - all(feature = "stm32f412", feature = "stm32f410"), - all(feature = "stm32f412", feature = "stm32f411"), - all(feature = "stm32f412", feature = "stm32f413"), - all(feature = "stm32f412", feature = "stm32f415"), - all(feature = "stm32f412", feature = "stm32f417"), - all(feature = "stm32f412", feature = "stm32f423"), - all(feature = "stm32f412", feature = "stm32f427"), - all(feature = "stm32f412", feature = "stm32f429"), - all(feature = "stm32f412", feature = "stm32f437"), - all(feature = "stm32f412", feature = "stm32f439"), - all(feature = "stm32f412", feature = "stm32f446"), - all(feature = "stm32f412", feature = "stm32f469"), - all(feature = "stm32f412", feature = "stm32f479"), - all(feature = "stm32f413", feature = "stm32f401"), - all(feature = "stm32f413", feature = "stm32f405"), - all(feature = "stm32f413", feature = "stm32f407"), - all(feature = "stm32f413", feature = "stm32f410"), - all(feature = "stm32f413", feature = "stm32f411"), - all(feature = "stm32f413", feature = "stm32f412"), - all(feature = "stm32f413", feature = "stm32f415"), - all(feature = "stm32f413", feature = "stm32f417"), - all(feature = "stm32f413", feature = "stm32f423"), - all(feature = "stm32f413", feature = "stm32f427"), - all(feature = "stm32f413", feature = "stm32f429"), - all(feature = "stm32f413", feature = "stm32f437"), - all(feature = "stm32f413", feature = "stm32f439"), - all(feature = "stm32f413", feature = "stm32f446"), - all(feature = "stm32f413", feature = "stm32f469"), - all(feature = "stm32f413", feature = "stm32f479"), - all(feature = "stm32f415", feature = "stm32f401"), - all(feature = "stm32f415", feature = "stm32f405"), - all(feature = "stm32f415", feature = "stm32f407"), - all(feature = "stm32f415", feature = "stm32f410"), - all(feature = "stm32f415", feature = "stm32f411"), - all(feature = "stm32f415", feature = "stm32f412"), - all(feature = "stm32f415", feature = "stm32f413"), - all(feature = "stm32f415", feature = "stm32f417"), - all(feature = "stm32f415", feature = "stm32f423"), - all(feature = "stm32f415", feature = "stm32f427"), - all(feature = "stm32f415", feature = "stm32f429"), - all(feature = "stm32f415", feature = "stm32f437"), - all(feature = "stm32f415", feature = "stm32f439"), - all(feature = "stm32f415", feature = "stm32f446"), - all(feature = "stm32f415", feature = "stm32f469"), - all(feature = "stm32f415", feature = "stm32f479"), - all(feature = "stm32f417", feature = "stm32f401"), - all(feature = "stm32f417", feature = "stm32f405"), - all(feature = "stm32f417", feature = "stm32f407"), - all(feature = "stm32f417", feature = "stm32f410"), - all(feature = "stm32f417", feature = "stm32f411"), - all(feature = "stm32f417", feature = "stm32f412"), - all(feature = "stm32f417", feature = "stm32f413"), - all(feature = "stm32f417", feature = "stm32f415"), - all(feature = "stm32f417", feature = "stm32f423"), - all(feature = "stm32f417", feature = "stm32f427"), - all(feature = "stm32f417", feature = "stm32f429"), - all(feature = "stm32f417", feature = "stm32f437"), - all(feature = "stm32f417", feature = "stm32f439"), - all(feature = "stm32f417", feature = "stm32f446"), - all(feature = "stm32f417", feature = "stm32f469"), - all(feature = "stm32f417", feature = "stm32f479"), - all(feature = "stm32f423", feature = "stm32f401"), - all(feature = "stm32f423", feature = "stm32f405"), - all(feature = "stm32f423", feature = "stm32f407"), - all(feature = "stm32f423", feature = "stm32f410"), - all(feature = "stm32f423", feature = "stm32f411"), - all(feature = "stm32f423", feature = "stm32f412"), - all(feature = "stm32f423", feature = "stm32f413"), - all(feature = "stm32f423", feature = "stm32f415"), - all(feature = "stm32f423", feature = "stm32f417"), - all(feature = "stm32f423", feature = "stm32f427"), - all(feature = "stm32f423", feature = "stm32f429"), - all(feature = "stm32f423", feature = "stm32f437"), - all(feature = "stm32f423", feature = "stm32f439"), - all(feature = "stm32f423", feature = "stm32f446"), - all(feature = "stm32f423", feature = "stm32f469"), - all(feature = "stm32f423", feature = "stm32f479"), - all(feature = "stm32f427", feature = "stm32f401"), - all(feature = "stm32f427", feature = "stm32f405"), - all(feature = "stm32f427", feature = "stm32f407"), - all(feature = "stm32f427", feature = "stm32f410"), - all(feature = "stm32f427", feature = "stm32f411"), - all(feature = "stm32f427", feature = "stm32f412"), - all(feature = "stm32f427", feature = "stm32f413"), - all(feature = "stm32f427", feature = "stm32f415"), - all(feature = "stm32f427", feature = "stm32f417"), - all(feature = "stm32f427", feature = "stm32f423"), - all(feature = "stm32f427", feature = "stm32f429"), - all(feature = "stm32f427", feature = "stm32f437"), - all(feature = "stm32f427", feature = "stm32f439"), - all(feature = "stm32f427", feature = "stm32f446"), - all(feature = "stm32f427", feature = "stm32f469"), - all(feature = "stm32f427", feature = "stm32f479"), - all(feature = "stm32f429", feature = "stm32f401"), - all(feature = "stm32f429", feature = "stm32f405"), - all(feature = "stm32f429", feature = "stm32f407"), - all(feature = "stm32f429", feature = "stm32f410"), - all(feature = "stm32f429", feature = "stm32f411"), - all(feature = "stm32f429", feature = "stm32f412"), - all(feature = "stm32f429", feature = "stm32f413"), - all(feature = "stm32f429", feature = "stm32f415"), - all(feature = "stm32f429", feature = "stm32f417"), - all(feature = "stm32f429", feature = "stm32f423"), - all(feature = "stm32f429", feature = "stm32f427"), - all(feature = "stm32f429", feature = "stm32f437"), - all(feature = "stm32f429", feature = "stm32f439"), - all(feature = "stm32f429", feature = "stm32f446"), - all(feature = "stm32f429", feature = "stm32f469"), - all(feature = "stm32f429", feature = "stm32f479"), - all(feature = "stm32f437", feature = "stm32f401"), - all(feature = "stm32f437", feature = "stm32f405"), - all(feature = "stm32f437", feature = "stm32f407"), - all(feature = "stm32f437", feature = "stm32f410"), - all(feature = "stm32f437", feature = "stm32f411"), - all(feature = "stm32f437", feature = "stm32f412"), - all(feature = "stm32f437", feature = "stm32f413"), - all(feature = "stm32f437", feature = "stm32f415"), - all(feature = "stm32f437", feature = "stm32f417"), - all(feature = "stm32f437", feature = "stm32f423"), - all(feature = "stm32f437", feature = "stm32f427"), - all(feature = "stm32f437", feature = "stm32f429"), - all(feature = "stm32f437", feature = "stm32f439"), - all(feature = "stm32f437", feature = "stm32f446"), - all(feature = "stm32f437", feature = "stm32f469"), - all(feature = "stm32f437", feature = "stm32f479"), - all(feature = "stm32f439", feature = "stm32f401"), - all(feature = "stm32f439", feature = "stm32f405"), - all(feature = "stm32f439", feature = "stm32f407"), - all(feature = "stm32f439", feature = "stm32f410"), - all(feature = "stm32f439", feature = "stm32f411"), - all(feature = "stm32f439", feature = "stm32f412"), - all(feature = "stm32f439", feature = "stm32f413"), - all(feature = "stm32f439", feature = "stm32f415"), - all(feature = "stm32f439", feature = "stm32f417"), - all(feature = "stm32f439", feature = "stm32f423"), - all(feature = "stm32f439", feature = "stm32f427"), - all(feature = "stm32f439", feature = "stm32f429"), - all(feature = "stm32f439", feature = "stm32f437"), - all(feature = "stm32f439", feature = "stm32f446"), - all(feature = "stm32f439", feature = "stm32f469"), - all(feature = "stm32f439", feature = "stm32f479"), - all(feature = "stm32f446", feature = "stm32f401"), - all(feature = "stm32f446", feature = "stm32f405"), - all(feature = "stm32f446", feature = "stm32f407"), - all(feature = "stm32f446", feature = "stm32f410"), - all(feature = "stm32f446", feature = "stm32f411"), - all(feature = "stm32f446", feature = "stm32f412"), - all(feature = "stm32f446", feature = "stm32f413"), - all(feature = "stm32f446", feature = "stm32f415"), - all(feature = "stm32f446", feature = "stm32f417"), - all(feature = "stm32f446", feature = "stm32f423"), - all(feature = "stm32f446", feature = "stm32f427"), - all(feature = "stm32f446", feature = "stm32f429"), - all(feature = "stm32f446", feature = "stm32f437"), - all(feature = "stm32f446", feature = "stm32f439"), - all(feature = "stm32f446", feature = "stm32f469"), - all(feature = "stm32f446", feature = "stm32f479"), - all(feature = "stm32f469", feature = "stm32f401"), - all(feature = "stm32f469", feature = "stm32f405"), - all(feature = "stm32f469", feature = "stm32f407"), - all(feature = "stm32f469", feature = "stm32f410"), - all(feature = "stm32f469", feature = "stm32f411"), - all(feature = "stm32f469", feature = "stm32f412"), - all(feature = "stm32f469", feature = "stm32f413"), - all(feature = "stm32f469", feature = "stm32f415"), - all(feature = "stm32f469", feature = "stm32f417"), - all(feature = "stm32f469", feature = "stm32f423"), - all(feature = "stm32f469", feature = "stm32f427"), - all(feature = "stm32f469", feature = "stm32f429"), - all(feature = "stm32f469", feature = "stm32f437"), - all(feature = "stm32f469", feature = "stm32f439"), - all(feature = "stm32f469", feature = "stm32f446"), - all(feature = "stm32f469", feature = "stm32f479"), - all(feature = "stm32f479", feature = "stm32f401"), - all(feature = "stm32f479", feature = "stm32f405"), - all(feature = "stm32f479", feature = "stm32f407"), - all(feature = "stm32f479", feature = "stm32f410"), - all(feature = "stm32f479", feature = "stm32f411"), - all(feature = "stm32f479", feature = "stm32f412"), - all(feature = "stm32f479", feature = "stm32f413"), - all(feature = "stm32f479", feature = "stm32f415"), - all(feature = "stm32f479", feature = "stm32f417"), - all(feature = "stm32f479", feature = "stm32f423"), - all(feature = "stm32f479", feature = "stm32f427"), - all(feature = "stm32f479", feature = "stm32f429"), - all(feature = "stm32f479", feature = "stm32f437"), - all(feature = "stm32f479", feature = "stm32f439"), - all(feature = "stm32f479", feature = "stm32f446"), - all(feature = "stm32f479", feature = "stm32f469"), -))] -compile_error!( - "Multile chip features activated. You must activate exactly one of the following features: " -); - -pub use embassy_stm32::{exti, fmt, hal, interrupt, pac, rtc}; - -#[cfg(not(any(feature = "stm32f401", feature = "stm32f410", feature = "stm32f411",)))] -pub use embassy_stm32::can; - -#[cfg(not(feature = "stm32f410"))] -pub mod qei; -pub mod serial; diff --git a/embassy-stm32f4/src/qei.rs b/embassy-stm32f4/src/qei.rs deleted file mode 100644 index 5973e62d9..000000000 --- a/embassy-stm32f4/src/qei.rs +++ /dev/null @@ -1,91 +0,0 @@ -use crate::interrupt; -use core::future::Future; -use core::pin::Pin; -use embassy::traits::qei::WaitForRotate; -use embedded_hal::Direction; -use stm32f4xx_hal::pac::TIM2; -use stm32f4xx_hal::{qei, qei::Pins}; - -pub struct Qei { - _qei: qei::Qei, - int: T::Interrupt, -} - -impl> Qei { - pub fn tim2(tim: TIM2, pins: PINS, interrupt: interrupt::TIM2) -> Self { - let qei = qei::Qei::tim2(tim, pins); - - let tim = unsafe { - &mut *(stm32f4xx_hal::stm32::TIM2::ptr() - as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) - }; - /* - enable qei interrupt - */ - tim.dier.write(|w| w.uie().set_bit()); - - Qei { - _qei: qei, - int: interrupt, - } - } -} - -impl + 'static> WaitForRotate for Qei { - type RotateFuture<'a> = impl Future + 'a; - - fn wait_for_rotate<'a>( - self: Pin<&'a mut Self>, - count_down: u16, - count_up: u16, - ) -> Self::RotateFuture<'a> { - let s = unsafe { self.get_unchecked_mut() }; - - let tim = unsafe { - &mut *(stm32f4xx_hal::stm32::TIM2::ptr() - as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) - }; - - /* - the interrupt will be reached at zero or the max count - write the total range to the qei. - */ - tim.arr - .write(|w| unsafe { w.bits((count_down + count_up) as u32) }); - - /* - set timer to the correct value in the range - */ - tim.cnt.write(|w| unsafe { w.bits(count_down as u32) }); - - /* - clear interrupt flag - */ - tim.sr.write(|w| w.uif().clear_bit()); - - async move { - embassy::util::InterruptFuture::new(&mut s.int).await; - - if tim.cnt.read().bits() == 0 { - Direction::Downcounting - } else if tim.cnt.read() == count_down + count_up { - Direction::Upcounting - } else { - panic!("unexpected value") - } - } - } -} - -mod sealed { - pub trait Sealed {} -} - -pub trait Instance: sealed::Sealed { - type Interrupt: interrupt::Interrupt; -} - -impl sealed::Sealed for TIM2 {} -impl Instance for TIM2 { - type Interrupt = interrupt::TIM2; -} diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs deleted file mode 100644 index 7539abf51..000000000 --- a/embassy-stm32f4/src/serial.rs +++ /dev/null @@ -1,364 +0,0 @@ -//! Async Serial. - -use core::future::Future; -use core::marker::PhantomData; -use core::pin::Pin; -use embassy::interrupt::Interrupt; -use embassy::traits::uart::{Error, Read, ReadUntilIdle, Write}; -use embassy::util::InterruptFuture; -use futures::{select_biased, FutureExt}; - -use crate::hal::{ - dma, - dma::config::DmaConfig, - dma::traits::{Channel, DMASet, PeriAddress, Stream}, - dma::{MemoryToPeripheral, PeripheralToMemory, Transfer}, - rcc::Clocks, - serial, - serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig}, - serial::{Event as SerialEvent, Pins}, -}; -use crate::interrupt; -use crate::pac; - -/// Interface to the Serial peripheral -pub struct Serial< - USART: PeriAddress + WithInterrupt, - TSTREAM: Stream + WithInterrupt, - RSTREAM: Stream + WithInterrupt, - CHANNEL: Channel, -> { - tx_stream: Option, - rx_stream: Option, - usart: Option, - tx_int: TSTREAM::Interrupt, - rx_int: RSTREAM::Interrupt, - usart_int: USART::Interrupt, - channel: PhantomData, -} - -// static mut INSTANCE: *const Serial, Stream2> = ptr::null_mut(); - -impl Serial -where - USART: serial::Instance - + PeriAddress - + DMASet - + DMASet - + WithInterrupt, - TSTREAM: Stream + WithInterrupt, - RSTREAM: Stream + WithInterrupt, - CHANNEL: Channel, -{ - // Leaking futures is forbidden! - pub unsafe fn new( - usart: USART, - streams: (TSTREAM, RSTREAM), - pins: PINS, - tx_int: TSTREAM::Interrupt, - rx_int: RSTREAM::Interrupt, - usart_int: USART::Interrupt, - mut config: SerialConfig, - clocks: Clocks, - ) -> Self - where - PINS: Pins, - { - config.dma = SerialDmaConfig::TxRx; - - let (usart, _) = serial::Serial::new(usart, pins, config, clocks) - .unwrap() - .release(); - - let (tx_stream, rx_stream) = streams; - - Serial { - tx_stream: Some(tx_stream), - rx_stream: Some(rx_stream), - usart: Some(usart), - tx_int: tx_int, - rx_int: rx_int, - usart_int: usart_int, - channel: PhantomData, - } - } -} - -impl Read for Serial -where - USART: serial::Instance - + PeriAddress - + DMASet - + DMASet - + WithInterrupt - + 'static, - TSTREAM: Stream + WithInterrupt + 'static, - RSTREAM: Stream + WithInterrupt + 'static, - CHANNEL: Channel + 'static, -{ - type ReadFuture<'a> = impl Future> + 'a; - - /// Receives serial data. - /// - /// The future is pending until the buffer is completely filled. - fn read<'a>(self: Pin<&'a mut Self>, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { - let this = unsafe { self.get_unchecked_mut() }; - let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) }; - - async move { - let rx_stream = this.rx_stream.take().unwrap(); - let usart = this.usart.take().unwrap(); - - let mut rx_transfer = Transfer::init( - rx_stream, - usart, - static_buf, - None, - DmaConfig::default() - .transfer_complete_interrupt(true) - .memory_increment(true) - .double_buffer(false), - ); - - let fut = InterruptFuture::new(&mut this.rx_int); - rx_transfer.start(|_usart| {}); - fut.await; - - let (rx_stream, usart, _, _) = rx_transfer.free(); - this.rx_stream.replace(rx_stream); - this.usart.replace(usart); - - Ok(()) - } - } -} - -impl Write for Serial -where - USART: serial::Instance - + PeriAddress - + DMASet - + DMASet - + WithInterrupt - + 'static, - TSTREAM: Stream + WithInterrupt + 'static, - RSTREAM: Stream + WithInterrupt + 'static, - CHANNEL: Channel + 'static, -{ - type WriteFuture<'a> = impl Future> + 'a; - - /// Sends serial data. - fn write<'a>(self: Pin<&'a mut Self>, buf: &'a [u8]) -> Self::WriteFuture<'a> { - let this = unsafe { self.get_unchecked_mut() }; - #[allow(mutable_transmutes)] - let static_buf = unsafe { core::mem::transmute::<&'a [u8], &'static mut [u8]>(buf) }; - - async move { - let tx_stream = this.tx_stream.take().unwrap(); - let usart = this.usart.take().unwrap(); - - let mut tx_transfer = Transfer::init( - tx_stream, - usart, - static_buf, - None, - DmaConfig::default() - .transfer_complete_interrupt(true) - .memory_increment(true) - .double_buffer(false), - ); - - let fut = InterruptFuture::new(&mut this.tx_int); - - tx_transfer.start(|_usart| {}); - fut.await; - - let (tx_stream, usart, _buf, _) = tx_transfer.free(); - - this.tx_stream.replace(tx_stream); - this.usart.replace(usart); - - Ok(()) - } - } -} - -impl ReadUntilIdle for Serial -where - USART: serial::Instance - + PeriAddress - + DMASet - + DMASet - + WithInterrupt - + 'static, - TSTREAM: Stream + WithInterrupt + 'static, - RSTREAM: Stream + WithInterrupt + 'static, - CHANNEL: Channel + 'static, -{ - type ReadUntilIdleFuture<'a> = impl Future> + 'a; - - /// Receives serial data. - /// - /// The future is pending until either the buffer is completely full, or the RX line falls idle after receiving some data. - /// - /// Returns the number of bytes read. - fn read_until_idle<'a>( - self: Pin<&'a mut Self>, - buf: &'a mut [u8], - ) -> Self::ReadUntilIdleFuture<'a> { - let this = unsafe { self.get_unchecked_mut() }; - let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) }; - - async move { - let rx_stream = this.rx_stream.take().unwrap(); - let usart = this.usart.take().unwrap(); - - unsafe { - /* __HAL_UART_ENABLE_IT(&uart->UartHandle, UART_IT_IDLE); */ - (*USART::ptr()).cr1.modify(|_, w| w.idleie().set_bit()); - - /* __HAL_UART_CLEAR_IDLEFLAG(&uart->UartHandle); */ - (*USART::ptr()).sr.read(); - (*USART::ptr()).dr.read(); - }; - - let mut rx_transfer = Transfer::init( - rx_stream, - usart, - static_buf, - None, - DmaConfig::default() - .transfer_complete_interrupt(true) - .memory_increment(true) - .double_buffer(false), - ); - - let total_bytes = RSTREAM::get_number_of_transfers() as usize; - - let fut = InterruptFuture::new(&mut this.rx_int); - let fut_idle = InterruptFuture::new(&mut this.usart_int); - - rx_transfer.start(|_usart| {}); - - futures::future::select(fut, fut_idle).await; - - let (rx_stream, usart, _, _) = rx_transfer.free(); - - let remaining_bytes = RSTREAM::get_number_of_transfers() as usize; - - unsafe { - (*USART::ptr()).cr1.modify(|_, w| w.idleie().clear_bit()); - } - this.rx_stream.replace(rx_stream); - this.usart.replace(usart); - - Ok(total_bytes - remaining_bytes) - } - } -} - -mod private { - pub trait Sealed {} -} - -pub trait WithInterrupt: private::Sealed { - type Interrupt: Interrupt; -} - -macro_rules! dma { - ($($PER:ident => ($dma:ident, $stream:ident),)+) => { - $( - impl private::Sealed for dma::$stream {} - impl WithInterrupt for dma::$stream { - type Interrupt = interrupt::$PER; - } - )+ - } - } - -macro_rules! usart { - ($($PER:ident => ($usart:ident),)+) => { - $( - impl private::Sealed for pac::$usart {} - impl WithInterrupt for pac::$usart { - type Interrupt = interrupt::$PER; - } - )+ - } -} - -dma! { - DMA2_STREAM0 => (DMA2, Stream0), - DMA2_STREAM1 => (DMA2, Stream1), - DMA2_STREAM2 => (DMA2, Stream2), - DMA2_STREAM3 => (DMA2, Stream3), - DMA2_STREAM4 => (DMA2, Stream4), - DMA2_STREAM5 => (DMA2, Stream5), - DMA2_STREAM6 => (DMA2, Stream6), - DMA2_STREAM7 => (DMA2, Stream7), - DMA1_STREAM0 => (DMA1, Stream0), - DMA1_STREAM1 => (DMA1, Stream1), - DMA1_STREAM2 => (DMA1, Stream2), - DMA1_STREAM3 => (DMA1, Stream3), - DMA1_STREAM4 => (DMA1, Stream4), - DMA1_STREAM5 => (DMA1, Stream5), - DMA1_STREAM6 => (DMA1, Stream6), -} - -#[cfg(any(feature = "stm32f401", feature = "stm32f410", feature = "stm32f411",))] -usart! { - USART1 => (USART1), - USART2 => (USART2), - USART6 => (USART6), -} - -#[cfg(any(feature = "stm32f405", feature = "stm32f407"))] -usart! { - USART1 => (USART1), - USART2 => (USART2), - USART3 => (USART3), - USART6 => (USART6), - - UART4 => (UART4), - UART5 => (UART5), -} - -#[cfg(feature = "stm32f412")] -usart! { - USART1 => (USART1), - USART2 => (USART2), - USART3 => (USART3), - USART6 => (USART6), -} - -#[cfg(feature = "stm32f413")] -usart! { - USART1 => (USART1), - USART2 => (USART2), - USART3 => (USART3), - USART6 => (USART6), - USART7 => (USART7), - USART8 => (USART8), - - UART5 => (UART5), - UART9 => (UART9), - UART10 => (UART10), -} - -#[cfg(any( - feature = "stm32f427", - feature = "stm32f429", - feature = "stm32f446", - feature = "stm32f469" -))] -usart! { - USART1 => (USART1), - USART2 => (USART2), - USART3 => (USART3), - USART6 => (USART6), - - UART4 => (UART4), - UART5 => (UART5), -// UART7 => (UART7), -// UART8 => (UART8), -} diff --git a/embassy-stm32l0/Cargo.toml b/embassy-stm32l0/Cargo.toml deleted file mode 100644 index 8926763d2..000000000 --- a/embassy-stm32l0/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "embassy-stm32l0" -version = "0.1.0" -authors = ["Michael Beaumont "] -edition = "2018" - -[features] -defmt-trace = [ ] -defmt-debug = [ ] -defmt-info = [ ] -defmt-warn = [ ] -defmt-error = [ ] - -stm32l0x1 = ["stm32l0xx-hal/stm32l0x1", "embassy-stm32/stm32l0x1"] -stm32l0x2 = ["stm32l0xx-hal/stm32l0x2", "embassy-stm32/stm32l0x2"] -stm32l0x3 = ["stm32l0xx-hal/stm32l0x3", "embassy-stm32/stm32l0x3"] - -[dependencies] -embassy = { version = "0.1.0", path = "../embassy" } -embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32" } -defmt = { version = "0.2.0", optional = true } -futures = { version = "0.3.5", default-features = false, features = [ "cfg-target-has-atomic", "unstable" ] } -log = { version = "0.4.11", optional = true } -cortex-m-rt = "0.6.13" -cortex-m = "0.7.1" -embedded-hal = { version = "0.2.4" } -embedded-dma = { version = "0.1.2" } -stm32l0xx-hal = { version = "0.7.0", features = ["rt"], git = "https://github.com/stm32-rs/stm32l0xx-hal.git"} diff --git a/embassy-stm32l0/src/lib.rs b/embassy-stm32l0/src/lib.rs deleted file mode 100644 index a684c4e3e..000000000 --- a/embassy-stm32l0/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![no_std] -#![feature(generic_associated_types)] -#![feature(asm)] -#![feature(type_alias_impl_trait)] -#![feature(min_type_alias_impl_trait)] -#![allow(incomplete_features)] - -#[cfg(not(any(feature = "stm32l0x1", feature = "stm32l0x2", feature = "stm32l0x3",)))] -compile_error!( - "No chip feature activated. You must activate exactly one of the following features: " -); - -#[cfg(any( - all(feature = "stm32l0x1", feature = "stm32l0x2"), - all(feature = "stm32l0x1", feature = "stm32l0x3"), - all(feature = "stm32l0x2", feature = "stm32l0x3"), -))] -compile_error!( - "Multile chip features activated. You must activate exactly one of the following features: " -); - -pub use embassy_stm32::{exti, fmt, hal, interrupt, pac}; diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index e4629bf9f..2fc86906f 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs @@ -121,7 +121,7 @@ unsafe impl cortex_m::interrupt::Nr for NrWrap { /// use embassy::traits::*; /// use embassy::util::InterruptFuture; /// use embassy::executor::task; -/// use embassy_stm32f4::interrupt; // Adjust this to your MCU's embassy HAL. +/// use embassy_stm32::interrupt; // Adjust this to your MCU's embassy HAL. /// #[embassy::task] /// async fn demo_interrupt_future() { /// // Using STM32f446 interrupt names, adjust this to your application as necessary. -- cgit