annotate f103c8/Src/system_stm32f1xx.c @ 2:0c59e7a7782a

Working on GPIO and RCC
author cin
date Mon, 16 Jan 2017 11:04:47 +0300
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3 * @file system_stm32f1xx.c
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4 * @author MCD Application Team
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5 * @version V4.1.0
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
6 * @date 29-April-2016
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
7 * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
8 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
9 * 1. This file provides two functions and one global variable to be called from
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * user application:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 * factors, AHB/APBx prescalers and Flash settings).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 * This function is called at startup just after reset and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 * before branch to main program. This call is made inside
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 * the "startup_stm32f1xx_xx.s" file.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 * by the user application to setup the SysTick
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 * timer or configure other parameters.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21 * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 * be called whenever the core clock is changed
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23 * during program execution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 * 2. After each device reset the HSI (8 MHz) is used as system clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 * configure the system clock before to branch to main program.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 * the product used), refer to "HSE_VALUE".
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31 * When HSE is used as system clock source, directly or through PLL, and you
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32 * are using different crystal you have to adapt the HSE value to your own
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33 * configuration.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 * @attention
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40 * Redistribution and use in source and binary forms, with or without modification,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41 * are permitted provided that the following conditions are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42 * 1. Redistributions of source code must retain the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43 * this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44 * 2. Redistributions in binary form must reproduce the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 * this list of conditions and the following disclaimer in the documentation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46 * and/or other materials provided with the distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47 * 3. Neither the name of STMicroelectronics nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48 * may be used to endorse or promote products derived from this software
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 * without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65 /** @addtogroup CMSIS
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 /** @addtogroup stm32f1xx_system
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73 /** @addtogroup STM32F1xx_System_Private_Includes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 #include "stm32f1xx.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
78
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
79 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
80 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 /** @addtogroup STM32F1xx_System_Private_TypesDefinitions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91 /** @addtogroup STM32F1xx_System_Private_Defines
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 #if !defined (HSE_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96 #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97 This value can be provided and adapted by the user application. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 #endif /* HSE_VALUE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100 #if !defined (HSI_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101 #define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102 This value can be provided and adapted by the user application. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 #endif /* HSI_VALUE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105 /*!< Uncomment the following line if you need to use external SRAM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107 /* #define DATA_IN_ExtSRAM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110 /*!< Uncomment the following line if you need to relocate your vector Table in
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111 Internal SRAM. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112 /* #define VECT_TAB_SRAM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 #define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114 This value must be a multiple of 0x200. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121 /** @addtogroup STM32F1xx_System_Private_Macros
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129 /** @addtogroup STM32F1xx_System_Private_Variables
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
131 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
132
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
133 /*******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
134 * Clock Definitions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
135 *******************************************************************************/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
136 #if defined(STM32F100xB) ||defined(STM32F100xE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
137 uint32_t SystemCoreClock = 24000000; /*!< System Clock Frequency (Core Clock) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
138 #else /*!< HSI Selected as System Clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
139 uint32_t SystemCoreClock = 72000000; /*!< System Clock Frequency (Core Clock) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
140 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
141
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
142 const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
143 const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
144
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
145 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
146 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
147 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
148
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
149 /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
150 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
151 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
152
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
153 #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
154 #ifdef DATA_IN_ExtSRAM
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
155 static void SystemInit_ExtMemCtl(void);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
156 #endif /* DATA_IN_ExtSRAM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
157 #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
158
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
159 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
160 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
161 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
162
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
163 /** @addtogroup STM32F1xx_System_Private_Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
164 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
165 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
166
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
167 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
168 * @brief Setup the microcontroller system
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
169 * Initialize the Embedded Flash Interface, the PLL and update the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
170 * SystemCoreClock variable.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
171 * @note This function should be used only after reset.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
172 * @param None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
173 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
174 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
175 void SystemInit (void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
176 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
177 /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
178 /* Set HSION bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
179 RCC->CR |= (uint32_t)0x00000001;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
180
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
181 /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
182 #if !defined(STM32F105xC) && !defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
183 RCC->CFGR &= (uint32_t)0xF8FF0000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
184 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
185 RCC->CFGR &= (uint32_t)0xF0FF0000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
186 #endif /* STM32F105xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
187
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
188 /* Reset HSEON, CSSON and PLLON bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
189 RCC->CR &= (uint32_t)0xFEF6FFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
190
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
191 /* Reset HSEBYP bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
192 RCC->CR &= (uint32_t)0xFFFBFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
193
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
194 /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
195 RCC->CFGR &= (uint32_t)0xFF80FFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
196
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
197 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
198 /* Reset PLL2ON and PLL3ON bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
199 RCC->CR &= (uint32_t)0xEBFFFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
200
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
201 /* Disable all interrupts and clear pending bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
202 RCC->CIR = 0x00FF0000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
203
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
204 /* Reset CFGR2 register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
205 RCC->CFGR2 = 0x00000000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
206 #elif defined(STM32F100xB) || defined(STM32F100xE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
207 /* Disable all interrupts and clear pending bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
208 RCC->CIR = 0x009F0000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
209
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
210 /* Reset CFGR2 register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
211 RCC->CFGR2 = 0x00000000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
212 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
213 /* Disable all interrupts and clear pending bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
214 RCC->CIR = 0x009F0000;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
215 #endif /* STM32F105xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
216
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
217 #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
218 #ifdef DATA_IN_ExtSRAM
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
219 SystemInit_ExtMemCtl();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
220 #endif /* DATA_IN_ExtSRAM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
221 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
222
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
223 #ifdef VECT_TAB_SRAM
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
224 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
225 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
226 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
227 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
228 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
229
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
230 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
231 * @brief Update SystemCoreClock variable according to Clock Register Values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
232 * The SystemCoreClock variable contains the core clock (HCLK), it can
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
233 * be used by the user application to setup the SysTick timer or configure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
234 * other parameters.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
235 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
236 * @note Each time the core clock (HCLK) changes, this function must be called
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
237 * to update SystemCoreClock variable value. Otherwise, any configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
238 * based on this variable will be incorrect.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
239 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
240 * @note - The system frequency computed by this function is not the real
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
241 * frequency in the chip. It is calculated based on the predefined
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
242 * constant and the selected clock source:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
243 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
244 * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
245 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
246 * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
247 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
248 * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
249 * or HSI_VALUE(*) multiplied by the PLL factors.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
250 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
251 * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
252 * 8 MHz) but the real value may vary depending on the variations
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
253 * in voltage and temperature.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
254 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
255 * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
256 * 8 MHz or 25 MHz, depending on the product used), user has to ensure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
257 * that HSE_VALUE is same as the real frequency of the crystal used.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
258 * Otherwise, this function may have wrong result.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
259 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
260 * - The result of this function could be not correct when using fractional
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
261 * value for HSE crystal.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
262 * @param None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
263 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
264 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
265 void SystemCoreClockUpdate (void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
266 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
267 uint32_t tmp = 0, pllmull = 0, pllsource = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
268
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
269 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
270 uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
271 #endif /* STM32F105xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
272
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
273 #if defined(STM32F100xB) || defined(STM32F100xE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
274 uint32_t prediv1factor = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
275 #endif /* STM32F100xB or STM32F100xE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
276
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
277 /* Get SYSCLK source -------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
278 tmp = RCC->CFGR & RCC_CFGR_SWS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
279
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
280 switch (tmp)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
281 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
282 case 0x00: /* HSI used as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
283 SystemCoreClock = HSI_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
284 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
285 case 0x04: /* HSE used as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
286 SystemCoreClock = HSE_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
287 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
288 case 0x08: /* PLL used as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
289
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
290 /* Get PLL clock source and multiplication factor ----------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
291 pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
292 pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
293
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
294 #if !defined(STM32F105xC) && !defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
295 pllmull = ( pllmull >> 18) + 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
296
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
297 if (pllsource == 0x00)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
298 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
299 /* HSI oscillator clock divided by 2 selected as PLL clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
300 SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
301 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
302 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
303 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
304 #if defined(STM32F100xB) || defined(STM32F100xE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
305 prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
306 /* HSE oscillator clock selected as PREDIV1 clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
307 SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
308 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
309 /* HSE selected as PLL clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
310 if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
311 {/* HSE oscillator clock divided by 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
312 SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
313 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
314 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
315 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
316 SystemCoreClock = HSE_VALUE * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
317 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
318 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
319 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
320 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
321 pllmull = pllmull >> 18;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
322
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
323 if (pllmull != 0x0D)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
324 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
325 pllmull += 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
326 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
327 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
328 { /* PLL multiplication factor = PLL input clock * 6.5 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
329 pllmull = 13 / 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
330 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
331
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
332 if (pllsource == 0x00)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
333 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
334 /* HSI oscillator clock divided by 2 selected as PLL clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
335 SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
336 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
337 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
338 {/* PREDIV1 selected as PLL clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
339
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
340 /* Get PREDIV1 clock source and division factor */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
341 prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
342 prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
343
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
344 if (prediv1source == 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
345 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
346 /* HSE oscillator clock selected as PREDIV1 clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
347 SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
348 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
349 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
350 {/* PLL2 clock selected as PREDIV1 clock entry */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
351
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
352 /* Get PREDIV2 division factor and PLL2 multiplication factor */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
353 prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
354 pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
355 SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
356 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
357 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
358 #endif /* STM32F105xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
359 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
360
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
361 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
362 SystemCoreClock = HSI_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
363 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
364 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
365
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
366 /* Compute HCLK clock frequency ----------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
367 /* Get HCLK prescaler */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
368 tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
369 /* HCLK clock frequency */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
370 SystemCoreClock >>= tmp;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
371 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
372
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
373 #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
374 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
375 * @brief Setup the external memory controller. Called in startup_stm32f1xx.s
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
376 * before jump to __main
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
377 * @param None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
378 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
379 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
380 #ifdef DATA_IN_ExtSRAM
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
381 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
382 * @brief Setup the external memory controller.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
383 * Called in startup_stm32f1xx_xx.s/.c before jump to main.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
384 * This function configures the external SRAM mounted on STM3210E-EVAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
385 * board (STM32 High density devices). This SRAM will be used as program
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
386 * data memory (including heap and stack).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
387 * @param None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
388 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
389 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
390 void SystemInit_ExtMemCtl(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
391 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
392 __IO uint32_t tmpreg;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
393 /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
394 required, then adjust the Register Addresses */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
395
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
396 /* Enable FSMC clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
397 RCC->AHBENR = 0x00000114;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
398
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
399 /* Delay after an RCC peripheral clock enabling */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
400 tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
401
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
402 /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
403 RCC->APB2ENR = 0x000001E0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
404
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
405 /* Delay after an RCC peripheral clock enabling */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
406 tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
407
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
408 (void)(tmpreg);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
409
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
410 /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
411 /*---------------- SRAM Address lines configuration -------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
412 /*---------------- NOE and NWE configuration --------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
413 /*---------------- NE3 configuration ----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
414 /*---------------- NBL0, NBL1 configuration ---------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
415
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
416 GPIOD->CRL = 0x44BB44BB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
417 GPIOD->CRH = 0xBBBBBBBB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
418
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
419 GPIOE->CRL = 0xB44444BB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
420 GPIOE->CRH = 0xBBBBBBBB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
421
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
422 GPIOF->CRL = 0x44BBBBBB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
423 GPIOF->CRH = 0xBBBB4444;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
424
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
425 GPIOG->CRL = 0x44BBBBBB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
426 GPIOG->CRH = 0x444B4B44;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
427
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
428 /*---------------- FSMC Configuration ---------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
429 /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
430
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
431 FSMC_Bank1->BTCR[4] = 0x00001091;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
432 FSMC_Bank1->BTCR[5] = 0x00110212;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
433 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
434 #endif /* DATA_IN_ExtSRAM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
435 #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
436
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
437 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
438 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
439 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
440
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
441 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
442 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
443 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
444
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
445 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
446 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
447 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
448 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/