From c5c46ba35b27bbf1eb88f6248e1cf273d70d6bdc Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sun, 13 Dec 2020 01:13:31 +0100 Subject: [PATCH] cpu/sam0_common: DAC: wait for DAC to be ready The DAC can have some start-up delay. If we try to write to it before it's ready, it will get stuck. This happens now that `tests/driver_dac_dds` immediately sets a DAC value after init. The samd2x class of MCUs doesn't have this bit, but a quick test on samd10 shows that it might not be nececary there - the DAC does not get stuck when writing to it immediately after init. --- cpu/sam0_common/periph/dac.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpu/sam0_common/periph/dac.c b/cpu/sam0_common/periph/dac.c index b333acc601..cd4ea10238 100644 --- a/cpu/sam0_common/periph/dac.c +++ b/cpu/sam0_common/periph/dac.c @@ -128,6 +128,12 @@ int8_t dac_init(dac_t line) DAC->CTRLA.bit.ENABLE = 1; _sync(); +#ifdef DAC_STATUS_READY + /* wait for DAC startup */ + const uint32_t mask = 1 << (DAC_STATUS_READY_Pos + line); + while (!(DAC->STATUS.reg & mask)) {} +#endif + return DAC_OK; }