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) 2015 TriaGnoSys GmbH
3
* 2017 Alexander Kurth, Sören Tempel, Tristan Bruns
4
* 2020 Inria
5
*
6
* This file is subject to the terms and conditions of the GNU Lesser
7
* General Public License v2.1. See the file LICENSE in the top level
8
* directory for more details.
9
*/
10
26
#ifndef CLK_F0F1F3_CFG_CLOCK_DEFAULT_H
27
#define CLK_F0F1F3_CFG_CLOCK_DEFAULT_H
28
29
#include "
cfg_clock_common_fx_gx_mp1_c0.h
"
30
#include "
kernel_defines.h
"
31
#include "
macros/units.h
"
32
33
#ifdef __cplusplus
34
extern
"C"
{
35
#endif
36
41
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(4) || CONFIG_CLOCK_HSE > MHZ(32))
42
#error "HSE clock frequency must be between 4MHz and 32MHz"
43
#endif
44
45
/* The following parameters configure:
46
- on F0: a 48MHz system clock with HSI (or default HSE) as input clock
47
On stm32f031x6 and stm32f042x6 lines, there's no HSE and PREDIV is
48
hard-wired to 2, so to reach 48MHz set PLL_PREDIV to 2 and PLL_MUL to 12 so
49
system clock = (HSI8 / 2) * 12 = 48MHz
50
- on F1/F3: a 72MHz system clock with HSE (8MHz or 16MHz) and HSI (8MHz) as input clock
51
On stm32f303x6, stm32f303x8, stm32f303xB, stm32f303xC, stm32f328x8 and
52
stm32f358xC lines, PREDIV is hard-wired to 2 (see RM0316 p.126 to p.128).
53
To reach the maximum possible system clock (64MHz) set PLL_PREDIV to 2 and
54
PLL_MUL to 16, so system clock = (HSI8 / 2) * 16 = 64MHz
55
*/
56
#ifndef CONFIG_CLOCK_PLL_PREDIV
57
#if (IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE == MHZ(16))) || \
58
defined(CPU_LINE_STM32F303x6) || defined(CPU_LINE_STM32F303x8) || \
59
defined(CPU_LINE_STM32F303xB) || defined(CPU_LINE_STM32F303xC) || \
60
defined(CPU_LINE_STM32F328x8) || defined(CPU_LINE_STM32F358xC) || \
61
defined(CPU_LINE_STM32F031x6) || defined(CPU_LINE_STM32F042x6)
62
#define CONFIG_CLOCK_PLL_PREDIV (2)
63
#else
64
#define CONFIG_CLOCK_PLL_PREDIV (1)
65
#endif
66
#endif
67
#ifndef CONFIG_CLOCK_PLL_MUL
68
#ifdef CPU_FAM_STM32F0
69
#if defined(CPU_LINE_STM32F031x6) || defined(CPU_LINE_STM32F042x6)
70
#define CONFIG_CLOCK_PLL_MUL (12)
71
#else
72
#define CONFIG_CLOCK_PLL_MUL (6)
73
#endif
74
#else
/* CPU_FAM_F1 || CPU_FAM_F3 */
75
#if defined(CPU_LINE_STM32F303x6) || defined(CPU_LINE_STM32F303x8) || \
76
defined(CPU_LINE_STM32F303xB) || defined(CPU_LINE_STM32F303xC) || \
77
defined(CPU_LINE_STM32F328x8) || defined(CPU_LINE_STM32F358xC)
78
#define CONFIG_CLOCK_PLL_MUL (16)
79
#else
80
#define CONFIG_CLOCK_PLL_MUL (9)
81
#endif
82
#endif
/* CPU_FAM_STM32F0 */
83
#endif
/* CONFIG_CLOCK_PLL_MUL */
84
85
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
86
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
87
88
#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
89
#if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
90
#error "The board doesn't provide an HSE oscillator"
91
#endif
92
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
93
94
#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
95
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
96
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
97
#else
/* CONFIG_CLOCK_HSI */
98
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
99
#endif
100
/* PLL configuration: make sure your values are legit!
101
*
102
* compute by: CORECLOCK = ((PLL_IN / PLL_PREDIV) * PLL_MUL)
103
* with:
104
* PLL_IN: input clock is HSE if available or HSI otherwise
105
* PLL_PREDIV : pre-divider, allowed range: [1:16]
106
* PLL_MUL: multiplier, allowed range: [2:16]
107
* CORECLOCK -> 48MHz Max on F0, 72MHz MAX on F1/F3!
108
*/
109
#define CLOCK_CORECLOCK ((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_PREDIV) * CONFIG_CLOCK_PLL_MUL)
110
#ifdef CPU_FAM_STM32F0
111
#if CLOCK_CORECLOCK > MHZ(48)
112
#error "SYSCLK cannot exceed 48MHz"
113
#endif
114
#else
115
#if CLOCK_CORECLOCK > MHZ(72)
116
#error "SYSCLK cannot exceed 72MHz"
117
#endif
118
#endif
119
#endif
/* CONFIG_USE_CLOCK_PLL */
120
121
#define CLOCK_AHB CLOCK_CORECLOCK
/* HCLK, max: 48MHz (F0), 72MHz (F1/F3)*/
122
123
#ifndef CONFIG_CLOCK_APB1_DIV
124
#ifdef CPU_FAM_STM32F0
125
#define CONFIG_CLOCK_APB1_DIV (1)
126
#else
127
#define CONFIG_CLOCK_APB1_DIV (2)
128
#endif
129
#endif
130
#define CLOCK_APB1 (CLOCK_AHB / CONFIG_CLOCK_APB1_DIV)
/* PCLK1, max: 48MHz (F0), 36MHz (F1/F3)*/
131
#ifdef CPU_FAM_STM32F0
132
/* APB2 and APB1 are the same bus but configuration registers still follows the
133
* split between APB1 and APB2. Since it's the same bus, APB2 clock is equal to APB1 clock.
134
*/
135
#define CLOCK_APB2 (CLOCK_APB1)
136
#else
137
#ifndef CONFIG_CLOCK_APB2_DIV
138
#define CONFIG_CLOCK_APB2_DIV (1)
139
#endif
140
#define CLOCK_APB2 (CLOCK_AHB / CONFIG_CLOCK_APB2_DIV)
/* PCLK2, max: 72MHz */
141
#endif
144
#ifdef __cplusplus
145
}
146
#endif
147
148
#endif
/* CLK_F0F1F3_CFG_CLOCK_DEFAULT_H */
cfg_clock_common_fx_gx_mp1_c0.h
Base STM32Fx/Gx/MP1/C0 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