diff --git a/arch/arm/src/nrf53/Kconfig b/arch/arm/src/nrf53/Kconfig index 25943e257f..4e472c1aae 100644 --- a/arch/arm/src/nrf53/Kconfig +++ b/arch/arm/src/nrf53/Kconfig @@ -87,3 +87,48 @@ config NRF53_UART1 select NRF53_UART endmenu # NRF53 Peripheral Selection + +menu "Clock Configuration" + +config NRF53_HFCLK_XTAL + bool "Enable HFCLK from external crystal" + default n + ---help--- + If the board includes an external high-frequency crystal, enable this + option to supply the HFCLK. If this option is disabled, the internal + oscillator will be used. + Note that the RADIO peripheral requires the HFCLK to be used. + +config NRF53_USE_LFCLK + bool "Enable LFCLK" + default n + ---help--- + Enable low-frequency clock. + +if NRF53_USE_LFCLK + +choice + prompt "LFCLK source" + default NRF53_LFCLK_XTAL + +config NRF53_LFCLK_XTAL + bool "External 32.768Khz crystal" + +config NRF53_LFCLK_RC + bool "Internal RC oscillator" + +config NRF53_LFCLK_SYNTH + bool "Synthesized from HFCLK" + +endchoice + +endif # NRF53_USE_LFCLK + +config NRF53_OSCILLATOR_LFXO + bool "Configure LFXO oscillator" + default y if NRF53_LFCLK_XTAL + depends on NRF53_APPCORE + ---help--- + Configure LFXO oscillator + +endmenu # Clock Configuration \ No newline at end of file diff --git a/arch/arm/src/nrf53/Make.defs b/arch/arm/src/nrf53/Make.defs index ae08ce82cb..9502da0c45 100644 --- a/arch/arm/src/nrf53/Make.defs +++ b/arch/arm/src/nrf53/Make.defs @@ -24,6 +24,10 @@ CHIP_CSRCS += nrf53_systick.c CHIP_CSRCS += nrf53_start.c nrf53_clockconfig.c nrf53_irq.c nrf53_utils.c CHIP_CSRCS += nrf53_allocateheap.c nrf53_lowputc.c nrf53_gpio.c +ifeq ($(CONFIG_NRF53_APPCORE),y) +CHIP_CSRCS += nrf53_oscconfig.c +endif + ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) CHIP_CSRCS += nrf53_idle.c endif diff --git a/arch/arm/src/nrf53/nrf53_clockconfig.c b/arch/arm/src/nrf53/nrf53_clockconfig.c index 46b4ba1d97..2ce7ff1871 100644 --- a/arch/arm/src/nrf53/nrf53_clockconfig.c +++ b/arch/arm/src/nrf53/nrf53_clockconfig.c @@ -32,6 +32,17 @@ #include "arm_internal.h" #include "nrf53_clockconfig.h" +#include "hardware/nrf53_clock.h" +#include "hardware/nrf53_power.h" +#include "hardware/nrf53_gpio.h" + +#ifdef CONFIG_NRF53_APPCORE +# include "nrf53_oscconfig.h" +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ /**************************************************************************** * Public Functions @@ -50,5 +61,47 @@ void nrf53_clockconfig(void) { - /* TODO */ +#ifdef CONFIG_NRF53_APPCORE + /* Configure oscillators */ + + nrf53_oscconfig(); +#endif + +#ifdef CONFIG_NRF53_HFCLK_XTAL + /* Initialize HFCLK crystal oscillator */ + + putreg32(0x0, NRF53_CLOCK_EVENTS_HFCLKSTARTED); + putreg32(0x1, NRF53_CLOCK_TASKS_HFCLKSTART); + + while (!getreg32(NRF53_CLOCK_EVENTS_HFCLKSTARTED)) + { + /* wait for external oscillator to start */ + } +#endif + +#ifdef CONFIG_NRF53_USE_LFCLK + /* Initialize LFCLK */ + +#if defined(CONFIG_NRF53_LFCLK_XTAL) + putreg32(CLOCK_LFCLKSRC_SRC_LFXO, NRF53_CLOCK_LFCLKSRC); +#elif defined(CONFIG_NRF53_LFCLK_SYNTH) + putreg32(CLOCK_LFCLKSRC_SRC_LFSYNT, NRF53_CLOCK_LFCLKSRC); +#else + putreg32(CLOCK_LFCLKSRC_SRC_LFRC, NRF53_CLOCK_LFCLKSRC); +#endif + + /* Trigger LFCLK start */ + + putreg32(0x0, NRF53_CLOCK_EVENTS_LFCLKSTARTED); + putreg32(0x1, NRF53_CLOCK_TASKS_LFCLKSTART); + + while (!getreg32(NRF53_CLOCK_EVENTS_LFCLKSTARTED)) + { + /* Wait for LFCLK to be running */ + } + +#if defined(CONFIG_NRF53_LFCLK_RC) + /* TODO: calibrate LFCLK RC oscillator */ +#endif +#endif } diff --git a/arch/arm/src/nrf53/nrf53_oscconfig.c b/arch/arm/src/nrf53/nrf53_oscconfig.c new file mode 100644 index 0000000000..c4c9a5ace6 --- /dev/null +++ b/arch/arm/src/nrf53/nrf53_oscconfig.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * arch/arm/src/nrf53/nrf53_oscconfig.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "arm_internal.h" +#include "nrf53_oscconfig.h" +#include "nrf53_gpio.h" +#include "hardware/nrf53_osc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_NRF53_NETCORE +# error Oscillators configuration availalbe only for the App core +#endif + +/* LFXO pins */ + +#define LFXO_XL1_GPIO_PIN (GPIO_MCUSEL_PERIP | GPIO_PORT0 | GPIO_PIN(0)) +#define LFXO_XL2_GPIO_PIN (GPIO_MCUSEL_PERIP | GPIO_PORT0 | GPIO_PIN(1)) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_oscconfig + ****************************************************************************/ + +void nrf53_oscconfig(void) +{ +#ifdef CONFIG_NRF53_OSCILLATOR_LFXO + /* Configure LFXO pins */ + + nrf53_gpio_config(LFXO_XL1_GPIO_PIN); + nrf53_gpio_config(LFXO_XL2_GPIO_PIN); + + /* Configure internal capacitors for LFXO */ + + putreg32(BOARD_OSC_XOSC32KI_INTCAP, NRF53_OSC_XOSC32KI_INTCAP); +#endif + +#ifdef CONFIG_NRF53_HFCLK_XTAL +# warning TODO: missing HFCLK XTAL oscillator config +#endif +} diff --git a/arch/arm/src/nrf53/nrf53_oscconfig.h b/arch/arm/src/nrf53/nrf53_oscconfig.h new file mode 100644 index 0000000000..893fcc1865 --- /dev/null +++ b/arch/arm/src/nrf53/nrf53_oscconfig.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * arch/arm/src/nrf53/nrf53_oscconfig.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_NRF53_NRF53_OSCCONFIG_H +#define __ARCH_ARM_SRC_NRF53_NRF53_OSCCONFIG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_oscconfig + ****************************************************************************/ + +void nrf53_oscconfig(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_NRF53_NRF53_OSCCONFIG_H */ diff --git a/boards/arm/nrf53/nrf5340-dk/include/board.h b/boards/arm/nrf53/nrf5340-dk/include/board.h index 9fab435bd9..a6d8b65ee5 100644 --- a/boards/arm/nrf53/nrf5340-dk/include/board.h +++ b/boards/arm/nrf53/nrf5340-dk/include/board.h @@ -32,6 +32,8 @@ # include #endif +#include "hardware/nrf53_osc.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -39,6 +41,7 @@ /* Clocking *****************************************************************/ #define BOARD_SYSTICK_CLOCK (64000000) +#define BOARD_OSC_XOSC32KI_INTCAP (OSC_XOSC32KI_INTCAP_C7PF) /* LED definitions **********************************************************/