From 64f04e4da9e0e2d7abb28324576b682be07c3fe3 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Sat, 7 Mar 2020 17:04:06 +0100 Subject: [PATCH] nrf5x: Add built-in DC/DC converter enable function The internal DC/DC converter is more efficient compared to the LDO regulator. The downside of the DC/DC converter is that it requires an external inductor to be present on the board. Enabling the DC/DC converter is guarded with NRF5X_ENABLE_DCDC, this macro must be defined if the DC/DC converter is to be enabled. --- cpu/nrf51/cpu.c | 3 +++ cpu/nrf52/cpu.c | 3 +++ cpu/nrf5x_common/include/nrfx.h | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cpu/nrf51/cpu.c b/cpu/nrf51/cpu.c index 28210f9a6d..54b42952d4 100644 --- a/cpu/nrf51/cpu.c +++ b/cpu/nrf51/cpu.c @@ -19,6 +19,7 @@ #include "cpu.h" #include "nrf_clock.h" +#include "nrfx.h" #include "periph_conf.h" #include "periph/init.h" #include "stdio_base.h" @@ -30,6 +31,8 @@ void cpu_init(void) { /* initialize the Cortex-M core */ cortexm_init(); + /* Enable the DC/DC power converter */ + nrfx_dcdc_init(); /* setup the HF clock */ clock_init_hf(); /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ diff --git a/cpu/nrf52/cpu.c b/cpu/nrf52/cpu.c index a26554023b..2b0f2a6885 100644 --- a/cpu/nrf52/cpu.c +++ b/cpu/nrf52/cpu.c @@ -23,6 +23,7 @@ #define DONT_OVERRIDE_NVIC #include "cpu.h" +#include "nrfx.h" #include "nrf_clock.h" #include "periph_conf.h" #include "periph/init.h" @@ -61,6 +62,8 @@ void cpu_init(void) NRF_CLOCK->EVENTS_DONE = 0; NRF_CLOCK->EVENTS_CTTO = 0; } + /* Enable the DC/DC power converter */ + nrfx_dcdc_init(); /* initialize hf clock */ clock_init_hf(); diff --git a/cpu/nrf5x_common/include/nrfx.h b/cpu/nrf5x_common/include/nrfx.h index 67ee9eed2b..9a3a2519db 100644 --- a/cpu/nrf5x_common/include/nrfx.h +++ b/cpu/nrf5x_common/include/nrfx.h @@ -1,5 +1,7 @@ /* * Copyright (C) 2018 Freie Universität Berlin + * Copyright (C) 2020 Inria + * Copyright (C) 2020 Koen Zandberg * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -14,18 +16,34 @@ * @brief nrfx compatibility layer * * @author Hauke Petersen + * @author Koen Zandberg */ #ifndef NRFX_H #define NRFX_H #include "cpu_conf.h" +#include "periph_conf.h" #ifdef __cplusplus extern "C" { #endif -/* nothing else to do here */ +/** + * @brief Enable the internal DC/DC power converter for the NRF5x MCU. + * + * The internal DC/DC converter is more efficient compared to the LDO regulator. + * The downside of the DC/DC converter is that it requires an external inductor + * to be present on the board. Enabling the DC/DC converter is guarded with + * NRF5X_ENABLE_DCDC, this macro must be defined if the DC/DC converter is to be + * enabled. + */ +static inline void nrfx_dcdc_init(void) +{ +#ifdef NRF5X_ENABLE_DCDC + NRF_POWER->DCDCEN = 1; +#endif +} #ifdef __cplusplus }