stm32: add g4 adc345 and misc.

This commit is contained in:
xoviat 2023-09-11 17:12:54 -05:00
parent 1133cbf90e
commit b9889ad3b5
3 changed files with 37 additions and 7 deletions

View File

@ -58,7 +58,7 @@ sdio-host = "0.5.0"
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
critical-section = "1.1" critical-section = "1.1"
atomic-polyfill = "1.0.1" atomic-polyfill = "1.0.1"
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-e667107cf81934383ec5744f49b2cda0599ec749" } stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-4e6a74f69c4bc5d2d4872ba50d805e75bfe55cad" }
vcell = "0.1.3" vcell = "0.1.3"
bxcan = "0.7.0" bxcan = "0.7.0"
nb = "1.0.0" nb = "1.0.0"
@ -77,7 +77,7 @@ critical-section = { version = "1.1", features = ["std"] }
[build-dependencies] [build-dependencies]
proc-macro2 = "1.0.36" proc-macro2 = "1.0.36"
quote = "1.0.15" quote = "1.0.15"
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-e667107cf81934383ec5744f49b2cda0599ec749", default-features = false, features = ["metadata"]} stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-4e6a74f69c4bc5d2d4872ba50d805e75bfe55cad", default-features = false, features = ["metadata"]}
[features] [features]
default = ["rt"] default = ["rt"]

View File

@ -80,17 +80,21 @@ foreach_peripheral!(
#[cfg(any(stm32h7, adc_f3, adc_v4))] #[cfg(any(stm32h7, adc_f3, adc_v4))]
foreach_peripheral!( foreach_peripheral!(
(adc, ADC3) => { (adc, ADC3) => {
#[cfg(not(any(stm32g4x1, stm32g4x2, stm32g4x3, stm32g4x4)))]
impl crate::adc::sealed::Instance for peripherals::ADC3 { impl crate::adc::sealed::Instance for peripherals::ADC3 {
fn regs() -> crate::pac::adc::Adc { fn regs() -> crate::pac::adc::Adc {
crate::pac::ADC3 crate::pac::ADC3
} }
#[cfg(all(not(adc_f1), not(adc_v1)))] #[cfg(all(not(adc_f1), not(adc_v1)))]
#[allow(unreachable_code)]
fn common_regs() -> crate::pac::adccommon::AdcCommon { fn common_regs() -> crate::pac::adccommon::AdcCommon {
foreach_peripheral!{ foreach_peripheral!{
(adccommon, ADC3_COMMON) => { (adccommon, ADC3_COMMON) => {
return crate::pac::ADC3_COMMON return crate::pac::ADC3_COMMON
}; };
// Fall back to ADC_COMMON if ADC3_COMMON does not exist
(adccommon, ADC_COMMON) => {
return crate::pac::ADC_COMMON
};
} }
} }
@ -100,21 +104,24 @@ foreach_peripheral!(
} }
} }
#[cfg(not(any(stm32g4x1, stm32g4x2, stm32g4x3, stm32g4x4)))]
impl crate::adc::Instance for peripherals::ADC3 {} impl crate::adc::Instance for peripherals::ADC3 {}
}; };
(adc, ADC4) => { (adc, ADC4) => {
#[cfg(not(any(stm32g4x1, stm32g4x2, stm32g4x3, stm32g4x4)))]
impl crate::adc::sealed::Instance for peripherals::ADC4 { impl crate::adc::sealed::Instance for peripherals::ADC4 {
fn regs() -> crate::pac::adc::Adc { fn regs() -> crate::pac::adc::Adc {
crate::pac::ADC4 crate::pac::ADC4
} }
#[cfg(not(any(adc_f1, adc_v1)))] #[cfg(not(any(adc_f1, adc_v1)))]
#[allow(unreachable_code)]
fn common_regs() -> crate::pac::adccommon::AdcCommon { fn common_regs() -> crate::pac::adccommon::AdcCommon {
foreach_peripheral!{ foreach_peripheral!{
(adccommon, ADC3_COMMON) => { (adccommon, ADC3_COMMON) => {
return crate::pac::ADC3_COMMON return crate::pac::ADC3_COMMON
}; };
// Fall back to ADC_COMMON if ADC3_COMMON does not exist
(adccommon, ADC_COMMON) => {
return crate::pac::ADC_COMMON
};
} }
} }
@ -124,11 +131,34 @@ foreach_peripheral!(
} }
} }
#[cfg(not(any(stm32g4x1, stm32g4x2, stm32g4x3, stm32g4x4)))]
impl crate::adc::Instance for peripherals::ADC4 {} impl crate::adc::Instance for peripherals::ADC4 {}
}; };
(adc, ADC5) => { (adc, ADC5) => {
impl crate::adc::sealed::Instance for peripherals::ADC5 {
fn regs() -> crate::pac::adc::Adc {
crate::pac::ADC5
}
#[cfg(not(any(adc_f1, adc_v1)))]
#[allow(unreachable_code)]
fn common_regs() -> crate::pac::adccommon::AdcCommon {
foreach_peripheral!{
(adccommon, ADC3_COMMON) => {
return crate::pac::ADC3_COMMON
};
// Fall back to ADC_COMMON if ADC3_COMMON does not exist
(adccommon, ADC_COMMON) => {
return crate::pac::ADC_COMMON
};
}
}
#[cfg(adc_f3)]
fn frequency() -> crate::time::Hertz {
unsafe { crate::rcc::get_freqs() }.adc34.unwrap()
}
}
impl crate::adc::Instance for peripherals::ADC5 {}
}; };
(adc, $inst:ident) => { (adc, $inst:ident) => {
impl crate::adc::sealed::Instance for peripherals::$inst { impl crate::adc::sealed::Instance for peripherals::$inst {

View File

@ -102,7 +102,7 @@ where
let presc = Prescaler::from_pclk2(T::frequency()); let presc = Prescaler::from_pclk2(T::frequency());
T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre()));
T::regs().cr2().modify(|reg| { T::regs().cr2().modify(|reg| {
reg.set_adon(crate::pac::adc::vals::Adon::ENABLED); reg.set_adon(true);
}); });
delay.delay_us(ADC_POWERUP_TIME_US); delay.delay_us(ADC_POWERUP_TIME_US);