arch/nrf53: initial clock configuration

This commit is contained in:
raiden00pl 2023-03-05 13:15:40 +01:00 committed by Alan Carvalho de Assis
parent 15a932f8e1
commit 3b92819792
6 changed files with 242 additions and 1 deletions

View File

@ -87,3 +87,48 @@ config NRF53_UART1
select NRF53_UART select NRF53_UART
endmenu # NRF53 Peripheral Selection 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

View File

@ -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_start.c nrf53_clockconfig.c nrf53_irq.c nrf53_utils.c
CHIP_CSRCS += nrf53_allocateheap.c nrf53_lowputc.c nrf53_gpio.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) ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y)
CHIP_CSRCS += nrf53_idle.c CHIP_CSRCS += nrf53_idle.c
endif endif

View File

@ -32,6 +32,17 @@
#include "arm_internal.h" #include "arm_internal.h"
#include "nrf53_clockconfig.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 * Public Functions
@ -50,5 +61,47 @@
void nrf53_clockconfig(void) 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
} }

View File

@ -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 <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <arch/board/board.h>
#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
}

View File

@ -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 <nuttx/config.h>
#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 */

View File

@ -32,6 +32,8 @@
# include <nuttx/irq.h> # include <nuttx/irq.h>
#endif #endif
#include "hardware/nrf53_osc.h"
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
@ -39,6 +41,7 @@
/* Clocking *****************************************************************/ /* Clocking *****************************************************************/
#define BOARD_SYSTICK_CLOCK (64000000) #define BOARD_SYSTICK_CLOCK (64000000)
#define BOARD_OSC_XOSC32KI_INTCAP (OSC_XOSC32KI_INTCAP_C7PF)
/* LED definitions **********************************************************/ /* LED definitions **********************************************************/