diff options
| -rw-r--r-- | embassy-stm32/src/ucpd.rs | 3 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/usb_c_pd.rs | 11 |
2 files changed, 12 insertions, 2 deletions
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index 02c81c2b6..071bfd1b1 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs | |||
| @@ -30,6 +30,7 @@ use crate::rcc::RccPeripheral; | |||
| 30 | 30 | ||
| 31 | /// Pull-up or Pull-down resistor state of both CC lines. | 31 | /// Pull-up or Pull-down resistor state of both CC lines. |
| 32 | #[derive(Debug, Clone, Copy, PartialEq)] | 32 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 33 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 33 | pub enum CcPull { | 34 | pub enum CcPull { |
| 34 | /// Analog PHY for CC pin disabled. | 35 | /// Analog PHY for CC pin disabled. |
| 35 | Disabled, | 36 | Disabled, |
| @@ -209,6 +210,7 @@ impl<'d, T: Instance> Ucpd<'d, T> { | |||
| 209 | 210 | ||
| 210 | /// Receive Error. | 211 | /// Receive Error. |
| 211 | #[derive(Debug, Clone, Copy)] | 212 | #[derive(Debug, Clone, Copy)] |
| 213 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 212 | pub enum RxError { | 214 | pub enum RxError { |
| 213 | /// Incorrect CRC or truncated message (a line becoming static before EOP is met). | 215 | /// Incorrect CRC or truncated message (a line becoming static before EOP is met). |
| 214 | Crc, | 216 | Crc, |
| @@ -219,6 +221,7 @@ pub enum RxError { | |||
| 219 | 221 | ||
| 220 | /// Transmit Error. | 222 | /// Transmit Error. |
| 221 | #[derive(Debug, Clone, Copy)] | 223 | #[derive(Debug, Clone, Copy)] |
| 224 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 222 | pub enum TxError { | 225 | pub enum TxError { |
| 223 | /// Concurrent receive in progress or excessive noise on the line. | 226 | /// Concurrent receive in progress or excessive noise on the line. |
| 224 | Discarded, | 227 | Discarded, |
diff --git a/examples/stm32g4/src/bin/usb_c_pd.rs b/examples/stm32g4/src/bin/usb_c_pd.rs index fd2400bd5..14abd542f 100644 --- a/examples/stm32g4/src/bin/usb_c_pd.rs +++ b/examples/stm32g4/src/bin/usb_c_pd.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use defmt::{info, Format}; | 4 | use defmt::{error, info, Format}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::ucpd::{self, CcPull, CcSel, CcVState, Ucpd}; | 6 | use embassy_stm32::ucpd::{self, CcPull, CcSel, CcVState, Ucpd}; |
| 7 | use embassy_stm32::Config; | 7 | use embassy_stm32::Config; |
| @@ -69,5 +69,12 @@ async fn main(_spawner: Spawner) { | |||
| 69 | }; | 69 | }; |
| 70 | let mut pd_phy = ucpd.pd_phy(p.DMA1_CH1, p.DMA1_CH2, cc_sel); | 70 | let mut pd_phy = ucpd.pd_phy(p.DMA1_CH1, p.DMA1_CH2, cc_sel); |
| 71 | 71 | ||
| 72 | loop {} | 72 | loop { |
| 73 | // Enough space for the longest non-extended data message. | ||
| 74 | let mut buf = [0_u8; 30]; | ||
| 75 | match pd_phy.receive(buf.as_mut()).await { | ||
| 76 | Ok(n) => info!("USB PD RX: {=[u8]:?}", &buf[..n]), | ||
| 77 | Err(e) => error!("USB PD RX: {}", e), | ||
| 78 | } | ||
| 79 | } | ||
| 73 | } | 80 | } |
