annotate Common/Drivers/STM32F4xx_v220/Source/Templates/system_stm32f4xx.c @ 105:68181cd61f20 kittz

fix comments
author Dmitry Romanov <kitt@bk.ru>
date Mon, 24 Dec 2018 16:19:09 +0300
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file system_stm32f4xx.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V2.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 15-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * This file provides two functions and one global variable to be called from
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * user application:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * - SystemInit(): This function is called at startup just after reset and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * before branch to main program. This call is made inside
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * the "startup_stm32f4xx.s" file.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 * by the user application to setup the SysTick
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 * timer or configure other parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 * be called whenever the core clock is changed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 * during program execution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 /** @addtogroup CMSIS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 /** @addtogroup stm32f4xx_system
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 /** @addtogroup STM32F4xx_System_Private_Includes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 #include "stm32f4xx.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 #if !defined (HSE_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 #endif /* HSE_VALUE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 #if !defined (HSI_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 #endif /* HSI_VALUE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 /** @addtogroup STM32F4xx_System_Private_TypesDefinitions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 /** @addtogroup STM32F4xx_System_Private_Defines
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 /************************* Miscellaneous Configuration ************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 /*!< Uncomment the following line if you need to use external SRAM or SDRAM mounted
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 on STM324xG_EVAL/STM324x9I_EVAL boards as data memory */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 /* #define DATA_IN_ExtSRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 /* #define DATA_IN_ExtSDRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 #if defined(DATA_IN_ExtSRAM) && defined(DATA_IN_ExtSDRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 #error "Please select DATA_IN_ExtSRAM or DATA_IN_ExtSDRAM "
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 #endif /* DATA_IN_ExtSRAM && DATA_IN_ExtSDRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 /*!< Uncomment the following line if you need to relocate your vector Table in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 Internal SRAM. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 /* #define VECT_TAB_SRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 This value must be a multiple of 0x200. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 /******************************************************************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 /** @addtogroup STM32F4xx_System_Private_Macros
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 /** @addtogroup STM32F4xx_System_Private_Variables
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 /* This variable is updated in three ways:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 1) by calling CMSIS function SystemCoreClockUpdate()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 Note: If you use this function to configure the system clock; then there
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 is no need to call the 2 first functions listed above, since SystemCoreClock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 variable is updated automatically.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 uint32_t SystemCoreClock = 16000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 __IO const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 /** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 static void SystemInit_ExtMemCtl(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 /** @addtogroup STM32F4xx_System_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 * @brief Setup the microcontroller system
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 * Initialize the FPU setting, vector table location and External memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 * configuration.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 * @param None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 void SystemInit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 /* FPU settings ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 /* Reset the RCC clock configuration to the default reset state ------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 /* Set HSION bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 RCC->CR |= (uint32_t)0x00000001;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 /* Reset CFGR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 RCC->CFGR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 /* Reset HSEON, CSSON and PLLON bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 RCC->CR &= (uint32_t)0xFEF6FFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 /* Reset PLLCFGR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 RCC->PLLCFGR = 0x24003010;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 /* Reset HSEBYP bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 RCC->CR &= (uint32_t)0xFFFBFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 /* Disable all interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 RCC->CIR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 SystemInit_ExtMemCtl();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 /* Configure the Vector Table location add offset address ------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 #ifdef VECT_TAB_SRAM
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 #else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 * @brief Update SystemCoreClock variable according to Clock Register Values.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 * The SystemCoreClock variable contains the core clock (HCLK), it can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 * be used by the user application to setup the SysTick timer or configure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 * other parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 * @note Each time the core clock (HCLK) changes, this function must be called
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 * to update SystemCoreClock variable value. Otherwise, any configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 * based on this variable will be incorrect.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 * @note - The system frequency computed by this function is not the real
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 * frequency in the chip. It is calculated based on the predefined
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 * constant and the selected clock source:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 * or HSI_VALUE(*) multiplied/divided by the PLL factors.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 * (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 * 16 MHz) but the real value may vary depending on the variations
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 * in voltage and temperature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 * (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (its value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 * depends on the application requirements), user has to ensure that HSE_VALUE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 * is same as the real frequency of the crystal used. Otherwise, this function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 * may have wrong result.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 * - The result of this function could be not correct when using fractional
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 * value for HSE crystal.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 * @param None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 void SystemCoreClockUpdate(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 /* Get SYSCLK source -------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 tmp = RCC->CFGR & RCC_CFGR_SWS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 switch (tmp)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 case 0x00: /* HSI used as system clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 SystemCoreClock = HSI_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 case 0x04: /* HSE used as system clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 SystemCoreClock = HSE_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 case 0x08: /* PLL used as system clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 SYSCLK = PLL_VCO / PLL_P
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 if (pllsource != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 /* HSE used as PLL clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 /* HSI used as PLL clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 SystemCoreClock = pllvco/pllp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 SystemCoreClock = HSI_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 /* Compute HCLK frequency --------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /* Get HCLK prescaler */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 /* HCLK frequency */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 SystemCoreClock >>= tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 * @brief Setup the external memory controller.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 * Called in startup_stm32f4xx.s before jump to main.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 * This function configures the external memories (SRAM/SDRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 * This SRAM/SDRAM will be used as program data memory (including heap and stack).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 * @param None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 void SystemInit_ExtMemCtl(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 #if defined (DATA_IN_ExtSDRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 register uint32_t tmpreg = 0, timeout = 0xFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 register uint32_t index;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 RCC->AHB1ENR |= 0x000001F8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 /* Connect PDx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 GPIOD->AFR[0] = 0x000000CC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 GPIOD->AFR[1] = 0xCC000CCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 /* Configure PDx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 GPIOD->MODER = 0xA02A000A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 /* Configure PDx pins speed to 50 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 GPIOD->OSPEEDR = 0xA02A000A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 /* Configure PDx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 GPIOD->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 /* No pull-up, pull-down for PDx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 GPIOD->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 /* Connect PEx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 GPIOE->AFR[0] = 0xC00000CC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 GPIOE->AFR[1] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 /* Configure PEx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 GPIOE->MODER = 0xAAAA800A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 /* Configure PEx pins speed to 50 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 GPIOE->OSPEEDR = 0xAAAA800A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 /* Configure PEx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 GPIOE->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 /* No pull-up, pull-down for PEx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 GPIOE->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 /* Connect PFx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 GPIOF->AFR[0] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 GPIOF->AFR[1] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 /* Configure PFx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 GPIOF->MODER = 0xAA800AAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 /* Configure PFx pins speed to 50 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 GPIOF->OSPEEDR = 0xAA800AAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 /* Configure PFx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 GPIOF->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 /* No pull-up, pull-down for PFx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 GPIOF->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 /* Connect PGx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 GPIOG->AFR[0] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 GPIOG->AFR[1] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 /* Configure PGx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 GPIOG->MODER = 0xAAAAAAAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 /* Configure PGx pins speed to 50 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 GPIOG->OSPEEDR = 0xAAAAAAAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 /* Configure PGx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 GPIOG->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 /* No pull-up, pull-down for PGx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 GPIOG->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 /* Connect PHx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 GPIOH->AFR[0] = 0x00C0CC00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 GPIOH->AFR[1] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /* Configure PHx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 GPIOH->MODER = 0xAAAA08A0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 /* Configure PHx pins speed to 50 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 GPIOH->OSPEEDR = 0xAAAA08A0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 /* Configure PHx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 GPIOH->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 /* No pull-up, pull-down for PHx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 GPIOH->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 /* Connect PIx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 GPIOI->AFR[0] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 GPIOI->AFR[1] = 0x00000CC0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /* Configure PIx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 GPIOI->MODER = 0x0028AAAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 /* Configure PIx pins speed to 50 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 GPIOI->OSPEEDR = 0x0028AAAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 /* Configure PIx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 GPIOI->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 /* No pull-up, pull-down for PIx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 GPIOI->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 /*-- FMC Configuration ------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 /* Enable the FMC interface clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 RCC->AHB3ENR |= 0x00000001;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 /* Configure and enable SDRAM bank1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 FMC_Bank5_6->SDCR[0] = 0x000019E4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 FMC_Bank5_6->SDTR[0] = 0x01115351;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* SDRAM initialization sequence */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 /* Clock enable command */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 FMC_Bank5_6->SDCMR = 0x00000011;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 while((tmpreg != 0) && (timeout-- > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 /* Delay */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 for (index = 0; index<1000; index++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 /* PALL command */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 FMC_Bank5_6->SDCMR = 0x00000012;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 timeout = 0xFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 while((tmpreg != 0) && (timeout-- > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 /* Auto refresh command */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 FMC_Bank5_6->SDCMR = 0x00000073;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 timeout = 0xFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 while((tmpreg != 0) && (timeout-- > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 /* MRD register program */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 FMC_Bank5_6->SDCMR = 0x00046014;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 timeout = 0xFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 while((tmpreg != 0) && (timeout-- > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 /* Set refresh count */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 tmpreg = FMC_Bank5_6->SDRTR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 /* Disable write protection */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 tmpreg = FMC_Bank5_6->SDCR[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 #endif /* DATA_IN_ExtSDRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 #if defined(DATA_IN_ExtSRAM)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 /*-- GPIOs Configuration -----------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 RCC->AHB1ENR |= 0x00000078;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 /* Connect PDx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 GPIOD->AFR[0] = 0x00CCC0CC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 GPIOD->AFR[1] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 /* Configure PDx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 GPIOD->MODER = 0xAAAA0A8A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 /* Configure PDx pins speed to 100 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 GPIOD->OSPEEDR = 0xFFFF0FCF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 /* Configure PDx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 GPIOD->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /* No pull-up, pull-down for PDx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 GPIOD->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 /* Connect PEx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 GPIOE->AFR[0] = 0xC00CC0CC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 GPIOE->AFR[1] = 0xCCCCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 /* Configure PEx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 GPIOE->MODER = 0xAAAA828A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 /* Configure PEx pins speed to 100 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 GPIOE->OSPEEDR = 0xFFFFC3CF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 /* Configure PEx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 GPIOE->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 /* No pull-up, pull-down for PEx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 GPIOE->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 /* Connect PFx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 GPIOF->AFR[0] = 0x00CCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 GPIOF->AFR[1] = 0xCCCC0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 /* Configure PFx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 GPIOF->MODER = 0xAA000AAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 /* Configure PFx pins speed to 100 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 GPIOF->OSPEEDR = 0xFF000FFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 /* Configure PFx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 GPIOF->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 /* No pull-up, pull-down for PFx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 GPIOF->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 /* Connect PGx pins to FMC Alternate function */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 GPIOG->AFR[0] = 0x00CCCCCC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 GPIOG->AFR[1] = 0x000000C0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 /* Configure PGx pins in Alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 GPIOG->MODER = 0x00085AAA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 /* Configure PGx pins speed to 100 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 GPIOG->OSPEEDR = 0x000CAFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 /* Configure PGx pins Output type to push-pull */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 GPIOG->OTYPER = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 /* No pull-up, pull-down for PGx pins */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 GPIOG->PUPDR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 /*-- FMC/FSMC Configuration --------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 /* Enable the FMC/FSMC interface clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 RCC->AHB3ENR |= 0x00000001;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 /* Configure and enable Bank1_SRAM2 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 FMC_Bank1->BTCR[2] = 0x00001011;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 FMC_Bank1->BTCR[3] = 0x00000201;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 FMC_Bank1E->BWTR[2] = 0x0fffffff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 /* Configure and enable Bank1_SRAM2 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 FSMC_Bank1->BTCR[2] = 0x00001011;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 FSMC_Bank1->BTCR[3] = 0x00000201;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 FSMC_Bank1E->BWTR[2] = 0x0FFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 #endif /* DATA_IN_ExtSRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/