![]() |
|
|||
File indexing completed on 2025-05-11 08:23:06
0001 /* SPDX-License-Identifier: BSD-3-Clause */ 0002 /** 0003 ****************************************************************************** 0004 * @file system_stm32h7xx.c 0005 * @author MCD Application Team 0006 * @brief CMSIS Cortex-Mx Device Peripheral Access Layer System Source File. 0007 * 0008 * This file provides two functions and one global variable to be called from 0009 * user application: 0010 * - SystemInit(): This function is called at startup just after reset and 0011 * before branch to main program. This call is made inside 0012 * the "startup_stm32h7xx.s" file. 0013 * 0014 * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used 0015 * by the user application to setup the SysTick 0016 * timer or configure other parameters. 0017 * 0018 * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must 0019 * be called whenever the core clock is changed 0020 * during program execution. 0021 * 0022 * 0023 ****************************************************************************** 0024 * @attention 0025 * 0026 * Copyright (c) 2019 STMicroelectronics. 0027 * All rights reserved. 0028 * 0029 * This software is licensed under terms that can be found in the LICENSE file 0030 * in the root directory of this software component. 0031 * If no LICENSE file comes with this software, it is provided AS-IS. 0032 * 0033 ****************************************************************************** 0034 */ 0035 /* 0036 * RTEMS committer clarification comment on license above: 0037 * 0038 * This file comes from STM32CubeH7 project from its Projects 0039 * subdirectory. There is Templates subdirectory per every supported 0040 * BSP there. The Templates contains the file. In our case the file is 0041 * here: 0042 * https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/STM32H747I-DISCO/Templates/BootCM4_CM7/Common/Src/system_stm32h7xx.c 0043 * 0044 * When we go up in the directory tree starting from the file, we find 0045 * out that the "root directory" in the sense of license claim above is Templates 0046 * directory here: 0047 * https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/STM32H747I-DISCO/Templates 0048 * 0049 * This directory contains LICENSE.md file with a following license text: 0050 * 0051 * Copyright 2019 STMicroelectronics. 0052 * All rights reserved. 0053 * 0054 * Redistribution and use in source and binary forms, with or without modification, 0055 * are permitted provided that the following conditions are met: 0056 * 0057 * 1. Redistributions of source code must retain the above copyright notice, this 0058 * list of conditions and the following disclaimer. 0059 * 0060 * 2. Redistributions in binary form must reproduce the above copyright notice, 0061 * this list of conditions and the following disclaimer in the documentation and/or 0062 * other materials provided with the distribution. 0063 * 0064 * 3. Neither the name of the copyright holder nor the names of its contributors 0065 * may be used to endorse or promote products derived from this software without 0066 * specific prior written permission. 0067 * 0068 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 0069 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 0070 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 0071 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 0072 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 0073 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 0074 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 0075 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0076 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 0077 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0078 */ 0079 0080 /** @addtogroup CMSIS 0081 * @{ 0082 */ 0083 0084 /** @addtogroup stm32h7xx_system 0085 * @{ 0086 */ 0087 0088 /** @addtogroup STM32H7xx_System_Private_Includes 0089 * @{ 0090 */ 0091 0092 #include "stm32h7xx.h" 0093 #include <math.h> 0094 #ifdef __rtems__ 0095 #include <bsp/linker-symbols.h> 0096 #include <bspopts.h> 0097 0098 #define HSE_VALUE STM32H7_HSE_FREQUENCY 0099 0100 #endif /* __rtems__ */ 0101 #if !defined (HSE_VALUE) 0102 #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ 0103 #endif /* HSE_VALUE */ 0104 0105 #if !defined (CSI_VALUE) 0106 #define CSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/ 0107 #endif /* CSI_VALUE */ 0108 0109 #if !defined (HSI_VALUE) 0110 #define HSI_VALUE ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/ 0111 #endif /* HSI_VALUE */ 0112 0113 /** 0114 * @} 0115 */ 0116 0117 /** @addtogroup STM32H7xx_System_Private_TypesDefinitions 0118 * @{ 0119 */ 0120 0121 /** 0122 * @} 0123 */ 0124 0125 /** @addtogroup STM32H7xx_System_Private_Defines 0126 * @{ 0127 */ 0128 0129 /************************* Miscellaneous Configuration ************************/ 0130 /*!< Uncomment the following line if you need to use external SDRAM mounted 0131 on DISCO board as data memory */ 0132 /*#define DATA_IN_ExtSDRAM*/ 0133 #ifdef __rtems__ 0134 #define DATA_IN_ExtSDRAM 0135 #endif /* __rtems__ */ 0136 /*!< Uncomment the following line if you need to relocate your vector Table in 0137 Internal SRAM. */ 0138 /* #define VECT_TAB_SRAM */ 0139 #define VECT_TAB_OFFSET 0x00000000UL /*!< Vector Table base offset field. 0140 This value must be a multiple of 0x200. */ 0141 /******************************************************************************/ 0142 0143 /** 0144 * @} 0145 */ 0146 0147 /** @addtogroup STM32H7xx_System_Private_Macros 0148 * @{ 0149 */ 0150 0151 /** 0152 * @} 0153 */ 0154 0155 /** @addtogroup STM32H7xx_System_Private_Variables 0156 * @{ 0157 */ 0158 /* This variable is updated in three ways: 0159 1) by calling CMSIS function SystemCoreClockUpdate() 0160 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 0161 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 0162 Note: If you use this function to configure the system clock; then there 0163 is no need to call the 2 first functions listed above, since SystemCoreClock 0164 variable is updated automatically. 0165 */ 0166 uint32_t SystemCoreClock = 64000000; 0167 uint32_t SystemD2Clock = 64000000; 0168 const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9}; 0169 0170 /** 0171 * @} 0172 */ 0173 0174 /** @addtogroup STM32H7xx_System_Private_FunctionPrototypes 0175 * @{ 0176 */ 0177 #ifndef __rtems__ 0178 #if defined (DATA_IN_ExtSDRAM) 0179 static void SystemInit_ExtMemCtl(void); 0180 #endif /* DATA_IN_ExtSDRAM */ 0181 #endif /* __rtems__ */ 0182 /** 0183 * @} 0184 */ 0185 0186 /** @addtogroup STM32H7xx_System_Private_Functions 0187 * @{ 0188 */ 0189 0190 /** 0191 * @brief Setup the microcontroller system 0192 * Initialize the FPU setting, vector table location and External memory 0193 * configuration. 0194 * @param None 0195 * @retval None 0196 */ 0197 void SystemInit (void) 0198 { 0199 /* FPU settings ------------------------------------------------------------*/ 0200 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) 0201 SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */ 0202 #endif 0203 0204 /*SEVONPEND enabled so that an interrupt coming from the CPU(n) interrupt signal is 0205 detectable by the CPU after a WFI/WFE instruction.*/ 0206 SCB->SCR |= SCB_SCR_SEVONPEND_Msk; 0207 0208 #ifdef CORE_CM7 0209 /* Reset the RCC clock configuration to the default reset state ------------*/ 0210 /* Set HSION bit */ 0211 RCC->CR |= RCC_CR_HSION; 0212 0213 /* Reset CFGR register */ 0214 RCC->CFGR = 0x00000000; 0215 0216 /* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */ 0217 RCC->CR &= 0xEAF6ED7FU; 0218 0219 /* Reset D1CFGR register */ 0220 RCC->D1CFGR = 0x00000000; 0221 0222 /* Reset D2CFGR register */ 0223 RCC->D2CFGR = 0x00000000; 0224 0225 /* Reset D3CFGR register */ 0226 RCC->D3CFGR = 0x00000000; 0227 0228 /* Reset PLLCKSELR register */ 0229 RCC->PLLCKSELR = 0x00000000; 0230 0231 /* Reset PLLCFGR register */ 0232 RCC->PLLCFGR = 0x00000000; 0233 /* Reset PLL1DIVR register */ 0234 RCC->PLL1DIVR = 0x00000000; 0235 /* Reset PLL1FRACR register */ 0236 RCC->PLL1FRACR = 0x00000000; 0237 0238 /* Reset PLL2DIVR register */ 0239 RCC->PLL2DIVR = 0x00000000; 0240 0241 /* Reset PLL2FRACR register */ 0242 0243 RCC->PLL2FRACR = 0x00000000; 0244 /* Reset PLL3DIVR register */ 0245 RCC->PLL3DIVR = 0x00000000; 0246 0247 /* Reset PLL3FRACR register */ 0248 RCC->PLL3FRACR = 0x00000000; 0249 0250 /* Reset HSEBYP bit */ 0251 RCC->CR &= 0xFFFBFFFFU; 0252 0253 /* Disable all interrupts */ 0254 RCC->CIER = 0x00000000; 0255 0256 /* Enable CortexM7 HSEM EXTI line (line 78)*/ 0257 EXTI_D2->EMR3 |= 0x4000UL; 0258 0259 /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */ 0260 if((DBGMCU->IDCODE & 0xFFFF0000U) < 0x20000000U) 0261 { 0262 /* if stm32h7 revY*/ 0263 /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */ 0264 *((__IO uint32_t*)0x51008108) = 0x00000001U; 0265 } 0266 0267 0268 /* 0269 * Disable the FMC bank1 (enabled after reset). 0270 * This, prevents CPU speculation access on this bank which blocks the use of FMC during 0271 * 24us. During this time the others FMC master (such as LTDC) cannot use it! 0272 */ 0273 FMC_Bank1_R->BTCR[0] = 0x000030D2; 0274 0275 #if defined (DATA_IN_ExtSDRAM) 0276 SystemInit_ExtMemCtl(); 0277 #endif /* DATA_IN_ExtSDRAM */ 0278 0279 #endif /* CORE_CM7*/ 0280 0281 #ifdef CORE_CM4 0282 0283 /* Configure the Vector Table location add offset address ------------------*/ 0284 #ifdef VECT_TAB_SRAM 0285 SCB->VTOR = D2_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ 0286 #else 0287 SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ 0288 #endif 0289 0290 #else 0291 #ifdef CORE_CM7 0292 0293 /* Configure the Vector Table location add offset address ------------------*/ 0294 #ifdef VECT_TAB_SRAM 0295 SCB->VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ 0296 #else 0297 SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ 0298 #endif 0299 0300 #else 0301 #error Please #define CORE_CM4 or CORE_CM7 0302 #endif 0303 #endif 0304 0305 } 0306 0307 /** 0308 * @brief Update SystemCoreClock variable according to Clock Register Values. 0309 * The SystemCoreClock variable contains the core clock , it can 0310 * be used by the user application to setup the SysTick timer or configure 0311 * other parameters. 0312 * 0313 * @note Each time the core clock changes, this function must be called 0314 * to update SystemCoreClock variable value. Otherwise, any configuration 0315 * based on this variable will be incorrect. 0316 * 0317 * @note - The system frequency computed by this function is not the real 0318 * frequency in the chip. It is calculated based on the predefined 0319 * constant and the selected clock source: 0320 * 0321 * - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*) 0322 * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) 0323 * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) 0324 * - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*), 0325 * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors. 0326 * 0327 * (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value 0328 * 4 MHz) but the real value may vary depending on the variations 0329 * in voltage and temperature. 0330 * (**) HSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value 0331 * 64 MHz) but the real value may vary depending on the variations 0332 * in voltage and temperature. 0333 * 0334 * (***)HSE_VALUE is a constant defined in stm32h7xx_hal.h file (default value 0335 * 25 MHz), user has to ensure that HSE_VALUE is same as the real 0336 * frequency of the crystal used. Otherwise, this function may 0337 * have wrong result. 0338 * 0339 * - The result of this function could be not correct when using fractional 0340 * value for HSE crystal. 0341 * @param None 0342 * @retval None 0343 */ 0344 void SystemCoreClockUpdate (void) 0345 { 0346 uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp; 0347 uint32_t common_system_clock; 0348 float_t fracn1, pllvco; 0349 0350 /* Get SYSCLK source -------------------------------------------------------*/ 0351 0352 switch (RCC->CFGR & RCC_CFGR_SWS) 0353 { 0354 case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */ 0355 common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)); 0356 break; 0357 0358 case RCC_CFGR_SWS_CSI: /* CSI used as system clock source */ 0359 common_system_clock = CSI_VALUE; 0360 break; 0361 0362 case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */ 0363 common_system_clock = HSE_VALUE; 0364 break; 0365 0366 case RCC_CFGR_SWS_PLL1: /* PLL1 used as system clock source */ 0367 0368 /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN 0369 SYSCLK = PLL_VCO / PLLR 0370 */ 0371 pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC); 0372 pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4) ; 0373 pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos); 0374 fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3)); 0375 0376 if (pllm != 0U) 0377 { 0378 switch (pllsource) 0379 { 0380 case RCC_PLLCKSELR_PLLSRC_HSI: /* HSI used as PLL clock source */ 0381 0382 hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ; 0383 pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 ); 0384 0385 break; 0386 0387 case RCC_PLLCKSELR_PLLSRC_CSI: /* CSI used as PLL clock source */ 0388 pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 ); 0389 break; 0390 0391 case RCC_PLLCKSELR_PLLSRC_HSE: /* HSE used as PLL clock source */ 0392 pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 ); 0393 break; 0394 0395 default: 0396 pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 ); 0397 break; 0398 } 0399 pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ; 0400 common_system_clock = (uint32_t)(float_t)(pllvco/(float_t)pllp); 0401 } 0402 else 0403 { 0404 common_system_clock = 0U; 0405 } 0406 break; 0407 0408 default: 0409 common_system_clock = CSI_VALUE; 0410 break; 0411 } 0412 0413 /* Compute SystemClock frequency --------------------------------------------------*/ 0414 tmp = D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos]; 0415 0416 /* common_system_clock frequency : CM7 CPU frequency */ 0417 common_system_clock >>= tmp; 0418 0419 /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency */ 0420 SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU)); 0421 0422 #if defined(DUAL_CORE) && defined(CORE_CM4) 0423 SystemCoreClock = SystemD2Clock; 0424 #else 0425 SystemCoreClock = common_system_clock; 0426 #endif /* DUAL_CORE && CORE_CM4 */ 0427 } 0428 #if defined (DATA_IN_ExtSDRAM) 0429 /** 0430 * @brief Setup the external memory controller. 0431 * Called in startup_stm32h7xx.s before jump to main. 0432 * This function configures the external memories SDRAM 0433 * This SDRAM will be used as program data memory (including heap and stack). 0434 * @param None 0435 * @retval None 0436 */ 0437 void SystemInit_ExtMemCtl(void) 0438 { 0439 __IO uint32_t tmp = 0; 0440 register uint32_t tmpreg = 0, timeout = 0xFFFF; 0441 register __IO uint32_t index; 0442 0443 /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface 0444 clock */ 0445 RCC->AHB4ENR |= 0x000001F8; 0446 0447 /* Delay after an RCC peripheral clock enabling */ 0448 tmp = READ_BIT(RCC->AHB4ENR, RCC_AHB4ENR_GPIOEEN); 0449 0450 /* Connect PDx pins to FMC Alternate function */ 0451 GPIOD->AFR[0] = 0x000000CC; 0452 GPIOD->AFR[1] = 0xCC000CCC; 0453 /* Configure PDx pins in Alternate function mode */ 0454 GPIOD->MODER = 0xAFEAFFFA; 0455 /* Configure PDx pins speed to 100 MHz */ 0456 GPIOD->OSPEEDR = 0xF03F000F; 0457 /* Configure PDx pins Output type to push-pull */ 0458 GPIOD->OTYPER = 0x00000000; 0459 /* Configure PDx pins in Pull-up */ 0460 GPIOD->PUPDR = 0x50150005; 0461 0462 /* Connect PEx pins to FMC Alternate function */ 0463 GPIOE->AFR[0] = 0xC00000CC; 0464 GPIOE->AFR[1] = 0xCCCCCCCC; 0465 /* Configure PEx pins in Alternate function mode */ 0466 GPIOE->MODER = 0xAAAABFFA; 0467 /* Configure PEx pins speed to 100 MHz */ 0468 GPIOE->OSPEEDR = 0xFFFFC00F; 0469 /* Configure PEx pins Output type to push-pull */ 0470 GPIOE->OTYPER = 0x00000000; 0471 /* Configure PEx pins in Pull-up */ 0472 GPIOE->PUPDR = 0x55554005; 0473 0474 /* Connect PFx pins to FMC Alternate function */ 0475 GPIOF->AFR[0] = 0x00CCCCCC; 0476 GPIOF->AFR[1] = 0xCCCCC000; 0477 /* Configure PFx pins in Alternate function mode */ 0478 GPIOF->MODER = 0xAABFFAAA; 0479 /* Configure PFx pins speed to 100 MHz */ 0480 GPIOF->OSPEEDR = 0xFFC00FFF; 0481 /* Configure PFx pins Output type to push-pull */ 0482 GPIOF->OTYPER = 0x00000000; 0483 /* Configure PFx pins in Pull-up */ 0484 GPIOF->PUPDR = 0x55400555; 0485 0486 /* Connect PGx pins to FMC Alternate function */ 0487 GPIOG->AFR[0] = 0x00CCCCCC; 0488 GPIOG->AFR[1] = 0xC000000C; 0489 /* Configure PGx pins in Alternate function mode */ 0490 GPIOG->MODER = 0xBFFEFAAA; 0491 /* Configure PGx pins speed to 100 MHz */ 0492 GPIOG->OSPEEDR = 0xC0030FFF; 0493 /* Configure PGx pins Output type to push-pull */ 0494 GPIOG->OTYPER = 0x00000000; 0495 /* Configure PGx pins in Pull-up */ 0496 GPIOG->PUPDR = 0x40010555; 0497 0498 /* Connect PHx pins to FMC Alternate function */ 0499 GPIOH->AFR[0] = 0xCCC00000; 0500 GPIOH->AFR[1] = 0xCCCCCCCC; 0501 /* Configure PHx pins in Alternate function mode */ 0502 GPIOH->MODER = 0xAAAAABFF; 0503 /* Configure PHx pins speed to 100 MHz */ 0504 GPIOH->OSPEEDR = 0xFFFFFC00; 0505 /* Configure PHx pins Output type to push-pull */ 0506 GPIOH->OTYPER = 0x00000000; 0507 /* Configure PHx pins in Pull-up */ 0508 GPIOH->PUPDR = 0x55555400; 0509 0510 /* Connect PIx pins to FMC Alternate function */ 0511 GPIOI->AFR[0] = 0xCCCCCCCC; 0512 GPIOI->AFR[1] = 0x00000CC0; 0513 /* Configure PIx pins in Alternate function mode */ 0514 GPIOI->MODER = 0xFFEBAAAA; 0515 /* Configure PIx pins speed to 100 MHz */ 0516 GPIOI->OSPEEDR = 0x003CFFFF; 0517 /* Configure PIx pins Output type to push-pull */ 0518 GPIOI->OTYPER = 0x00000000; 0519 /* Configure PIx pins in Pull-up */ 0520 GPIOI->PUPDR = 0x00145555; 0521 0522 /*-- FMC Configuration ------------------------------------------------------*/ 0523 /* Enable the FMC interface clock */ 0524 (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN)); 0525 /*SDRAM Timing and access interface configuration*/ 0526 /*LoadToActiveDelay = 2 0527 ExitSelfRefreshDelay = 6 0528 SelfRefreshTime = 4 0529 RowCycleDelay = 6 0530 WriteRecoveryTime = 2 0531 RPDelay = 2 0532 RCDDelay = 2 0533 SDBank = FMC_SDRAM_BANK2 0534 ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9 0535 RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12 0536 MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_32 0537 InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4 0538 CASLatency = FMC_SDRAM_CAS_LATENCY_2 0539 WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE 0540 SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2 0541 ReadBurst = FMC_SDRAM_RBURST_ENABLE 0542 ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0*/ 0543 0544 FMC_Bank5_6_R->SDCR[0] = 0x00001800; 0545 FMC_Bank5_6_R->SDCR[1] = 0x00000165; 0546 FMC_Bank5_6_R->SDTR[0] = 0x00105000; 0547 FMC_Bank5_6_R->SDTR[1] = 0x01010351; 0548 0549 /* SDRAM initialization sequence */ 0550 /* Clock enable command */ 0551 FMC_Bank5_6_R->SDCMR = 0x00000009; 0552 tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020; 0553 while((tmpreg != 0) && (timeout-- > 0)) 0554 { 0555 tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020; 0556 } 0557 0558 /* Delay */ 0559 for (index = 0; index<1000; index++); 0560 0561 /* PALL command */ 0562 FMC_Bank5_6_R->SDCMR = 0x0000000A; 0563 timeout = 0xFFFF; 0564 while((tmpreg != 0) && (timeout-- > 0)) 0565 { 0566 tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020; 0567 } 0568 0569 FMC_Bank5_6_R->SDCMR = 0x000000EB; 0570 timeout = 0xFFFF; 0571 while((tmpreg != 0) && (timeout-- > 0)) 0572 { 0573 tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020; 0574 } 0575 0576 FMC_Bank5_6_R->SDCMR = 0x0004400C; 0577 timeout = 0xFFFF; 0578 while((tmpreg != 0) && (timeout-- > 0)) 0579 { 0580 tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020; 0581 } 0582 /* Set refresh count */ 0583 tmpreg = FMC_Bank5_6_R->SDRTR; 0584 FMC_Bank5_6_R->SDRTR = (tmpreg | (0x00000603<<1)); 0585 0586 /* Disable write protection */ 0587 tmpreg = FMC_Bank5_6_R->SDCR[1]; 0588 FMC_Bank5_6_R->SDCR[1] = (tmpreg & 0xFFFFFDFF); 0589 0590 /*FMC controller Enable*/ 0591 FMC_Bank1_R->BTCR[0] |= 0x80000000; 0592 0593 (void)(tmp); 0594 } 0595 #endif /* DATA_IN_ExtSDRAM */ 0596 0597 0598 /** 0599 * @} 0600 */ 0601 0602 /** 0603 * @} 0604 */ 0605 0606 /** 0607 * @} 0608 */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |