Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 61 | Rev 77 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file system_stm32l1xx.c |
3 | * @file system_stm32l1xx.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. |
5 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. |
6 | * |
6 | * |
7 | * This file provides two functions and one global variable to be called from |
7 | * This file provides two functions and one global variable to be called from |
8 | * user application: |
8 | * user application: |
9 | * - SystemInit(): This function is called at startup just after reset and |
9 | * - SystemInit(): This function is called at startup just after reset and |
10 | * before branch to main program. This call is made inside |
10 | * before branch to main program. This call is made inside |
11 | * the "startup_stm32l1xx.s" file. |
11 | * the "startup_stm32l1xx.s" file. |
12 | * |
12 | * |
13 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used |
13 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used |
14 | * by the user application to setup the SysTick |
14 | * by the user application to setup the SysTick |
15 | * timer or configure other parameters. |
15 | * timer or configure other parameters. |
16 | * |
16 | * |
17 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must |
17 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must |
18 | * be called whenever the core clock is changed |
18 | * be called whenever the core clock is changed |
19 | * during program execution. |
19 | * during program execution. |
20 | * |
20 | * |
21 | ****************************************************************************** |
21 | ****************************************************************************** |
22 | * @attention |
22 | * @attention |
23 | * |
23 | * |
24 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
24 | * Copyright (c) 2017-2021 STMicroelectronics. |
25 | * All rights reserved.</center></h2> |
25 | * All rights reserved. |
26 | * |
26 | * |
27 | * This software component is licensed by ST under BSD 3-Clause license, |
27 | * This software is licensed under terms that can be found in the LICENSE file |
28 | * the "License"; You may not use this file except in compliance with the |
28 | * in the root directory of this software component. |
29 | * License. You may obtain a copy of the License at: |
29 | * If no LICENSE file comes with this software, it is provided AS-IS. |
30 | * opensource.org/licenses/BSD-3-Clause |
30 | * |
31 | * |
31 | ****************************************************************************** |
32 | ****************************************************************************** |
32 | */ |
33 | */ |
33 | |
34 | 34 | /** @addtogroup CMSIS |
|
35 | /** @addtogroup CMSIS |
35 | * @{ |
36 | * @{ |
36 | */ |
37 | */ |
37 | |
38 | 38 | /** @addtogroup stm32l1xx_system |
|
39 | /** @addtogroup stm32l1xx_system |
39 | * @{ |
40 | * @{ |
40 | */ |
41 | */ |
41 | |
42 | 42 | /** @addtogroup STM32L1xx_System_Private_Includes |
|
43 | /** @addtogroup STM32L1xx_System_Private_Includes |
43 | * @{ |
44 | * @{ |
44 | */ |
45 | */ |
45 | |
46 | 46 | #include "stm32l1xx.h" |
|
47 | #include "stm32l1xx.h" |
47 | |
48 | 48 | /** |
|
49 | /** |
49 | * @} |
50 | * @} |
50 | */ |
51 | */ |
51 | |
52 | 52 | /** @addtogroup STM32L1xx_System_Private_TypesDefinitions |
|
53 | /** @addtogroup STM32L1xx_System_Private_TypesDefinitions |
53 | * @{ |
54 | * @{ |
54 | */ |
55 | */ |
55 | |
56 | 56 | /** |
|
57 | /** |
57 | * @} |
58 | * @} |
58 | */ |
59 | */ |
59 | |
60 | 60 | /** @addtogroup STM32L1xx_System_Private_Defines |
|
61 | /** @addtogroup STM32L1xx_System_Private_Defines |
61 | * @{ |
62 | * @{ |
62 | */ |
63 | */ |
63 | #if !defined (HSE_VALUE) |
64 | #if !defined (HSE_VALUE) |
64 | #define HSE_VALUE ((uint32_t)8000000U) /*!< Default value of the External oscillator in Hz. |
65 | #define HSE_VALUE ((uint32_t)8000000U) /*!< Default value of the External oscillator in Hz. |
65 | This value can be provided and adapted by the user application. */ |
66 | This value can be provided and adapted by the user application. */ |
66 | #endif /* HSE_VALUE */ |
67 | #endif /* HSE_VALUE */ |
67 | |
68 | 68 | #if !defined (HSI_VALUE) |
|
69 | #if !defined (HSI_VALUE) |
69 | #define HSI_VALUE ((uint32_t)16000000U) /*!< Default value of the Internal oscillator in Hz. |
70 | #define HSI_VALUE ((uint32_t)8000000U) /*!< Default value of the Internal oscillator in Hz. |
70 | This value can be provided and adapted by the user application. */ |
71 | This value can be provided and adapted by the user application. */ |
71 | #endif /* HSI_VALUE */ |
72 | #endif /* HSI_VALUE */ |
72 | |
73 | 73 | /*!< Uncomment the following line if you need to use external SRAM mounted |
|
74 | /*!< Uncomment the following line if you need to use external SRAM mounted |
74 | on STM32L152D_EVAL board as data memory */ |
75 | on STM32L152D_EVAL board as data memory */ |
75 | /* #define DATA_IN_ExtSRAM */ |
76 | /* #define DATA_IN_ExtSRAM */ |
76 | |
77 | 77 | /* Note: Following vector table addresses must be defined in line with linker |
|
78 | /* Note: Following vector table addresses must be defined in line with linker |
78 | configuration. */ |
79 | configuration. */ |
79 | /*!< Uncomment the following line if you need to relocate the vector table |
80 | /*!< Uncomment the following line if you need to relocate the vector table |
80 | anywhere in Flash or Sram, else the vector table is kept at the automatic |
81 | anywhere in Flash or Sram, else the vector table is kept at the automatic |
81 | remap of boot address selected */ |
82 | remap of boot address selected */ |
82 | /* #define USER_VECT_TAB_ADDRESS */ |
83 | /* #define USER_VECT_TAB_ADDRESS */ |
83 | |
84 | 84 | #if defined(USER_VECT_TAB_ADDRESS) |
|
85 | #if defined(USER_VECT_TAB_ADDRESS) |
85 | /*!< Uncomment the following line if you need to relocate your vector Table |
86 | /*!< Uncomment the following line if you need to relocate your vector Table |
86 | in Sram else user remap will be done in Flash. */ |
87 | in Sram else user remap will be done in Flash. */ |
87 | /* #define VECT_TAB_SRAM */ |
88 | /* #define VECT_TAB_SRAM */ |
88 | #if defined(VECT_TAB_SRAM) |
89 | #if defined(VECT_TAB_SRAM) |
89 | #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. |
90 | #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. |
90 | This value must be a multiple of 0x200. */ |
91 | This value must be a multiple of 0x200. */ |
91 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. |
92 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. |
92 | This value must be a multiple of 0x200. */ |
93 | This value must be a multiple of 0x200. */ |
93 | #else |
94 | #else |
94 | #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. |
95 | #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. |
95 | This value must be a multiple of 0x200. */ |
96 | This value must be a multiple of 0x200. */ |
96 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. |
97 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. |
97 | This value must be a multiple of 0x200. */ |
98 | This value must be a multiple of 0x200. */ |
98 | #endif /* VECT_TAB_SRAM */ |
99 | #endif /* VECT_TAB_SRAM */ |
99 | #endif /* USER_VECT_TAB_ADDRESS */ |
100 | #endif /* USER_VECT_TAB_ADDRESS */ |
100 | |
101 | 101 | /******************************************************************************/ |
|
102 | /******************************************************************************/ |
102 | /** |
103 | /** |
103 | * @} |
104 | * @} |
104 | */ |
105 | */ |
105 | |
106 | 106 | /** @addtogroup STM32L1xx_System_Private_Macros |
|
107 | /** @addtogroup STM32L1xx_System_Private_Macros |
107 | * @{ |
108 | * @{ |
108 | */ |
109 | */ |
109 | |
110 | 110 | /** |
|
111 | /** |
111 | * @} |
112 | * @} |
112 | */ |
113 | */ |
113 | |
114 | 114 | /** @addtogroup STM32L1xx_System_Private_Variables |
|
115 | /** @addtogroup STM32L1xx_System_Private_Variables |
115 | * @{ |
116 | * @{ |
116 | */ |
117 | */ |
117 | /* This variable is updated in three ways: |
118 | /* This variable is updated in three ways: |
118 | 1) by calling CMSIS function SystemCoreClockUpdate() |
119 | 1) by calling CMSIS function SystemCoreClockUpdate() |
119 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() |
120 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() |
120 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency |
121 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency |
121 | Note: If you use this function to configure the system clock; then there |
122 | Note: If you use this function to configure the system clock; then there |
122 | is no need to call the 2 first functions listed above, since SystemCoreClock |
123 | is no need to call the 2 first functions listed above, since SystemCoreClock |
123 | variable is updated automatically. |
124 | variable is updated automatically. |
124 | */ |
125 | */ |
125 | uint32_t SystemCoreClock = 2097000U; |
126 | uint32_t SystemCoreClock = 2097000U; |
126 | const uint8_t PLLMulTable[9] = {3U, 4U, 6U, 8U, 12U, 16U, 24U, 32U, 48U}; |
127 | const uint8_t PLLMulTable[9] = {3U, 4U, 6U, 8U, 12U, 16U, 24U, 32U, 48U}; |
127 | const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; |
128 | const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; |
128 | const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; |
129 | const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; |
129 | |
130 | 130 | /** |
|
131 | /** |
131 | * @} |
132 | * @} |
132 | */ |
133 | */ |
133 | |
134 | 134 | /** @addtogroup STM32L1xx_System_Private_FunctionPrototypes |
|
135 | /** @addtogroup STM32L1xx_System_Private_FunctionPrototypes |
135 | * @{ |
136 | * @{ |
136 | */ |
137 | */ |
137 | |
138 | 138 | #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) |
|
139 | #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) |
139 | #ifdef DATA_IN_ExtSRAM |
140 | #ifdef DATA_IN_ExtSRAM |
140 | static void SystemInit_ExtMemCtl(void); |
141 | static void SystemInit_ExtMemCtl(void); |
141 | #endif /* DATA_IN_ExtSRAM */ |
142 | #endif /* DATA_IN_ExtSRAM */ |
142 | #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ |
143 | #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ |
143 | |
144 | 144 | /** |
|
145 | /** |
145 | * @} |
146 | * @} |
146 | */ |
147 | */ |
147 | |
148 | 148 | /** @addtogroup STM32L1xx_System_Private_Functions |
|
149 | /** @addtogroup STM32L1xx_System_Private_Functions |
149 | * @{ |
150 | * @{ |
150 | */ |
151 | */ |
151 | |
152 | 152 | /** |
|
153 | /** |
153 | * @brief Setup the microcontroller system. |
154 | * @brief Setup the microcontroller system. |
154 | * Initialize the Embedded Flash Interface, the PLL and update the |
155 | * Initialize the Embedded Flash Interface, the PLL and update the |
155 | * SystemCoreClock variable. |
156 | * SystemCoreClock variable. |
156 | * @param None |
157 | * @param None |
157 | * @retval None |
158 | * @retval None |
158 | */ |
159 | */ |
159 | void SystemInit (void) |
160 | void SystemInit (void) |
160 | { |
161 | { |
161 | #ifdef DATA_IN_ExtSRAM |
162 | #ifdef DATA_IN_ExtSRAM |
162 | SystemInit_ExtMemCtl(); |
163 | SystemInit_ExtMemCtl(); |
163 | #endif /* DATA_IN_ExtSRAM */ |
164 | #endif /* DATA_IN_ExtSRAM */ |
164 | |
165 | 165 | /* Configure the Vector Table location -------------------------------------*/ |
|
166 | /* Configure the Vector Table location -------------------------------------*/ |
166 | #if defined(USER_VECT_TAB_ADDRESS) |
167 | #if defined(USER_VECT_TAB_ADDRESS) |
167 | SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ |
168 | SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ |
168 | #endif /* USER_VECT_TAB_ADDRESS */ |
169 | #endif /* USER_VECT_TAB_ADDRESS */ |
169 | } |
170 | } |
170 | |
171 | 171 | /** |
|
172 | /** |
172 | * @brief Update SystemCoreClock according to Clock Register Values |
173 | * @brief Update SystemCoreClock according to Clock Register Values |
173 | * The SystemCoreClock variable contains the core clock (HCLK), it can |
174 | * The SystemCoreClock variable contains the core clock (HCLK), it can |
174 | * be used by the user application to setup the SysTick timer or configure |
175 | * be used by the user application to setup the SysTick timer or configure |
175 | * other parameters. |
176 | * other parameters. |
176 | * |
177 | * |
177 | * @note Each time the core clock (HCLK) changes, this function must be called |
178 | * @note Each time the core clock (HCLK) changes, this function must be called |
178 | * to update SystemCoreClock variable value. Otherwise, any configuration |
179 | * to update SystemCoreClock variable value. Otherwise, any configuration |
179 | * based on this variable will be incorrect. |
180 | * based on this variable will be incorrect. |
180 | * |
181 | * |
181 | * @note - The system frequency computed by this function is not the real |
182 | * @note - The system frequency computed by this function is not the real |
182 | * frequency in the chip. It is calculated based on the predefined |
183 | * frequency in the chip. It is calculated based on the predefined |
183 | * constant and the selected clock source: |
184 | * constant and the selected clock source: |
184 | * |
185 | * |
185 | * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI |
186 | * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI |
186 | * value as defined by the MSI range. |
187 | * value as defined by the MSI range. |
187 | * |
188 | * |
188 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) |
189 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) |
189 | * |
190 | * |
190 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) |
191 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) |
191 | * |
192 | * |
192 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) |
193 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) |
193 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. |
194 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. |
194 | * |
195 | * |
195 | * (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value |
196 | * (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value |
196 | * 16 MHz) but the real value may vary depending on the variations |
197 | * 16 MHz) but the real value may vary depending on the variations |
197 | * in voltage and temperature. |
198 | * in voltage and temperature. |
198 | * |
199 | * |
199 | * (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value |
200 | * (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value |
200 | * 8 MHz), user has to ensure that HSE_VALUE is same as the real |
201 | * 8 MHz), user has to ensure that HSE_VALUE is same as the real |
201 | * frequency of the crystal used. Otherwise, this function may |
202 | * frequency of the crystal used. Otherwise, this function may |
202 | * have wrong result. |
203 | * have wrong result. |
203 | * |
204 | * |
204 | * - The result of this function could be not correct when using fractional |
205 | * - The result of this function could be not correct when using fractional |
205 | * value for HSE crystal. |
206 | * value for HSE crystal. |
206 | * @param None |
207 | * @param None |
207 | * @retval None |
208 | * @retval None |
208 | */ |
209 | */ |
209 | void SystemCoreClockUpdate (void) |
210 | void SystemCoreClockUpdate (void) |
210 | { |
211 | { |
211 | uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, msirange = 0; |
212 | uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, msirange = 0; |
212 | |
213 | 213 | /* Get SYSCLK source -------------------------------------------------------*/ |
|
214 | /* Get SYSCLK source -------------------------------------------------------*/ |
214 | tmp = RCC->CFGR & RCC_CFGR_SWS; |
215 | tmp = RCC->CFGR & RCC_CFGR_SWS; |
215 | |
216 | 216 | switch (tmp) |
|
217 | switch (tmp) |
217 | { |
218 | { |
218 | case 0x00: /* MSI used as system clock */ |
219 | case 0x00: /* MSI used as system clock */ |
219 | msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13; |
220 | msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13; |
220 | SystemCoreClock = (32768 * (1 << (msirange + 1))); |
221 | SystemCoreClock = (32768 * (1 << (msirange + 1))); |
221 | break; |
222 | break; |
222 | case 0x04: /* HSI used as system clock */ |
223 | case 0x04: /* HSI used as system clock */ |
223 | SystemCoreClock = HSI_VALUE; |
224 | SystemCoreClock = HSI_VALUE; |
224 | break; |
225 | break; |
225 | case 0x08: /* HSE used as system clock */ |
226 | case 0x08: /* HSE used as system clock */ |
226 | SystemCoreClock = HSE_VALUE; |
227 | SystemCoreClock = HSE_VALUE; |
227 | break; |
228 | break; |
228 | case 0x0C: /* PLL used as system clock */ |
229 | case 0x0C: /* PLL used as system clock */ |
229 | /* Get PLL clock source and multiplication factor ----------------------*/ |
230 | /* Get PLL clock source and multiplication factor ----------------------*/ |
230 | pllmul = RCC->CFGR & RCC_CFGR_PLLMUL; |
231 | pllmul = RCC->CFGR & RCC_CFGR_PLLMUL; |
231 | plldiv = RCC->CFGR & RCC_CFGR_PLLDIV; |
232 | plldiv = RCC->CFGR & RCC_CFGR_PLLDIV; |
232 | pllmul = PLLMulTable[(pllmul >> 18)]; |
233 | pllmul = PLLMulTable[(pllmul >> 18)]; |
233 | plldiv = (plldiv >> 22) + 1; |
234 | plldiv = (plldiv >> 22) + 1; |
234 | |
235 | 235 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; |
|
236 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; |
236 | |
237 | 237 | if (pllsource == 0x00) |
|
238 | if (pllsource == 0x00) |
238 | { |
239 | { |
239 | /* HSI oscillator clock selected as PLL clock entry */ |
240 | /* HSI oscillator clock selected as PLL clock entry */ |
240 | SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv); |
241 | SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv); |
241 | } |
242 | } |
242 | else |
243 | else |
243 | { |
244 | { |
244 | /* HSE selected as PLL clock entry */ |
245 | /* HSE selected as PLL clock entry */ |
245 | SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv); |
246 | SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv); |
246 | } |
247 | } |
247 | break; |
248 | break; |
248 | default: /* MSI used as system clock */ |
249 | default: /* MSI used as system clock */ |
249 | msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13; |
250 | msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13; |
250 | SystemCoreClock = (32768 * (1 << (msirange + 1))); |
251 | SystemCoreClock = (32768 * (1 << (msirange + 1))); |
251 | break; |
252 | break; |
252 | } |
253 | } |
253 | /* Compute HCLK clock frequency --------------------------------------------*/ |
254 | /* Compute HCLK clock frequency --------------------------------------------*/ |
254 | /* Get HCLK prescaler */ |
255 | /* Get HCLK prescaler */ |
255 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; |
256 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; |
256 | /* HCLK clock frequency */ |
257 | /* HCLK clock frequency */ |
257 | SystemCoreClock >>= tmp; |
258 | SystemCoreClock >>= tmp; |
258 | } |
259 | } |
259 | |
260 | 260 | #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) |
|
261 | #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) |
261 | #ifdef DATA_IN_ExtSRAM |
262 | #ifdef DATA_IN_ExtSRAM |
262 | /** |
263 | /** |
263 | * @brief Setup the external memory controller. |
264 | * @brief Setup the external memory controller. |
264 | * Called in SystemInit() function before jump to main. |
265 | * Called in SystemInit() function before jump to main. |
265 | * This function configures the external SRAM mounted on STM32L152D_EVAL board |
266 | * This function configures the external SRAM mounted on STM32L152D_EVAL board |
266 | * This SRAM will be used as program data memory (including heap and stack). |
267 | * This SRAM will be used as program data memory (including heap and stack). |
267 | * @param None |
268 | * @param None |
268 | * @retval None |
269 | * @retval None |
269 | */ |
270 | */ |
270 | void SystemInit_ExtMemCtl(void) |
271 | void SystemInit_ExtMemCtl(void) |
271 | { |
272 | { |
272 | __IO uint32_t tmpreg = 0; |
273 | __IO uint32_t tmpreg = 0; |
273 | |
274 | 274 | /* Flash 1 wait state */ |
|
275 | /* Flash 1 wait state */ |
275 | FLASH->ACR |= FLASH_ACR_LATENCY; |
276 | FLASH->ACR |= FLASH_ACR_LATENCY; |
276 | |
277 | 277 | /* Power enable */ |
|
278 | /* Power enable */ |
278 | RCC->APB1ENR |= RCC_APB1ENR_PWREN; |
279 | RCC->APB1ENR |= RCC_APB1ENR_PWREN; |
279 | |
280 | 280 | /* Delay after an RCC peripheral clock enabling */ |
|
281 | /* Delay after an RCC peripheral clock enabling */ |
281 | tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN); |
282 | tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN); |
282 | |
283 | 283 | /* Select the Voltage Range 1 (1.8 V) */ |
|
284 | /* Select the Voltage Range 1 (1.8 V) */ |
284 | PWR->CR = PWR_CR_VOS_0; |
285 | PWR->CR = PWR_CR_VOS_0; |
285 | |
286 | 286 | /* Wait Until the Voltage Regulator is ready */ |
|
287 | /* Wait Until the Voltage Regulator is ready */ |
287 | while((PWR->CSR & PWR_CSR_VOSF) != RESET) |
288 | while((PWR->CSR & PWR_CSR_VOSF) != RESET) |
288 | { |
289 | { |
289 | } |
290 | } |
290 | |
291 | 291 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
|
292 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
292 | /* |
293 | /* |
293 | +-------------------+--------------------+------------------+------------------+ |
294 | +-------------------+--------------------+------------------+------------------+ |
294 | + SRAM pins assignment + |
295 | + SRAM pins assignment + |
295 | +-------------------+--------------------+------------------+------------------+ |
296 | +-------------------+--------------------+------------------+------------------+ |
296 | | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | |
297 | | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | |
297 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | |
298 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | |
298 | | PD4 <-> FSMC_NOE | PE7 <-> FSMC_D4 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | |
299 | | PD4 <-> FSMC_NOE | PE7 <-> FSMC_D4 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | |
299 | | PD5 <-> FSMC_NWE | PE8 <-> FSMC_D5 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | |
300 | | PD5 <-> FSMC_NWE | PE8 <-> FSMC_D5 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | |
300 | | PD8 <-> FSMC_D13 | PE9 <-> FSMC_D6 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | |
301 | | PD8 <-> FSMC_D13 | PE9 <-> FSMC_D6 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | |
301 | | PD9 <-> FSMC_D14 | PE10 <-> FSMC_D7 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | |
302 | | PD9 <-> FSMC_D14 | PE10 <-> FSMC_D7 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | |
302 | | PD10 <-> FSMC_D15 | PE11 <-> FSMC_D8 | PF12 <-> FSMC_A6 | PG10<-> FSMC_NE2 | |
303 | | PD10 <-> FSMC_D15 | PE11 <-> FSMC_D8 | PF12 <-> FSMC_A6 | PG10<-> FSMC_NE2 | |
303 | | PD11 <-> FSMC_A16 | PE12 <-> FSMC_D9 | PF13 <-> FSMC_A7 |------------------+ |
304 | | PD11 <-> FSMC_A16 | PE12 <-> FSMC_D9 | PF13 <-> FSMC_A7 |------------------+ |
304 | | PD12 <-> FSMC_A17 | PE13 <-> FSMC_D10 | PF14 <-> FSMC_A8 | |
305 | | PD12 <-> FSMC_A17 | PE13 <-> FSMC_D10 | PF14 <-> FSMC_A8 | |
305 | | PD13 <-> FSMC_A18 | PE14 <-> FSMC_D11 | PF15 <-> FSMC_A9 | |
306 | | PD13 <-> FSMC_A18 | PE14 <-> FSMC_D11 | PF15 <-> FSMC_A9 | |
306 | | PD14 <-> FSMC_D0 | PE15 <-> FSMC_D12 |------------------+ |
307 | | PD14 <-> FSMC_D0 | PE15 <-> FSMC_D12 |------------------+ |
307 | | PD15 <-> FSMC_D1 |--------------------+ |
308 | | PD15 <-> FSMC_D1 |--------------------+ |
308 | +-------------------+ |
309 | +-------------------+ |
309 | */ |
310 | */ |
310 | |
311 | 311 | /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ |
|
312 | /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ |
312 | RCC->AHBENR = 0x000080D8; |
313 | RCC->AHBENR = 0x000080D8; |
313 | |
314 | 314 | /* Delay after an RCC peripheral clock enabling */ |
|
315 | /* Delay after an RCC peripheral clock enabling */ |
315 | tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN); |
316 | tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN); |
316 | |
317 | 317 | /* Connect PDx pins to FSMC Alternate function */ |
|
318 | /* Connect PDx pins to FSMC Alternate function */ |
318 | GPIOD->AFR[0] = 0x00CC00CC; |
319 | GPIOD->AFR[0] = 0x00CC00CC; |
319 | GPIOD->AFR[1] = 0xCCCCCCCC; |
320 | GPIOD->AFR[1] = 0xCCCCCCCC; |
320 | /* Configure PDx pins in Alternate function mode */ |
321 | /* Configure PDx pins in Alternate function mode */ |
321 | GPIOD->MODER = 0xAAAA0A0A; |
322 | GPIOD->MODER = 0xAAAA0A0A; |
322 | /* Configure PDx pins speed to 40 MHz */ |
323 | /* Configure PDx pins speed to 40 MHz */ |
323 | GPIOD->OSPEEDR = 0xFFFF0F0F; |
324 | GPIOD->OSPEEDR = 0xFFFF0F0F; |
324 | /* Configure PDx pins Output type to push-pull */ |
325 | /* Configure PDx pins Output type to push-pull */ |
325 | GPIOD->OTYPER = 0x00000000; |
326 | GPIOD->OTYPER = 0x00000000; |
326 | /* No pull-up, pull-down for PDx pins */ |
327 | /* No pull-up, pull-down for PDx pins */ |
327 | GPIOD->PUPDR = 0x00000000; |
328 | GPIOD->PUPDR = 0x00000000; |
328 | |
329 | 329 | /* Connect PEx pins to FSMC Alternate function */ |
|
330 | /* Connect PEx pins to FSMC Alternate function */ |
330 | GPIOE->AFR[0] = 0xC00000CC; |
331 | GPIOE->AFR[0] = 0xC00000CC; |
331 | GPIOE->AFR[1] = 0xCCCCCCCC; |
332 | GPIOE->AFR[1] = 0xCCCCCCCC; |
332 | /* Configure PEx pins in Alternate function mode */ |
333 | /* Configure PEx pins in Alternate function mode */ |
333 | GPIOE->MODER = 0xAAAA800A; |
334 | GPIOE->MODER = 0xAAAA800A; |
334 | /* Configure PEx pins speed to 40 MHz */ |
335 | /* Configure PEx pins speed to 40 MHz */ |
335 | GPIOE->OSPEEDR = 0xFFFFC00F; |
336 | GPIOE->OSPEEDR = 0xFFFFC00F; |
336 | /* Configure PEx pins Output type to push-pull */ |
337 | /* Configure PEx pins Output type to push-pull */ |
337 | GPIOE->OTYPER = 0x00000000; |
338 | GPIOE->OTYPER = 0x00000000; |
338 | /* No pull-up, pull-down for PEx pins */ |
339 | /* No pull-up, pull-down for PEx pins */ |
339 | GPIOE->PUPDR = 0x00000000; |
340 | GPIOE->PUPDR = 0x00000000; |
340 | |
341 | 341 | /* Connect PFx pins to FSMC Alternate function */ |
|
342 | /* Connect PFx pins to FSMC Alternate function */ |
342 | GPIOF->AFR[0] = 0x00CCCCCC; |
343 | GPIOF->AFR[0] = 0x00CCCCCC; |
343 | GPIOF->AFR[1] = 0xCCCC0000; |
344 | GPIOF->AFR[1] = 0xCCCC0000; |
344 | /* Configure PFx pins in Alternate function mode */ |
345 | /* Configure PFx pins in Alternate function mode */ |
345 | GPIOF->MODER = 0xAA000AAA; |
346 | GPIOF->MODER = 0xAA000AAA; |
346 | /* Configure PFx pins speed to 40 MHz */ |
347 | /* Configure PFx pins speed to 40 MHz */ |
347 | GPIOF->OSPEEDR = 0xFF000FFF; |
348 | GPIOF->OSPEEDR = 0xFF000FFF; |
348 | /* Configure PFx pins Output type to push-pull */ |
349 | /* Configure PFx pins Output type to push-pull */ |
349 | GPIOF->OTYPER = 0x00000000; |
350 | GPIOF->OTYPER = 0x00000000; |
350 | /* No pull-up, pull-down for PFx pins */ |
351 | /* No pull-up, pull-down for PFx pins */ |
351 | GPIOF->PUPDR = 0x00000000; |
352 | GPIOF->PUPDR = 0x00000000; |
352 | |
353 | 353 | /* Connect PGx pins to FSMC Alternate function */ |
|
354 | /* Connect PGx pins to FSMC Alternate function */ |
354 | GPIOG->AFR[0] = 0x00CCCCCC; |
355 | GPIOG->AFR[0] = 0x00CCCCCC; |
355 | GPIOG->AFR[1] = 0x00000C00; |
356 | GPIOG->AFR[1] = 0x00000C00; |
356 | /* Configure PGx pins in Alternate function mode */ |
357 | /* Configure PGx pins in Alternate function mode */ |
357 | GPIOG->MODER = 0x00200AAA; |
358 | GPIOG->MODER = 0x00200AAA; |
358 | /* Configure PGx pins speed to 40 MHz */ |
359 | /* Configure PGx pins speed to 40 MHz */ |
359 | GPIOG->OSPEEDR = 0x00300FFF; |
360 | GPIOG->OSPEEDR = 0x00300FFF; |
360 | /* Configure PGx pins Output type to push-pull */ |
361 | /* Configure PGx pins Output type to push-pull */ |
361 | GPIOG->OTYPER = 0x00000000; |
362 | GPIOG->OTYPER = 0x00000000; |
362 | /* No pull-up, pull-down for PGx pins */ |
363 | /* No pull-up, pull-down for PGx pins */ |
363 | GPIOG->PUPDR = 0x00000000; |
364 | GPIOG->PUPDR = 0x00000000; |
364 | |
365 | 365 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
366 | /*-- FSMC Configuration ------------------------------------------------------*/ |
366 | /* Enable the FSMC interface clock */ |
367 | /* Enable the FSMC interface clock */ |
367 | RCC->AHBENR = 0x400080D8; |
368 | RCC->AHBENR = 0x400080D8; |
368 | |
369 | 369 | /* Delay after an RCC peripheral clock enabling */ |
|
370 | /* Delay after an RCC peripheral clock enabling */ |
370 | tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); |
371 | tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); |
371 | |
372 | 372 | (void)(tmpreg); |
|
373 | (void)(tmpreg); |
373 | |
374 | 374 | /* Configure and enable Bank1_SRAM3 */ |
|
375 | /* Configure and enable Bank1_SRAM3 */ |
375 | FSMC_Bank1->BTCR[4] = 0x00001011; |
376 | FSMC_Bank1->BTCR[4] = 0x00001011; |
376 | FSMC_Bank1->BTCR[5] = 0x00000300; |
377 | FSMC_Bank1->BTCR[5] = 0x00000300; |
377 | FSMC_Bank1E->BWTR[4] = 0x0FFFFFFF; |
378 | FSMC_Bank1E->BWTR[4] = 0x0FFFFFFF; |
378 | /* |
379 | /* |
379 | Bank1_SRAM3 is configured as follow: |
380 | Bank1_SRAM3 is configured as follow: |
380 | |
381 | 381 | p.FSMC_AddressSetupTime = 0; |
|
382 | p.FSMC_AddressSetupTime = 0; |
382 | p.FSMC_AddressHoldTime = 0; |
383 | p.FSMC_AddressHoldTime = 0; |
383 | p.FSMC_DataSetupTime = 3; |
384 | p.FSMC_DataSetupTime = 3; |
384 | p.FSMC_BusTurnAroundDuration = 0; |
385 | p.FSMC_BusTurnAroundDuration = 0; |
385 | p.FSMC_CLKDivision = 0; |
386 | p.FSMC_CLKDivision = 0; |
386 | p.FSMC_DataLatency = 0; |
387 | p.FSMC_DataLatency = 0; |
387 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
388 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
388 | |
389 | 389 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; |
|
390 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; |
390 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
391 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
391 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
392 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
392 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
393 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
393 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
394 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
394 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
395 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
395 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
396 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
396 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
397 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
397 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
398 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
398 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
399 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
399 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
400 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
400 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
401 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
401 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
402 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
402 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
403 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
403 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
404 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
404 | |
405 | 405 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
406 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
406 | |
407 | 407 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); |
|
408 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); |
408 | */ |
409 | */ |
409 | |
410 | 410 | } |
|
411 | } |
411 | #endif /* DATA_IN_ExtSRAM */ |
412 | #endif /* DATA_IN_ExtSRAM */ |
412 | #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ |
413 | #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ |
413 | |
414 | 414 | /** |
|
415 | /** |
415 | * @} |
416 | * @} |
416 | */ |
417 | */ |
417 | |
418 | 418 | /** |
|
419 | /** |
419 | * @} |
420 | * @} |
420 | */ |
421 | */ |
421 | |
422 | 422 | /** |
|
423 | /** |
423 | * @} |
424 | * @} |
424 | */ |
425 | */ |
425 | |
426 | 426 | ||
427 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
- |