aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjoerd Simons <[email protected]>2024-06-15 16:38:07 +0200
committerSjoerd Simons <[email protected]>2024-06-16 10:59:21 +0200
commit84cbf1d198d035471965232e89b4650c54edcfb1 (patch)
tree6a0b11d19a9d86caf0b7a3ddfa977880505cb2d3
parentc818125c22034dd15b8525b3d41219a566542cee (diff)
[UCPD] Don't disable ucpd rx after each reception
When disabling the UCPD RX after every reception it's relatively easy to drop packets. This seems to happen in particular with GoodCRC packets which can be sent very quickly by a receiver. To avoid this enable reception as soon as the pd phy get split out (preparing for packet processing) and only disable again when the pd phy gets dropped.
-rw-r--r--embassy-stm32/src/ucpd.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs
index 89e2f5d49..cbec85ff3 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
320impl<'d, T: Instance> Drop for PdPhy<'d, T> { 323impl<'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) {
@@ -350,9 +354,7 @@ impl<'d, T: Instance> PdPhy<'d, T> {
350 w.set_rxmsgendcf(true); 354 w.set_rxmsgendcf(true);
351 }); 355 });
352 356
353 r.cr().modify(|w| w.set_phyrxen(true));
354 let _on_drop = OnDrop::new(|| { 357 let _on_drop = OnDrop::new(|| {
355 r.cr().modify(|w| w.set_phyrxen(false));
356 Self::enable_rx_interrupt(false); 358 Self::enable_rx_interrupt(false);
357 }); 359 });
358 360