aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Esden-Tempski <[email protected]>2025-08-01 18:06:42 -0700
committerPiotr Esden-Tempski <[email protected]>2025-08-01 18:10:00 -0700
commit701e824175bf709f032e25fa991259582211b1d6 (patch)
tree239addf76636fade9f654e44caa7324163f5fa0b
parent0eceb08b90b1a7917db64ace80c3564d09394439 (diff)
ucpd: Add software trim setting of the CC Rp/Rd for stm32u5 parts.
-rw-r--r--embassy-stm32/src/ucpd.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs
index 87693f148..0a80adb8f 100644
--- a/embassy-stm32/src/ucpd.rs
+++ b/embassy-stm32/src/ucpd.rs
@@ -193,6 +193,18 @@ impl<'d, T: Instance> Ucpd<'d, T> {
193 }); 193 });
194 } 194 }
195 195
196 // Software trim according to RM0456, p. 3480/3462
197 #[cfg(stm32u5)]
198 {
199 let trim_rd_cc1 = unsafe { *(0x0BFA_0544 as *const u8) & 0xF };
200 let trim_rd_cc2 = unsafe { *(0x0BFA_0546 as *const u8) & 0xF };
201
202 r.cfgr3().write(|w| {
203 w.set_trim_cc1_rd(trim_rd_cc1);
204 w.set_trim_cc2_rd(trim_rd_cc2);
205 });
206 }
207
196 Self { 208 Self {
197 cc_phy: CcPhy { _lifetime: PhantomData }, 209 cc_phy: CcPhy { _lifetime: PhantomData },
198 } 210 }
@@ -314,6 +326,25 @@ impl<'d, T: Instance> CcPhy<'d, T> {
314 } 326 }
315 }); 327 });
316 328
329 // Software trim according to RM0456, p. 3480/3462
330 #[cfg(stm32u5)]
331 T::REGS.cfgr3().modify(|w| match cc_pull {
332 CcPull::Source1_5A => {
333 let trim_1a5_cc1 = unsafe { *(0x0BFA_07A7 as *const u8) & 0xF };
334 let trim_1a5_cc2 = unsafe { *(0x0BFA_07A8 as *const u8) & 0xF };
335
336 w.set_trim_cc1_rp(trim_1a5_cc1);
337 w.set_trim_cc2_rp(trim_1a5_cc2);
338 }
339 _ => {
340 let trim_3a0_cc1 = unsafe { *(0x0BFA_0545 as *const u8) & 0xF };
341 let trim_3a0_cc2 = unsafe { *(0x0BFA_0547 as *const u8) & 0xF };
342
343 w.set_trim_cc1_rp(trim_3a0_cc1);
344 w.set_trim_cc2_rp(trim_3a0_cc2);
345 }
346 });
347
317 // Disable dead-battery pull-down resistors which are enabled by default on boot. 348 // Disable dead-battery pull-down resistors which are enabled by default on boot.
318 critical_section::with(|cs| { 349 critical_section::with(|cs| {
319 init( 350 init(