fix LPC812 PWM
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/system_stm32f4xx.c@129:2e517c56bcfb, 2016-05-16 (annotated)
- Committer:
- nameless129
- Date:
- Mon May 16 16:50:30 2016 +0000
- Revision:
- 129:2e517c56bcfb
- Parent:
- 25:ac5b0a371348
PWM Fix:Duty 0%??H???????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 25:ac5b0a371348 | 1 | /** |
mbed_official | 25:ac5b0a371348 | 2 | ****************************************************************************** |
mbed_official | 25:ac5b0a371348 | 3 | * @file system_stm32f4xx.c |
mbed_official | 25:ac5b0a371348 | 4 | * @author MCD Application Team |
mbed_official | 25:ac5b0a371348 | 5 | * @version V2.4.1 |
mbed_official | 25:ac5b0a371348 | 6 | * @date 09-October-2015 |
mbed_official | 25:ac5b0a371348 | 7 | * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File. |
mbed_official | 25:ac5b0a371348 | 8 | * |
mbed_official | 25:ac5b0a371348 | 9 | * This file provides two functions and one global variable to be called from |
mbed_official | 25:ac5b0a371348 | 10 | * user application: |
mbed_official | 25:ac5b0a371348 | 11 | * - SystemInit(): This function is called at startup just after reset and |
mbed_official | 25:ac5b0a371348 | 12 | * before branch to main program. This call is made inside |
mbed_official | 25:ac5b0a371348 | 13 | * the "startup_stm32f4xx.s" file. |
mbed_official | 25:ac5b0a371348 | 14 | * |
mbed_official | 25:ac5b0a371348 | 15 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used |
mbed_official | 25:ac5b0a371348 | 16 | * by the user application to setup the SysTick |
mbed_official | 25:ac5b0a371348 | 17 | * timer or configure other parameters. |
mbed_official | 25:ac5b0a371348 | 18 | * |
mbed_official | 25:ac5b0a371348 | 19 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must |
mbed_official | 25:ac5b0a371348 | 20 | * be called whenever the core clock is changed |
mbed_official | 25:ac5b0a371348 | 21 | * during program execution. |
mbed_official | 25:ac5b0a371348 | 22 | * |
mbed_official | 25:ac5b0a371348 | 23 | * |
mbed_official | 25:ac5b0a371348 | 24 | ****************************************************************************** |
mbed_official | 25:ac5b0a371348 | 25 | * @attention |
mbed_official | 25:ac5b0a371348 | 26 | * |
mbed_official | 25:ac5b0a371348 | 27 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
mbed_official | 25:ac5b0a371348 | 28 | * |
mbed_official | 25:ac5b0a371348 | 29 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 25:ac5b0a371348 | 30 | * are permitted provided that the following conditions are met: |
mbed_official | 25:ac5b0a371348 | 31 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 25:ac5b0a371348 | 32 | * this list of conditions and the following disclaimer. |
mbed_official | 25:ac5b0a371348 | 33 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 25:ac5b0a371348 | 34 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 25:ac5b0a371348 | 35 | * and/or other materials provided with the distribution. |
mbed_official | 25:ac5b0a371348 | 36 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 25:ac5b0a371348 | 37 | * may be used to endorse or promote products derived from this software |
mbed_official | 25:ac5b0a371348 | 38 | * without specific prior written permission. |
mbed_official | 25:ac5b0a371348 | 39 | * |
mbed_official | 25:ac5b0a371348 | 40 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 25:ac5b0a371348 | 41 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 25:ac5b0a371348 | 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 25:ac5b0a371348 | 43 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 25:ac5b0a371348 | 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 25:ac5b0a371348 | 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 25:ac5b0a371348 | 46 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 25:ac5b0a371348 | 47 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 25:ac5b0a371348 | 48 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 25:ac5b0a371348 | 49 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 25:ac5b0a371348 | 50 | * |
mbed_official | 25:ac5b0a371348 | 51 | ****************************************************************************** |
mbed_official | 25:ac5b0a371348 | 52 | */ |
mbed_official | 25:ac5b0a371348 | 53 | |
mbed_official | 25:ac5b0a371348 | 54 | /** @addtogroup CMSIS |
mbed_official | 25:ac5b0a371348 | 55 | * @{ |
mbed_official | 25:ac5b0a371348 | 56 | */ |
mbed_official | 25:ac5b0a371348 | 57 | |
mbed_official | 25:ac5b0a371348 | 58 | /** @addtogroup stm32f4xx_system |
mbed_official | 25:ac5b0a371348 | 59 | * @{ |
mbed_official | 25:ac5b0a371348 | 60 | */ |
mbed_official | 25:ac5b0a371348 | 61 | |
mbed_official | 25:ac5b0a371348 | 62 | /** @addtogroup STM32F4xx_System_Private_Includes |
mbed_official | 25:ac5b0a371348 | 63 | * @{ |
mbed_official | 25:ac5b0a371348 | 64 | */ |
mbed_official | 25:ac5b0a371348 | 65 | |
mbed_official | 25:ac5b0a371348 | 66 | |
mbed_official | 25:ac5b0a371348 | 67 | #include "stm32f4xx.h" |
mbed_official | 25:ac5b0a371348 | 68 | #include "hal_tick.h" |
mbed_official | 25:ac5b0a371348 | 69 | |
mbed_official | 25:ac5b0a371348 | 70 | #if !defined (HSE_VALUE) |
mbed_official | 25:ac5b0a371348 | 71 | #define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */ |
mbed_official | 25:ac5b0a371348 | 72 | #endif /* HSE_VALUE */ |
mbed_official | 25:ac5b0a371348 | 73 | |
mbed_official | 25:ac5b0a371348 | 74 | #if !defined (HSI_VALUE) |
mbed_official | 25:ac5b0a371348 | 75 | #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ |
mbed_official | 25:ac5b0a371348 | 76 | #endif /* HSI_VALUE */ |
mbed_official | 25:ac5b0a371348 | 77 | |
mbed_official | 25:ac5b0a371348 | 78 | /** |
mbed_official | 25:ac5b0a371348 | 79 | * @} |
mbed_official | 25:ac5b0a371348 | 80 | */ |
mbed_official | 25:ac5b0a371348 | 81 | |
mbed_official | 25:ac5b0a371348 | 82 | /** @addtogroup STM32F4xx_System_Private_TypesDefinitions |
mbed_official | 25:ac5b0a371348 | 83 | * @{ |
mbed_official | 25:ac5b0a371348 | 84 | */ |
mbed_official | 25:ac5b0a371348 | 85 | |
mbed_official | 25:ac5b0a371348 | 86 | /** |
mbed_official | 25:ac5b0a371348 | 87 | * @} |
mbed_official | 25:ac5b0a371348 | 88 | */ |
mbed_official | 25:ac5b0a371348 | 89 | |
mbed_official | 25:ac5b0a371348 | 90 | /** @addtogroup STM32F4xx_System_Private_Defines |
mbed_official | 25:ac5b0a371348 | 91 | * @{ |
mbed_official | 25:ac5b0a371348 | 92 | */ |
mbed_official | 25:ac5b0a371348 | 93 | |
mbed_official | 25:ac5b0a371348 | 94 | /************************* Miscellaneous Configuration ************************/ |
mbed_official | 25:ac5b0a371348 | 95 | /*!< Uncomment the following line if you need to use external SRAM or SDRAM as data memory */ |
mbed_official | 25:ac5b0a371348 | 96 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\ |
mbed_official | 25:ac5b0a371348 | 97 | || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ |
mbed_official | 25:ac5b0a371348 | 98 | || defined(STM32F469xx) || defined(STM32F479xx) |
mbed_official | 25:ac5b0a371348 | 99 | /* #define DATA_IN_ExtSRAM */ |
mbed_official | 25:ac5b0a371348 | 100 | #endif /* STM32F40xxx || STM32F41xxx || STM32F42xxx || STM32F43xxx || STM32F469xx || STM32F479xx */ |
mbed_official | 25:ac5b0a371348 | 101 | |
mbed_official | 25:ac5b0a371348 | 102 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ |
mbed_official | 25:ac5b0a371348 | 103 | || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) |
mbed_official | 25:ac5b0a371348 | 104 | /* #define DATA_IN_ExtSDRAM */ |
mbed_official | 25:ac5b0a371348 | 105 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\ |
mbed_official | 25:ac5b0a371348 | 106 | STM32F479xx */ |
mbed_official | 25:ac5b0a371348 | 107 | |
mbed_official | 25:ac5b0a371348 | 108 | #if defined(DATA_IN_ExtSRAM) && defined(DATA_IN_ExtSDRAM) |
mbed_official | 25:ac5b0a371348 | 109 | #error "Please select DATA_IN_ExtSRAM or DATA_IN_ExtSDRAM " |
mbed_official | 25:ac5b0a371348 | 110 | #endif /* DATA_IN_ExtSRAM && DATA_IN_ExtSDRAM */ |
mbed_official | 25:ac5b0a371348 | 111 | |
mbed_official | 25:ac5b0a371348 | 112 | /*!< Uncomment the following line if you need to relocate your vector Table in |
mbed_official | 25:ac5b0a371348 | 113 | Internal SRAM. */ |
mbed_official | 25:ac5b0a371348 | 114 | /* #define VECT_TAB_SRAM */ |
mbed_official | 25:ac5b0a371348 | 115 | #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. |
mbed_official | 25:ac5b0a371348 | 116 | This value must be a multiple of 0x200. */ |
mbed_official | 25:ac5b0a371348 | 117 | /******************************************************************************/ |
mbed_official | 25:ac5b0a371348 | 118 | |
mbed_official | 25:ac5b0a371348 | 119 | /** |
mbed_official | 25:ac5b0a371348 | 120 | * @} |
mbed_official | 25:ac5b0a371348 | 121 | */ |
mbed_official | 25:ac5b0a371348 | 122 | |
mbed_official | 25:ac5b0a371348 | 123 | /** @addtogroup STM32F4xx_System_Private_Macros |
mbed_official | 25:ac5b0a371348 | 124 | * @{ |
mbed_official | 25:ac5b0a371348 | 125 | */ |
mbed_official | 25:ac5b0a371348 | 126 | |
mbed_official | 25:ac5b0a371348 | 127 | /* Select the clock sources (other than HSI) to start with (0=OFF, 1=ON) */ |
mbed_official | 25:ac5b0a371348 | 128 | #define USE_PLL_HSE_EXTC (1) /* Use external clock */ |
mbed_official | 25:ac5b0a371348 | 129 | #define USE_PLL_HSE_XTAL (1) /* Use external xtal */ |
mbed_official | 25:ac5b0a371348 | 130 | |
mbed_official | 25:ac5b0a371348 | 131 | /** |
mbed_official | 25:ac5b0a371348 | 132 | * @} |
mbed_official | 25:ac5b0a371348 | 133 | */ |
mbed_official | 25:ac5b0a371348 | 134 | |
mbed_official | 25:ac5b0a371348 | 135 | /** @addtogroup STM32F4xx_System_Private_Variables |
mbed_official | 25:ac5b0a371348 | 136 | * @{ |
mbed_official | 25:ac5b0a371348 | 137 | */ |
mbed_official | 25:ac5b0a371348 | 138 | /* This variable is updated in three ways: |
mbed_official | 25:ac5b0a371348 | 139 | 1) by calling CMSIS function SystemCoreClockUpdate() |
mbed_official | 25:ac5b0a371348 | 140 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() |
mbed_official | 25:ac5b0a371348 | 141 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency |
mbed_official | 25:ac5b0a371348 | 142 | Note: If you use this function to configure the system clock; then there |
mbed_official | 25:ac5b0a371348 | 143 | is no need to call the 2 first functions listed above, since SystemCoreClock |
mbed_official | 25:ac5b0a371348 | 144 | variable is updated automatically. |
mbed_official | 25:ac5b0a371348 | 145 | */ |
mbed_official | 25:ac5b0a371348 | 146 | uint32_t SystemCoreClock = 16000000; |
mbed_official | 25:ac5b0a371348 | 147 | const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; |
mbed_official | 25:ac5b0a371348 | 148 | |
mbed_official | 25:ac5b0a371348 | 149 | /** |
mbed_official | 25:ac5b0a371348 | 150 | * @} |
mbed_official | 25:ac5b0a371348 | 151 | */ |
mbed_official | 25:ac5b0a371348 | 152 | |
mbed_official | 25:ac5b0a371348 | 153 | /** @addtogroup STM32F4xx_System_Private_FunctionPrototypes |
mbed_official | 25:ac5b0a371348 | 154 | * @{ |
mbed_official | 25:ac5b0a371348 | 155 | */ |
mbed_official | 25:ac5b0a371348 | 156 | |
mbed_official | 25:ac5b0a371348 | 157 | #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM) |
mbed_official | 25:ac5b0a371348 | 158 | static void SystemInit_ExtMemCtl(void); |
mbed_official | 25:ac5b0a371348 | 159 | #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */ |
mbed_official | 25:ac5b0a371348 | 160 | |
mbed_official | 25:ac5b0a371348 | 161 | #if (USE_PLL_HSE_XTAL != 0) || (USE_PLL_HSE_EXTC != 0) |
mbed_official | 25:ac5b0a371348 | 162 | uint8_t SetSysClock_PLL_HSE(uint8_t bypass); |
mbed_official | 25:ac5b0a371348 | 163 | #endif |
mbed_official | 25:ac5b0a371348 | 164 | |
mbed_official | 25:ac5b0a371348 | 165 | uint8_t SetSysClock_PLL_HSI(void); |
mbed_official | 25:ac5b0a371348 | 166 | |
mbed_official | 25:ac5b0a371348 | 167 | /** |
mbed_official | 25:ac5b0a371348 | 168 | * @} |
mbed_official | 25:ac5b0a371348 | 169 | */ |
mbed_official | 25:ac5b0a371348 | 170 | |
mbed_official | 25:ac5b0a371348 | 171 | /** @addtogroup STM32F4xx_System_Private_Functions |
mbed_official | 25:ac5b0a371348 | 172 | * @{ |
mbed_official | 25:ac5b0a371348 | 173 | */ |
mbed_official | 25:ac5b0a371348 | 174 | |
mbed_official | 25:ac5b0a371348 | 175 | /** |
mbed_official | 25:ac5b0a371348 | 176 | * @brief Setup the microcontroller system |
mbed_official | 25:ac5b0a371348 | 177 | * Initialize the FPU setting, vector table location and External memory |
mbed_official | 25:ac5b0a371348 | 178 | * configuration. |
mbed_official | 25:ac5b0a371348 | 179 | * @param None |
mbed_official | 25:ac5b0a371348 | 180 | * @retval None |
mbed_official | 25:ac5b0a371348 | 181 | */ |
mbed_official | 25:ac5b0a371348 | 182 | void SystemInit(void) |
mbed_official | 25:ac5b0a371348 | 183 | { |
mbed_official | 25:ac5b0a371348 | 184 | /* FPU settings ------------------------------------------------------------*/ |
mbed_official | 25:ac5b0a371348 | 185 | #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) |
mbed_official | 25:ac5b0a371348 | 186 | SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ |
mbed_official | 25:ac5b0a371348 | 187 | #endif |
mbed_official | 25:ac5b0a371348 | 188 | /* Reset the RCC clock configuration to the default reset state ------------*/ |
mbed_official | 25:ac5b0a371348 | 189 | /* Set HSION bit */ |
mbed_official | 25:ac5b0a371348 | 190 | RCC->CR |= (uint32_t)0x00000001; |
mbed_official | 25:ac5b0a371348 | 191 | |
mbed_official | 25:ac5b0a371348 | 192 | /* Reset CFGR register */ |
mbed_official | 25:ac5b0a371348 | 193 | RCC->CFGR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 194 | |
mbed_official | 25:ac5b0a371348 | 195 | /* Reset HSEON, CSSON and PLLON bits */ |
mbed_official | 25:ac5b0a371348 | 196 | RCC->CR &= (uint32_t)0xFEF6FFFF; |
mbed_official | 25:ac5b0a371348 | 197 | |
mbed_official | 25:ac5b0a371348 | 198 | /* Reset PLLCFGR register */ |
mbed_official | 25:ac5b0a371348 | 199 | RCC->PLLCFGR = 0x24003010; |
mbed_official | 25:ac5b0a371348 | 200 | |
mbed_official | 25:ac5b0a371348 | 201 | /* Reset HSEBYP bit */ |
mbed_official | 25:ac5b0a371348 | 202 | RCC->CR &= (uint32_t)0xFFFBFFFF; |
mbed_official | 25:ac5b0a371348 | 203 | |
mbed_official | 25:ac5b0a371348 | 204 | /* Disable all interrupts */ |
mbed_official | 25:ac5b0a371348 | 205 | RCC->CIR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 206 | |
mbed_official | 25:ac5b0a371348 | 207 | #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM) |
mbed_official | 25:ac5b0a371348 | 208 | SystemInit_ExtMemCtl(); |
mbed_official | 25:ac5b0a371348 | 209 | #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */ |
mbed_official | 25:ac5b0a371348 | 210 | |
mbed_official | 25:ac5b0a371348 | 211 | /* Configure the Vector Table location add offset address ------------------*/ |
mbed_official | 25:ac5b0a371348 | 212 | #ifdef VECT_TAB_SRAM |
mbed_official | 25:ac5b0a371348 | 213 | SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ |
mbed_official | 25:ac5b0a371348 | 214 | #else |
mbed_official | 25:ac5b0a371348 | 215 | SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ |
mbed_official | 25:ac5b0a371348 | 216 | #endif |
mbed_official | 25:ac5b0a371348 | 217 | |
mbed_official | 25:ac5b0a371348 | 218 | /* Configure the Cube driver */ |
mbed_official | 25:ac5b0a371348 | 219 | SystemCoreClock = 16000000; // At this stage the HSI is used as system clock |
mbed_official | 25:ac5b0a371348 | 220 | HAL_Init(); |
mbed_official | 25:ac5b0a371348 | 221 | |
mbed_official | 25:ac5b0a371348 | 222 | /* Configure the System clock source, PLL Multiplier and Divider factors, |
mbed_official | 25:ac5b0a371348 | 223 | AHB/APBx prescalers and Flash settings */ |
mbed_official | 25:ac5b0a371348 | 224 | SetSysClock(); |
mbed_official | 25:ac5b0a371348 | 225 | |
mbed_official | 25:ac5b0a371348 | 226 | /* Reset the timer to avoid issues after the RAM initialization */ |
mbed_official | 25:ac5b0a371348 | 227 | TIM_MST_RESET_ON; |
mbed_official | 25:ac5b0a371348 | 228 | TIM_MST_RESET_OFF; |
mbed_official | 25:ac5b0a371348 | 229 | } |
mbed_official | 25:ac5b0a371348 | 230 | |
mbed_official | 25:ac5b0a371348 | 231 | /** |
mbed_official | 25:ac5b0a371348 | 232 | * @brief Update SystemCoreClock variable according to Clock Register Values. |
mbed_official | 25:ac5b0a371348 | 233 | * The SystemCoreClock variable contains the core clock (HCLK), it can |
mbed_official | 25:ac5b0a371348 | 234 | * be used by the user application to setup the SysTick timer or configure |
mbed_official | 25:ac5b0a371348 | 235 | * other parameters. |
mbed_official | 25:ac5b0a371348 | 236 | * |
mbed_official | 25:ac5b0a371348 | 237 | * @note Each time the core clock (HCLK) changes, this function must be called |
mbed_official | 25:ac5b0a371348 | 238 | * to update SystemCoreClock variable value. Otherwise, any configuration |
mbed_official | 25:ac5b0a371348 | 239 | * based on this variable will be incorrect. |
mbed_official | 25:ac5b0a371348 | 240 | * |
mbed_official | 25:ac5b0a371348 | 241 | * @note - The system frequency computed by this function is not the real |
mbed_official | 25:ac5b0a371348 | 242 | * frequency in the chip. It is calculated based on the predefined |
mbed_official | 25:ac5b0a371348 | 243 | * constant and the selected clock source: |
mbed_official | 25:ac5b0a371348 | 244 | * |
mbed_official | 25:ac5b0a371348 | 245 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) |
mbed_official | 25:ac5b0a371348 | 246 | * |
mbed_official | 25:ac5b0a371348 | 247 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) |
mbed_official | 25:ac5b0a371348 | 248 | * |
mbed_official | 25:ac5b0a371348 | 249 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) |
mbed_official | 25:ac5b0a371348 | 250 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. |
mbed_official | 25:ac5b0a371348 | 251 | * |
mbed_official | 25:ac5b0a371348 | 252 | * (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value |
mbed_official | 25:ac5b0a371348 | 253 | * 16 MHz) but the real value may vary depending on the variations |
mbed_official | 25:ac5b0a371348 | 254 | * in voltage and temperature. |
mbed_official | 25:ac5b0a371348 | 255 | * |
mbed_official | 25:ac5b0a371348 | 256 | * (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (its value |
mbed_official | 25:ac5b0a371348 | 257 | * depends on the application requirements), user has to ensure that HSE_VALUE |
mbed_official | 25:ac5b0a371348 | 258 | * is same as the real frequency of the crystal used. Otherwise, this function |
mbed_official | 25:ac5b0a371348 | 259 | * may have wrong result. |
mbed_official | 25:ac5b0a371348 | 260 | * |
mbed_official | 25:ac5b0a371348 | 261 | * - The result of this function could be not correct when using fractional |
mbed_official | 25:ac5b0a371348 | 262 | * value for HSE crystal. |
mbed_official | 25:ac5b0a371348 | 263 | * |
mbed_official | 25:ac5b0a371348 | 264 | * @param None |
mbed_official | 25:ac5b0a371348 | 265 | * @retval None |
mbed_official | 25:ac5b0a371348 | 266 | */ |
mbed_official | 25:ac5b0a371348 | 267 | void SystemCoreClockUpdate(void) |
mbed_official | 25:ac5b0a371348 | 268 | { |
mbed_official | 25:ac5b0a371348 | 269 | uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; |
mbed_official | 25:ac5b0a371348 | 270 | |
mbed_official | 25:ac5b0a371348 | 271 | /* Get SYSCLK source -------------------------------------------------------*/ |
mbed_official | 25:ac5b0a371348 | 272 | tmp = RCC->CFGR & RCC_CFGR_SWS; |
mbed_official | 25:ac5b0a371348 | 273 | |
mbed_official | 25:ac5b0a371348 | 274 | switch (tmp) |
mbed_official | 25:ac5b0a371348 | 275 | { |
mbed_official | 25:ac5b0a371348 | 276 | case 0x00: /* HSI used as system clock source */ |
mbed_official | 25:ac5b0a371348 | 277 | SystemCoreClock = HSI_VALUE; |
mbed_official | 25:ac5b0a371348 | 278 | break; |
mbed_official | 25:ac5b0a371348 | 279 | case 0x04: /* HSE used as system clock source */ |
mbed_official | 25:ac5b0a371348 | 280 | SystemCoreClock = HSE_VALUE; |
mbed_official | 25:ac5b0a371348 | 281 | break; |
mbed_official | 25:ac5b0a371348 | 282 | case 0x08: /* PLL used as system clock source */ |
mbed_official | 25:ac5b0a371348 | 283 | |
mbed_official | 25:ac5b0a371348 | 284 | /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N |
mbed_official | 25:ac5b0a371348 | 285 | SYSCLK = PLL_VCO / PLL_P |
mbed_official | 25:ac5b0a371348 | 286 | */ |
mbed_official | 25:ac5b0a371348 | 287 | pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; |
mbed_official | 25:ac5b0a371348 | 288 | pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; |
mbed_official | 25:ac5b0a371348 | 289 | |
mbed_official | 25:ac5b0a371348 | 290 | if (pllsource != 0) |
mbed_official | 25:ac5b0a371348 | 291 | { |
mbed_official | 25:ac5b0a371348 | 292 | /* HSE used as PLL clock source */ |
mbed_official | 25:ac5b0a371348 | 293 | pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); |
mbed_official | 25:ac5b0a371348 | 294 | } |
mbed_official | 25:ac5b0a371348 | 295 | else |
mbed_official | 25:ac5b0a371348 | 296 | { |
mbed_official | 25:ac5b0a371348 | 297 | /* HSI used as PLL clock source */ |
mbed_official | 25:ac5b0a371348 | 298 | pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); |
mbed_official | 25:ac5b0a371348 | 299 | } |
mbed_official | 25:ac5b0a371348 | 300 | |
mbed_official | 25:ac5b0a371348 | 301 | pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; |
mbed_official | 25:ac5b0a371348 | 302 | SystemCoreClock = pllvco/pllp; |
mbed_official | 25:ac5b0a371348 | 303 | break; |
mbed_official | 25:ac5b0a371348 | 304 | default: |
mbed_official | 25:ac5b0a371348 | 305 | SystemCoreClock = HSI_VALUE; |
mbed_official | 25:ac5b0a371348 | 306 | break; |
mbed_official | 25:ac5b0a371348 | 307 | } |
mbed_official | 25:ac5b0a371348 | 308 | /* Compute HCLK frequency --------------------------------------------------*/ |
mbed_official | 25:ac5b0a371348 | 309 | /* Get HCLK prescaler */ |
mbed_official | 25:ac5b0a371348 | 310 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; |
mbed_official | 25:ac5b0a371348 | 311 | /* HCLK frequency */ |
mbed_official | 25:ac5b0a371348 | 312 | SystemCoreClock >>= tmp; |
mbed_official | 25:ac5b0a371348 | 313 | } |
mbed_official | 25:ac5b0a371348 | 314 | |
mbed_official | 25:ac5b0a371348 | 315 | #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM) |
mbed_official | 25:ac5b0a371348 | 316 | /** |
mbed_official | 25:ac5b0a371348 | 317 | * @brief Setup the external memory controller. |
mbed_official | 25:ac5b0a371348 | 318 | * Called in startup_stm32f4xx.s before jump to main. |
mbed_official | 25:ac5b0a371348 | 319 | * This function configures the external memories (SRAM/SDRAM) |
mbed_official | 25:ac5b0a371348 | 320 | * This SRAM/SDRAM will be used as program data memory (including heap and stack). |
mbed_official | 25:ac5b0a371348 | 321 | * @param None |
mbed_official | 25:ac5b0a371348 | 322 | * @retval None |
mbed_official | 25:ac5b0a371348 | 323 | */ |
mbed_official | 25:ac5b0a371348 | 324 | void SystemInit_ExtMemCtl(void) |
mbed_official | 25:ac5b0a371348 | 325 | { |
mbed_official | 25:ac5b0a371348 | 326 | __IO uint32_t tmp = 0x00; |
mbed_official | 25:ac5b0a371348 | 327 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ |
mbed_official | 25:ac5b0a371348 | 328 | || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) |
mbed_official | 25:ac5b0a371348 | 329 | #if defined (DATA_IN_ExtSDRAM) |
mbed_official | 25:ac5b0a371348 | 330 | register uint32_t tmpreg = 0, timeout = 0xFFFF; |
mbed_official | 25:ac5b0a371348 | 331 | register uint32_t index; |
mbed_official | 25:ac5b0a371348 | 332 | |
mbed_official | 25:ac5b0a371348 | 333 | #if defined(STM32F446xx) |
mbed_official | 25:ac5b0a371348 | 334 | /* Enable GPIOA, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG interface |
mbed_official | 25:ac5b0a371348 | 335 | clock */ |
mbed_official | 25:ac5b0a371348 | 336 | RCC->AHB1ENR |= 0x0000007D; |
mbed_official | 25:ac5b0a371348 | 337 | #else |
mbed_official | 25:ac5b0a371348 | 338 | /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface |
mbed_official | 25:ac5b0a371348 | 339 | clock */ |
mbed_official | 25:ac5b0a371348 | 340 | RCC->AHB1ENR |= 0x000001F8; |
mbed_official | 25:ac5b0a371348 | 341 | #endif /* STM32F446xx */ |
mbed_official | 25:ac5b0a371348 | 342 | /* Delay after an RCC peripheral clock enabling */ |
mbed_official | 25:ac5b0a371348 | 343 | tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN); |
mbed_official | 25:ac5b0a371348 | 344 | |
mbed_official | 25:ac5b0a371348 | 345 | #if defined(STM32F446xx) |
mbed_official | 25:ac5b0a371348 | 346 | /* Connect PAx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 347 | GPIOA->AFR[0] |= 0xC0000000; |
mbed_official | 25:ac5b0a371348 | 348 | GPIOA->AFR[1] |= 0x00000000; |
mbed_official | 25:ac5b0a371348 | 349 | /* Configure PDx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 350 | GPIOA->MODER |= 0x00008000; |
mbed_official | 25:ac5b0a371348 | 351 | /* Configure PDx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 352 | GPIOA->OSPEEDR |= 0x00008000; |
mbed_official | 25:ac5b0a371348 | 353 | /* Configure PDx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 354 | GPIOA->OTYPER |= 0x00000000; |
mbed_official | 25:ac5b0a371348 | 355 | /* No pull-up, pull-down for PDx pins */ |
mbed_official | 25:ac5b0a371348 | 356 | GPIOA->PUPDR |= 0x00000000; |
mbed_official | 25:ac5b0a371348 | 357 | |
mbed_official | 25:ac5b0a371348 | 358 | /* Connect PCx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 359 | GPIOC->AFR[0] |= 0x00CC0000; |
mbed_official | 25:ac5b0a371348 | 360 | GPIOC->AFR[1] |= 0x00000000; |
mbed_official | 25:ac5b0a371348 | 361 | /* Configure PDx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 362 | GPIOC->MODER |= 0x00000A00; |
mbed_official | 25:ac5b0a371348 | 363 | /* Configure PDx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 364 | GPIOC->OSPEEDR |= 0x00000A00; |
mbed_official | 25:ac5b0a371348 | 365 | /* Configure PDx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 366 | GPIOC->OTYPER |= 0x00000000; |
mbed_official | 25:ac5b0a371348 | 367 | /* No pull-up, pull-down for PDx pins */ |
mbed_official | 25:ac5b0a371348 | 368 | GPIOC->PUPDR |= 0x00000000; |
mbed_official | 25:ac5b0a371348 | 369 | #endif /* STM32F446xx */ |
mbed_official | 25:ac5b0a371348 | 370 | |
mbed_official | 25:ac5b0a371348 | 371 | /* Connect PDx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 372 | GPIOD->AFR[0] = 0x000000CC; |
mbed_official | 25:ac5b0a371348 | 373 | GPIOD->AFR[1] = 0xCC000CCC; |
mbed_official | 25:ac5b0a371348 | 374 | /* Configure PDx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 375 | GPIOD->MODER = 0xA02A000A; |
mbed_official | 25:ac5b0a371348 | 376 | /* Configure PDx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 377 | GPIOD->OSPEEDR = 0xA02A000A; |
mbed_official | 25:ac5b0a371348 | 378 | /* Configure PDx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 379 | GPIOD->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 380 | /* No pull-up, pull-down for PDx pins */ |
mbed_official | 25:ac5b0a371348 | 381 | GPIOD->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 382 | |
mbed_official | 25:ac5b0a371348 | 383 | /* Connect PEx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 384 | GPIOE->AFR[0] = 0xC00000CC; |
mbed_official | 25:ac5b0a371348 | 385 | GPIOE->AFR[1] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 386 | /* Configure PEx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 387 | GPIOE->MODER = 0xAAAA800A; |
mbed_official | 25:ac5b0a371348 | 388 | /* Configure PEx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 389 | GPIOE->OSPEEDR = 0xAAAA800A; |
mbed_official | 25:ac5b0a371348 | 390 | /* Configure PEx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 391 | GPIOE->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 392 | /* No pull-up, pull-down for PEx pins */ |
mbed_official | 25:ac5b0a371348 | 393 | GPIOE->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 394 | |
mbed_official | 25:ac5b0a371348 | 395 | /* Connect PFx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 396 | GPIOF->AFR[0] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 397 | GPIOF->AFR[1] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 398 | /* Configure PFx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 399 | GPIOF->MODER = 0xAA800AAA; |
mbed_official | 25:ac5b0a371348 | 400 | /* Configure PFx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 401 | GPIOF->OSPEEDR = 0xAA800AAA; |
mbed_official | 25:ac5b0a371348 | 402 | /* Configure PFx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 403 | GPIOF->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 404 | /* No pull-up, pull-down for PFx pins */ |
mbed_official | 25:ac5b0a371348 | 405 | GPIOF->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 406 | |
mbed_official | 25:ac5b0a371348 | 407 | /* Connect PGx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 408 | GPIOG->AFR[0] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 409 | GPIOG->AFR[1] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 410 | /* Configure PGx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 411 | GPIOG->MODER = 0xAAAAAAAA; |
mbed_official | 25:ac5b0a371348 | 412 | /* Configure PGx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 413 | GPIOG->OSPEEDR = 0xAAAAAAAA; |
mbed_official | 25:ac5b0a371348 | 414 | /* Configure PGx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 415 | GPIOG->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 416 | /* No pull-up, pull-down for PGx pins */ |
mbed_official | 25:ac5b0a371348 | 417 | GPIOG->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 418 | |
mbed_official | 25:ac5b0a371348 | 419 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ |
mbed_official | 25:ac5b0a371348 | 420 | || defined(STM32F469xx) || defined(STM32F479xx) |
mbed_official | 25:ac5b0a371348 | 421 | /* Connect PHx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 422 | GPIOH->AFR[0] = 0x00C0CC00; |
mbed_official | 25:ac5b0a371348 | 423 | GPIOH->AFR[1] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 424 | /* Configure PHx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 425 | GPIOH->MODER = 0xAAAA08A0; |
mbed_official | 25:ac5b0a371348 | 426 | /* Configure PHx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 427 | GPIOH->OSPEEDR = 0xAAAA08A0; |
mbed_official | 25:ac5b0a371348 | 428 | /* Configure PHx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 429 | GPIOH->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 430 | /* No pull-up, pull-down for PHx pins */ |
mbed_official | 25:ac5b0a371348 | 431 | GPIOH->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 432 | |
mbed_official | 25:ac5b0a371348 | 433 | /* Connect PIx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 434 | GPIOI->AFR[0] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 435 | GPIOI->AFR[1] = 0x00000CC0; |
mbed_official | 25:ac5b0a371348 | 436 | /* Configure PIx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 437 | GPIOI->MODER = 0x0028AAAA; |
mbed_official | 25:ac5b0a371348 | 438 | /* Configure PIx pins speed to 50 MHz */ |
mbed_official | 25:ac5b0a371348 | 439 | GPIOI->OSPEEDR = 0x0028AAAA; |
mbed_official | 25:ac5b0a371348 | 440 | /* Configure PIx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 441 | GPIOI->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 442 | /* No pull-up, pull-down for PIx pins */ |
mbed_official | 25:ac5b0a371348 | 443 | GPIOI->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 444 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
mbed_official | 25:ac5b0a371348 | 445 | |
mbed_official | 25:ac5b0a371348 | 446 | /*-- FMC Configuration -------------------------------------------------------*/ |
mbed_official | 25:ac5b0a371348 | 447 | /* Enable the FMC interface clock */ |
mbed_official | 25:ac5b0a371348 | 448 | RCC->AHB3ENR |= 0x00000001; |
mbed_official | 25:ac5b0a371348 | 449 | /* Delay after an RCC peripheral clock enabling */ |
mbed_official | 25:ac5b0a371348 | 450 | tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); |
mbed_official | 25:ac5b0a371348 | 451 | |
mbed_official | 25:ac5b0a371348 | 452 | /* Configure and enable SDRAM bank1 */ |
mbed_official | 25:ac5b0a371348 | 453 | #if defined(STM32F446xx) |
mbed_official | 25:ac5b0a371348 | 454 | FMC_Bank5_6->SDCR[0] = 0x00001954; |
mbed_official | 25:ac5b0a371348 | 455 | #else |
mbed_official | 25:ac5b0a371348 | 456 | FMC_Bank5_6->SDCR[0] = 0x000019E4; |
mbed_official | 25:ac5b0a371348 | 457 | #endif /* STM32F446xx */ |
mbed_official | 25:ac5b0a371348 | 458 | FMC_Bank5_6->SDTR[0] = 0x01115351; |
mbed_official | 25:ac5b0a371348 | 459 | |
mbed_official | 25:ac5b0a371348 | 460 | /* SDRAM initialization sequence */ |
mbed_official | 25:ac5b0a371348 | 461 | /* Clock enable command */ |
mbed_official | 25:ac5b0a371348 | 462 | FMC_Bank5_6->SDCMR = 0x00000011; |
mbed_official | 25:ac5b0a371348 | 463 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; |
mbed_official | 25:ac5b0a371348 | 464 | while((tmpreg != 0) && (timeout-- > 0)) |
mbed_official | 25:ac5b0a371348 | 465 | { |
mbed_official | 25:ac5b0a371348 | 466 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; |
mbed_official | 25:ac5b0a371348 | 467 | } |
mbed_official | 25:ac5b0a371348 | 468 | |
mbed_official | 25:ac5b0a371348 | 469 | /* Delay */ |
mbed_official | 25:ac5b0a371348 | 470 | for (index = 0; index<1000; index++); |
mbed_official | 25:ac5b0a371348 | 471 | |
mbed_official | 25:ac5b0a371348 | 472 | /* PALL command */ |
mbed_official | 25:ac5b0a371348 | 473 | FMC_Bank5_6->SDCMR = 0x00000012; |
mbed_official | 25:ac5b0a371348 | 474 | timeout = 0xFFFF; |
mbed_official | 25:ac5b0a371348 | 475 | while((tmpreg != 0) && (timeout-- > 0)) |
mbed_official | 25:ac5b0a371348 | 476 | { |
mbed_official | 25:ac5b0a371348 | 477 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; |
mbed_official | 25:ac5b0a371348 | 478 | } |
mbed_official | 25:ac5b0a371348 | 479 | |
mbed_official | 25:ac5b0a371348 | 480 | /* Auto refresh command */ |
mbed_official | 25:ac5b0a371348 | 481 | #if defined(STM32F446xx) |
mbed_official | 25:ac5b0a371348 | 482 | FMC_Bank5_6->SDCMR = 0x000000F3; |
mbed_official | 25:ac5b0a371348 | 483 | #else |
mbed_official | 25:ac5b0a371348 | 484 | FMC_Bank5_6->SDCMR = 0x00000073; |
mbed_official | 25:ac5b0a371348 | 485 | #endif /* STM32F446xx */ |
mbed_official | 25:ac5b0a371348 | 486 | timeout = 0xFFFF; |
mbed_official | 25:ac5b0a371348 | 487 | while((tmpreg != 0) && (timeout-- > 0)) |
mbed_official | 25:ac5b0a371348 | 488 | { |
mbed_official | 25:ac5b0a371348 | 489 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; |
mbed_official | 25:ac5b0a371348 | 490 | } |
mbed_official | 25:ac5b0a371348 | 491 | |
mbed_official | 25:ac5b0a371348 | 492 | /* MRD register program */ |
mbed_official | 25:ac5b0a371348 | 493 | #if defined(STM32F446xx) |
mbed_official | 25:ac5b0a371348 | 494 | FMC_Bank5_6->SDCMR = 0x00044014; |
mbed_official | 25:ac5b0a371348 | 495 | #else |
mbed_official | 25:ac5b0a371348 | 496 | FMC_Bank5_6->SDCMR = 0x00046014; |
mbed_official | 25:ac5b0a371348 | 497 | #endif /* STM32F446xx */ |
mbed_official | 25:ac5b0a371348 | 498 | timeout = 0xFFFF; |
mbed_official | 25:ac5b0a371348 | 499 | while((tmpreg != 0) && (timeout-- > 0)) |
mbed_official | 25:ac5b0a371348 | 500 | { |
mbed_official | 25:ac5b0a371348 | 501 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; |
mbed_official | 25:ac5b0a371348 | 502 | } |
mbed_official | 25:ac5b0a371348 | 503 | |
mbed_official | 25:ac5b0a371348 | 504 | /* Set refresh count */ |
mbed_official | 25:ac5b0a371348 | 505 | tmpreg = FMC_Bank5_6->SDRTR; |
mbed_official | 25:ac5b0a371348 | 506 | #if defined(STM32F446xx) |
mbed_official | 25:ac5b0a371348 | 507 | FMC_Bank5_6->SDRTR = (tmpreg | (0x0000050C<<1)); |
mbed_official | 25:ac5b0a371348 | 508 | #else |
mbed_official | 25:ac5b0a371348 | 509 | FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1)); |
mbed_official | 25:ac5b0a371348 | 510 | #endif /* STM32F446xx */ |
mbed_official | 25:ac5b0a371348 | 511 | |
mbed_official | 25:ac5b0a371348 | 512 | /* Disable write protection */ |
mbed_official | 25:ac5b0a371348 | 513 | tmpreg = FMC_Bank5_6->SDCR[0]; |
mbed_official | 25:ac5b0a371348 | 514 | FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF); |
mbed_official | 25:ac5b0a371348 | 515 | #endif /* DATA_IN_ExtSDRAM */ |
mbed_official | 25:ac5b0a371348 | 516 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ |
mbed_official | 25:ac5b0a371348 | 517 | |
mbed_official | 25:ac5b0a371348 | 518 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\ |
mbed_official | 25:ac5b0a371348 | 519 | || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ |
mbed_official | 25:ac5b0a371348 | 520 | || defined(STM32F469xx) || defined(STM32F479xx) |
mbed_official | 25:ac5b0a371348 | 521 | |
mbed_official | 25:ac5b0a371348 | 522 | #if defined(DATA_IN_ExtSRAM) |
mbed_official | 25:ac5b0a371348 | 523 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
mbed_official | 25:ac5b0a371348 | 524 | /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ |
mbed_official | 25:ac5b0a371348 | 525 | RCC->AHB1ENR |= 0x00000078; |
mbed_official | 25:ac5b0a371348 | 526 | /* Delay after an RCC peripheral clock enabling */ |
mbed_official | 25:ac5b0a371348 | 527 | tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN); |
mbed_official | 25:ac5b0a371348 | 528 | |
mbed_official | 25:ac5b0a371348 | 529 | /* Connect PDx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 530 | GPIOD->AFR[0] = 0x00CCC0CC; |
mbed_official | 25:ac5b0a371348 | 531 | GPIOD->AFR[1] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 532 | /* Configure PDx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 533 | GPIOD->MODER = 0xAAAA0A8A; |
mbed_official | 25:ac5b0a371348 | 534 | /* Configure PDx pins speed to 100 MHz */ |
mbed_official | 25:ac5b0a371348 | 535 | GPIOD->OSPEEDR = 0xFFFF0FCF; |
mbed_official | 25:ac5b0a371348 | 536 | /* Configure PDx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 537 | GPIOD->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 538 | /* No pull-up, pull-down for PDx pins */ |
mbed_official | 25:ac5b0a371348 | 539 | GPIOD->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 540 | |
mbed_official | 25:ac5b0a371348 | 541 | /* Connect PEx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 542 | GPIOE->AFR[0] = 0xC00CC0CC; |
mbed_official | 25:ac5b0a371348 | 543 | GPIOE->AFR[1] = 0xCCCCCCCC; |
mbed_official | 25:ac5b0a371348 | 544 | /* Configure PEx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 545 | GPIOE->MODER = 0xAAAA828A; |
mbed_official | 25:ac5b0a371348 | 546 | /* Configure PEx pins speed to 100 MHz */ |
mbed_official | 25:ac5b0a371348 | 547 | GPIOE->OSPEEDR = 0xFFFFC3CF; |
mbed_official | 25:ac5b0a371348 | 548 | /* Configure PEx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 549 | GPIOE->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 550 | /* No pull-up, pull-down for PEx pins */ |
mbed_official | 25:ac5b0a371348 | 551 | GPIOE->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 552 | |
mbed_official | 25:ac5b0a371348 | 553 | /* Connect PFx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 554 | GPIOF->AFR[0] = 0x00CCCCCC; |
mbed_official | 25:ac5b0a371348 | 555 | GPIOF->AFR[1] = 0xCCCC0000; |
mbed_official | 25:ac5b0a371348 | 556 | /* Configure PFx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 557 | GPIOF->MODER = 0xAA000AAA; |
mbed_official | 25:ac5b0a371348 | 558 | /* Configure PFx pins speed to 100 MHz */ |
mbed_official | 25:ac5b0a371348 | 559 | GPIOF->OSPEEDR = 0xFF000FFF; |
mbed_official | 25:ac5b0a371348 | 560 | /* Configure PFx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 561 | GPIOF->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 562 | /* No pull-up, pull-down for PFx pins */ |
mbed_official | 25:ac5b0a371348 | 563 | GPIOF->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 564 | |
mbed_official | 25:ac5b0a371348 | 565 | /* Connect PGx pins to FMC Alternate function */ |
mbed_official | 25:ac5b0a371348 | 566 | GPIOG->AFR[0] = 0x00CCCCCC; |
mbed_official | 25:ac5b0a371348 | 567 | GPIOG->AFR[1] = 0x000000C0; |
mbed_official | 25:ac5b0a371348 | 568 | /* Configure PGx pins in Alternate function mode */ |
mbed_official | 25:ac5b0a371348 | 569 | GPIOG->MODER = 0x00085AAA; |
mbed_official | 25:ac5b0a371348 | 570 | /* Configure PGx pins speed to 100 MHz */ |
mbed_official | 25:ac5b0a371348 | 571 | GPIOG->OSPEEDR = 0x000CAFFF; |
mbed_official | 25:ac5b0a371348 | 572 | /* Configure PGx pins Output type to push-pull */ |
mbed_official | 25:ac5b0a371348 | 573 | GPIOG->OTYPER = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 574 | /* No pull-up, pull-down for PGx pins */ |
mbed_official | 25:ac5b0a371348 | 575 | GPIOG->PUPDR = 0x00000000; |
mbed_official | 25:ac5b0a371348 | 576 | |
mbed_official | 25:ac5b0a371348 | 577 | /*-- FMC/FSMC Configuration --------------------------------------------------*/ |
mbed_official | 25:ac5b0a371348 | 578 | /* Enable the FMC/FSMC interface clock */ |
mbed_official | 25:ac5b0a371348 | 579 | RCC->AHB3ENR |= 0x00000001; |
mbed_official | 25:ac5b0a371348 | 580 | |
mbed_official | 25:ac5b0a371348 | 581 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) |
mbed_official | 25:ac5b0a371348 | 582 | /* Delay after an RCC peripheral clock enabling */ |
mbed_official | 25:ac5b0a371348 | 583 | tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); |
mbed_official | 25:ac5b0a371348 | 584 | /* Configure and enable Bank1_SRAM2 */ |
mbed_official | 25:ac5b0a371348 | 585 | FMC_Bank1->BTCR[2] = 0x00001011; |
mbed_official | 25:ac5b0a371348 | 586 | FMC_Bank1->BTCR[3] = 0x00000201; |
mbed_official | 25:ac5b0a371348 | 587 | FMC_Bank1E->BWTR[2] = 0x0fffffff; |
mbed_official | 25:ac5b0a371348 | 588 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 25:ac5b0a371348 | 589 | #if defined(STM32F469xx) || defined(STM32F479xx) |
mbed_official | 25:ac5b0a371348 | 590 | /* Delay after an RCC peripheral clock enabling */ |
mbed_official | 25:ac5b0a371348 | 591 | tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); |
mbed_official | 25:ac5b0a371348 | 592 | /* Configure and enable Bank1_SRAM2 */ |
mbed_official | 25:ac5b0a371348 | 593 | FMC_Bank1->BTCR[2] = 0x00001091; |
mbed_official | 25:ac5b0a371348 | 594 | FMC_Bank1->BTCR[3] = 0x00110212; |
mbed_official | 25:ac5b0a371348 | 595 | FMC_Bank1E->BWTR[2] = 0x0fffffff; |
mbed_official | 25:ac5b0a371348 | 596 | #endif /* STM32F469xx || STM32F479xx */ |
mbed_official | 25:ac5b0a371348 | 597 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx) |
mbed_official | 25:ac5b0a371348 | 598 | /* Delay after an RCC peripheral clock enabling */ |
mbed_official | 25:ac5b0a371348 | 599 | tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FSMCEN); |
mbed_official | 25:ac5b0a371348 | 600 | /* Configure and enable Bank1_SRAM2 */ |
mbed_official | 25:ac5b0a371348 | 601 | FSMC_Bank1->BTCR[2] = 0x00001011; |
mbed_official | 25:ac5b0a371348 | 602 | FSMC_Bank1->BTCR[3] = 0x00000201; |
mbed_official | 25:ac5b0a371348 | 603 | FSMC_Bank1E->BWTR[2] = 0x0FFFFFFF; |
mbed_official | 25:ac5b0a371348 | 604 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */ |
mbed_official | 25:ac5b0a371348 | 605 | |
mbed_official | 25:ac5b0a371348 | 606 | #endif /* DATA_IN_ExtSRAM */ |
mbed_official | 25:ac5b0a371348 | 607 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\ |
mbed_official | 25:ac5b0a371348 | 608 | STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
mbed_official | 25:ac5b0a371348 | 609 | (void)(tmp); |
mbed_official | 25:ac5b0a371348 | 610 | } |
mbed_official | 25:ac5b0a371348 | 611 | #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */ |
mbed_official | 25:ac5b0a371348 | 612 | /** |
mbed_official | 25:ac5b0a371348 | 613 | * @brief Configures the System clock source, PLL Multiplier and Divider factors, |
mbed_official | 25:ac5b0a371348 | 614 | * AHB/APBx prescalers and Flash settings |
mbed_official | 25:ac5b0a371348 | 615 | * @note This function should be called only once the RCC clock configuration |
mbed_official | 25:ac5b0a371348 | 616 | * is reset to the default reset state (done in SystemInit() function). |
mbed_official | 25:ac5b0a371348 | 617 | * @param None |
mbed_official | 25:ac5b0a371348 | 618 | * @retval None |
mbed_official | 25:ac5b0a371348 | 619 | */ |
mbed_official | 25:ac5b0a371348 | 620 | void SetSysClock(void) |
mbed_official | 25:ac5b0a371348 | 621 | { |
mbed_official | 25:ac5b0a371348 | 622 | /* 1- Try to start with HSE and external clock */ |
mbed_official | 25:ac5b0a371348 | 623 | #if USE_PLL_HSE_EXTC != 0 |
mbed_official | 25:ac5b0a371348 | 624 | if (SetSysClock_PLL_HSE(1) == 0) |
mbed_official | 25:ac5b0a371348 | 625 | #endif |
mbed_official | 25:ac5b0a371348 | 626 | { |
mbed_official | 25:ac5b0a371348 | 627 | /* 2- If fail try to start with HSE and external xtal */ |
mbed_official | 25:ac5b0a371348 | 628 | #if USE_PLL_HSE_XTAL != 0 |
mbed_official | 25:ac5b0a371348 | 629 | if (SetSysClock_PLL_HSE(0) == 0) |
mbed_official | 25:ac5b0a371348 | 630 | #endif |
mbed_official | 25:ac5b0a371348 | 631 | { |
mbed_official | 25:ac5b0a371348 | 632 | /* 3- If fail start with HSI clock */ |
mbed_official | 25:ac5b0a371348 | 633 | if (SetSysClock_PLL_HSI() == 0) |
mbed_official | 25:ac5b0a371348 | 634 | { |
mbed_official | 25:ac5b0a371348 | 635 | while(1) |
mbed_official | 25:ac5b0a371348 | 636 | { |
mbed_official | 25:ac5b0a371348 | 637 | // [TODO] Put something here to tell the user that a problem occured... |
mbed_official | 25:ac5b0a371348 | 638 | } |
mbed_official | 25:ac5b0a371348 | 639 | } |
mbed_official | 25:ac5b0a371348 | 640 | } |
mbed_official | 25:ac5b0a371348 | 641 | } |
mbed_official | 25:ac5b0a371348 | 642 | |
mbed_official | 25:ac5b0a371348 | 643 | /* Output clock on MCO2 pin(PC9) for debugging purpose */ |
mbed_official | 25:ac5b0a371348 | 644 | //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4); // 100 MHz / 4 = 25 MHz |
mbed_official | 25:ac5b0a371348 | 645 | } |
mbed_official | 25:ac5b0a371348 | 646 | |
mbed_official | 25:ac5b0a371348 | 647 | #if (USE_PLL_HSE_XTAL != 0) || (USE_PLL_HSE_EXTC != 0) |
mbed_official | 25:ac5b0a371348 | 648 | /******************************************************************************/ |
mbed_official | 25:ac5b0a371348 | 649 | /* PLL (clocked by HSE) used as System clock source */ |
mbed_official | 25:ac5b0a371348 | 650 | /******************************************************************************/ |
mbed_official | 25:ac5b0a371348 | 651 | uint8_t SetSysClock_PLL_HSE(uint8_t bypass) |
mbed_official | 25:ac5b0a371348 | 652 | { |
mbed_official | 25:ac5b0a371348 | 653 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
mbed_official | 25:ac5b0a371348 | 654 | RCC_OscInitTypeDef RCC_OscInitStruct; |
mbed_official | 25:ac5b0a371348 | 655 | |
mbed_official | 25:ac5b0a371348 | 656 | /* The voltage scaling allows optimizing the power consumption when the device is |
mbed_official | 25:ac5b0a371348 | 657 | clocked below the maximum system frequency, to update the voltage scaling value |
mbed_official | 25:ac5b0a371348 | 658 | regarding system frequency refer to product datasheet. */ |
mbed_official | 25:ac5b0a371348 | 659 | __PWR_CLK_ENABLE(); |
mbed_official | 25:ac5b0a371348 | 660 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
mbed_official | 25:ac5b0a371348 | 661 | |
mbed_official | 25:ac5b0a371348 | 662 | /* Enable HSE oscillator and activate PLL with HSE as source */ |
mbed_official | 25:ac5b0a371348 | 663 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
mbed_official | 25:ac5b0a371348 | 664 | if (bypass == 0) |
mbed_official | 25:ac5b0a371348 | 665 | { |
mbed_official | 25:ac5b0a371348 | 666 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; /* External 8 MHz xtal on OSC_IN/OSC_OUT */ |
mbed_official | 25:ac5b0a371348 | 667 | } |
mbed_official | 25:ac5b0a371348 | 668 | else |
mbed_official | 25:ac5b0a371348 | 669 | { |
mbed_official | 25:ac5b0a371348 | 670 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; /* External 8 MHz clock on OSC_IN */ |
mbed_official | 25:ac5b0a371348 | 671 | } |
mbed_official | 25:ac5b0a371348 | 672 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
mbed_official | 25:ac5b0a371348 | 673 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
mbed_official | 25:ac5b0a371348 | 674 | //RCC_OscInitStruct.PLL.PLLM = 8; // VCO input clock = 1 MHz (8 MHz / 8) |
mbed_official | 25:ac5b0a371348 | 675 | //RCC_OscInitStruct.PLL.PLLN = 384; // VCO output clock = 384 MHz (1 MHz * 384) |
mbed_official | 25:ac5b0a371348 | 676 | RCC_OscInitStruct.PLL.PLLM = 4; // VCO input clock = 2 MHz (8 MHz / 4) |
mbed_official | 25:ac5b0a371348 | 677 | RCC_OscInitStruct.PLL.PLLN = 192; // VCO output clock = 384 MHz (2 MHz * 192) |
mbed_official | 25:ac5b0a371348 | 678 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; // PLLCLK = 96 MHz (384 MHz / 4) |
mbed_official | 25:ac5b0a371348 | 679 | RCC_OscInitStruct.PLL.PLLQ = 8; // USB clock = 48 MHz (384 MHz / 8) --> Good for USB |
mbed_official | 25:ac5b0a371348 | 680 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
mbed_official | 25:ac5b0a371348 | 681 | { |
mbed_official | 25:ac5b0a371348 | 682 | return 0; // FAIL |
mbed_official | 25:ac5b0a371348 | 683 | } |
mbed_official | 25:ac5b0a371348 | 684 | |
mbed_official | 25:ac5b0a371348 | 685 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ |
mbed_official | 25:ac5b0a371348 | 686 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
mbed_official | 25:ac5b0a371348 | 687 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 96 MHz |
mbed_official | 25:ac5b0a371348 | 688 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 96 MHz |
mbed_official | 25:ac5b0a371348 | 689 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // 48 MHz |
mbed_official | 25:ac5b0a371348 | 690 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 96 MHz |
mbed_official | 25:ac5b0a371348 | 691 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) |
mbed_official | 25:ac5b0a371348 | 692 | { |
mbed_official | 25:ac5b0a371348 | 693 | return 0; // FAIL |
mbed_official | 25:ac5b0a371348 | 694 | } |
mbed_official | 25:ac5b0a371348 | 695 | |
mbed_official | 25:ac5b0a371348 | 696 | /* Output clock on MCO1 pin(PA8) for debugging purpose */ |
mbed_official | 25:ac5b0a371348 | 697 | |
mbed_official | 25:ac5b0a371348 | 698 | //if (bypass == 0) |
mbed_official | 25:ac5b0a371348 | 699 | // HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2); // 4 MHz with xtal |
mbed_official | 25:ac5b0a371348 | 700 | //else |
mbed_official | 25:ac5b0a371348 | 701 | // HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); // 8 MHz with external clock |
mbed_official | 25:ac5b0a371348 | 702 | |
mbed_official | 25:ac5b0a371348 | 703 | return 1; // OK |
mbed_official | 25:ac5b0a371348 | 704 | } |
mbed_official | 25:ac5b0a371348 | 705 | #endif |
mbed_official | 25:ac5b0a371348 | 706 | |
mbed_official | 25:ac5b0a371348 | 707 | /******************************************************************************/ |
mbed_official | 25:ac5b0a371348 | 708 | /* PLL (clocked by HSI) used as System clock source */ |
mbed_official | 25:ac5b0a371348 | 709 | /******************************************************************************/ |
mbed_official | 25:ac5b0a371348 | 710 | uint8_t SetSysClock_PLL_HSI(void) |
mbed_official | 25:ac5b0a371348 | 711 | { |
mbed_official | 25:ac5b0a371348 | 712 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
mbed_official | 25:ac5b0a371348 | 713 | RCC_OscInitTypeDef RCC_OscInitStruct; |
mbed_official | 25:ac5b0a371348 | 714 | |
mbed_official | 25:ac5b0a371348 | 715 | /* The voltage scaling allows optimizing the power consumption when the device is |
mbed_official | 25:ac5b0a371348 | 716 | clocked below the maximum system frequency, to update the voltage scaling value |
mbed_official | 25:ac5b0a371348 | 717 | regarding system frequency refer to product datasheet. */ |
mbed_official | 25:ac5b0a371348 | 718 | __PWR_CLK_ENABLE(); |
mbed_official | 25:ac5b0a371348 | 719 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
mbed_official | 25:ac5b0a371348 | 720 | |
mbed_official | 25:ac5b0a371348 | 721 | /* Enable HSI oscillator and activate PLL with HSI as source */ |
mbed_official | 25:ac5b0a371348 | 722 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE; |
mbed_official | 25:ac5b0a371348 | 723 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
mbed_official | 25:ac5b0a371348 | 724 | RCC_OscInitStruct.HSEState = RCC_HSE_OFF; |
mbed_official | 25:ac5b0a371348 | 725 | RCC_OscInitStruct.HSICalibrationValue = 16; |
mbed_official | 25:ac5b0a371348 | 726 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
mbed_official | 25:ac5b0a371348 | 727 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
mbed_official | 25:ac5b0a371348 | 728 | //RCC_OscInitStruct.PLL.PLLM = 16; // VCO input clock = 1 MHz (16 MHz / 16) |
mbed_official | 25:ac5b0a371348 | 729 | //RCC_OscInitStruct.PLL.PLLN = 384; // VCO output clock = 384 MHz (1 MHz * 384) |
mbed_official | 25:ac5b0a371348 | 730 | RCC_OscInitStruct.PLL.PLLM = 8; // VCO input clock = 2 MHz (16 MHz / 8) |
mbed_official | 25:ac5b0a371348 | 731 | RCC_OscInitStruct.PLL.PLLN = 192; // VCO output clock = 384 MHz (2 MHz * 192) |
mbed_official | 25:ac5b0a371348 | 732 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; // PLLCLK = 96 MHz (384 MHz / 4) |
mbed_official | 25:ac5b0a371348 | 733 | RCC_OscInitStruct.PLL.PLLQ = 8; // USB clock = 48 MHz (384 MHz / 8) --> Good for USB |
mbed_official | 25:ac5b0a371348 | 734 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
mbed_official | 25:ac5b0a371348 | 735 | { |
mbed_official | 25:ac5b0a371348 | 736 | return 0; // FAIL |
mbed_official | 25:ac5b0a371348 | 737 | } |
mbed_official | 25:ac5b0a371348 | 738 | |
mbed_official | 25:ac5b0a371348 | 739 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ |
mbed_official | 25:ac5b0a371348 | 740 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
mbed_official | 25:ac5b0a371348 | 741 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 96 MHz |
mbed_official | 25:ac5b0a371348 | 742 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 96 MHz |
mbed_official | 25:ac5b0a371348 | 743 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // 48 MHz |
mbed_official | 25:ac5b0a371348 | 744 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 96 MHz |
mbed_official | 25:ac5b0a371348 | 745 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) |
mbed_official | 25:ac5b0a371348 | 746 | { |
mbed_official | 25:ac5b0a371348 | 747 | return 0; // FAIL |
mbed_official | 25:ac5b0a371348 | 748 | } |
mbed_official | 25:ac5b0a371348 | 749 | |
mbed_official | 25:ac5b0a371348 | 750 | /* Output clock on MCO1 pin(PA8) for debugging purpose */ |
mbed_official | 25:ac5b0a371348 | 751 | //HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); // 16 MHz |
mbed_official | 25:ac5b0a371348 | 752 | |
mbed_official | 25:ac5b0a371348 | 753 | return 1; // OK |
mbed_official | 25:ac5b0a371348 | 754 | } |
mbed_official | 25:ac5b0a371348 | 755 | |
mbed_official | 25:ac5b0a371348 | 756 | /** |
mbed_official | 25:ac5b0a371348 | 757 | * @} |
mbed_official | 25:ac5b0a371348 | 758 | */ |
mbed_official | 25:ac5b0a371348 | 759 | |
mbed_official | 25:ac5b0a371348 | 760 | /** |
mbed_official | 25:ac5b0a371348 | 761 | * @} |
mbed_official | 25:ac5b0a371348 | 762 | */ |
mbed_official | 25:ac5b0a371348 | 763 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |