Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

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