2019-05-18 20:06:16 +02:00
|
|
|
/*
|
2020-08-28 13:59:07 +02:00
|
|
|
* Copyright (C) 2018-2020 Inria
|
2019-05-18 20:06:16 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup boards_common_stm32
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2020-08-28 21:30:38 +02:00
|
|
|
* @brief Default STM32L0/STM32L1 clock configuration
|
2019-05-18 20:06:16 +02:00
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
*/
|
|
|
|
|
2020-08-28 21:30:38 +02:00
|
|
|
#ifndef L0L1_CFG_CLOCK_DEFAULT_H
|
|
|
|
#define L0L1_CFG_CLOCK_DEFAULT_H
|
2019-05-18 20:06:16 +02:00
|
|
|
|
|
|
|
#include "periph_cpu.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Clock system configuration
|
|
|
|
* @{
|
|
|
|
*/
|
2020-08-28 18:35:52 +02:00
|
|
|
/* Select the desired system clock source between PLL, HSE or HSI */
|
|
|
|
#ifndef CONFIG_USE_CLOCK_PLL
|
|
|
|
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSE) || IS_ACTIVE(CONFIG_USE_CLOCK_HSI) || \
|
|
|
|
IS_ACTIVE(CONFIG_USE_CLOCK_MSI)
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_USE_CLOCK_PLL 0
|
2020-08-28 18:35:52 +02:00
|
|
|
#else
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_USE_CLOCK_PLL 1 /* Use PLL by default */
|
2020-08-28 18:35:52 +02:00
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_USE_CLOCK_PLL */
|
|
|
|
|
|
|
|
#ifndef CONFIG_USE_CLOCK_MSI
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_USE_CLOCK_MSI 0
|
2020-08-28 18:35:52 +02:00
|
|
|
#endif /* CONFIG_USE_CLOCK_MSI */
|
|
|
|
|
|
|
|
#ifndef CONFIG_USE_CLOCK_HSE
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_USE_CLOCK_HSE 0
|
2020-08-28 18:35:52 +02:00
|
|
|
#endif /* CONFIG_USE_CLOCK_HSE */
|
|
|
|
|
|
|
|
#ifndef CONFIG_USE_CLOCK_HSI
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_USE_CLOCK_HSI 0
|
2020-08-28 18:35:52 +02:00
|
|
|
#endif /* CONFIG_USE_CLOCK_HSI */
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#if IS_ACTIVE(CONFIG_USE_CLOCK_PLL) && \
|
|
|
|
(IS_ACTIVE(CONFIG_USE_CLOCK_MSI) || IS_ACTIVE(CONFIG_USE_CLOCK_HSE) || \
|
|
|
|
IS_ACTIVE(CONFIG_USE_CLOCK_HSI))
|
2020-08-28 18:35:52 +02:00
|
|
|
#error "Cannot use PLL as clock source with other clock configurations"
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#if IS_ACTIVE(CONFIG_USE_CLOCK_MSI) && \
|
|
|
|
(IS_ACTIVE(CONFIG_USE_CLOCK_PLL) || IS_ACTIVE(CONFIG_USE_CLOCK_HSE) || \
|
|
|
|
IS_ACTIVE(CONFIG_USE_CLOCK_HSI))
|
2020-08-28 18:35:52 +02:00
|
|
|
#error "Cannot use MSI as clock source with other clock configurations"
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSE) && \
|
|
|
|
(IS_ACTIVE(CONFIG_USE_CLOCK_PLL) || IS_ACTIVE(CONFIG_USE_CLOCK_MSI) || \
|
|
|
|
IS_ACTIVE(CONFIG_USE_CLOCK_HSI))
|
2020-08-28 18:35:52 +02:00
|
|
|
#error "Cannot use HSE as clock source with other clock configurations"
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI) && \
|
|
|
|
(IS_ACTIVE(CONFIG_USE_CLOCK_PLL) || IS_ACTIVE(CONFIG_USE_CLOCK_MSI) || \
|
|
|
|
IS_ACTIVE(CONFIG_USE_CLOCK_HSE))
|
2020-08-28 18:35:52 +02:00
|
|
|
#error "Cannot use HSI as clock source with other clock configurations"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_BOARD_HAS_HSE
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_BOARD_HAS_HSE 0
|
2020-08-28 18:35:52 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CLOCK_HSE
|
|
|
|
#define CLOCK_HSE MHZ(24)
|
|
|
|
#endif
|
2020-09-04 09:17:40 +02:00
|
|
|
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CLOCK_HSE < MHZ(1) || CLOCK_HSE > MHZ(24))
|
2020-08-28 18:35:52 +02:00
|
|
|
#error "HSE clock frequency must be between 1MHz and 24MHz"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_BOARD_HAS_LSE
|
2020-09-04 09:17:40 +02:00
|
|
|
#define CONFIG_BOARD_HAS_LSE 0
|
2020-08-28 18:35:52 +02:00
|
|
|
#endif
|
2020-09-04 09:17:40 +02:00
|
|
|
#if IS_ACTIVE(CONFIG_BOARD_HAS_LSE)
|
2020-08-28 18:35:52 +02:00
|
|
|
#define CLOCK_LSE (1)
|
|
|
|
#else
|
|
|
|
#define CLOCK_LSE (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CLOCK_HSI MHZ(16)
|
|
|
|
|
2020-08-28 21:30:38 +02:00
|
|
|
#ifndef CONFIG_CLOCK_MSI
|
|
|
|
#define CONFIG_CLOCK_MSI KHZ(4194)
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
/* The following parameters configure a 32MHz system clock with HSI as input clock */
|
|
|
|
#ifndef CONFIG_CLOCK_PLL_DIV
|
|
|
|
#define CONFIG_CLOCK_PLL_DIV (2)
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_CLOCK_PLL_MUL
|
|
|
|
#define CONFIG_CLOCK_PLL_MUL (4)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
|
2020-08-28 18:35:52 +02:00
|
|
|
#define CLOCK_CORECLOCK (CLOCK_HSI)
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
|
|
|
|
#if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
|
2020-08-28 18:35:52 +02:00
|
|
|
#error "The board doesn't provide an HSE oscillator"
|
|
|
|
#endif
|
|
|
|
#define CLOCK_CORECLOCK (CLOCK_HSE)
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#elif IS_ACTIVE(CONFIG_USE_CLOCK_MSI)
|
2020-08-28 18:35:52 +02:00
|
|
|
#define CLOCK_CORECLOCK (CONFIG_CLOCK_MSI)
|
|
|
|
|
2020-09-04 09:17:40 +02:00
|
|
|
#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
|
|
|
|
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
|
2020-08-28 18:35:52 +02:00
|
|
|
#if CLOCK_HSE < MHZ(2)
|
|
|
|
#error "HSE must be greater than 2MHz when used as PLL input clock"
|
|
|
|
#endif
|
|
|
|
#define CLOCK_PLL_SRC (CLOCK_HSE)
|
|
|
|
#else /* CLOCK_HSI */
|
|
|
|
#define CLOCK_PLL_SRC (CLOCK_HSI)
|
|
|
|
#endif /* CONFIG_BOARD_HAS_HSE */
|
2020-08-28 21:30:38 +02:00
|
|
|
/* PLL configuration: make sure your values are legit!
|
|
|
|
*
|
|
|
|
* compute by: CORECLOCK = ((PLL_IN / PLL_PREDIV) * PLL_MUL)
|
|
|
|
* with:
|
|
|
|
* PLL_IN: input clock is HSE if available or HSI otherwise
|
2020-09-04 09:17:40 +02:00
|
|
|
* PLL_DIV : divider, allowed values: 2, 3, 4. Default is 2.
|
|
|
|
* PLL_MUL: multiplier, allowed values: 3, 4, 6, 8, 12, 16, 24, 32, 48. Default is 4.
|
|
|
|
* CORECLOCK -> 32MHz MAX!
|
2020-08-28 21:30:38 +02:00
|
|
|
*/
|
2020-08-28 18:35:52 +02:00
|
|
|
#define CLOCK_CORECLOCK ((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_DIV) * CONFIG_CLOCK_PLL_MUL)
|
|
|
|
#if CLOCK_CORECLOCK > MHZ(32)
|
|
|
|
#error "SYSCLK cannot exceed 32MHz"
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_USE_CLOCK_PLL */
|
|
|
|
|
|
|
|
#define CLOCK_AHB CLOCK_CORECLOCK /* max: 32MHz */
|
|
|
|
|
|
|
|
#ifndef CONFIG_CLOCK_APB1_DIV
|
|
|
|
#define CONFIG_CLOCK_APB1_DIV (1)
|
|
|
|
#endif
|
|
|
|
#define CLOCK_APB1 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB1_DIV) /* max: 32MHz */
|
|
|
|
#ifndef CONFIG_CLOCK_APB2_DIV
|
|
|
|
#define CONFIG_CLOCK_APB2_DIV (1)
|
|
|
|
#endif
|
2020-08-28 21:30:38 +02:00
|
|
|
#define CLOCK_APB2 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB2_DIV) /* max: 32MHz */
|
2019-05-18 20:06:16 +02:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-28 21:30:38 +02:00
|
|
|
#endif /* L0L1_CFG_CLOCK_DEFAULT_H */
|
2019-05-18 20:06:16 +02:00
|
|
|
/** @} */
|