mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:32:45 +01:00
boards/hifive1* cpu/fe310: improve clock customization
This commit is contained in:
parent
b2c8270a40
commit
7acf81552a
@ -30,27 +30,60 @@ extern "C" {
|
||||
* @name Core Clock configuration
|
||||
* @{
|
||||
*/
|
||||
#define USE_CLOCK_HFXOSC_PLL (1)
|
||||
#define USE_CLOCK_HFXOSC (0)
|
||||
#define USE_CLOCK_HFROSC_PLL (0)
|
||||
#ifndef CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
#if IS_ACTIVE(CONFIG_USE_CLOCK_HFXOSC) || IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC_PLL) || \
|
||||
IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC)
|
||||
#define CONFIG_USE_CLOCK_HFXOSC_PLL (0)
|
||||
#else
|
||||
#define CONFIG_USE_CLOCK_HFXOSC_PLL (1) /* Use PLL clocked by HFXOSC by default */
|
||||
#endif
|
||||
#endif /* CONFIG_USE_CLOCK_HFXOSC_PLL */
|
||||
|
||||
#if USE_CLOCK_HFROSC_PLL && (USE_CLOCK_HFXOSC_PLL || USE_CLOCK_HFXOSC)
|
||||
#error "Cannot use HFROSC_PLL with HFXOSC based configurations"
|
||||
#ifndef CONFIG_USE_CLOCK_HFXOSC
|
||||
#define CONFIG_USE_CLOCK_HFXOSC (0)
|
||||
#endif /* CONFIG_USE_CLOCK_HFXOSC */
|
||||
|
||||
#ifndef CONFIG_USE_CLOCK_HFROSC_PLL
|
||||
#define CONFIG_USE_CLOCK_HFROSC_PLL (0)
|
||||
#endif /* CONFIG_USE_CLOCK_HFROSC_PLL */
|
||||
|
||||
#ifndef CONFIG_USE_CLOCK_HFROSC
|
||||
#define CONFIG_USE_CLOCK_HFROSC (0)
|
||||
#endif /* CONFIG_USE_CLOCK_HFROSC */
|
||||
|
||||
#if CONFIG_USE_CLOCK_HFXOSC_PLL && \
|
||||
(CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || CONFIG_USE_CLOCK_HFXOSC)
|
||||
#error "Cannot use HFXOSC_PLL with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if USE_CLOCK_HFXOSC_PLL && USE_CLOCK_HFXOSC
|
||||
#error "Cannot use HFXOSC with HFXOSC_PLL"
|
||||
#if CONFIG_USE_CLOCK_HFXOSC && \
|
||||
(CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || CONFIG_USE_CLOCK_HFXOSC_PLL)
|
||||
#error "Cannot use HFXOSC with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if USE_CLOCK_HFXOSC_PLL
|
||||
#define CLOCK_PLL_R (1) /* Divide input clock by 2, mandatory with HFXOSC */
|
||||
#define CLOCK_PLL_F (39) /* Multiply REFR by 80, e.g 2 * (39 + 1) */
|
||||
#define CLOCK_PLL_Q (1) /* Divide VCO by 2, e.g 2^1 */
|
||||
#define CLOCK_PLL_INPUT_CLOCK (16000000UL)
|
||||
#define CLOCK_PLL_REFR (CLOCK_PLL_INPUT_CLOCK / (CLOCK_PLL_R + 1))
|
||||
#define CLOCK_PLL_VCO (CLOCK_PLL_REFR * (2 * (CLOCK_PLL_F + 1)))
|
||||
#define CLOCK_PLL_OUT (CLOCK_PLL_VCO / (1 << CLOCK_PLL_Q))
|
||||
#define CLOCK_CORECLOCK (CLOCK_PLL_OUT) /* 320000000Hz with the values used above */
|
||||
#if CONFIG_USE_CLOCK_HFROSC_PLL && \
|
||||
(CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFROSC)
|
||||
#error "Cannot use HFROSC_PLL with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_CLOCK_HFROSC && \
|
||||
(CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFROSC_PLL)
|
||||
#error "Cannot use HFROSC with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
#define CONFIG_CLOCK_PLL_R (1) /* Divide input clock by 2, mandatory with HFXOSC */
|
||||
#ifndef CONFIG_CLOCK_PLL_F
|
||||
#define CONFIG_CLOCK_PLL_F (39) /* Multiply REFR by 80, e.g 2 * (39 + 1) */
|
||||
#endif
|
||||
#ifndef CONFIG_CLOCK_PLL_Q
|
||||
#define CONFIG_CLOCK_PLL_Q (1) /* Divide VCO by 2, e.g 2^1 */
|
||||
#endif
|
||||
#define CLOCK_PLL_INPUT_CLOCK (16000000UL)
|
||||
#define CLOCK_PLL_REFR (CLOCK_PLL_INPUT_CLOCK / (CONFIG_CLOCK_PLL_R + 1))
|
||||
#define CLOCK_PLL_VCO (CLOCK_PLL_REFR * (2 * (CONFIG_CLOCK_PLL_F + 1)))
|
||||
#define CLOCK_PLL_OUT (CLOCK_PLL_VCO / (1 << CONFIG_CLOCK_PLL_Q))
|
||||
#define CLOCK_CORECLOCK (CLOCK_PLL_OUT) /* 320000000Hz with the values used above */
|
||||
|
||||
/* Check PLL settings */
|
||||
#if CLOCK_PLL_REFR != 8000000
|
||||
@ -63,19 +96,28 @@ extern "C" {
|
||||
#error "PLL output frequency must be in the range [48MHz - 384MHz], check the CLOCK_PLL_Q value"
|
||||
#endif
|
||||
|
||||
#elif USE_CLOCK_HFXOSC
|
||||
#define CLOCK_CORECLOCK (16000000UL)
|
||||
#elif CONFIG_USE_CLOCK_HFXOSC
|
||||
#define CLOCK_CORECLOCK (16000000UL)
|
||||
|
||||
/*
|
||||
When using HFROSC input clock, the core clock cannot be computed from settings,
|
||||
call cpu_freq() to get the configured CPU frequency.
|
||||
*/
|
||||
#elif USE_CLOCK_HFROSC_PLL
|
||||
#define CLOCK_DESIRED_FREQUENCY (320000000UL)
|
||||
#elif CONFIG_USE_CLOCK_HFROSC_PLL
|
||||
#ifndef CONFIG_CLOCK_DESIRED_FREQUENCY
|
||||
#define CONFIG_CLOCK_DESIRED_FREQUENCY (320000000UL)
|
||||
#endif
|
||||
|
||||
#elif CONFIG_USE_CLOCK_HFROSC
|
||||
#ifndef CONFIG_CLOCK_HFROSC_TRIM
|
||||
#define CONFIG_CLOCK_HFROSC_TRIM (6) /* ~72000000Hz input freq */
|
||||
#endif
|
||||
#ifndef CONFIG_CLOCK_HFROSC_DIV
|
||||
#define CONFIG_CLOCK_HFROSC_DIV (1) /* Divide by 2 */
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define CLOCK_HFROSC_TRIM (6) /* ~72000000Hz input freq */
|
||||
#define CLOCK_HFROSC_DIV (1) /* Divide by 2 */
|
||||
#error "Invalid clock configuration"
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
|
@ -31,27 +31,60 @@ extern "C" {
|
||||
* @name Core Clock configuration
|
||||
* @{
|
||||
*/
|
||||
#define USE_CLOCK_HFXOSC_PLL (1)
|
||||
#define USE_CLOCK_HFXOSC (0)
|
||||
#define USE_CLOCK_HFROSC_PLL (0)
|
||||
#ifndef CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
#if IS_ACTIVE(CONFIG_USE_CLOCK_HFXOSC) || IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC_PLL) || \
|
||||
IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC)
|
||||
#define CONFIG_USE_CLOCK_HFXOSC_PLL (0)
|
||||
#else
|
||||
#define CONFIG_USE_CLOCK_HFXOSC_PLL (1) /* Use PLL clocked by HFXOSC by default */
|
||||
#endif
|
||||
#endif /* CONFIG_USE_CLOCK_HFXOSC_PLL */
|
||||
|
||||
#if USE_CLOCK_HFROSC_PLL && (USE_CLOCK_HFXOSC_PLL || USE_CLOCK_HFXOSC)
|
||||
#error "Cannot use HFROSC_PLL with HFXOSC based configurations"
|
||||
#ifndef CONFIG_USE_CLOCK_HFXOSC
|
||||
#define CONFIG_USE_CLOCK_HFXOSC (0)
|
||||
#endif /* CONFIG_USE_CLOCK_HFXOSC */
|
||||
|
||||
#ifndef CONFIG_USE_CLOCK_HFROSC_PLL
|
||||
#define CONFIG_USE_CLOCK_HFROSC_PLL (0)
|
||||
#endif /* CONFIG_USE_CLOCK_HFROSC_PLL */
|
||||
|
||||
#ifndef CONFIG_USE_CLOCK_HFROSC
|
||||
#define CONFIG_USE_CLOCK_HFROSC (0)
|
||||
#endif /* CONFIG_USE_CLOCK_HFROSC */
|
||||
|
||||
#if CONFIG_USE_CLOCK_HFXOSC_PLL && \
|
||||
(CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || CONFIG_USE_CLOCK_HFXOSC)
|
||||
#error "Cannot use HFXOSC_PLL with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if USE_CLOCK_HFXOSC_PLL && USE_CLOCK_HFXOSC
|
||||
#error "Cannot use HFXOSC with HFXOSC_PLL"
|
||||
#if CONFIG_USE_CLOCK_HFXOSC && \
|
||||
(CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || CONFIG_USE_CLOCK_HFXOSC_PLL)
|
||||
#error "Cannot use HFXOSC with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if USE_CLOCK_HFXOSC_PLL
|
||||
#define CLOCK_PLL_R (1) /* Divide input clock by 2, mandatory with HFXOSC */
|
||||
#define CLOCK_PLL_F (39) /* Multiply REFR by 80, e.g 2 * (39 + 1) */
|
||||
#define CLOCK_PLL_Q (1) /* Divide VCO by 2, e.g 2^1 */
|
||||
#define CLOCK_PLL_INPUT_CLOCK (16000000UL)
|
||||
#define CLOCK_PLL_REFR (CLOCK_PLL_INPUT_CLOCK / (CLOCK_PLL_R + 1))
|
||||
#define CLOCK_PLL_VCO (CLOCK_PLL_REFR * (2 * (CLOCK_PLL_F + 1)))
|
||||
#define CLOCK_PLL_OUT (CLOCK_PLL_VCO / (1 << CLOCK_PLL_Q))
|
||||
#define CLOCK_CORECLOCK (CLOCK_PLL_OUT) /* 320000000Hz with the values used above */
|
||||
#if CONFIG_USE_CLOCK_HFROSC_PLL && \
|
||||
(CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFROSC)
|
||||
#error "Cannot use HFROSC_PLL with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_CLOCK_HFROSC && \
|
||||
(CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFROSC_PLL)
|
||||
#error "Cannot use HFROSC with other clock configurations"
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
#define CONFIG_CLOCK_PLL_R (1) /* Divide input clock by 2, mandatory with HFXOSC */
|
||||
#ifndef CONFIG_CLOCK_PLL_F
|
||||
#define CONFIG_CLOCK_PLL_F (39) /* Multiply REFR by 80, e.g 2 * (39 + 1) */
|
||||
#endif
|
||||
#ifndef CONFIG_CLOCK_PLL_Q
|
||||
#define CONFIG_CLOCK_PLL_Q (1) /* Divide VCO by 2, e.g 2^1 */
|
||||
#endif
|
||||
#define CLOCK_PLL_INPUT_CLOCK (16000000UL)
|
||||
#define CLOCK_PLL_REFR (CLOCK_PLL_INPUT_CLOCK / (CONFIG_CLOCK_PLL_R + 1))
|
||||
#define CLOCK_PLL_VCO (CLOCK_PLL_REFR * (2 * (CONFIG_CLOCK_PLL_F + 1)))
|
||||
#define CLOCK_PLL_OUT (CLOCK_PLL_VCO / (1 << CONFIG_CLOCK_PLL_Q))
|
||||
#define CLOCK_CORECLOCK (CLOCK_PLL_OUT) /* 320000000Hz with the values used above */
|
||||
|
||||
/* Check PLL settings */
|
||||
#if CLOCK_PLL_REFR != 8000000
|
||||
@ -64,19 +97,28 @@ extern "C" {
|
||||
#error "PLL output frequency must be in the range [48MHz - 384MHz], check the CLOCK_PLL_Q value"
|
||||
#endif
|
||||
|
||||
#elif USE_CLOCK_HFXOSC
|
||||
#define CLOCK_CORECLOCK (16000000UL)
|
||||
#elif CONFIG_USE_CLOCK_HFXOSC
|
||||
#define CLOCK_CORECLOCK (16000000UL)
|
||||
|
||||
/*
|
||||
When using HFROSC input clock, the core clock cannot be computed from settings,
|
||||
call cpu_freq() to get the configured CPU frequency.
|
||||
*/
|
||||
#elif USE_CLOCK_HFROSC_PLL
|
||||
#define CLOCK_DESIRED_FREQUENCY (320000000UL)
|
||||
#elif CONFIG_USE_CLOCK_HFROSC_PLL
|
||||
#ifndef CONFIG_CLOCK_DESIRED_FREQUENCY
|
||||
#define CONFIG_CLOCK_DESIRED_FREQUENCY (320000000UL)
|
||||
#endif
|
||||
|
||||
#elif CONFIG_USE_CLOCK_HFROSC
|
||||
#ifndef CONFIG_CLOCK_HFROSC_TRIM
|
||||
#define CONFIG_CLOCK_HFROSC_TRIM (6) /* ~72000000Hz input freq */
|
||||
#endif
|
||||
#ifndef CONFIG_CLOCK_HFROSC_DIV
|
||||
#define CONFIG_CLOCK_HFROSC_DIV (1) /* Divide by 2 */
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define CLOCK_HFROSC_TRIM (6) /* ~72000000Hz input freq */
|
||||
#define CLOCK_HFROSC_DIV (1) /* Divide by 2 */
|
||||
#error "Invalid clock configuration"
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "vendor/prci_driver.h"
|
||||
|
||||
#if !(USE_CLOCK_HFXOSC || USE_CLOCK_HFXOSC_PLL)
|
||||
#if !(CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFXOSC_PLL)
|
||||
static uint32_t _cpu_frequency = 0;
|
||||
#endif
|
||||
|
||||
@ -41,7 +41,7 @@ void clock_init(void)
|
||||
PRCI_REG(PRCI_PLLCFG) &= ~PLL_SEL(PLL_SEL_PLL);
|
||||
}
|
||||
|
||||
#if USE_CLOCK_HFXOSC || USE_CLOCK_HFXOSC_PLL
|
||||
#if CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
/* Ensure HFXOSC is enabled */
|
||||
PRCI_REG(PRCI_HFXOSCCFG) = XOSC_EN(1);
|
||||
|
||||
@ -51,12 +51,12 @@ void clock_init(void)
|
||||
/* Select HFXOSC as reference frequency and bypass PLL */
|
||||
PRCI_REG(PRCI_PLLCFG) = PLL_REFSEL(PLL_REFSEL_HFXOSC) | PLL_BYPASS(1);
|
||||
|
||||
#if USE_CLOCK_HFXOSC_PLL
|
||||
#if CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
/* Divide final output frequency by 1 */
|
||||
PRCI_REG(PRCI_PLLDIV) = (PLL_FINAL_DIV_BY_1(1) | PLL_FINAL_DIV(0));
|
||||
|
||||
/* Configure PLL */
|
||||
PRCI_REG(PRCI_PLLCFG) |= PLL_R(CLOCK_PLL_R) | PLL_F(CLOCK_PLL_F) | PLL_Q(CLOCK_PLL_Q);
|
||||
PRCI_REG(PRCI_PLLCFG) |= PLL_R(CONFIG_CLOCK_PLL_R) | PLL_F(CONFIG_CLOCK_PLL_F) | PLL_Q(CONFIG_CLOCK_PLL_Q);
|
||||
|
||||
/* Disable PLL Bypass */
|
||||
PRCI_REG(PRCI_PLLCFG) &= ~PLL_BYPASS(1);
|
||||
@ -70,14 +70,14 @@ void clock_init(void)
|
||||
|
||||
/* Turn off the HFROSC */
|
||||
PRCI_REG(PRCI_HFROSCCFG) &= ~ROSC_EN(1);
|
||||
#elif USE_CLOCK_HFROSC_PLL
|
||||
PRCI_set_hfrosctrim_for_f_cpu(CLOCK_DESIRED_FREQUENCY, PRCI_FREQ_UNDERSHOOT);
|
||||
#elif CONFIG_USE_CLOCK_HFROSC_PLL
|
||||
PRCI_set_hfrosctrim_for_f_cpu(CONFIG_CLOCK_DESIRED_FREQUENCY, PRCI_FREQ_UNDERSHOOT);
|
||||
#else /* Clock HFROSC */
|
||||
/* Disable Bypass */
|
||||
PRCI_REG(PRCI_PLLCFG) &= ~PLL_BYPASS(1);
|
||||
|
||||
/* Configure trim and divider values of HFROSC */
|
||||
PRCI_REG(PRCI_HFROSCCFG) = (ROSC_DIV(CLOCK_HFROSC_DIV) | ROSC_TRIM(CLOCK_HFROSC_TRIM) | ROSC_EN(1));
|
||||
PRCI_REG(PRCI_HFROSCCFG) = (ROSC_DIV(CONFIG_CLOCK_HFROSC_DIV) | ROSC_TRIM(CONFIG_CLOCK_HFROSC_TRIM) | ROSC_EN(1));
|
||||
|
||||
/* Wait for HFROSC to be ready */
|
||||
while ((PRCI_REG(PRCI_HFROSCCFG) & ROSC_RDY(1)) == 0);
|
||||
@ -89,7 +89,7 @@ void clock_init(void)
|
||||
|
||||
uint32_t cpu_freq(void)
|
||||
{
|
||||
#if USE_CLOCK_HFXOSC || USE_CLOCK_HFXOSC_PLL
|
||||
#if CONFIG_USE_CLOCK_HFXOSC || CONFIG_USE_CLOCK_HFXOSC_PLL
|
||||
return CLOCK_CORECLOCK;
|
||||
#else /* Clock frequency with HFROSC cannot be determined precisely from
|
||||
settings */
|
||||
|
Loading…
Reference in New Issue
Block a user