From 9b90fd478a93c4c09baafe3b2f9c9a57de05c46a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 3 Mar 2020 14:22:21 +0100 Subject: [PATCH] cpu/sam0_common: provide function to switch voltage regulator Add a fucntion to switch between LDO and Buck concerter to provide the internal CPU voltage. The Buck Converter is not compatible with internal fast oscillators (DFLL, DPLL) and requires an inductivity to be present on the board. --- cpu/sam0_common/include/periph_cpu_common.h | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index 9efb0e8aea..99bf1d0d70 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -392,6 +392,39 @@ static inline void sam0_cortexm_sleep(int deep) */ void gpio_disable_mux(gpio_t pin); +/** + * @brief Available voltage regulators on the supply controller. + */ +typedef enum { + SAM0_VREG_LDO, /*< LDO, always available but not very power efficient */ + SAM0_VREG_BUCK /*< Buck converter, efficient but may clash with internal + fast clock generators (see errata sheets) */ +} sam0_supc_t; + +/** + * @brief Switch the internal voltage regulator used for generating the + * internal MCU voltages. + * Available options are: + * + * - LDO: not very efficient, but will always work + * - BUCK converter: Most efficient, but incompatible with the + * use of DFLL or DPLL. + * Please refer to the errata sheet, further restrictions may + * apply depending on the MCU. + * + * @param[in] src + */ +static inline void sam0_set_voltage_regulator(sam0_supc_t src) +{ +#ifdef REG_SUPC_VREG + SUPC->VREG.bit.SEL = src; + while (!SUPC->STATUS.bit.VREGRDY) {} +#else + (void) src; + assert(0); +#endif +} + /** * @brief Returns the frequency of a GCLK provider. *