Add OTG_HS support for STM32H7R/S

This commit is contained in:
Kevin
2024-09-15 02:44:16 +02:00
parent afd8a86962
commit 2f60d78ea3
7 changed files with 405 additions and 4 deletions

View File

@@ -584,6 +584,22 @@ impl<'d, const MAX_EP_COUNT: usize> Bus<'d, MAX_EP_COUNT> {
});
}
pub fn config_v5(&mut self) {
let r = self.instance.regs;
r.gccfg_v3().modify(|w| {
w.set_vbvaloven(true);
w.set_vbvaloval(true);
w.set_vbden(self.config.vbus_detection);
});
// Force B-peripheral session
r.gotgctl().modify(|w| {
w.set_vbvaloen(!self.config.vbus_detection);
w.set_bvaloval(true);
});
}
fn init(&mut self) {
let r = self.instance.regs;
let phy_type = self.instance.phy_type;

View File

@@ -186,6 +186,11 @@ impl Otg {
pub const fn gccfg_v2(self) -> Reg<regs::GccfgV2, RW> {
unsafe { Reg::from_ptr(self.ptr.add(0x38usize) as _) }
}
#[doc = "General core configuration register, for core_id 0x0000_5xxx"]
#[inline(always)]
pub const fn gccfg_v3(self) -> Reg<regs::GccfgV3, RW> {
unsafe { Reg::from_ptr(self.ptr.add(0x38usize) as _) }
}
#[doc = "Core ID register"]
#[inline(always)]
pub const fn cid(self) -> Reg<regs::Cid, RW> {
@@ -1831,6 +1836,172 @@ pub mod regs {
GccfgV2(0)
}
}
#[doc = "OTG general core configuration register."]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct GccfgV3(pub u32);
impl GccfgV3 {
#[doc = "Charger detection, result of the current mode (primary or secondary)."]
#[inline(always)]
pub const fn chgdet(&self) -> bool {
let val = (self.0 >> 0usize) & 0x01;
val != 0
}
#[doc = "Charger detection, result of the current mode (primary or secondary)."]
#[inline(always)]
pub fn set_chgdet(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize);
}
#[doc = "Single-Ended DP indicator This bit gives the voltage level on DP (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
#[inline(always)]
pub const fn fsvplus(&self) -> bool {
let val = (self.0 >> 1usize) & 0x01;
val != 0
}
#[doc = "Single-Ended DP indicator This bit gives the voltage level on DP (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
#[inline(always)]
pub fn set_fsvplus(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 1usize)) | (((val as u32) & 0x01) << 1usize);
}
#[doc = "Single-Ended DM indicator This bit gives the voltage level on DM (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
#[inline(always)]
pub const fn fsvminus(&self) -> bool {
let val = (self.0 >> 2usize) & 0x01;
val != 0
}
#[doc = "Single-Ended DM indicator This bit gives the voltage level on DM (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
#[inline(always)]
pub fn set_fsvminus(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 2usize)) | (((val as u32) & 0x01) << 2usize);
}
#[doc = "VBUS session indicator Indicates if VBUS is above VBUS session threshold."]
#[inline(always)]
pub const fn sessvld(&self) -> bool {
let val = (self.0 >> 3usize) & 0x01;
val != 0
}
#[doc = "VBUS session indicator Indicates if VBUS is above VBUS session threshold."]
#[inline(always)]
pub fn set_sessvld(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 3usize)) | (((val as u32) & 0x01) << 3usize);
}
#[doc = "Host CDP behavior enable."]
#[inline(always)]
pub const fn hcdpen(&self) -> bool {
let val = (self.0 >> 16usize) & 0x01;
val != 0
}
#[doc = "Host CDP behavior enable."]
#[inline(always)]
pub fn set_hcdpen(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 16usize)) | (((val as u32) & 0x01) << 16usize);
}
#[doc = "Host CDP port voltage detector enable on DP."]
#[inline(always)]
pub const fn hcdpdeten(&self) -> bool {
let val = (self.0 >> 17usize) & 0x01;
val != 0
}
#[doc = "Host CDP port voltage detector enable on DP."]
#[inline(always)]
pub fn set_hcdpdeten(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 17usize)) | (((val as u32) & 0x01) << 17usize);
}
#[doc = "Host CDP port Voltage source enable on DM."]
#[inline(always)]
pub const fn hvdmsrcen(&self) -> bool {
let val = (self.0 >> 18usize) & 0x01;
val != 0
}
#[doc = "Host CDP port Voltage source enable on DM."]
#[inline(always)]
pub fn set_hvdmsrcen(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 18usize)) | (((val as u32) & 0x01) << 18usize);
}
#[doc = "Data Contact Detection enable."]
#[inline(always)]
pub const fn dcden(&self) -> bool {
let val = (self.0 >> 19usize) & 0x01;
val != 0
}
#[doc = "Data Contact Detection enable."]
#[inline(always)]
pub fn set_dcden(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 19usize)) | (((val as u32) & 0x01) << 19usize);
}
#[doc = "Primary detection enable."]
#[inline(always)]
pub const fn pden(&self) -> bool {
let val = (self.0 >> 20usize) & 0x01;
val != 0
}
#[doc = "Primary detection enable."]
#[inline(always)]
pub fn set_pden(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 20usize)) | (((val as u32) & 0x01) << 20usize);
}
#[doc = "VBUS detection enable Enables VBUS Sensing Comparators in order to detect VBUS presence and/or perform OTG operation."]
#[inline(always)]
pub const fn vbden(&self) -> bool {
let val = (self.0 >> 21usize) & 0x01;
val != 0
}
#[doc = "VBUS detection enable Enables VBUS Sensing Comparators in order to detect VBUS presence and/or perform OTG operation."]
#[inline(always)]
pub fn set_vbden(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 21usize)) | (((val as u32) & 0x01) << 21usize);
}
#[doc = "Secondary detection enable."]
#[inline(always)]
pub const fn sden(&self) -> bool {
let val = (self.0 >> 22usize) & 0x01;
val != 0
}
#[doc = "Secondary detection enable."]
#[inline(always)]
pub fn set_sden(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 22usize)) | (((val as u32) & 0x01) << 22usize);
}
#[doc = "Software override value of the VBUS B-session detection."]
#[inline(always)]
pub const fn vbvaloval(&self) -> bool {
let val = (self.0 >> 23usize) & 0x01;
val != 0
}
#[doc = "Software override value of the VBUS B-session detection."]
#[inline(always)]
pub fn set_vbvaloval(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 23usize)) | (((val as u32) & 0x01) << 23usize);
}
#[doc = "Enables a software override of the VBUS B-session detection."]
#[inline(always)]
pub const fn vbvaloven(&self) -> bool {
let val = (self.0 >> 24usize) & 0x01;
val != 0
}
#[doc = "Enables a software override of the VBUS B-session detection."]
#[inline(always)]
pub fn set_vbvaloven(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 24usize)) | (((val as u32) & 0x01) << 24usize);
}
#[doc = "Force host mode pull-downs If the ID pin functions are enabled, the host mode pull-downs on DP and DM activate automatically. However, whenever that is not the case, yet host mode is required, this bit must be used to force the pull-downs active."]
#[inline(always)]
pub const fn forcehostpd(&self) -> bool {
let val = (self.0 >> 25usize) & 0x01;
val != 0
}
#[doc = "Force host mode pull-downs If the ID pin functions are enabled, the host mode pull-downs on DP and DM activate automatically. However, whenever that is not the case, yet host mode is required, this bit must be used to force the pull-downs active."]
#[inline(always)]
pub fn set_forcehostpd(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 25usize)) | (((val as u32) & 0x01) << 25usize);
}
}
impl Default for GccfgV3 {
#[inline(always)]
fn default() -> GccfgV3 {
GccfgV3(0)
}
}
#[doc = "I2C access register"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]