Skip to content

Commit f5ebdaf

Browse files
committed
[L5] new system cortex M33 Device Peripheral Access Layer
Signed-off-by: Francois Ramu <[email protected]>
1 parent d0c4ac4 commit f5ebdaf

File tree

2 files changed

+252
-5
lines changed

2 files changed

+252
-5
lines changed

system/STM32L5xx/stm32l5xx_hal_conf.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
/* STM32L5xx specific HAL configuration options. */
77
#if __has_include("hal_conf_custom.h")
8-
#include "hal_conf_custom.h"
8+
#include "hal_conf_custom.h"
99
#else
10-
#if __has_include("hal_conf_extra.h")
11-
#include "hal_conf_extra.h"
12-
#endif
13-
#include "stm32l5xx_hal_conf_default.h"
10+
#if __has_include("hal_conf_extra.h")
11+
#include "hal_conf_extra.h"
12+
#endif
13+
#include "stm32l5xx_hal_conf_default.h"
1414
#endif
1515

1616
#endif /* __STM32L5xx_HAL_CONF_H */

system/STM32L5xx/system_stm32l5xx.c

+247
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
/**
2+
******************************************************************************
3+
* @file system_stm32l5xx_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_stm32l5xx.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 MSI (4 MHz) is used as system clock source.
24+
* Then SystemInit() function is called, in "startup_stm32l5xx.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_stm32l5xx.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+
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
34+
* All rights reserved.</center></h2>
35+
*
36+
* This software component is licensed by ST under Apache License, Version 2.0,
37+
* the "License"; You may not use this file except in compliance with the
38+
* License. You may obtain a copy of the License at:
39+
* opensource.org/licenses/Apache-2.0
40+
*
41+
******************************************************************************
42+
*/
43+
44+
/** @addtogroup CMSIS
45+
* @{
46+
*/
47+
48+
/** @addtogroup STM32L5xx_System
49+
* @{
50+
*/
51+
52+
/** @addtogroup STM32L5xx_System_Private_Includes
53+
* @{
54+
*/
55+
56+
#include "stm32l5xx.h"
57+
58+
/**
59+
* @}
60+
*/
61+
62+
/** @addtogroup STM32L5xx_System_Private_TypesDefinitions
63+
* @{
64+
*/
65+
66+
/**
67+
* @}
68+
*/
69+
70+
/** @addtogroup STM32L5xx_System_Private_Defines
71+
* @{
72+
*/
73+
74+
#if !defined (HSE_VALUE)
75+
#define HSE_VALUE 16000000U /*!< Value of the External oscillator in Hz */
76+
#endif /* HSE_VALUE */
77+
78+
#if !defined (MSI_VALUE)
79+
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
80+
#endif /* MSI_VALUE */
81+
82+
#if !defined (HSI_VALUE)
83+
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
84+
#endif /* HSI_VALUE */
85+
86+
#if !defined (LSI_VALUE)
87+
#define LSI_VALUE 32000U /*!< Value of the Internal oscillator in Hz*/
88+
#endif /* LSI_VALUE */
89+
90+
/* Note: Following vector table addresses must be defined in line with linker
91+
configuration. */
92+
/*!< Uncomment the following line if you need to relocate the vector table
93+
anywhere in Flash or Sram, else the vector table is kept at the automatic
94+
remap of boot address selected */
95+
/* #define USER_VECT_TAB_ADDRESS */
96+
97+
#if defined(USER_VECT_TAB_ADDRESS)
98+
/*!< Uncomment the following line if you need to relocate your vector Table
99+
in Sram else user remap will be done in Flash. */
100+
/* #define VECT_TAB_SRAM */
101+
102+
#if defined(VECT_TAB_SRAM)
103+
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE_NS /*!< Vector Table base address field.
104+
This value must be a multiple of 0x200. */
105+
#define VECT_TAB_OFFSET 0x00018000U /*!< Vector Table base offset field.
106+
This value must be a multiple of 0x200. */
107+
#else
108+
#define VECT_TAB_BASE_ADDRESS FLASH_BASE_NS /*!< Vector Table base address field.
109+
This value must be a multiple of 0x200. */
110+
#define VECT_TAB_OFFSET 0x00040000U /*!< Vector Table base offset field.
111+
This value must be a multiple of 0x200. */
112+
#endif /* VECT_TAB_SRAM */
113+
#endif /* USER_VECT_TAB_ADDRESS */
114+
115+
/******************************************************************************/
116+
/**
117+
* @}
118+
*/
119+
120+
/** @addtogroup STM32L5xx_System_Private_Macros
121+
* @{
122+
*/
123+
124+
/**
125+
* @}
126+
*/
127+
128+
/** @addtogroup STM32L5xx_System_Private_Variables
129+
* @{
130+
*/
131+
/* The SystemCoreClock variable is updated in three ways:
132+
1) by calling CMSIS function SystemCoreClockUpdate()
133+
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
134+
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
135+
Note: If you use this function to configure the system clock; then there
136+
is no need to call the 2 first functions listed above, since SystemCoreClock
137+
variable is updated automatically.
138+
*/
139+
uint32_t SystemCoreClock = 4000000U;
140+
141+
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
142+
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
143+
const uint32_t MSIRangeTable[16] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
144+
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U, \
145+
0U, 0U, 0U, 0U}; /* MISRAC-2012: 0U for unexpected value */
146+
/**
147+
* @}
148+
*/
149+
150+
/** @addtogroup STM32L5xx_System_Private_FunctionPrototypes
151+
* @{
152+
*/
153+
154+
/**
155+
* @}
156+
*/
157+
158+
/** @addtogroup STM32L5xx_System_Private_Functions
159+
* @{
160+
*/
161+
162+
/**
163+
* @brief Setup the microcontroller system.
164+
* @retval None
165+
*/
166+
167+
void SystemInit(void)
168+
{
169+
/* Vector table location and FPU setup done by secure application */
170+
171+
/* Configure the Vector Table location -------------------------------------*/
172+
#if defined(USER_VECT_TAB_ADDRESS)
173+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
174+
#endif
175+
176+
/* Non-secure main application shall call SystemCoreClockUpdate() to update */
177+
/* the SystemCoreClock variable to insure non-secure application relies on */
178+
/* the initial clock reference set by secure application. */
179+
}
180+
181+
/**
182+
* @brief Update SystemCoreClock variable according to Clock Register Values.
183+
* The SystemCoreClock variable contains the core clock (HCLK), it can
184+
* be used by the user application to setup the SysTick timer or configure
185+
* other parameters.
186+
*
187+
* @note From the non-secure application, the SystemCoreClock value is
188+
* retrieved from the secure domain via a Non-Secure Callable function
189+
* since the RCC peripheral may be protected with security attributes
190+
* that prevent to compute the SystemCoreClock variable from the RCC
191+
* peripheral registers.
192+
*
193+
* @note Each time the core clock (HCLK) changes, this function must be called
194+
* to update SystemCoreClock variable value. Otherwise, any configuration
195+
* based on this variable will be incorrect.
196+
*
197+
* @note - The system frequency computed by this function is not the real
198+
* frequency in the chip. It is calculated based on the predefined
199+
* constant and the selected clock source:
200+
*
201+
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
202+
*
203+
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
204+
*
205+
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
206+
*
207+
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
208+
* or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
209+
*
210+
* (*) MSI_VALUE is a constant defined in stm32l5xx_hal.h file (default value
211+
* 4 MHz) but the real value may vary depending on the variations
212+
* in voltage and temperature.
213+
*
214+
* (**) HSI_VALUE is a constant defined in stm32l5xx_hal.h file (default value
215+
* 16 MHz) but the real value may vary depending on the variations
216+
* in voltage and temperature.
217+
*
218+
* (***) HSE_VALUE is a constant defined in stm32l5xx_hal.h file (default value
219+
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
220+
* frequency of the crystal used. Otherwise, this function may
221+
* have wrong result.
222+
*
223+
* - The result of this function could be not correct when using fractional
224+
* value for HSE crystal.
225+
*
226+
* @retval None
227+
*/
228+
void SystemCoreClockUpdate(void)
229+
{
230+
/* Get the SystemCoreClock value from the secure domain */
231+
SystemCoreClock = SECURE_SystemCoreClockUpdate();
232+
}
233+
234+
235+
/**
236+
* @}
237+
*/
238+
239+
/**
240+
* @}
241+
*/
242+
243+
/**
244+
* @}
245+
*/
246+
247+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)