From 2a210c157bac6f802c74d8c460f7813a998ab00d Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Wed, 10 May 2023 08:43:46 +0200 Subject: [PATCH] cpu/stm32/periph_dac: support of DAC mode register If the DAC peripheral has a mode register (DAC_MCR), it is set to normal mode with buffer enabled and connected to external pin and on-chip peripherals. This allows to measure the current value of a DAC channel or to use the DAC channel also for other on-chip peripherals. --- cpu/stm32/periph/dac.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cpu/stm32/periph/dac.c b/cpu/stm32/periph/dac.c index 63b317ddf8..f03d8cf4d5 100644 --- a/cpu/stm32/periph/dac.c +++ b/cpu/stm32/periph/dac.c @@ -109,8 +109,14 @@ void dac_poweron(dac_t line) while (!(VREFBUF->CSR & VREFBUF_CSR_VRR)) { } #endif +#ifdef DAC_MCR_MODE1 + /* Normal mode with Buffer enabled and connected to external pin and on-chip + * peripherals */ + dev(line)->MCR |= (DAC_MCR_MODE1_0 << (16 * (dac_config[line].chan & 0x01))); +#endif + /* enable corresponding DAC channel */ - dev(line)->CR |= (1 << (16 * (dac_config[line].chan & 0x01))); + dev(line)->CR |= (DAC_CR_EN1 << (16 * (dac_config[line].chan & 0x01))); } void dac_poweroff(dac_t line) @@ -118,7 +124,7 @@ void dac_poweroff(dac_t line) assert(line < DAC_NUMOF); /* disable corresponding channel */ - dev(line)->CR &= ~(1 << (16 * (dac_config[line].chan & 0x01))); + dev(line)->CR &= ~(DAC_CR_EN1 << (16 * (dac_config[line].chan & 0x01))); /* disable the DAC's clock in case no channel is active anymore */ if (!(dev(line)->CR & EN_MASK)) {