diff options
| -rw-r--r-- | embassy-stm32/src/ucpd.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index 89e2f5d49..40aea75cb 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs | |||
| @@ -169,6 +169,9 @@ impl<'d, T: Instance> Ucpd<'d, T> { | |||
| 169 | // Enable hard reset receive interrupt. | 169 | // Enable hard reset receive interrupt. |
| 170 | r.imr().modify(|w| w.set_rxhrstdetie(true)); | 170 | r.imr().modify(|w| w.set_rxhrstdetie(true)); |
| 171 | 171 | ||
| 172 | // Enable PD packet reception | ||
| 173 | r.cr().modify(|w| w.set_phyrxen(true)); | ||
| 174 | |||
| 172 | // Both parts must be dropped before the peripheral can be disabled. | 175 | // Both parts must be dropped before the peripheral can be disabled. |
| 173 | T::state().drop_not_ready.store(true, Ordering::Relaxed); | 176 | T::state().drop_not_ready.store(true, Ordering::Relaxed); |
| 174 | 177 | ||
| @@ -319,6 +322,7 @@ pub struct PdPhy<'d, T: Instance> { | |||
| 319 | 322 | ||
| 320 | impl<'d, T: Instance> Drop for PdPhy<'d, T> { | 323 | impl<'d, T: Instance> Drop for PdPhy<'d, T> { |
| 321 | fn drop(&mut self) { | 324 | fn drop(&mut self) { |
| 325 | T::REGS.cr().modify(|w| w.set_phyrxen(false)); | ||
| 322 | // Check if the Type-C part was dropped already. | 326 | // Check if the Type-C part was dropped already. |
| 323 | let drop_not_ready = &T::state().drop_not_ready; | 327 | let drop_not_ready = &T::state().drop_not_ready; |
| 324 | if drop_not_ready.load(Ordering::Relaxed) { | 328 | if drop_not_ready.load(Ordering::Relaxed) { |
| @@ -343,17 +347,14 @@ impl<'d, T: Instance> PdPhy<'d, T> { | |||
| 343 | .read(r.rxdr().as_ptr() as *mut u8, buf, TransferOptions::default()) | 347 | .read(r.rxdr().as_ptr() as *mut u8, buf, TransferOptions::default()) |
| 344 | }; | 348 | }; |
| 345 | 349 | ||
| 346 | // Clear interrupt flags (possibly set from last receive). | ||
| 347 | r.icr().write(|w| { | ||
| 348 | w.set_rxorddetcf(true); | ||
| 349 | w.set_rxovrcf(true); | ||
| 350 | w.set_rxmsgendcf(true); | ||
| 351 | }); | ||
| 352 | |||
| 353 | r.cr().modify(|w| w.set_phyrxen(true)); | ||
| 354 | let _on_drop = OnDrop::new(|| { | 350 | let _on_drop = OnDrop::new(|| { |
| 355 | r.cr().modify(|w| w.set_phyrxen(false)); | ||
| 356 | Self::enable_rx_interrupt(false); | 351 | Self::enable_rx_interrupt(false); |
| 352 | // Clear interrupt flags | ||
| 353 | r.icr().write(|w| { | ||
| 354 | w.set_rxorddetcf(true); | ||
| 355 | w.set_rxovrcf(true); | ||
| 356 | w.set_rxmsgendcf(true); | ||
| 357 | }); | ||
| 357 | }); | 358 | }); |
| 358 | 359 | ||
| 359 | poll_fn(|cx| { | 360 | poll_fn(|cx| { |
