Loading...
Searching...
No Matches
cfg_clock_default.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Inria
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
23#ifndef CLK_G0G4_CFG_CLOCK_DEFAULT_H
24#define CLK_G0G4_CFG_CLOCK_DEFAULT_H
25
27#include "kernel_defines.h"
28#include "macros/units.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
39#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(4) || CONFIG_CLOCK_HSE > MHZ(48))
40#error "HSE clock frequency must be between 4MHz and 48MHz"
41#endif
42
43#ifdef CPU_FAM_STM32G0
44#ifndef CONFIG_CLOCK_HSISYS_DIV
45#define CONFIG_CLOCK_HSISYS_DIV (1)
46#endif
47#endif
48
49#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
50#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
51#else /* CONFIG_CLOCK_HSI */
52#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
53#endif
54
55/* The following parameters configure a 64MHz system clock with HSI as input clock */
56#ifndef CONFIG_CLOCK_PLL_M
57#ifdef CPU_FAM_STM32G0
58#define CONFIG_CLOCK_PLL_M (1)
59#else
60#define CONFIG_CLOCK_PLL_M (4)
61#endif
62#endif
63#ifndef CONFIG_CLOCK_PLL_N
64#ifdef CPU_FAM_STM32G0
65#define CONFIG_CLOCK_PLL_N (20)
66#else
67#define CONFIG_CLOCK_PLL_N (85)
68#endif
69#endif
70#ifndef CONFIG_CLOCK_PLL_R
71#ifdef CPU_FAM_STM32G0
72#define CONFIG_CLOCK_PLL_R (5)
73#else
74#define CONFIG_CLOCK_PLL_R (2)
75#endif
76#endif
77
78#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
79#ifdef CPU_FAM_STM32G0
80#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI / CONFIG_CLOCK_HSISYS_DIV)
81#else
82#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
83#endif
84
85#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
86#if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
87#error "The board doesn't provide an HSE oscillator"
88#endif
89#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
90
91#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
92#define CLOCK_CORECLOCK \
93 ((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_R
94#ifdef CPU_FAM_STM32G0
95#if CLOCK_CORECLOCK > MHZ(64)
96#error "SYSCLK cannot exceed 64MHz"
97#endif
98#else /* CPU_FAM_STM32G4 */
99#if CLOCK_CORECLOCK > MHZ(170)
100#error "SYSCLK cannot exceed 170MHz"
101#endif
102#endif
103#endif /* CONFIG_USE_CLOCK_PLL */
104
105#define CLOCK_AHB CLOCK_CORECLOCK /* max: 64MHz (G0), 170MHZ (G4) */
106
107#ifndef CONFIG_CLOCK_APB1_DIV
108#define CONFIG_CLOCK_APB1_DIV (1)
109#endif
110#define CLOCK_APB1 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB1_DIV) /* max: 64MHz (G0), 170MHZ (G4) */
111#ifdef CPU_FAM_STM32G4
112#ifndef CONFIG_CLOCK_APB2_DIV
113#define CONFIG_CLOCK_APB2_DIV (1)
114#endif
115#define CLOCK_APB2 (CLOCK_AHB / CONFIG_CLOCK_APB2_DIV) /* max: 170MHz (only on G4) */
116#endif
119#ifdef __cplusplus
120}
121#endif
122
123#endif /* CLK_G0G4_CFG_CLOCK_DEFAULT_H */
Base STM32Fx/Gx/MP1/C0 clock configuration.
Common macros and compiler attributes/pragmas configuration.
Unit helper macros.