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