Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
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
9
#pragma once
10
25
#include "
cfg_clock_common_fx_gx_mp1_c0.h
"
26
#include "
kernel_defines.h
"
27
#include "
macros/units.h
"
28
29
#ifdef __cplusplus
30
extern
"C"
{
31
#endif
32
38
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(4) || CONFIG_CLOCK_HSE > MHZ(48))
39
#error "HSE clock frequency must be between 4MHz and 48MHz"
40
#endif
41
42
#ifdef CPU_FAM_STM32G0
43
#ifndef CONFIG_CLOCK_HSISYS_DIV
44
#define CONFIG_CLOCK_HSISYS_DIV (1)
45
#endif
46
#endif
47
48
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
49
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
50
#else
/* CONFIG_CLOCK_HSI */
51
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
52
#endif
53
54
/* The following parameters configure a 64MHz system clock with HSI as input clock */
55
#ifndef CONFIG_CLOCK_PLL_M
56
#ifdef CPU_FAM_STM32G0
57
#define CONFIG_CLOCK_PLL_M (1)
58
#else
59
#define CONFIG_CLOCK_PLL_M (4)
60
#endif
61
#endif
62
#ifndef CONFIG_CLOCK_PLL_N
63
#ifdef CPU_FAM_STM32G0
64
#define CONFIG_CLOCK_PLL_N (20)
65
#else
66
#define CONFIG_CLOCK_PLL_N (85)
67
#endif
68
#endif
69
#ifndef CONFIG_CLOCK_PLL_R
70
#ifdef CPU_FAM_STM32G0
71
#define CONFIG_CLOCK_PLL_R (5)
72
#else
73
#define CONFIG_CLOCK_PLL_R (2)
74
#endif
75
#endif
76
77
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
78
#ifdef CPU_FAM_STM32G0
79
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI / CONFIG_CLOCK_HSISYS_DIV)
80
#else
81
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
82
#endif
83
84
#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
85
#if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
86
#error "The board doesn't provide an HSE oscillator"
87
#endif
88
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
89
90
#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
91
#define CLOCK_CORECLOCK \
92
((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_R
93
#ifdef CPU_FAM_STM32G0
94
#if CLOCK_CORECLOCK > MHZ(64)
95
#error "SYSCLK cannot exceed 64MHz"
96
#endif
97
#else
/* CPU_FAM_STM32G4 */
98
#if CLOCK_CORECLOCK > MHZ(170)
99
#error "SYSCLK cannot exceed 170MHz"
100
#endif
101
#endif
102
#endif
/* CONFIG_USE_CLOCK_PLL */
103
104
#define CLOCK_AHB CLOCK_CORECLOCK
/* max: 64MHz (G0), 170MHZ (G4) */
105
106
#ifndef CONFIG_CLOCK_APB1_DIV
107
#define CONFIG_CLOCK_APB1_DIV (1)
108
#endif
109
#define CLOCK_APB1 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB1_DIV)
/* max: 64MHz (G0), 170MHZ (G4) */
110
#ifdef CPU_FAM_STM32G4
111
#ifndef CONFIG_CLOCK_APB2_DIV
112
#define CONFIG_CLOCK_APB2_DIV (1)
113
#endif
114
#define CLOCK_APB2 (CLOCK_AHB / CONFIG_CLOCK_APB2_DIV)
/* max: 170MHz (only on G4) */
115
#endif
118
#ifdef __cplusplus
119
}
120
#endif
121
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 Thu Jun 26 2025 14:14:45 by
1.9.1