Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_STM/TARGET_STM32F2/device/system_stm32f2xx.c@170:19eb464bc2be, 2017-08-03 (annotated)
- Committer:
- Kojto
- Date:
- Thu Aug 03 13:13:39 2017 +0100
- Revision:
- 170:19eb464bc2be
This updates the lib to the mbed lib v 148
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 170:19eb464bc2be | 1 | /** |
Kojto | 170:19eb464bc2be | 2 | ****************************************************************************** |
Kojto | 170:19eb464bc2be | 3 | * @file system_stm32f2xx.c |
Kojto | 170:19eb464bc2be | 4 | * @author MCD Application Team |
Kojto | 170:19eb464bc2be | 5 | * @version V2.2.0 |
Kojto | 170:19eb464bc2be | 6 | * @date 17-March-2017 |
Kojto | 170:19eb464bc2be | 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. |
Kojto | 170:19eb464bc2be | 8 | * |
Kojto | 170:19eb464bc2be | 9 | * This file provides two functions and one global variable to be called from |
Kojto | 170:19eb464bc2be | 10 | * user application: |
Kojto | 170:19eb464bc2be | 11 | * - SystemInit(): This function is called at startup just after reset and |
Kojto | 170:19eb464bc2be | 12 | * before branch to main program. This call is made inside |
Kojto | 170:19eb464bc2be | 13 | * the "startup_stm32f2xx.s" file. |
Kojto | 170:19eb464bc2be | 14 | * |
Kojto | 170:19eb464bc2be | 15 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used |
Kojto | 170:19eb464bc2be | 16 | * by the user application to setup the SysTick |
Kojto | 170:19eb464bc2be | 17 | * timer or configure other parameters. |
Kojto | 170:19eb464bc2be | 18 | * |
Kojto | 170:19eb464bc2be | 19 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must |
Kojto | 170:19eb464bc2be | 20 | * be called whenever the core clock is changed |
Kojto | 170:19eb464bc2be | 21 | * during program execution. |
Kojto | 170:19eb464bc2be | 22 | * |
Kojto | 170:19eb464bc2be | 23 | ****************************************************************************** |
Kojto | 170:19eb464bc2be | 24 | * @attention |
Kojto | 170:19eb464bc2be | 25 | * |
Kojto | 170:19eb464bc2be | 26 | * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> |
Kojto | 170:19eb464bc2be | 27 | * |
Kojto | 170:19eb464bc2be | 28 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 170:19eb464bc2be | 29 | * are permitted provided that the following conditions are met: |
Kojto | 170:19eb464bc2be | 30 | * 1. Redistributions of source code must retain the above copyright notice, |
Kojto | 170:19eb464bc2be | 31 | * this list of conditions and the following disclaimer. |
Kojto | 170:19eb464bc2be | 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Kojto | 170:19eb464bc2be | 33 | * this list of conditions and the following disclaimer in the documentation |
Kojto | 170:19eb464bc2be | 34 | * and/or other materials provided with the distribution. |
Kojto | 170:19eb464bc2be | 35 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Kojto | 170:19eb464bc2be | 36 | * may be used to endorse or promote products derived from this software |
Kojto | 170:19eb464bc2be | 37 | * without specific prior written permission. |
Kojto | 170:19eb464bc2be | 38 | * |
Kojto | 170:19eb464bc2be | 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Kojto | 170:19eb464bc2be | 40 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Kojto | 170:19eb464bc2be | 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 170:19eb464bc2be | 42 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Kojto | 170:19eb464bc2be | 43 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Kojto | 170:19eb464bc2be | 44 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Kojto | 170:19eb464bc2be | 45 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Kojto | 170:19eb464bc2be | 46 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Kojto | 170:19eb464bc2be | 47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Kojto | 170:19eb464bc2be | 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 170:19eb464bc2be | 49 | * |
Kojto | 170:19eb464bc2be | 50 | ****************************************************************************** |
Kojto | 170:19eb464bc2be | 51 | */ |
Kojto | 170:19eb464bc2be | 52 | |
Kojto | 170:19eb464bc2be | 53 | /** @addtogroup CMSIS |
Kojto | 170:19eb464bc2be | 54 | * @{ |
Kojto | 170:19eb464bc2be | 55 | */ |
Kojto | 170:19eb464bc2be | 56 | |
Kojto | 170:19eb464bc2be | 57 | /** @addtogroup stm32f2xx_system |
Kojto | 170:19eb464bc2be | 58 | * @{ |
Kojto | 170:19eb464bc2be | 59 | */ |
Kojto | 170:19eb464bc2be | 60 | |
Kojto | 170:19eb464bc2be | 61 | /** @addtogroup STM32F2xx_System_Private_Includes |
Kojto | 170:19eb464bc2be | 62 | * @{ |
Kojto | 170:19eb464bc2be | 63 | */ |
Kojto | 170:19eb464bc2be | 64 | |
Kojto | 170:19eb464bc2be | 65 | #include "stm32f2xx.h" |
Kojto | 170:19eb464bc2be | 66 | |
Kojto | 170:19eb464bc2be | 67 | #if !defined (HSE_VALUE) |
Kojto | 170:19eb464bc2be | 68 | #define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */ |
Kojto | 170:19eb464bc2be | 69 | #endif /* HSE_VALUE */ |
Kojto | 170:19eb464bc2be | 70 | |
Kojto | 170:19eb464bc2be | 71 | #if !defined (HSI_VALUE) |
Kojto | 170:19eb464bc2be | 72 | #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ |
Kojto | 170:19eb464bc2be | 73 | #endif /* HSI_VALUE */ |
Kojto | 170:19eb464bc2be | 74 | |
Kojto | 170:19eb464bc2be | 75 | /** |
Kojto | 170:19eb464bc2be | 76 | * @} |
Kojto | 170:19eb464bc2be | 77 | */ |
Kojto | 170:19eb464bc2be | 78 | |
Kojto | 170:19eb464bc2be | 79 | /** @addtogroup STM32F2xx_System_Private_TypesDefinitions |
Kojto | 170:19eb464bc2be | 80 | * @{ |
Kojto | 170:19eb464bc2be | 81 | */ |
Kojto | 170:19eb464bc2be | 82 | |
Kojto | 170:19eb464bc2be | 83 | /** |
Kojto | 170:19eb464bc2be | 84 | * @} |
Kojto | 170:19eb464bc2be | 85 | */ |
Kojto | 170:19eb464bc2be | 86 | |
Kojto | 170:19eb464bc2be | 87 | /** @addtogroup STM32F2xx_System_Private_Defines |
Kojto | 170:19eb464bc2be | 88 | * @{ |
Kojto | 170:19eb464bc2be | 89 | */ |
Kojto | 170:19eb464bc2be | 90 | /************************* Miscellaneous Configuration ************************/ |
Kojto | 170:19eb464bc2be | 91 | /*!< Uncomment the following line if you need to use external SRAM mounted |
Kojto | 170:19eb464bc2be | 92 | on STM322xG_EVAL board as data memory */ |
Kojto | 170:19eb464bc2be | 93 | /* #define DATA_IN_ExtSRAM */ |
Kojto | 170:19eb464bc2be | 94 | |
Kojto | 170:19eb464bc2be | 95 | /*!< Uncomment the following line if you need to relocate your vector Table in |
Kojto | 170:19eb464bc2be | 96 | Internal SRAM. */ |
Kojto | 170:19eb464bc2be | 97 | /* #define VECT_TAB_SRAM */ |
Kojto | 170:19eb464bc2be | 98 | #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. |
Kojto | 170:19eb464bc2be | 99 | This value must be a multiple of 0x200. */ |
Kojto | 170:19eb464bc2be | 100 | /******************************************************************************/ |
Kojto | 170:19eb464bc2be | 101 | |
Kojto | 170:19eb464bc2be | 102 | /** |
Kojto | 170:19eb464bc2be | 103 | * @} |
Kojto | 170:19eb464bc2be | 104 | */ |
Kojto | 170:19eb464bc2be | 105 | |
Kojto | 170:19eb464bc2be | 106 | /** @addtogroup STM32F2xx_System_Private_Macros |
Kojto | 170:19eb464bc2be | 107 | * @{ |
Kojto | 170:19eb464bc2be | 108 | */ |
Kojto | 170:19eb464bc2be | 109 | |
Kojto | 170:19eb464bc2be | 110 | /** |
Kojto | 170:19eb464bc2be | 111 | * @} |
Kojto | 170:19eb464bc2be | 112 | */ |
Kojto | 170:19eb464bc2be | 113 | |
Kojto | 170:19eb464bc2be | 114 | /** @addtogroup STM32F2xx_System_Private_Variables |
Kojto | 170:19eb464bc2be | 115 | * @{ |
Kojto | 170:19eb464bc2be | 116 | */ |
Kojto | 170:19eb464bc2be | 117 | |
Kojto | 170:19eb464bc2be | 118 | /* This variable can be updated in Three ways : |
Kojto | 170:19eb464bc2be | 119 | 1) by calling CMSIS function SystemCoreClockUpdate() |
Kojto | 170:19eb464bc2be | 120 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() |
Kojto | 170:19eb464bc2be | 121 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency |
Kojto | 170:19eb464bc2be | 122 | Note: If you use this function to configure the system clock; then there |
Kojto | 170:19eb464bc2be | 123 | is no need to call the 2 first functions listed above, since SystemCoreClock |
Kojto | 170:19eb464bc2be | 124 | variable is updated automatically. |
Kojto | 170:19eb464bc2be | 125 | */ |
Kojto | 170:19eb464bc2be | 126 | uint32_t SystemCoreClock = 16000000; |
Kojto | 170:19eb464bc2be | 127 | const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; |
Kojto | 170:19eb464bc2be | 128 | const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; |
Kojto | 170:19eb464bc2be | 129 | /** |
Kojto | 170:19eb464bc2be | 130 | * @} |
Kojto | 170:19eb464bc2be | 131 | */ |
Kojto | 170:19eb464bc2be | 132 | |
Kojto | 170:19eb464bc2be | 133 | /** @addtogroup STM32F2xx_System_Private_FunctionPrototypes |
Kojto | 170:19eb464bc2be | 134 | * @{ |
Kojto | 170:19eb464bc2be | 135 | */ |
Kojto | 170:19eb464bc2be | 136 | |
Kojto | 170:19eb464bc2be | 137 | #ifdef DATA_IN_ExtSRAM |
Kojto | 170:19eb464bc2be | 138 | static void SystemInit_ExtMemCtl(void); |
Kojto | 170:19eb464bc2be | 139 | #endif /* DATA_IN_ExtSRAM */ |
Kojto | 170:19eb464bc2be | 140 | |
Kojto | 170:19eb464bc2be | 141 | /** |
Kojto | 170:19eb464bc2be | 142 | * @} |
Kojto | 170:19eb464bc2be | 143 | */ |
Kojto | 170:19eb464bc2be | 144 | |
Kojto | 170:19eb464bc2be | 145 | /** @addtogroup STM32F2xx_System_Private_Functions |
Kojto | 170:19eb464bc2be | 146 | * @{ |
Kojto | 170:19eb464bc2be | 147 | */ |
Kojto | 170:19eb464bc2be | 148 | |
Kojto | 170:19eb464bc2be | 149 | /*+ MBED */ |
Kojto | 170:19eb464bc2be | 150 | #if 0 |
Kojto | 170:19eb464bc2be | 151 | /*- MBED */ |
Kojto | 170:19eb464bc2be | 152 | |
Kojto | 170:19eb464bc2be | 153 | /** |
Kojto | 170:19eb464bc2be | 154 | * @brief Setup the microcontroller system |
Kojto | 170:19eb464bc2be | 155 | * Initialize the Embedded Flash Interface, the PLL and update the |
Kojto | 170:19eb464bc2be | 156 | * SystemFrequency variable. |
Kojto | 170:19eb464bc2be | 157 | * @param None |
Kojto | 170:19eb464bc2be | 158 | * @retval None |
Kojto | 170:19eb464bc2be | 159 | */ |
Kojto | 170:19eb464bc2be | 160 | void SystemInit(void) |
Kojto | 170:19eb464bc2be | 161 | { |
Kojto | 170:19eb464bc2be | 162 | /* Reset the RCC clock configuration to the default reset state ------------*/ |
Kojto | 170:19eb464bc2be | 163 | /* Set HSION bit */ |
Kojto | 170:19eb464bc2be | 164 | RCC->CR |= (uint32_t)0x00000001; |
Kojto | 170:19eb464bc2be | 165 | |
Kojto | 170:19eb464bc2be | 166 | /* Reset CFGR register */ |
Kojto | 170:19eb464bc2be | 167 | RCC->CFGR = 0x00000000; |
Kojto | 170:19eb464bc2be | 168 | |
Kojto | 170:19eb464bc2be | 169 | /* Reset HSEON, CSSON and PLLON bits */ |
Kojto | 170:19eb464bc2be | 170 | RCC->CR &= (uint32_t)0xFEF6FFFF; |
Kojto | 170:19eb464bc2be | 171 | |
Kojto | 170:19eb464bc2be | 172 | /* Reset PLLCFGR register */ |
Kojto | 170:19eb464bc2be | 173 | RCC->PLLCFGR = 0x24003010; |
Kojto | 170:19eb464bc2be | 174 | |
Kojto | 170:19eb464bc2be | 175 | /* Reset HSEBYP bit */ |
Kojto | 170:19eb464bc2be | 176 | RCC->CR &= (uint32_t)0xFFFBFFFF; |
Kojto | 170:19eb464bc2be | 177 | |
Kojto | 170:19eb464bc2be | 178 | /* Disable all interrupts */ |
Kojto | 170:19eb464bc2be | 179 | RCC->CIR = 0x00000000; |
Kojto | 170:19eb464bc2be | 180 | |
Kojto | 170:19eb464bc2be | 181 | #ifdef DATA_IN_ExtSRAM |
Kojto | 170:19eb464bc2be | 182 | SystemInit_ExtMemCtl(); |
Kojto | 170:19eb464bc2be | 183 | #endif /* DATA_IN_ExtSRAM */ |
Kojto | 170:19eb464bc2be | 184 | |
Kojto | 170:19eb464bc2be | 185 | /* Configure the Vector Table location add offset address ------------------*/ |
Kojto | 170:19eb464bc2be | 186 | #ifdef VECT_TAB_SRAM |
Kojto | 170:19eb464bc2be | 187 | SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ |
Kojto | 170:19eb464bc2be | 188 | #else |
Kojto | 170:19eb464bc2be | 189 | SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ |
Kojto | 170:19eb464bc2be | 190 | #endif |
Kojto | 170:19eb464bc2be | 191 | } |
Kojto | 170:19eb464bc2be | 192 | |
Kojto | 170:19eb464bc2be | 193 | /*+ MBED */ |
Kojto | 170:19eb464bc2be | 194 | #endif |
Kojto | 170:19eb464bc2be | 195 | /*- MBED */ |
Kojto | 170:19eb464bc2be | 196 | |
Kojto | 170:19eb464bc2be | 197 | /** |
Kojto | 170:19eb464bc2be | 198 | * @brief Update SystemCoreClock variable according to Clock Register Values. |
Kojto | 170:19eb464bc2be | 199 | * The SystemCoreClock variable contains the core clock (HCLK), it can |
Kojto | 170:19eb464bc2be | 200 | * be used by the user application to setup the SysTick timer or configure |
Kojto | 170:19eb464bc2be | 201 | * other parameters. |
Kojto | 170:19eb464bc2be | 202 | * |
Kojto | 170:19eb464bc2be | 203 | * @note Each time the core clock (HCLK) changes, this function must be called |
Kojto | 170:19eb464bc2be | 204 | * to update SystemCoreClock variable value. Otherwise, any configuration |
Kojto | 170:19eb464bc2be | 205 | * based on this variable will be incorrect. |
Kojto | 170:19eb464bc2be | 206 | * |
Kojto | 170:19eb464bc2be | 207 | * @note - The system frequency computed by this function is not the real |
Kojto | 170:19eb464bc2be | 208 | * frequency in the chip. It is calculated based on the predefined |
Kojto | 170:19eb464bc2be | 209 | * constant and the selected clock source: |
Kojto | 170:19eb464bc2be | 210 | * |
Kojto | 170:19eb464bc2be | 211 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) |
Kojto | 170:19eb464bc2be | 212 | * |
Kojto | 170:19eb464bc2be | 213 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) |
Kojto | 170:19eb464bc2be | 214 | * |
Kojto | 170:19eb464bc2be | 215 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) |
Kojto | 170:19eb464bc2be | 216 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. |
Kojto | 170:19eb464bc2be | 217 | * |
Kojto | 170:19eb464bc2be | 218 | * (*) HSI_VALUE is a constant defined in stm32f2xx_hal_conf.h file (default value |
Kojto | 170:19eb464bc2be | 219 | * 16 MHz) but the real value may vary depending on the variations |
Kojto | 170:19eb464bc2be | 220 | * in voltage and temperature. |
Kojto | 170:19eb464bc2be | 221 | * |
Kojto | 170:19eb464bc2be | 222 | * (**) HSE_VALUE is a constant defined in stm32f2xx_hal_conf.h file (its value |
Kojto | 170:19eb464bc2be | 223 | * depends on the application requirements), user has to ensure that HSE_VALUE |
Kojto | 170:19eb464bc2be | 224 | * is same as the real frequency of the crystal used. Otherwise, this function |
Kojto | 170:19eb464bc2be | 225 | * may have wrong result. |
Kojto | 170:19eb464bc2be | 226 | * |
Kojto | 170:19eb464bc2be | 227 | * - The result of this function could be not correct when using fractional |
Kojto | 170:19eb464bc2be | 228 | * value for HSE crystal. |
Kojto | 170:19eb464bc2be | 229 | * |
Kojto | 170:19eb464bc2be | 230 | * @param None |
Kojto | 170:19eb464bc2be | 231 | * @retval None |
Kojto | 170:19eb464bc2be | 232 | */ |
Kojto | 170:19eb464bc2be | 233 | void SystemCoreClockUpdate(void) |
Kojto | 170:19eb464bc2be | 234 | { |
Kojto | 170:19eb464bc2be | 235 | uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; |
Kojto | 170:19eb464bc2be | 236 | |
Kojto | 170:19eb464bc2be | 237 | /* Get SYSCLK source -------------------------------------------------------*/ |
Kojto | 170:19eb464bc2be | 238 | tmp = RCC->CFGR & RCC_CFGR_SWS; |
Kojto | 170:19eb464bc2be | 239 | |
Kojto | 170:19eb464bc2be | 240 | switch (tmp) |
Kojto | 170:19eb464bc2be | 241 | { |
Kojto | 170:19eb464bc2be | 242 | case 0x00: /* HSI used as system clock source */ |
Kojto | 170:19eb464bc2be | 243 | SystemCoreClock = HSI_VALUE; |
Kojto | 170:19eb464bc2be | 244 | break; |
Kojto | 170:19eb464bc2be | 245 | case 0x04: /* HSE used as system clock source */ |
Kojto | 170:19eb464bc2be | 246 | SystemCoreClock = HSE_VALUE; |
Kojto | 170:19eb464bc2be | 247 | break; |
Kojto | 170:19eb464bc2be | 248 | case 0x08: /* PLL used as system clock source */ |
Kojto | 170:19eb464bc2be | 249 | |
Kojto | 170:19eb464bc2be | 250 | /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N |
Kojto | 170:19eb464bc2be | 251 | SYSCLK = PLL_VCO / PLL_P |
Kojto | 170:19eb464bc2be | 252 | */ |
Kojto | 170:19eb464bc2be | 253 | pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; |
Kojto | 170:19eb464bc2be | 254 | pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; |
Kojto | 170:19eb464bc2be | 255 | |
Kojto | 170:19eb464bc2be | 256 | if (pllsource != 0) |
Kojto | 170:19eb464bc2be | 257 | { |
Kojto | 170:19eb464bc2be | 258 | /* HSE used as PLL clock source */ |
Kojto | 170:19eb464bc2be | 259 | pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); |
Kojto | 170:19eb464bc2be | 260 | } |
Kojto | 170:19eb464bc2be | 261 | else |
Kojto | 170:19eb464bc2be | 262 | { |
Kojto | 170:19eb464bc2be | 263 | /* HSI used as PLL clock source */ |
Kojto | 170:19eb464bc2be | 264 | pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); |
Kojto | 170:19eb464bc2be | 265 | } |
Kojto | 170:19eb464bc2be | 266 | |
Kojto | 170:19eb464bc2be | 267 | pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; |
Kojto | 170:19eb464bc2be | 268 | SystemCoreClock = pllvco/pllp; |
Kojto | 170:19eb464bc2be | 269 | break; |
Kojto | 170:19eb464bc2be | 270 | default: |
Kojto | 170:19eb464bc2be | 271 | SystemCoreClock = HSI_VALUE; |
Kojto | 170:19eb464bc2be | 272 | break; |
Kojto | 170:19eb464bc2be | 273 | } |
Kojto | 170:19eb464bc2be | 274 | /* Compute HCLK frequency --------------------------------------------------*/ |
Kojto | 170:19eb464bc2be | 275 | /* Get HCLK prescaler */ |
Kojto | 170:19eb464bc2be | 276 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; |
Kojto | 170:19eb464bc2be | 277 | /* HCLK frequency */ |
Kojto | 170:19eb464bc2be | 278 | SystemCoreClock >>= tmp; |
Kojto | 170:19eb464bc2be | 279 | } |
Kojto | 170:19eb464bc2be | 280 | |
Kojto | 170:19eb464bc2be | 281 | #ifdef DATA_IN_ExtSRAM |
Kojto | 170:19eb464bc2be | 282 | /** |
Kojto | 170:19eb464bc2be | 283 | * @brief Setup the external memory controller. |
Kojto | 170:19eb464bc2be | 284 | * Called in startup_stm32f2xx.s before jump to main. |
Kojto | 170:19eb464bc2be | 285 | * This function configures the external SRAM mounted on STM322xG_EVAL board |
Kojto | 170:19eb464bc2be | 286 | * This SRAM will be used as program data memory (including heap and stack). |
Kojto | 170:19eb464bc2be | 287 | * @param None |
Kojto | 170:19eb464bc2be | 288 | * @retval None |
Kojto | 170:19eb464bc2be | 289 | */ |
Kojto | 170:19eb464bc2be | 290 | void SystemInit_ExtMemCtl(void) |
Kojto | 170:19eb464bc2be | 291 | { |
Kojto | 170:19eb464bc2be | 292 | __IO uint32_t tmp = 0x00; |
Kojto | 170:19eb464bc2be | 293 | |
Kojto | 170:19eb464bc2be | 294 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
Kojto | 170:19eb464bc2be | 295 | /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ |
Kojto | 170:19eb464bc2be | 296 | RCC->AHB1ENR |= 0x00000078; |
Kojto | 170:19eb464bc2be | 297 | /* Delay after an RCC peripheral clock enabling */ |
Kojto | 170:19eb464bc2be | 298 | tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN); |
Kojto | 170:19eb464bc2be | 299 | (void)(tmp); |
Kojto | 170:19eb464bc2be | 300 | |
Kojto | 170:19eb464bc2be | 301 | /* Connect PDx pins to FSMC Alternate function */ |
Kojto | 170:19eb464bc2be | 302 | GPIOD->AFR[0] = 0x00CCC0CC; |
Kojto | 170:19eb464bc2be | 303 | GPIOD->AFR[1] = 0xCCCCCCCC; |
Kojto | 170:19eb464bc2be | 304 | /* Configure PDx pins in Alternate function mode */ |
Kojto | 170:19eb464bc2be | 305 | GPIOD->MODER = 0xAAAA0A8A; |
Kojto | 170:19eb464bc2be | 306 | /* Configure PDx pins speed to 100 MHz */ |
Kojto | 170:19eb464bc2be | 307 | GPIOD->OSPEEDR = 0xFFFF0FCF; |
Kojto | 170:19eb464bc2be | 308 | /* Configure PDx pins Output type to push-pull */ |
Kojto | 170:19eb464bc2be | 309 | GPIOD->OTYPER = 0x00000000; |
Kojto | 170:19eb464bc2be | 310 | /* No pull-up, pull-down for PDx pins */ |
Kojto | 170:19eb464bc2be | 311 | GPIOD->PUPDR = 0x00000000; |
Kojto | 170:19eb464bc2be | 312 | |
Kojto | 170:19eb464bc2be | 313 | /* Connect PEx pins to FSMC Alternate function */ |
Kojto | 170:19eb464bc2be | 314 | GPIOE->AFR[0] = 0xC00CC0CC; |
Kojto | 170:19eb464bc2be | 315 | GPIOE->AFR[1] = 0xCCCCCCCC; |
Kojto | 170:19eb464bc2be | 316 | /* Configure PEx pins in Alternate function mode */ |
Kojto | 170:19eb464bc2be | 317 | GPIOE->MODER = 0xAAAA828A; |
Kojto | 170:19eb464bc2be | 318 | /* Configure PEx pins speed to 100 MHz */ |
Kojto | 170:19eb464bc2be | 319 | GPIOE->OSPEEDR = 0xFFFFC3CF; |
Kojto | 170:19eb464bc2be | 320 | /* Configure PEx pins Output type to push-pull */ |
Kojto | 170:19eb464bc2be | 321 | GPIOE->OTYPER = 0x00000000; |
Kojto | 170:19eb464bc2be | 322 | /* No pull-up, pull-down for PEx pins */ |
Kojto | 170:19eb464bc2be | 323 | GPIOE->PUPDR = 0x00000000; |
Kojto | 170:19eb464bc2be | 324 | |
Kojto | 170:19eb464bc2be | 325 | /* Connect PFx pins to FSMC Alternate function */ |
Kojto | 170:19eb464bc2be | 326 | GPIOF->AFR[0] = 0x00CCCCCC; |
Kojto | 170:19eb464bc2be | 327 | GPIOF->AFR[1] = 0xCCCC0000; |
Kojto | 170:19eb464bc2be | 328 | /* Configure PFx pins in Alternate function mode */ |
Kojto | 170:19eb464bc2be | 329 | GPIOF->MODER = 0xAA000AAA; |
Kojto | 170:19eb464bc2be | 330 | /* Configure PFx pins speed to 100 MHz */ |
Kojto | 170:19eb464bc2be | 331 | GPIOF->OSPEEDR = 0xFF000FFF; |
Kojto | 170:19eb464bc2be | 332 | /* Configure PFx pins Output type to push-pull */ |
Kojto | 170:19eb464bc2be | 333 | GPIOF->OTYPER = 0x00000000; |
Kojto | 170:19eb464bc2be | 334 | /* No pull-up, pull-down for PFx pins */ |
Kojto | 170:19eb464bc2be | 335 | GPIOF->PUPDR = 0x00000000; |
Kojto | 170:19eb464bc2be | 336 | |
Kojto | 170:19eb464bc2be | 337 | /* Connect PGx pins to FSMC Alternate function */ |
Kojto | 170:19eb464bc2be | 338 | GPIOG->AFR[0] = 0x00CCCCCC; |
Kojto | 170:19eb464bc2be | 339 | GPIOG->AFR[1] = 0x000000C0; |
Kojto | 170:19eb464bc2be | 340 | /* Configure PGx pins in Alternate function mode */ |
Kojto | 170:19eb464bc2be | 341 | GPIOG->MODER = 0x00085AAA; |
Kojto | 170:19eb464bc2be | 342 | /* Configure PGx pins speed to 100 MHz */ |
Kojto | 170:19eb464bc2be | 343 | GPIOG->OSPEEDR = 0x000CAFFF; |
Kojto | 170:19eb464bc2be | 344 | /* Configure PGx pins Output type to push-pull */ |
Kojto | 170:19eb464bc2be | 345 | GPIOG->OTYPER = 0x00000000; |
Kojto | 170:19eb464bc2be | 346 | /* No pull-up, pull-down for PGx pins */ |
Kojto | 170:19eb464bc2be | 347 | GPIOG->PUPDR = 0x00000000; |
Kojto | 170:19eb464bc2be | 348 | |
Kojto | 170:19eb464bc2be | 349 | /*--FSMC Configuration -------------------------------------------------------*/ |
Kojto | 170:19eb464bc2be | 350 | /* Enable the FSMC interface clock */ |
Kojto | 170:19eb464bc2be | 351 | RCC->AHB3ENR |= 0x00000001; |
Kojto | 170:19eb464bc2be | 352 | |
Kojto | 170:19eb464bc2be | 353 | /* Configure and enable Bank1_SRAM2 */ |
Kojto | 170:19eb464bc2be | 354 | FSMC_Bank1->BTCR[2] = 0x00001011; |
Kojto | 170:19eb464bc2be | 355 | FSMC_Bank1->BTCR[3] = 0x00000201; |
Kojto | 170:19eb464bc2be | 356 | FSMC_Bank1E->BWTR[2] = 0x0FFFFFFF; |
Kojto | 170:19eb464bc2be | 357 | } |
Kojto | 170:19eb464bc2be | 358 | #endif /* DATA_IN_ExtSRAM */ |
Kojto | 170:19eb464bc2be | 359 | |
Kojto | 170:19eb464bc2be | 360 | |
Kojto | 170:19eb464bc2be | 361 | /** |
Kojto | 170:19eb464bc2be | 362 | * @} |
Kojto | 170:19eb464bc2be | 363 | */ |
Kojto | 170:19eb464bc2be | 364 | |
Kojto | 170:19eb464bc2be | 365 | /** |
Kojto | 170:19eb464bc2be | 366 | * @} |
Kojto | 170:19eb464bc2be | 367 | */ |
Kojto | 170:19eb464bc2be | 368 | |
Kojto | 170:19eb464bc2be | 369 | /** |
Kojto | 170:19eb464bc2be | 370 | * @} |
Kojto | 170:19eb464bc2be | 371 | */ |
Kojto | 170:19eb464bc2be | 372 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |