Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
Loading...
Searching...
No Matches
cfg_clock_default.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2021 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
19
#ifndef CLK_U5_CFG_CLOCK_DEFAULT_H
20
#define CLK_U5_CFG_CLOCK_DEFAULT_H
21
22
#include "
cfg_clock_common_lx_u5_wx.h
"
23
#include "
kernel_defines.h
"
24
#include "
macros/units.h
"
25
26
#ifdef __cplusplus
27
extern
"C"
{
28
#endif
29
34
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(4) || CONFIG_CLOCK_HSE > MHZ(48))
35
#error "HSE clock frequency must be between 4MHz and 48MHz"
36
#endif
37
38
/* The following parameters configure a 80MHz system clock with PLL as input clock */
39
#ifndef CONFIG_CLOCK_PLL_SRC_MSI
40
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE) || IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSI) || \
41
IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
42
#define CONFIG_CLOCK_PLL_SRC_MSI 0
43
#else
44
#define CONFIG_CLOCK_PLL_SRC_MSI 1
/* Use MSI as input clock by default */
45
#endif
46
#endif
/* CONFIG_CLOCK_PLL_SRC_MSI */
47
#ifndef CONFIG_CLOCK_PLL_SRC_HSE
48
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && \
49
!IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSI) && !IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_MSI)
50
#define CONFIG_CLOCK_PLL_SRC_HSE 1
51
#else
52
#define CONFIG_CLOCK_PLL_SRC_HSE 0
53
#endif
54
#endif
55
#ifndef CONFIG_CLOCK_PLL_SRC_HSI
56
#define CONFIG_CLOCK_PLL_SRC_HSI 0
57
#endif
58
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_MSI)
59
#define CLOCK_PLL_SRC (CONFIG_CLOCK_MSI)
60
#elif IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE)
61
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
62
#else
/* CONFIG_CLOCK_PLL_SRC_ */
63
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
64
#endif
65
#ifndef CONFIG_CLOCK_PLL_M
66
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_MSI)
67
#define CONFIG_CLOCK_PLL_M (6)
/* MSI at 48MHz */
68
#else
69
#define CONFIG_CLOCK_PLL_M (2)
/* HSI/HSE at 16MHz */
70
#endif
71
#endif
72
#ifndef CONFIG_CLOCK_PLL_N
73
#define CONFIG_CLOCK_PLL_N (40)
74
#endif
75
#ifndef CONFIG_CLOCK_PLL_Q
76
#define CONFIG_CLOCK_PLL_Q (2)
77
#endif
78
#ifndef CONFIG_CLOCK_PLL_R
79
#define CONFIG_CLOCK_PLL_R (2)
80
#endif
81
82
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
83
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
84
85
#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
86
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
87
88
#elif IS_ACTIVE(CONFIG_USE_CLOCK_MSI)
89
#define CLOCK_CORECLOCK (CONFIG_CLOCK_MSI)
90
91
#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
92
/* PLL configuration: make sure your values are legit!
93
*
94
* compute by: CORECLOCK = (((PLL_IN / M) * N) / R)
95
* with:
96
* PLL_IN: input clock, HSE or MSI
97
* M: pre-divider, allowed range: [1:8]
98
* N: multiplier, allowed range: [5:512]
99
* R: post-divider, allowed range: [2:8]
100
*
101
* Also the following constraints need to be met:
102
* (PLL_IN / M) -> [4MHz:16MHz]
103
* (PLL_IN / M) * N -> [64MHz:344MHz]
104
* CORECLOCK -> 64MHz, 80MHZ or 120MHz MAX!
105
*/
106
#define CLOCK_CORECLOCK \
107
((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_R
108
109
/* Set max allowed sysclk */
110
#define CLOCK_CORECLOCK_MAX MHZ(160)
111
112
#if CLOCK_CORECLOCK > CLOCK_CORECLOCK_MAX
113
#error "SYSCLK cannot exceed 160MHz"
114
#endif
/* CLOCK_CORECLOCK > CLOCK_CORECLOCK_MAX */
115
#endif
/* CONFIG_USE_CLOCK_PLL */
116
117
#define CLOCK_AHB CLOCK_CORECLOCK
/* HCLK, max: 160MHz */
118
119
#ifndef CONFIG_CLOCK_APB1_DIV
120
#define CONFIG_CLOCK_APB1_DIV (4)
121
#endif
122
#define CLOCK_APB1 (CLOCK_AHB / CONFIG_CLOCK_APB1_DIV)
/* PCLK1, max: 160MHz */
123
#ifndef CONFIG_CLOCK_APB2_DIV
124
#define CONFIG_CLOCK_APB2_DIV (2)
125
#endif
126
#define CLOCK_APB2 (CLOCK_AHB / CONFIG_CLOCK_APB2_DIV)
/* PCLK1, max: 160MHz */
129
#ifdef __cplusplus
130
}
131
#endif
132
133
#endif
/* CLK_U5_CFG_CLOCK_DEFAULT_H */
cfg_clock_common_lx_u5_wx.h
Base STM32Lx/U5/Wx clock configuration.
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
units.h
Unit helper macros.
Generated on Sat Nov 23 2024 01:58:06 by
1.9.8