1 /**
2 ******************************************************************************
3 * @file system_stm32h5xx_ns.c
4 * @author MCD Application Team
5 * @brief CMSIS Cortex-M33 Device Peripheral Access Layer System Source File
6 * to be used in non-secure application when the system implements
7 * the TrustZone-M security.
8 *
9 * This file provides two functions and one global variable to be called from
10 * user application:
11 * - SystemInit(): This function is called at non-secure startup before
12 * branch to non-secure main program.
13 * This call is made inside the "startup_stm32h5xx.s" file.
14 *
15 * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
16 * by the user application to setup the SysTick
17 * timer or configure other parameters.
18 *
19 * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
20 * be called whenever the core clock is changed
21 * during program execution.
22 *
23 * After each device reset the HSI (64 MHz) is used as system clock source.
24 * Then SystemInit() function is called, in "startup_stm32h5xx.s" file, to
25 * configure the system clock before to branch to main secure program.
26 * Later, when non-secure SystemInit() function is called, in "startup_stm32h5xx.s"
27 * file, the system clock may have been updated from reset value by the main
28 * secure program.
29 *
30 ******************************************************************************
31 * @attention
32 *
33 * Copyright (c) 2023 STMicroelectronics.
34 * All rights reserved.
35 *
36 * This software is licensed under terms that can be found in the LICENSE file
37 * in the root directory of this software component.
38 * If no LICENSE file comes with this software, it is provided AS-IS.
39 *
40 ******************************************************************************
41 */
42
43 /** @addtogroup CMSIS
44 * @{
45 */
46
47 /** @addtogroup STM32H5xx_system
48 * @{
49 */
50
51 /** @addtogroup STM32H5xx_System_Private_Includes
52 * @{
53 */
54
55 #include "stm32h5xx.h"
56
57 /**
58 * @}
59 */
60
61 /** @addtogroup STM32H5xx_System_Private_TypesDefinitions
62 * @{
63 */
64
65 /**
66 * @}
67 */
68
69 /** @addtogroup STM32H5xx_System_Private_Defines
70 * @{
71 */
72
73 #if !defined (HSE_VALUE)
74 #define HSE_VALUE (25000000UL) /*!< Value of the External oscillator in Hz */
75 #endif /* HSE_VALUE */
76
77 #if !defined (CSI_VALUE)
78 #define CSI_VALUE (4000000UL) /*!< Value of the Internal oscillator in Hz*/
79 #endif /* CSI_VALUE */
80
81 #if !defined (HSI_VALUE)
82 #define HSI_VALUE (64000000UL) /*!< Value of the Internal oscillator in Hz */
83 #endif /* HSI_VALUE */
84
85 /**
86 * @}
87 */
88
89 /** @addtogroup STM32H5xx_System_Private_Macros
90 * @{
91 */
92
93 /**
94 * @}
95 */
96
97 /** @addtogroup STM32H5xx_System_Private_Variables
98 * @{
99 */
100 /* The SystemCoreClock variable is updated in three ways:
101 1) by calling CMSIS function SystemCoreClockUpdate()
102 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
103 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
104 Note: If you use this function to configure the system clock; then there
105 is no need to call the 2 first functions listed above, since SystemCoreClock
106 variable is updated automatically.
107 */
108 uint32_t SystemCoreClock = 64000000U;
109
110 const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
111 const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
112 /**
113 * @}
114 */
115
116 /** @addtogroup STM32H5xx_System_Private_FunctionPrototypes
117 * @{
118 */
119
120 /**
121 * @}
122 */
123
124 /** @addtogroup STM32H5xx_System_Private_Functions
125 * @{
126 */
127
128 /**
129 * @brief Setup the microcontroller system.
130 * @param None
131 * @retval None
132 */
133
SystemInit(void)134 void SystemInit(void)
135 {
136 /* Nothing done in non-secure */
137
138 /* Non-secure main application shall call SystemCoreClockUpdate() to update */
139 /* the SystemCoreClock variable to insure non-secure application relies on */
140 /* the initial clock reference set by secure application. */
141 }
142
143 /**
144 * @brief Update SystemCoreClock variable according to Clock Register Values.
145 * The SystemCoreClock variable contains the core clock (HCLK), it can
146 * be used by the user application to setup the SysTick timer or configure
147 * other parameters.
148 *
149 * @note From the non-secure application, the SystemCoreClock value is
150 * retrieved from the secure domain via a Non-Secure Callable function
151 * since the RCC peripheral may be protected with security attributes
152 * that prevent to compute the SystemCoreClock variable from the RCC
153 * peripheral registers.
154 *
155 * @note Each time the core clock (HCLK) changes, this function must be called
156 * to update SystemCoreClock variable value. Otherwise, any configuration
157 * based on this variable will be incorrect.
158 *
159 * @note - The system frequency computed by this function is not the real
160 * frequency in the chip. It is calculated based on the predefined
161 * constant and the selected clock source:
162 *
163 * - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)
164 *
165 * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
166 *
167 * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
168 *
169 * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
170 * or HSI_VALUE(**) or CSI_VALUE(*) multiplied/divided by the PLL factors.
171 *
172 * (*) CSI_VALUE is a constant defined in stm32h5xx_hal.h file (default value
173 * 4 MHz) but the real value may vary depending on the variations
174 * in voltage and temperature.
175 *
176 * (**) HSI_VALUE is a constant defined in stm32h5xx_hal.h file (default value
177 * 64 MHz) but the real value may vary depending on the variations
178 * in voltage and temperature.
179 *
180 * (***) HSE_VALUE is a constant defined in stm32h5xx_hal.h file (default value
181 * 25 MHz), user has to ensure that HSE_VALUE is same as the real
182 * frequency of the crystal used. Otherwise, this function may
183 * have wrong result.
184 *
185 * - The result of this function could be not correct when using fractional
186 * value for HSE crystal.
187 *
188 * @retval None
189 */
SystemCoreClockUpdate(void)190 void SystemCoreClockUpdate(void)
191 {
192 /* Get the SystemCoreClock value from the secure domain */
193 SystemCoreClock = SECURE_SystemCoreClockUpdate();
194 }
195
196
197 /**
198 * @}
199 */
200
201 /**
202 * @}
203 */
204
205 /**
206 * @}
207 */
208