diff options
| author | Tobias Pisani <[email protected]> | 2021-10-09 11:35:05 +0200 |
|---|---|---|
| committer | Tobias Pisani <[email protected]> | 2021-10-11 22:57:10 +0200 |
| commit | 39880de9589bb67a88939cba29301ade8dfb592a (patch) | |
| tree | cbb25ad5b544733e74de6ce4b1bc8986e4b03bb0 | |
| parent | f9a576d13d736ccbcf17960228ac0df8d82d0928 (diff) | |
partial alternate function configuration on STM32f1
| -rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/eth/v2/mod.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 35 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 13 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v1.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v1.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/v1.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/v2.rs | 6 |
9 files changed, 72 insertions, 28 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 9e10a8b02..b73b88391 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -5,7 +5,7 @@ use embassy::util::Unborrow; | |||
| 5 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 6 | 6 | ||
| 7 | use crate::gpio::{ | 7 | use crate::gpio::{ |
| 8 | sealed::OutputType::{OpenDrain, PushPull}, | 8 | sealed::AFType::{OutputOpenDrain, OutputPushPull}, |
| 9 | Pin, | 9 | Pin, |
| 10 | }; | 10 | }; |
| 11 | use crate::{peripherals, rcc::RccPeripheral}; | 11 | use crate::{peripherals, rcc::RccPeripheral}; |
| @@ -26,8 +26,8 @@ impl<'d, T: Instance + bxcan::Instance> Can<'d, T> { | |||
| 26 | unborrow!(peri, rx, tx); | 26 | unborrow!(peri, rx, tx); |
| 27 | 27 | ||
| 28 | unsafe { | 28 | unsafe { |
| 29 | rx.set_as_af(rx.af_num(), OpenDrain); | 29 | rx.set_as_af(rx.af_num(), OutputOpenDrain); |
| 30 | tx.set_as_af(tx.af_num(), PushPull); | 30 | tx.set_as_af(tx.af_num(), OutputPushPull); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | T::enable(); | 33 | T::enable(); |
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 8eb7c3393..001ac3154 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -10,7 +10,7 @@ use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | |||
| 10 | 10 | ||
| 11 | use crate::gpio::sealed::Pin as __GpioPin; | 11 | use crate::gpio::sealed::Pin as __GpioPin; |
| 12 | use crate::gpio::Pin as GpioPin; | 12 | use crate::gpio::Pin as GpioPin; |
| 13 | use crate::gpio::{sealed::OutputType::PushPull, AnyPin}; | 13 | use crate::gpio::{sealed::AFType::OutputPushPull, AnyPin}; |
| 14 | use crate::pac::gpio::vals::Ospeedr; | 14 | use crate::pac::gpio::vals::Ospeedr; |
| 15 | use crate::pac::{ETH, RCC, SYSCFG}; | 15 | use crate::pac::{ETH, RCC, SYSCFG}; |
| 16 | use crate::peripherals; | 16 | use crate::peripherals; |
| @@ -416,7 +416,7 @@ macro_rules! impl_pin { | |||
| 416 | fn configure(&mut self) { | 416 | fn configure(&mut self) { |
| 417 | // NOTE(unsafe) Exclusive access to the registers | 417 | // NOTE(unsafe) Exclusive access to the registers |
| 418 | critical_section::with(|_| unsafe { | 418 | critical_section::with(|_| unsafe { |
| 419 | self.set_as_af($af, PushPull); | 419 | self.set_as_af($af, OutputPushPull); |
| 420 | self.block() | 420 | self.block() |
| 421 | .ospeedr() | 421 | .ospeedr() |
| 422 | .modify(|w| w.set_ospeedr(self.pin() as usize, Ospeedr::VERYHIGHSPEED)); | 422 | .modify(|w| w.set_ospeedr(self.pin() as usize, Ospeedr::VERYHIGHSPEED)); |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index c7b644e94..3a8117e9d 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -350,12 +350,15 @@ impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> { | |||
| 350 | pub(crate) mod sealed { | 350 | pub(crate) mod sealed { |
| 351 | use super::*; | 351 | use super::*; |
| 352 | 352 | ||
| 353 | /// Output type settings | 353 | /// Alternate function type settings |
| 354 | #[derive(Debug)] | 354 | #[derive(Debug)] |
| 355 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 355 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 356 | pub enum OutputType { | 356 | pub enum AFType { |
| 357 | PushPull, | 357 | // InputFloating, |
| 358 | OpenDrain, | 358 | // InputPullUp, |
| 359 | // InputPullDown, | ||
| 360 | OutputPushPull, | ||
| 361 | OutputOpenDrain, | ||
| 359 | } | 362 | } |
| 360 | 363 | ||
| 361 | pub trait Pin { | 364 | pub trait Pin { |
| @@ -394,21 +397,35 @@ pub(crate) mod sealed { | |||
| 394 | } | 397 | } |
| 395 | 398 | ||
| 396 | #[cfg(gpio_v1)] | 399 | #[cfg(gpio_v1)] |
| 397 | unsafe fn set_as_af(&self, _af_num: u8, _af_type: OutputType) { | 400 | unsafe fn set_as_af(&self, _af_num: u8, af_type: AFType) { |
| 398 | panic!("F1 alternate GPIO functions not supported yet!"); | 401 | // F1 uses the AFIO register for remapping. |
| 402 | // For now, this is not implemented, so af_num is ignored | ||
| 403 | // _af_num should be zero here, since it is not set by stm32-data | ||
| 404 | let r = pin.block(); | ||
| 405 | let n = pin.pin() as usize; | ||
| 406 | let crlh = if n < 8 { 0 } else { 1 }; | ||
| 407 | match af_type { | ||
| 408 | // TODO: Do we need to configure input AF pins differently? | ||
| 409 | AfType::OutputPushPull => { | ||
| 410 | r.cr(crlh).modify(|w| w.set_cnf(n % 8, vals::Cnf::PUSHPULL)); | ||
| 411 | } | ||
| 412 | AfType::OutputOpenDrain => r | ||
| 413 | .cr(crlh) | ||
| 414 | .modify(|w| w.set_cnf(n % 8, vals::Cnf::OPENDRAIN)), | ||
| 415 | } | ||
| 399 | } | 416 | } |
| 400 | #[cfg(gpio_v2)] | 417 | #[cfg(gpio_v2)] |
| 401 | unsafe fn set_as_af(&self, af_num: u8, af_type: OutputType) { | 418 | unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) { |
| 402 | let pin = self._pin() as usize; | 419 | let pin = self._pin() as usize; |
| 403 | let block = self.block(); | 420 | let block = self.block(); |
| 404 | block | 421 | block |
| 405 | .afr(pin / 8) | 422 | .afr(pin / 8) |
| 406 | .modify(|w| w.set_afr(pin % 8, vals::Afr(af_num))); | 423 | .modify(|w| w.set_afr(pin % 8, vals::Afr(af_num))); |
| 407 | match af_type { | 424 | match af_type { |
| 408 | OutputType::PushPull => { | 425 | AfType::OutputPushPull => { |
| 409 | block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) | 426 | block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) |
| 410 | } | 427 | } |
| 411 | OutputType::OpenDrain => block | 428 | AfType::OutputOpenDrain => block |
| 412 | .otyper() | 429 | .otyper() |
| 413 | .modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)), | 430 | .modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)), |
| 414 | } | 431 | } |
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 4af5051db..e922fe429 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -96,7 +96,6 @@ crate::pac::interrupts!( | |||
| 96 | }; | 96 | }; |
| 97 | ); | 97 | ); |
| 98 | 98 | ||
| 99 | #[cfg(not(rcc_f1))] | ||
| 100 | macro_rules! impl_pin { | 99 | macro_rules! impl_pin { |
| 101 | ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { | 100 | ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { |
| 102 | impl $signal<peripherals::$inst> for peripherals::$pin {} | 101 | impl $signal<peripherals::$inst> for peripherals::$pin {} |
| @@ -109,6 +108,7 @@ macro_rules! impl_pin { | |||
| 109 | }; | 108 | }; |
| 110 | } | 109 | } |
| 111 | 110 | ||
| 111 | #[cfg(not(rcc_f1))] | ||
| 112 | crate::pac::peripheral_pins!( | 112 | crate::pac::peripheral_pins!( |
| 113 | ($inst:ident, i2c, I2C, $pin:ident, SDA, $af:expr) => { | 113 | ($inst:ident, i2c, I2C, $pin:ident, SDA, $af:expr) => { |
| 114 | impl_pin!($inst, $pin, SdaPin, $af); | 114 | impl_pin!($inst, $pin, SdaPin, $af); |
| @@ -119,6 +119,17 @@ crate::pac::peripheral_pins!( | |||
| 119 | }; | 119 | }; |
| 120 | ); | 120 | ); |
| 121 | 121 | ||
| 122 | #[cfg(rcc_f1)] | ||
| 123 | crate::pac::peripheral_pins!( | ||
| 124 | ($inst:ident, i2c, I2C, $pin:ident, SDA) => { | ||
| 125 | impl_pin!($inst, $pin, SdaPin, 0); | ||
| 126 | }; | ||
| 127 | |||
| 128 | ($inst:ident, i2c, I2C, $pin:ident, SCL) => { | ||
| 129 | impl_pin!($inst, $pin, SclPin, 0); | ||
| 130 | }; | ||
| 131 | ); | ||
| 132 | |||
| 122 | macro_rules! impl_dma { | 133 | macro_rules! impl_dma { |
| 123 | ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { | 134 | ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { |
| 124 | impl<T> sealed::$signal<peripherals::$inst> for T | 135 | impl<T> sealed::$signal<peripherals::$inst> for T |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index c5d5dee0c..6fa269fc2 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -9,7 +9,7 @@ use embedded_hal::blocking::i2c::WriteRead; | |||
| 9 | 9 | ||
| 10 | use crate::pac::i2c; | 10 | use crate::pac::i2c; |
| 11 | 11 | ||
| 12 | use crate::gpio::sealed::OutputType::OpenDrain; | 12 | use crate::gpio::sealed::AFType::OutputOpenDrain; |
| 13 | 13 | ||
| 14 | pub struct I2c<'d, T: Instance> { | 14 | pub struct I2c<'d, T: Instance> { |
| 15 | phantom: PhantomData<&'d mut T>, | 15 | phantom: PhantomData<&'d mut T>, |
| @@ -30,8 +30,8 @@ impl<'d, T: Instance> I2c<'d, T> { | |||
| 30 | T::enable(); | 30 | T::enable(); |
| 31 | 31 | ||
| 32 | unsafe { | 32 | unsafe { |
| 33 | scl.set_as_af(scl.af_num(), OpenDrain); | 33 | scl.set_as_af(scl.af_num(), OutputOpenDrain); |
| 34 | sda.set_as_af(sda.af_num(), OpenDrain); | 34 | sda.set_as_af(sda.af_num(), OutputOpenDrain); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | unsafe { | 37 | unsafe { |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 808854f00..492fc41c6 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -105,6 +105,7 @@ macro_rules! impl_pin { | |||
| 105 | }; | 105 | }; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | #[cfg(not(rcc_f1))] | ||
| 108 | crate::pac::peripheral_pins!( | 109 | crate::pac::peripheral_pins!( |
| 109 | ($inst:ident, spi, SPI, $pin:ident, SCK, $af:expr) => { | 110 | ($inst:ident, spi, SPI, $pin:ident, SCK, $af:expr) => { |
| 110 | impl_pin!($inst, $pin, SckPin, $af); | 111 | impl_pin!($inst, $pin, SckPin, $af); |
| @@ -119,6 +120,21 @@ crate::pac::peripheral_pins!( | |||
| 119 | }; | 120 | }; |
| 120 | ); | 121 | ); |
| 121 | 122 | ||
| 123 | #[cfg(rcc_f1)] | ||
| 124 | crate::pac::peripheral_pins!( | ||
| 125 | ($inst:ident, spi, SPI, $pin:ident, SCK) => { | ||
| 126 | impl_pin!($inst, $pin, SckPin, 0); | ||
| 127 | }; | ||
| 128 | |||
| 129 | ($inst:ident, spi, SPI, $pin:ident, MOSI) => { | ||
| 130 | impl_pin!($inst, $pin, MosiPin, 0); | ||
| 131 | }; | ||
| 132 | |||
| 133 | ($inst:ident, spi, SPI, $pin:ident, MISO) => { | ||
| 134 | impl_pin!($inst, $pin, MisoPin, 0); | ||
| 135 | }; | ||
| 136 | ); | ||
| 137 | |||
| 122 | macro_rules! impl_dma { | 138 | macro_rules! impl_dma { |
| 123 | ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { | 139 | ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { |
| 124 | impl<T> sealed::$signal<peripherals::$inst> for T | 140 | impl<T> sealed::$signal<peripherals::$inst> for T |
diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index 982f1cc4b..560d99a2f 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use crate::dma::NoDma; | 3 | use crate::dma::NoDma; |
| 4 | use crate::gpio::{ | 4 | use crate::gpio::{ |
| 5 | sealed::{ | 5 | sealed::{ |
| 6 | OutputType::{OpenDrain, PushPull}, | 6 | AFType::{OutputOpenDrain, OutputPushPull}, |
| 7 | Pin, | 7 | Pin, |
| 8 | }, | 8 | }, |
| 9 | AnyPin, | 9 | AnyPin, |
| @@ -59,9 +59,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 59 | unborrow!(sck, mosi, miso, txdma, rxdma); | 59 | unborrow!(sck, mosi, miso, txdma, rxdma); |
| 60 | 60 | ||
| 61 | unsafe { | 61 | unsafe { |
| 62 | sck.set_as_af(sck.af_num(), PushPull); | 62 | sck.set_as_af(sck.af_num(), OutputPushPull); |
| 63 | mosi.set_as_af(mosi.af_num(), PushPull); | 63 | mosi.set_as_af(mosi.af_num(), OutputPushPull); |
| 64 | miso.set_as_af(miso.af_num(), OpenDrain); | 64 | miso.set_as_af(miso.af_num(), OutputOpenDrain); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | let sck = sck.degrade(); | 67 | let sck = sck.degrade(); |
diff --git a/embassy-stm32/src/usart/v1.rs b/embassy-stm32/src/usart/v1.rs index d1dd68305..8cd392d18 100644 --- a/embassy-stm32/src/usart/v1.rs +++ b/embassy-stm32/src/usart/v1.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::gpio::sealed::OutputType::{OpenDrain, PushPull}; | 1 | use crate::gpio::sealed::AFType::{OutputOpenDrain, OutputPushPull}; |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use embassy::util::Unborrow; | 4 | use embassy::util::Unborrow; |
| @@ -37,8 +37,8 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 37 | let r = inner.regs(); | 37 | let r = inner.regs(); |
| 38 | 38 | ||
| 39 | unsafe { | 39 | unsafe { |
| 40 | rx.set_as_af(rx.af_num(), OpenDrain); | 40 | rx.set_as_af(rx.af_num(), OutputOpenDrain); |
| 41 | tx.set_as_af(tx.af_num(), PushPull); | 41 | tx.set_as_af(tx.af_num(), OutputPushPull); |
| 42 | 42 | ||
| 43 | r.brr().write_value(regs::Brr(div)); | 43 | r.brr().write_value(regs::Brr(div)); |
| 44 | r.cr1().write(|w| { | 44 | r.cr1().write(|w| { |
diff --git a/embassy-stm32/src/usart/v2.rs b/embassy-stm32/src/usart/v2.rs index 5e6696351..e6e5f69db 100644 --- a/embassy-stm32/src/usart/v2.rs +++ b/embassy-stm32/src/usart/v2.rs | |||
| @@ -13,7 +13,7 @@ use futures::TryFutureExt; | |||
| 13 | 13 | ||
| 14 | use super::*; | 14 | use super::*; |
| 15 | use crate::dma::NoDma; | 15 | use crate::dma::NoDma; |
| 16 | use crate::gpio::sealed::OutputType::{OpenDrain, PushPull}; | 16 | use crate::gpio::sealed::AFType::{OutputOpenDrain, OutputPushPull}; |
| 17 | use crate::pac::usart::{regs, vals}; | 17 | use crate::pac::usart::{regs, vals}; |
| 18 | 18 | ||
| 19 | pub struct Uart<'d, T: Instance, TxDma = NoDma, RxDma = NoDma> { | 19 | pub struct Uart<'d, T: Instance, TxDma = NoDma, RxDma = NoDma> { |
| @@ -43,8 +43,8 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 43 | let r = inner.regs(); | 43 | let r = inner.regs(); |
| 44 | 44 | ||
| 45 | unsafe { | 45 | unsafe { |
| 46 | rx.set_as_af(rx.af_num(), OpenDrain); | 46 | rx.set_as_af(rx.af_num(), OutputOpenDrain); |
| 47 | tx.set_as_af(tx.af_num(), PushPull); | 47 | tx.set_as_af(tx.af_num(), OutputPushPull); |
| 48 | 48 | ||
| 49 | r.cr2().write(|_w| {}); | 49 | r.cr2().write(|_w| {}); |
| 50 | r.cr3().write(|_w| {}); | 50 | r.cr3().write(|_w| {}); |
