cfg_clock_default.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Savoir-faire Linux
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
19 #ifndef CLK_MP1_CFG_CLOCK_DEFAULT_H
20 #define CLK_MP1_CFG_CLOCK_DEFAULT_H
21 
23 #include "kernel_defines.h"
24 #include "macros/units.h"
25 
30 /* The following parameters configure a 208MHz system clock with HSE (24MHz)
31  * or HSI (16MHz) as PLL input clock */
32 #ifndef CONFIG_CLOCK_PLL_M
33 #define CONFIG_CLOCK_PLL_M (2)
34 #endif
35 #if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE == MHZ(24))
36 #ifndef CONFIG_CLOCK_PLL_N
37 #define CONFIG_CLOCK_PLL_N (52)
38 #endif
39 #else /* HSI */
40 #ifndef CONFIG_CLOCK_PLL_N
41 #define CONFIG_CLOCK_PLL_N (78)
42 #endif
43 #endif
44 #ifndef CONFIG_CLOCK_PLL_P
45 #define CONFIG_CLOCK_PLL_P (3)
46 #endif
47 #ifndef CONFIG_CLOCK_PLL_Q
48 #define CONFIG_CLOCK_PLL_Q (13)
49 #endif
50 #ifndef CONFIG_CLOCK_PLL_R
51 #define CONFIG_CLOCK_PLL_R (3)
52 #endif
59 #ifndef CONFIG_CLOCK_MCU_DIV
60 #define CONFIG_CLOCK_MCU_DIV (1) /* max 208MHz */
61 #endif
62 #ifndef CONFIG_CLOCK_APB1_DIV
63 #define CONFIG_CLOCK_APB1_DIV (2) /* max 104MHz */
64 #endif
65 #ifndef CONFIG_CLOCK_APB2_DIV
66 #define CONFIG_CLOCK_APB2_DIV (2) /* max 104MHz */
67 #endif
68 #ifndef CONFIG_CLOCK_APB3_DIV
69 #define CONFIG_CLOCK_APB3_DIV (2) /* max 104MHz */
70 #endif
73 #if CLOCK_CORECLOCK > MHZ(208)
74 #error "SYSCLK cannot exceed 208MHz"
75 #endif
76 
81 #if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
82 #define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
83 #else /* CONFIG_CLOCK_HSI */
84 #define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
85 #endif
86 
87 #if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
88 #define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
89 
90 #elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
91 #if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
92 #error "The board doesn't provide an HSE oscillator"
93 #endif
94 #define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
95 
96 #elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
97 #define CLOCK_CORECLOCK (((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) \
98  * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_P)
99 #endif /* CONFIG_USE_CLOCK_PLL */
100 
101 #define CLOCK_PLLQ (((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) \
102  * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_Q)
103 
104 #define CLOCK_APB1 (CLOCK_CORECLOCK \
105  / CONFIG_CLOCK_APB1_DIV)
106 #define CLOCK_APB2 (CLOCK_CORECLOCK \
107  / CONFIG_CLOCK_APB2_DIV)
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* CLK_MP1_CFG_CLOCK_DEFAULT_H */
Base STM32Fx/Gx/MP1/C0 clock configuration.
Common macros and compiler attributes/pragmas configuration.
Unit helper macros.