system_stm32h7xx.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /**
  2. ******************************************************************************
  3. * @file system_stm32h7xx.c
  4. * @author MCD Application Team
  5. * @brief CMSIS Cortex-Mx Device Peripheral Access Layer System Source File.
  6. *
  7. * This file provides two functions and one global variable to be called from
  8. * user application:
  9. * - SystemInit(): This function is called at startup just after reset and
  10. * before branch to main program. This call is made inside
  11. * the "startup_stm32h7xx.s" file.
  12. *
  13. * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
  14. * by the user application to setup the SysTick
  15. * timer or configure other parameters.
  16. *
  17. * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
  18. * be called whenever the core clock is changed
  19. * during program execution.
  20. *
  21. *
  22. ******************************************************************************
  23. * @attention
  24. *
  25. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  26. *
  27. * Redistribution and use in source and binary forms, with or without modification,
  28. * are permitted provided that the following conditions are met:
  29. * 1. Redistributions of source code must retain the above copyright notice,
  30. * this list of conditions and the following disclaimer.
  31. * 2. Redistributions in binary form must reproduce the above copyright notice,
  32. * this list of conditions and the following disclaimer in the documentation
  33. * and/or other materials provided with the distribution.
  34. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  35. * may be used to endorse or promote products derived from this software
  36. * without specific prior written permission.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  39. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  40. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  41. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  42. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  43. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  44. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  45. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  47. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48. *
  49. ******************************************************************************
  50. */
  51. /** @addtogroup CMSIS
  52. * @{
  53. */
  54. /** @addtogroup stm32h7xx_system
  55. * @{
  56. */
  57. /** @addtogroup STM32H7xx_System_Private_Includes
  58. * @{
  59. */
  60. #include "stm32h7xx.h"
  61. #if !defined (HSE_VALUE)
  62. #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
  63. #endif /* HSE_VALUE */
  64. #if !defined (CSI_VALUE)
  65. #define CSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
  66. #endif /* CSI_VALUE */
  67. #if !defined (HSI_VALUE)
  68. #define HSI_VALUE ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/
  69. #endif /* HSI_VALUE */
  70. /**
  71. * @}
  72. */
  73. /** @addtogroup STM32H7xx_System_Private_TypesDefinitions
  74. * @{
  75. */
  76. /**
  77. * @}
  78. */
  79. /** @addtogroup STM32H7xx_System_Private_Defines
  80. * @{
  81. */
  82. /************************* Miscellaneous Configuration ************************/
  83. /*!< Uncomment the following line if you need to use external SRAM or SDRAM mounted
  84. on EVAL board as data memory */
  85. /*#define DATA_IN_ExtSRAM */
  86. /*#define DATA_IN_ExtSDRAM*/
  87. #if defined(DATA_IN_ExtSRAM) && defined(DATA_IN_ExtSDRAM)
  88. #error "Please select DATA_IN_ExtSRAM or DATA_IN_ExtSDRAM "
  89. #endif /* DATA_IN_ExtSRAM && DATA_IN_ExtSDRAM */
  90. /*!< Uncomment the following line if you need to relocate your vector Table in
  91. Internal SRAM. */
  92. /* #define VECT_TAB_SRAM */
  93. #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
  94. This value must be a multiple of 0x200. */
  95. /******************************************************************************/
  96. /**
  97. * @}
  98. */
  99. /** @addtogroup STM32H7xx_System_Private_Macros
  100. * @{
  101. */
  102. /**
  103. * @}
  104. */
  105. /** @addtogroup STM32H7xx_System_Private_Variables
  106. * @{
  107. */
  108. /* This variable is updated in three ways:
  109. 1) by calling CMSIS function SystemCoreClockUpdate()
  110. 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
  111. 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
  112. Note: If you use this function to configure the system clock; then there
  113. is no need to call the 2 first functions listed above, since SystemCoreClock
  114. variable is updated automatically.
  115. */
  116. uint32_t SystemCoreClock = 64000000;
  117. uint32_t SystemD2Clock = 64000000;
  118. const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
  119. /**
  120. * @}
  121. */
  122. /** @addtogroup STM32H7xx_System_Private_FunctionPrototypes
  123. * @{
  124. */
  125. #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
  126. static void SystemInit_ExtMemCtl(void);
  127. #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
  128. /**
  129. * @}
  130. */
  131. /** @addtogroup STM32H7xx_System_Private_Functions
  132. * @{
  133. */
  134. /**
  135. * @brief Setup the microcontroller system
  136. * Initialize the FPU setting, vector table location and External memory
  137. * configuration.
  138. * @param None
  139. * @retval None
  140. */
  141. void SystemInit (void)
  142. {
  143. /* FPU settings ------------------------------------------------------------*/
  144. #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  145. SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
  146. #endif
  147. /* Reset the RCC clock configuration to the default reset state ------------*/
  148. /* Set HSION bit */
  149. RCC->CR |= RCC_CR_HSION;
  150. /* Reset CFGR register */
  151. RCC->CFGR = 0x00000000;
  152. /* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */
  153. RCC->CR &= (uint32_t)0xEAF6ED7F;
  154. /* Reset D1CFGR register */
  155. RCC->D1CFGR = 0x00000000;
  156. /* Reset D2CFGR register */
  157. RCC->D2CFGR = 0x00000000;
  158. /* Reset D3CFGR register */
  159. RCC->D3CFGR = 0x00000000;
  160. /* Reset PLLCKSELR register */
  161. RCC->PLLCKSELR = 0x00000000;
  162. /* Reset PLLCFGR register */
  163. RCC->PLLCFGR = 0x00000000;
  164. /* Reset PLL1DIVR register */
  165. RCC->PLL1DIVR = 0x00000000;
  166. /* Reset PLL1FRACR register */
  167. RCC->PLL1FRACR = 0x00000000;
  168. /* Reset PLL2DIVR register */
  169. RCC->PLL2DIVR = 0x00000000;
  170. /* Reset PLL2FRACR register */
  171. RCC->PLL2FRACR = 0x00000000;
  172. /* Reset PLL3DIVR register */
  173. RCC->PLL3DIVR = 0x00000000;
  174. /* Reset PLL3FRACR register */
  175. RCC->PLL3FRACR = 0x00000000;
  176. /* Reset HSEBYP bit */
  177. RCC->CR &= (uint32_t)0xFFFBFFFF;
  178. /* Disable all interrupts */
  179. RCC->CIER = 0x00000000;
  180. /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
  181. *((__IO uint32_t*)0x51008108) = 0x00000001;
  182. #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
  183. SystemInit_ExtMemCtl();
  184. #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
  185. /* Configure the Vector Table location add offset address ------------------*/
  186. #ifdef VECT_TAB_SRAM
  187. SCB->VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal ITCMSRAM */
  188. #else
  189. SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
  190. #endif
  191. }
  192. /**
  193. * @brief Update SystemCoreClock variable according to Clock Register Values.
  194. * The SystemCoreClock variable contains the core clock , it can
  195. * be used by the user application to setup the SysTick timer or configure
  196. * other parameters.
  197. *
  198. * @note Each time the core clock changes, this function must be called
  199. * to update SystemCoreClock variable value. Otherwise, any configuration
  200. * based on this variable will be incorrect.
  201. *
  202. * @note - The system frequency computed by this function is not the real
  203. * frequency in the chip. It is calculated based on the predefined
  204. * constant and the selected clock source:
  205. *
  206. * - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)
  207. * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
  208. * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
  209. * - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*),
  210. * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
  211. *
  212. * (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
  213. * 4 MHz) but the real value may vary depending on the variations
  214. * in voltage and temperature.
  215. * (**) HSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
  216. * 64 MHz) but the real value may vary depending on the variations
  217. * in voltage and temperature.
  218. *
  219. * (***)HSE_VALUE is a constant defined in stm32h7xx_hal.h file (default value
  220. * 25 MHz), user has to ensure that HSE_VALUE is same as the real
  221. * frequency of the crystal used. Otherwise, this function may
  222. * have wrong result.
  223. *
  224. * - The result of this function could be not correct when using fractional
  225. * value for HSE crystal.
  226. * @param None
  227. * @retval None
  228. */
  229. void SystemCoreClockUpdate (void)
  230. {
  231. uint32_t pllp = 2, pllsource = 0, pllm = 2 ,tmp, pllfracen =0 , hsivalue = 0;
  232. float fracn1, pllvco = 0 ;
  233. /* Get SYSCLK source -------------------------------------------------------*/
  234. switch (RCC->CFGR & RCC_CFGR_SWS)
  235. {
  236. case 0x00: /* HSI used as system clock source */
  237. SystemCoreClock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
  238. break;
  239. case 0x08: /* CSI used as system clock source */
  240. SystemCoreClock = CSI_VALUE;
  241. break;
  242. case 0x10: /* HSE used as system clock source */
  243. SystemCoreClock = HSE_VALUE;
  244. break;
  245. case 0x18: /* PLL1 used as system clock source */
  246. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
  247. SYSCLK = PLL_VCO / PLLR
  248. */
  249. pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  250. pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4) ;
  251. pllfracen = RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN;
  252. fracn1 = (pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
  253. switch (pllsource)
  254. {
  255. case 0x00: /* HSI used as PLL clock source */
  256. hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
  257. pllvco = (hsivalue/ pllm) * ((RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/0x2000) +1 );
  258. break;
  259. case 0x01: /* CSI used as PLL clock source */
  260. pllvco = (CSI_VALUE / pllm) * ((RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/0x2000) +1 );
  261. break;
  262. case 0x02: /* HSE used as PLL clock source */
  263. pllvco = (HSE_VALUE / pllm) * ((RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/0x2000) +1 );
  264. break;
  265. default:
  266. pllvco = (CSI_VALUE / pllm) * ((RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/0x2000) +1 );
  267. break;
  268. }
  269. pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1 ) ;
  270. SystemCoreClock = (uint32_t) (pllvco/pllp);
  271. break;
  272. default:
  273. SystemCoreClock = CSI_VALUE;
  274. break;
  275. }
  276. /* Compute HCLK frequency --------------------------------------------------*/
  277. /* Get HCLK prescaler */
  278. tmp = D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> POSITION_VAL(RCC_D1CFGR_D1CPRE_0)];
  279. /* HCLK frequency */
  280. SystemCoreClock >>= tmp;
  281. }
  282. #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
  283. /**
  284. * @brief Setup the external memory controller.
  285. * Called in startup_stm32h7xx.s before jump to main.
  286. * This function configures the external memories (SRAM/SDRAM)
  287. * This SRAM/SDRAM will be used as program data memory (including heap and stack).
  288. * @param None
  289. * @retval None
  290. */
  291. void SystemInit_ExtMemCtl(void)
  292. {
  293. #if defined (DATA_IN_ExtSDRAM)
  294. register uint32_t tmpreg = 0, timeout = 0xFFFF;
  295. register __IO uint32_t index;
  296. /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
  297. clock */
  298. RCC->AHB4ENR |= 0x000001F8;
  299. /* Connect PDx pins to FMC Alternate function */
  300. GPIOD->AFR[0] = 0x000000CC;
  301. GPIOD->AFR[1] = 0xCC000CCC;
  302. /* Configure PDx pins in Alternate function mode */
  303. GPIOD->MODER = 0xAFEAFFFA;
  304. /* Configure PDx pins speed to 50 MHz */
  305. GPIOD->OSPEEDR = 0xA02A000A;
  306. /* Configure PDx pins Output type to push-pull */
  307. GPIOD->OTYPER = 0x00000000;
  308. /* No pull-up, pull-down for PDx pins */
  309. GPIOD->PUPDR = 0x55555505;
  310. /* Connect PEx pins to FMC Alternate function */
  311. GPIOE->AFR[0] = 0xC00000CC;
  312. GPIOE->AFR[1] = 0xCCCCCCCC;
  313. /* Configure PEx pins in Alternate function mode */
  314. GPIOE->MODER = 0xAAAABFFA;
  315. /* Configure PEx pins speed to 50 MHz */
  316. GPIOE->OSPEEDR = 0xAAAA800A;
  317. /* Configure PEx pins Output type to push-pull */
  318. GPIOE->OTYPER = 0x00000000;
  319. /* No pull-up, pull-down for PEx pins */
  320. GPIOE->PUPDR = 0x55554005;
  321. /* Connect PFx pins to FMC Alternate function */
  322. GPIOF->AFR[0] = 0x00CCCCCC;
  323. GPIOF->AFR[1] = 0xCCCCC000;
  324. /* Configure PFx pins in Alternate function mode */
  325. GPIOF->MODER = 0xAABFFAAA;
  326. /* Configure PFx pins speed to 50 MHz */
  327. GPIOF->OSPEEDR = 0xAA800AAA;
  328. /* Configure PFx pins Output type to push-pull */
  329. GPIOF->OTYPER = 0x00000000;
  330. /* No pull-up, pull-down for PFx pins */
  331. GPIOF->PUPDR = 0x55400555;
  332. /* Connect PGx pins to FMC Alternate function */
  333. GPIOG->AFR[0] = 0x00CCCCCC;
  334. GPIOG->AFR[1] = 0xC000000C;
  335. /* Configure PGx pins in Alternate function mode */
  336. GPIOG->MODER = 0xBFFEFAAA;
  337. /* Configure PGx pins speed to 50 MHz */
  338. GPIOG->OSPEEDR = 0x80020AAA;
  339. /* Configure PGx pins Output type to push-pull */
  340. GPIOG->OTYPER = 0x00000000;
  341. /* No pull-up, pull-down for PGx pins */
  342. GPIOG->PUPDR = 0x40010515;
  343. /* Connect PHx pins to FMC Alternate function */
  344. GPIOH->AFR[0] = 0xCCC00000;
  345. GPIOH->AFR[1] = 0xCCCCCCCC;
  346. /* Configure PHx pins in Alternate function mode */
  347. GPIOH->MODER = 0xAAAAABFF;
  348. /* Configure PHx pins speed to 50 MHz */
  349. GPIOH->OSPEEDR = 0xAAAAA800;
  350. /* Configure PHx pins Output type to push-pull */
  351. GPIOH->OTYPER = 0x00000000;
  352. /* No pull-up, pull-down for PHx pins */
  353. GPIOH->PUPDR = 0x55555400;
  354. /* Connect PIx pins to FMC Alternate function */
  355. GPIOI->AFR[0] = 0xCCCCCCCC;
  356. GPIOI->AFR[1] = 0x00000CC0;
  357. /* Configure PIx pins in Alternate function mode */
  358. GPIOI->MODER = 0xFFEBAAAA;
  359. /* Configure PIx pins speed to 50 MHz */
  360. GPIOI->OSPEEDR = 0x0028AAAA;
  361. /* Configure PIx pins Output type to push-pull */
  362. GPIOI->OTYPER = 0x00000000;
  363. /* No pull-up, pull-down for PIx pins */
  364. GPIOI->PUPDR = 0x00145555;
  365. /*-- FMC Configuration ------------------------------------------------------*/
  366. /* Enable the FMC interface clock */
  367. (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
  368. /*SDRAM Timing and access interface configuration*/
  369. /*LoadToActiveDelay = 2
  370. ExitSelfRefreshDelay = 6
  371. SelfRefreshTime = 4
  372. RowCycleDelay = 6
  373. WriteRecoveryTime = 2
  374. RPDelay = 2
  375. RCDDelay = 2
  376. SDBank = FMC_SDRAM_BANK2
  377. ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9
  378. RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12
  379. MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_32
  380. InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4
  381. CASLatency = FMC_SDRAM_CAS_LATENCY_2
  382. WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE
  383. SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2
  384. ReadBurst = FMC_SDRAM_RBURST_ENABLE
  385. ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0*/
  386. FMC_Bank5_6->SDCR[0] = 0x00001800;
  387. FMC_Bank5_6->SDCR[1] = 0x00000165;
  388. FMC_Bank5_6->SDTR[0] = 0x00105000;
  389. FMC_Bank5_6->SDTR[1] = 0x01010351;
  390. /* SDRAM initialization sequence */
  391. /* Clock enable command */
  392. FMC_Bank5_6->SDCMR = 0x00000009;
  393. tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
  394. while((tmpreg != 0) && (timeout-- > 0))
  395. {
  396. tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
  397. }
  398. /* Delay */
  399. for (index = 0; index<1000; index++);
  400. /* PALL command */
  401. FMC_Bank5_6->SDCMR = 0x0000000A;
  402. timeout = 0xFFFF;
  403. while((tmpreg != 0) && (timeout-- > 0))
  404. {
  405. tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
  406. }
  407. FMC_Bank5_6->SDCMR = 0x000000EB;
  408. timeout = 0xFFFF;
  409. while((tmpreg != 0) && (timeout-- > 0))
  410. {
  411. tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
  412. }
  413. FMC_Bank5_6->SDCMR = 0x0004400C;
  414. timeout = 0xFFFF;
  415. while((tmpreg != 0) && (timeout-- > 0))
  416. {
  417. tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
  418. }
  419. /* Set refresh count */
  420. tmpreg = FMC_Bank5_6->SDRTR;
  421. FMC_Bank5_6->SDRTR = (tmpreg | (0x00000603<<1));
  422. /* Disable write protection */
  423. tmpreg = FMC_Bank5_6->SDCR[1];
  424. FMC_Bank5_6->SDCR[1] = (tmpreg & 0xFFFFFDFF);
  425. /*FMC controller Enable*/
  426. FMC_Bank1->BTCR[0] |= 0x80000000;
  427. #endif /* DATA_IN_ExtSDRAM */
  428. #if defined(DATA_IN_ExtSRAM)
  429. /*-- GPIOs Configuration -----------------------------------------------------*/
  430. /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
  431. RCC->AHB4ENR |= 0x00000078;
  432. /* Connect PDx pins to FMC Alternate function */
  433. GPIOD->AFR[0] = 0x00CCC0CC;
  434. GPIOD->AFR[1] = 0xCCCCCCCC;
  435. /* Configure PDx pins in Alternate function mode */
  436. GPIOD->MODER = 0xAAAA0A8A;
  437. /* Configure PDx pins speed to 100 MHz */
  438. GPIOD->OSPEEDR = 0xFFFF0FCF;
  439. /* Configure PDx pins Output type to push-pull */
  440. GPIOD->OTYPER = 0x00000000;
  441. /* No pull-up, pull-down for PDx pins */
  442. GPIOD->PUPDR = 0x55550545;
  443. /* Connect PEx pins to FMC Alternate function */
  444. GPIOE->AFR[0] = 0xC00CC0CC;
  445. GPIOE->AFR[1] = 0xCCCCCCCC;
  446. /* Configure PEx pins in Alternate function mode */
  447. GPIOE->MODER = 0xAAAA828A;
  448. /* Configure PEx pins speed to 100 MHz */
  449. GPIOE->OSPEEDR = 0xFFFFC3CF;
  450. /* Configure PEx pins Output type to push-pull */
  451. GPIOE->OTYPER = 0x00000000;
  452. /* No pull-up, pull-down for PEx pins */
  453. GPIOE->PUPDR = 0x55554145;
  454. /* Connect PFx pins to FMC Alternate function */
  455. GPIOF->AFR[0] = 0x00CCCCCC;
  456. GPIOF->AFR[1] = 0xCCCC0000;
  457. /* Configure PFx pins in Alternate function mode */
  458. GPIOF->MODER = 0xAA000AAA;
  459. /* Configure PFx pins speed to 100 MHz */
  460. GPIOF->OSPEEDR = 0xFF000FFF;
  461. /* Configure PFx pins Output type to push-pull */
  462. GPIOF->OTYPER = 0x00000000;
  463. /* No pull-up, pull-down for PFx pins */
  464. GPIOF->PUPDR = 0x55000555;
  465. /* Connect PGx pins to FMC Alternate function */
  466. GPIOG->AFR[0] = 0x00CCCCCC;
  467. GPIOG->AFR[1] = 0x000000C0;
  468. /* Configure PGx pins in Alternate function mode */
  469. GPIOG->MODER = 0x00200AAA;
  470. /* Configure PGx pins speed to 100 MHz */
  471. GPIOG->OSPEEDR = 0x00300FFF;
  472. /* Configure PGx pins Output type to push-pull */
  473. GPIOG->OTYPER = 0x00000000;
  474. /* No pull-up, pull-down for PGx pins */
  475. GPIOG->PUPDR = 0x00100555;
  476. /*-- FMC/FSMC Configuration --------------------------------------------------*/
  477. /* Enable the FMC/FSMC interface clock */
  478. (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
  479. /* Configure and enable Bank1_SRAM2 */
  480. FMC_Bank1->BTCR[4] = 0x00001091;
  481. FMC_Bank1->BTCR[5] = 0x00110212;
  482. FMC_Bank1E->BWTR[4] = 0x0FFFFFFF;
  483. /*FMC controller Enable*/
  484. FMC_Bank1->BTCR[0] |= 0x80000000;
  485. #endif /* DATA_IN_ExtSRAM */
  486. }
  487. #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
  488. /**
  489. * @}
  490. */
  491. /**
  492. * @}
  493. */
  494. /**
  495. * @}
  496. */
  497. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/