From 5a38cc214079aed4c8778bd210c1ece2fe64fdf7 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 28 Sep 2021 20:56:19 -0400 Subject: [PATCH] stm32/dac: Ensure that clock is enabled --- embassy-stm32/src/dac/v2.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index f46145b8d..55a881d89 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs @@ -5,6 +5,17 @@ use core::marker::PhantomData; use embassy::util::Unborrow; use embassy_hal_common::unborrow; +/// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent DAC clock +/// configuration. +unsafe fn enable() { + #[cfg(rcc_h7)] + crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(true)); + #[cfg(rcc_g0)] + crate::pac::RCC.apbenr1().modify(|w| w.set_dac1en(true)); + #[cfg(rcc_l4)] + crate::pac::RCC.apb1enr1().modify(|w| w.set_dac1en(true)); +} + #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { @@ -91,6 +102,10 @@ impl<'d, T: Instance> Dac<'d, T> { ) -> Self { unborrow!(ch1, ch2); + unsafe { + enable(); + } + let ch1 = ch1.degrade_optional(); if ch1.is_some() { unsafe {