cfg_clock_default.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 Inria
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
23 #include "kernel_defines.h"
24 #include "macros/units.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
35 #if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(4) || CONFIG_CLOCK_HSE > MHZ(48))
36 #error "HSE clock frequency must be between 4MHz and 48MHz"
37 #endif
38 
39 #ifdef CPU_FAM_STM32G0
40 #ifndef CONFIG_CLOCK_HSISYS_DIV
41 #define CONFIG_CLOCK_HSISYS_DIV (1)
42 #endif
43 #endif
44 
45 #if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
46 #define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
47 #else /* CONFIG_CLOCK_HSI */
48 #define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
49 #endif
50 
51 /* The following parameters configure a 64MHz system clock with HSI as input clock */
52 #ifndef CONFIG_CLOCK_PLL_M
53 #ifdef CPU_FAM_STM32G0
54 #define CONFIG_CLOCK_PLL_M (1)
55 #else
56 #define CONFIG_CLOCK_PLL_M (4)
57 #endif
58 #endif
59 #ifndef CONFIG_CLOCK_PLL_N
60 #ifdef CPU_FAM_STM32G0
61 #define CONFIG_CLOCK_PLL_N (20)
62 #else
63 #define CONFIG_CLOCK_PLL_N (85)
64 #endif
65 #endif
66 #ifndef CONFIG_CLOCK_PLL_R
67 #ifdef CPU_FAM_STM32G0
68 #define CONFIG_CLOCK_PLL_R (5)
69 #else
70 #define CONFIG_CLOCK_PLL_R (2)
71 #endif
72 #endif
73 
74 #if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
75 #ifdef CPU_FAM_STM32G0
76 #define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI / CONFIG_CLOCK_HSISYS_DIV)
77 #else
78 #define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
79 #endif
80 
81 #elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
82 #if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
83 #error "The board doesn't provide an HSE oscillator"
84 #endif
85 #define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
86 
87 #elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
88 #define CLOCK_CORECLOCK \
89  ((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_R
90 #ifdef CPU_FAM_STM32G0
91 #if CLOCK_CORECLOCK > MHZ(64)
92 #error "SYSCLK cannot exceed 64MHz"
93 #endif
94 #else /* CPU_FAM_STM32G4 */
95 #if CLOCK_CORECLOCK > MHZ(170)
96 #error "SYSCLK cannot exceed 170MHz"
97 #endif
98 #endif
99 #endif /* CONFIG_USE_CLOCK_PLL */
100 
101 #define CLOCK_AHB CLOCK_CORECLOCK /* max: 64MHz (G0), 170MHZ (G4) */
102 
103 #ifndef CONFIG_CLOCK_APB1_DIV
104 #define CONFIG_CLOCK_APB1_DIV (1)
105 #endif
106 #define CLOCK_APB1 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB1_DIV) /* max: 64MHz (G0), 170MHZ (G4) */
107 #ifdef CPU_FAM_STM32G4
108 #ifndef CONFIG_CLOCK_APB2_DIV
109 #define CONFIG_CLOCK_APB2_DIV (1)
110 #endif
111 #define CLOCK_APB2 (CLOCK_AHB / CONFIG_CLOCK_APB2_DIV) /* max: 170MHz (only on G4) */
112 #endif
115 #ifdef __cplusplus
116 }
117 #endif
118 
Base STM32Fx/Gx/MP1/C0 clock configuration.
Common macros and compiler attributes/pragmas configuration.
Unit helper macros.