diff options
| author | Thales Fragoso <[email protected]> | 2021-03-18 22:23:09 -0300 |
|---|---|---|
| committer | Thales Fragoso <[email protected]> | 2021-03-18 22:37:08 -0300 |
| commit | 88a25b042aee96a73bdfbc44409bd8f6cd15035a (patch) | |
| tree | 7ab313f59c039764374257a1a8fcc29d5f214ae3 | |
| parent | 456e04c79fb5070fadffa6e80832e78aec7c2e59 (diff) | |
F4: Fix compilation for other MCUs
| -rwxr-xr-x | ci.sh | 2 | ||||
| -rw-r--r-- | embassy-stm32f4-examples/Cargo.toml | 22 | ||||
| -rw-r--r-- | embassy-stm32f4-examples/src/bin/can.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32f4-examples/src/bin/serial.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32f4/src/can.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32f4/src/exti.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32f4/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32f4/src/qei.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32f4/src/serial.rs | 56 |
9 files changed, 80 insertions, 19 deletions
| @@ -30,7 +30,7 @@ cargo fmt --all -- --check | |||
| 30 | 30 | ||
| 31 | # embassy-stm32f4 | 31 | # embassy-stm32f4 |
| 32 | 32 | ||
| 33 | (cd embassy-stm32f4-examples; cargo build --target thumbv7em-none-eabi --bins) | 33 | (cd embassy-stm32f4-examples; cargo build --target thumbv7em-none-eabi --bins --features stm32f405) |
| 34 | (cd embassy-stm32f4; cargo build --target thumbv7em-none-eabi --features stm32f405) | 34 | (cd embassy-stm32f4; cargo build --target thumbv7em-none-eabi --features stm32f405) |
| 35 | (cd embassy-stm32f4; cargo build --target thumbv7em-none-eabi --features stm32f405,defmt) | 35 | (cd embassy-stm32f4; cargo build --target thumbv7em-none-eabi --features stm32f405,defmt) |
| 36 | 36 | ||
diff --git a/embassy-stm32f4-examples/Cargo.toml b/embassy-stm32f4-examples/Cargo.toml index 60ba44554..5bbaecc58 100644 --- a/embassy-stm32f4-examples/Cargo.toml +++ b/embassy-stm32f4-examples/Cargo.toml | |||
| @@ -15,11 +15,29 @@ defmt-info = [] | |||
| 15 | defmt-warn = [] | 15 | defmt-warn = [] |
| 16 | defmt-error = [] | 16 | defmt-error = [] |
| 17 | 17 | ||
| 18 | stm32f401 = ["stm32f4xx-hal/stm32f401", "embassy-stm32f4/stm32f401"] | ||
| 19 | stm32f405 = ["stm32f4xx-hal/stm32f405", "embassy-stm32f4/stm32f405"] | ||
| 20 | stm32f407 = ["stm32f4xx-hal/stm32f407", "embassy-stm32f4/stm32f407"] | ||
| 21 | stm32f410 = ["stm32f4xx-hal/stm32f410", "embassy-stm32f4/stm32f410"] | ||
| 22 | stm32f411 = ["stm32f4xx-hal/stm32f411", "embassy-stm32f4/stm32f411"] | ||
| 23 | stm32f412 = ["stm32f4xx-hal/stm32f412", "embassy-stm32f4/stm32f412"] | ||
| 24 | stm32f413 = ["stm32f4xx-hal/stm32f413", "embassy-stm32f4/stm32f413"] | ||
| 25 | stm32f415 = ["stm32f4xx-hal/stm32f405", "embassy-stm32f4/stm32f405"] | ||
| 26 | stm32f417 = ["stm32f4xx-hal/stm32f407", "embassy-stm32f4/stm32f407"] | ||
| 27 | stm32f423 = ["stm32f4xx-hal/stm32f413", "embassy-stm32f4/stm32f413"] | ||
| 28 | stm32f427 = ["stm32f4xx-hal/stm32f427", "embassy-stm32f4/stm32f427"] | ||
| 29 | stm32f429 = ["stm32f4xx-hal/stm32f429", "embassy-stm32f4/stm32f429"] | ||
| 30 | stm32f437 = ["stm32f4xx-hal/stm32f427", "embassy-stm32f4/stm32f427"] | ||
| 31 | stm32f439 = ["stm32f4xx-hal/stm32f429", "embassy-stm32f4/stm32f429"] | ||
| 32 | stm32f446 = ["stm32f4xx-hal/stm32f446", "embassy-stm32f4/stm32f446"] | ||
| 33 | stm32f469 = ["stm32f4xx-hal/stm32f469", "embassy-stm32f4/stm32f469"] | ||
| 34 | stm32f479 = ["stm32f4xx-hal/stm32f469", "embassy-stm32f4/stm32f469"] | ||
| 35 | |||
| 18 | 36 | ||
| 19 | [dependencies] | 37 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } | 38 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } | 39 | embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32f4 = { version = "*", path = "../embassy-stm32f4", features = ["stm32f405"] } | 40 | embassy-stm32f4 = { version = "*", path = "../embassy-stm32f4" } |
| 23 | 41 | ||
| 24 | defmt = "0.2.0" | 42 | defmt = "0.2.0" |
| 25 | defmt-rtt = "0.2.0" | 43 | defmt-rtt = "0.2.0" |
| @@ -28,7 +46,7 @@ cortex-m = "0.7.1" | |||
| 28 | cortex-m-rt = "0.6.13" | 46 | cortex-m-rt = "0.6.13" |
| 29 | embedded-hal = { version = "0.2.4" } | 47 | embedded-hal = { version = "0.2.4" } |
| 30 | panic-probe = "0.1.0" | 48 | panic-probe = "0.1.0" |
| 31 | stm32f4xx-hal = { version = "0.8.3", features = ["rt", "stm32f405"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"} | 49 | stm32f4xx-hal = { version = "0.8.3", features = ["rt"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"} |
| 32 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | 50 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } |
| 33 | rtt-target = { version = "0.3", features = ["cortex-m"] } | 51 | rtt-target = { version = "0.3", features = ["cortex-m"] } |
| 34 | bxcan = "0.5.0" \ No newline at end of file | 52 | bxcan = "0.5.0" \ No newline at end of file |
diff --git a/embassy-stm32f4-examples/src/bin/can.rs b/embassy-stm32f4-examples/src/bin/can.rs index 701a277ec..5ffde2471 100644 --- a/embassy-stm32f4-examples/src/bin/can.rs +++ b/embassy-stm32f4-examples/src/bin/can.rs | |||
| @@ -12,10 +12,8 @@ use example_common::{panic, *}; | |||
| 12 | use bxcan::filter::Mask32; | 12 | use bxcan::filter::Mask32; |
| 13 | use cortex_m_rt::entry; | 13 | use cortex_m_rt::entry; |
| 14 | use embassy::executor::{task, Executor}; | 14 | use embassy::executor::{task, Executor}; |
| 15 | use embassy::traits::gpio::*; | ||
| 16 | use embassy::util::Forever; | 15 | use embassy::util::Forever; |
| 17 | use embassy_stm32f4::{can, interrupt}; | 16 | use embassy_stm32f4::{can, interrupt}; |
| 18 | use futures::pin_mut; | ||
| 19 | use stm32f4xx_hal::prelude::*; | 17 | use stm32f4xx_hal::prelude::*; |
| 20 | use stm32f4xx_hal::{can::Can, stm32}; | 18 | use stm32f4xx_hal::{can::Can, stm32}; |
| 21 | 19 | ||
| @@ -35,7 +33,7 @@ async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { | |||
| 35 | 33 | ||
| 36 | let mut can = can::Can::new(can, interrupt::take!(CAN1_TX), interrupt::take!(CAN1_RX0)); | 34 | let mut can = can::Can::new(can, interrupt::take!(CAN1_TX), interrupt::take!(CAN1_RX0)); |
| 37 | 35 | ||
| 38 | let frame = can.receive().await; | 36 | let _frame = can.receive().await; |
| 39 | } | 37 | } |
| 40 | 38 | ||
| 41 | static EXECUTOR: Forever<Executor> = Forever::new(); | 39 | static EXECUTOR: Forever<Executor> = Forever::new(); |
diff --git a/embassy-stm32f4-examples/src/bin/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs index b138bfdd8..49a588c25 100644 --- a/embassy-stm32f4-examples/src/bin/serial.rs +++ b/embassy-stm32f4-examples/src/bin/serial.rs | |||
| @@ -43,7 +43,7 @@ async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { | |||
| 43 | 43 | ||
| 44 | let streams = StreamsTuple::new(dp.DMA2); | 44 | let streams = StreamsTuple::new(dp.DMA2); |
| 45 | 45 | ||
| 46 | let mut serial = unsafe { | 46 | let _serial = unsafe { |
| 47 | serial::Serial::new( | 47 | serial::Serial::new( |
| 48 | dp.USART1, | 48 | dp.USART1, |
| 49 | (streams.7, streams.2), | 49 | (streams.7, streams.2), |
diff --git a/embassy-stm32f4/src/can.rs b/embassy-stm32f4/src/can.rs index 7c5311a9d..526d002c0 100644 --- a/embassy-stm32f4/src/can.rs +++ b/embassy-stm32f4/src/can.rs | |||
| @@ -42,7 +42,8 @@ impl<T: Instance> Can<T> { | |||
| 42 | pub fn transmit<'a>(&'a mut self, frame: &'a bxcan::Frame) -> impl Future<Output = ()> + 'a { | 42 | pub fn transmit<'a>(&'a mut self, frame: &'a bxcan::Frame) -> impl Future<Output = ()> + 'a { |
| 43 | async move { | 43 | async move { |
| 44 | let fut = InterruptFuture::new(&mut self.tx_int); | 44 | let fut = InterruptFuture::new(&mut self.tx_int); |
| 45 | self.can.transmit(frame); | 45 | // Infallible |
| 46 | self.can.transmit(frame).unwrap(); | ||
| 46 | 47 | ||
| 47 | fut.await; | 48 | fut.await; |
| 48 | } | 49 | } |
| @@ -94,7 +95,6 @@ macro_rules! can { | |||
| 94 | } | 95 | } |
| 95 | } | 96 | } |
| 96 | 97 | ||
| 97 | #[cfg(any(feature = "stm32f405",))] | ||
| 98 | can! { | 98 | can! { |
| 99 | CAN1 => (CAN1_TX, CAN1_RX0), | 99 | CAN1 => (CAN1_TX, CAN1_RX0), |
| 100 | CAN2 => (CAN2_TX, CAN2_RX0), | 100 | CAN2 => (CAN2_TX, CAN2_RX0), |
diff --git a/embassy-stm32f4/src/exti.rs b/embassy-stm32f4/src/exti.rs index 9df021634..154ca45c1 100644 --- a/embassy-stm32f4/src/exti.rs +++ b/embassy-stm32f4/src/exti.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use core::cell::UnsafeCell; | ||
| 2 | use core::future::Future; | 1 | use core::future::Future; |
| 3 | use core::mem; | 2 | use core::mem; |
| 4 | use core::pin::Pin; | 3 | use core::pin::Pin; |
diff --git a/embassy-stm32f4/src/lib.rs b/embassy-stm32f4/src/lib.rs index 19375d962..82d26d952 100644 --- a/embassy-stm32f4/src/lib.rs +++ b/embassy-stm32f4/src/lib.rs | |||
| @@ -313,9 +313,11 @@ pub use stm32f4xx_hal::stm32 as pac; | |||
| 313 | // This mod MUST go first, so that the others see its macros. | 313 | // This mod MUST go first, so that the others see its macros. |
| 314 | pub(crate) mod fmt; | 314 | pub(crate) mod fmt; |
| 315 | 315 | ||
| 316 | #[cfg(not(any(feature = "stm32f401", feature = "stm32f410", feature = "stm32f411",)))] | ||
| 316 | pub mod can; | 317 | pub mod can; |
| 317 | pub mod exti; | 318 | pub mod exti; |
| 318 | pub mod interrupt; | 319 | pub mod interrupt; |
| 320 | #[cfg(not(feature = "stm32f410"))] | ||
| 319 | pub mod qei; | 321 | pub mod qei; |
| 320 | pub mod rtc; | 322 | pub mod rtc; |
| 321 | pub mod serial; | 323 | pub mod serial; |
diff --git a/embassy-stm32f4/src/qei.rs b/embassy-stm32f4/src/qei.rs index 391c8f7c2..5973e62d9 100644 --- a/embassy-stm32f4/src/qei.rs +++ b/embassy-stm32f4/src/qei.rs | |||
| @@ -7,7 +7,7 @@ use stm32f4xx_hal::pac::TIM2; | |||
| 7 | use stm32f4xx_hal::{qei, qei::Pins}; | 7 | use stm32f4xx_hal::{qei, qei::Pins}; |
| 8 | 8 | ||
| 9 | pub struct Qei<T: Instance, PINS> { | 9 | pub struct Qei<T: Instance, PINS> { |
| 10 | qei: qei::Qei<T, PINS>, | 10 | _qei: qei::Qei<T, PINS>, |
| 11 | int: T::Interrupt, | 11 | int: T::Interrupt, |
| 12 | } | 12 | } |
| 13 | 13 | ||
| @@ -25,7 +25,7 @@ impl<PINS: Pins<TIM2>> Qei<TIM2, PINS> { | |||
| 25 | tim.dier.write(|w| w.uie().set_bit()); | 25 | tim.dier.write(|w| w.uie().set_bit()); |
| 26 | 26 | ||
| 27 | Qei { | 27 | Qei { |
| 28 | qei: qei, | 28 | _qei: qei, |
| 29 | int: interrupt, | 29 | int: interrupt, |
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| @@ -85,9 +85,7 @@ pub trait Instance: sealed::Sealed { | |||
| 85 | type Interrupt: interrupt::Interrupt; | 85 | type Interrupt: interrupt::Interrupt; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | #[cfg(feature = "stm32f405")] | ||
| 89 | impl sealed::Sealed for TIM2 {} | 88 | impl sealed::Sealed for TIM2 {} |
| 90 | #[cfg(feature = "stm32f405")] | ||
| 91 | impl Instance for TIM2 { | 89 | impl Instance for TIM2 { |
| 92 | type Interrupt = interrupt::TIM2; | 90 | type Interrupt = interrupt::TIM2; |
| 93 | } | 91 | } |
diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index 97b365a11..87d0caaaf 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | use core::future::Future; | 7 | use core::future::Future; |
| 8 | use core::marker::PhantomData; | 8 | use core::marker::PhantomData; |
| 9 | use core::sync::atomic::{self, Ordering}; | ||
| 10 | 9 | ||
| 11 | use embassy::interrupt::Interrupt; | 10 | use embassy::interrupt::Interrupt; |
| 12 | use embassy::traits::uart::{Error, Uart}; | 11 | use embassy::traits::uart::{Error, Uart}; |
| @@ -37,7 +36,7 @@ pub struct Serial< | |||
| 37 | usart: Option<USART>, | 36 | usart: Option<USART>, |
| 38 | tx_int: TSTREAM::Interrupt, | 37 | tx_int: TSTREAM::Interrupt, |
| 39 | rx_int: RSTREAM::Interrupt, | 38 | rx_int: RSTREAM::Interrupt, |
| 40 | usart_int: USART::Interrupt, | 39 | _usart_int: USART::Interrupt, |
| 41 | channel: PhantomData<CHANNEL>, | 40 | channel: PhantomData<CHANNEL>, |
| 42 | } | 41 | } |
| 43 | 42 | ||
| @@ -84,7 +83,7 @@ where | |||
| 84 | usart: Some(usart), | 83 | usart: Some(usart), |
| 85 | tx_int: tx_int, | 84 | tx_int: tx_int, |
| 86 | rx_int: rx_int, | 85 | rx_int: rx_int, |
| 87 | usart_int: usart_int, | 86 | _usart_int: usart_int, |
| 88 | channel: core::marker::PhantomData, | 87 | channel: core::marker::PhantomData, |
| 89 | } | 88 | } |
| 90 | } | 89 | } |
| @@ -207,7 +206,6 @@ macro_rules! usart { | |||
| 207 | } | 206 | } |
| 208 | } | 207 | } |
| 209 | 208 | ||
| 210 | #[cfg(any(feature = "stm32f405",))] | ||
| 211 | dma! { | 209 | dma! { |
| 212 | DMA2_STREAM0 => (DMA2, Stream0), | 210 | DMA2_STREAM0 => (DMA2, Stream0), |
| 213 | DMA2_STREAM1 => (DMA2, Stream1), | 211 | DMA2_STREAM1 => (DMA2, Stream1), |
| @@ -226,12 +224,60 @@ dma! { | |||
| 226 | DMA1_STREAM6 => (DMA1, Stream6), | 224 | DMA1_STREAM6 => (DMA1, Stream6), |
| 227 | } | 225 | } |
| 228 | 226 | ||
| 229 | #[cfg(any(feature = "stm32f405",))] | 227 | #[cfg(any(feature = "stm32f401", feature = "stm32f410", feature = "stm32f411",))] |
| 228 | usart! { | ||
| 229 | USART1 => (USART1), | ||
| 230 | USART2 => (USART2), | ||
| 231 | USART6 => (USART6), | ||
| 232 | } | ||
| 233 | |||
| 234 | #[cfg(any(feature = "stm32f405", feature = "stm32f407"))] | ||
| 230 | usart! { | 235 | usart! { |
| 231 | USART1 => (USART1), | 236 | USART1 => (USART1), |
| 232 | USART2 => (USART2), | 237 | USART2 => (USART2), |
| 233 | USART3 => (USART3), | 238 | USART3 => (USART3), |
| 239 | USART6 => (USART6), | ||
| 240 | |||
| 234 | UART4 => (UART4), | 241 | UART4 => (UART4), |
| 235 | UART5 => (UART5), | 242 | UART5 => (UART5), |
| 243 | } | ||
| 244 | |||
| 245 | #[cfg(feature = "stm32f412")] | ||
| 246 | usart! { | ||
| 247 | USART1 => (USART1), | ||
| 248 | USART2 => (USART2), | ||
| 249 | USART3 => (USART3), | ||
| 236 | USART6 => (USART6), | 250 | USART6 => (USART6), |
| 237 | } | 251 | } |
| 252 | |||
| 253 | #[cfg(feature = "stm32f413")] | ||
| 254 | usart! { | ||
| 255 | USART1 => (USART1), | ||
| 256 | USART2 => (USART2), | ||
| 257 | USART3 => (USART3), | ||
| 258 | USART6 => (USART6), | ||
| 259 | USART7 => (USART7), | ||
| 260 | USART8 => (USART8), | ||
| 261 | |||
| 262 | UART5 => (UART5), | ||
| 263 | UART9 => (UART9), | ||
| 264 | UART10 => (UART10), | ||
| 265 | } | ||
| 266 | |||
| 267 | #[cfg(any( | ||
| 268 | feature = "stm32f427", | ||
| 269 | feature = "stm32f429", | ||
| 270 | feature = "stm32f446", | ||
| 271 | feature = "stm32f469" | ||
| 272 | ))] | ||
| 273 | usart! { | ||
| 274 | USART1 => (USART1), | ||
| 275 | USART2 => (USART2), | ||
| 276 | USART3 => (USART3), | ||
| 277 | USART6 => (USART6), | ||
| 278 | |||
| 279 | UART4 => (UART4), | ||
| 280 | UART5 => (UART5), | ||
| 281 | UART7 => (UART7), | ||
| 282 | UART8 => (UART8), | ||
| 283 | } | ||
