source: rtems/bsps/arm/stm32h7/boards/stm/stm32h757i-eval/system_stm32h7xx.c @ 2fded81

Last change on this file since 2fded81 was 2fded81, checked in by Karel Gardas <karel@…>, on 05/16/22 at 10:58:10

bsps/stm32h7: add board C files for stm32h757i-eval BSP

Besides C files for the BSP variant the patch also provides license
clarification on system_stm32h7xx.c file which is provided
in boards/stm/stm32h757i-eval directory.
The files comes from STM32CubeH7 project and references "root directory"
in its license comment and it's not clear where this points out.
Let's add clarification comment about it and also based on it
and resulting license let's add SPDX license identifier.

Sponsored-By: Precidata

  • Property mode set to 100644
File size: 28.1 KB
Line 
1/* SPDX-License-Identifier: BSD-3-Clause */
2/**
3  ******************************************************************************
4  * @file    system_stm32h7xx.c
5  * @author  MCD Application Team
6  * @brief   CMSIS Cortex-Mx Device Peripheral Access Layer System Source File.
7  *
8  *   This file provides two functions and one global variable to be called from
9  *   user application:
10  *      - SystemInit(): This function is called at startup just after reset and
11  *                      before branch to main program. This call is made inside
12  *                      the "startup_stm32h7xx.s" file.
13  *
14  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
15  *                                  by the user application to setup the SysTick
16  *                                  timer or configure other parameters.
17  *                                     
18  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
19  *                                 be called whenever the core clock is changed
20  *                                 during program execution.
21  *
22  *
23  ******************************************************************************
24  * @attention
25  *
26  * Copyright (c) 2019 STMicroelectronics.
27  * All rights reserved.
28  *
29  * This software is licensed under terms that can be found in the LICENSE file
30  * in the root directory of this software component.
31  * If no LICENSE file comes with this software, it is provided AS-IS.
32  *
33  ******************************************************************************
34  */
35/*
36 * RTEMS committer clarification comment on license above:
37 *
38 * This file comes from STM32CubeH7 project from its Projects
39 * subdirectory. There is Templates subdirectory per every supported
40 * BSP there. The Templates contains the file. In our case the file is
41 * here:
42 * https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/STM32H747I-EVAL/Templates/BootCM4_CM7/Common/Src/system_stm32h7xx.c
43 *
44 * When we go up in the directory tree starting from the file, we find
45 * out that the "root directory" in the sense of license claim above is Templates
46 * directory here:
47 * https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/STM32H747I-EVAL/Templates
48 *
49 * This directory contains LICENSE.md file with a following license text:
50 *
51 * Copyright 2019 STMicroelectronics.
52 * All rights reserved.
53 *
54 * Redistribution and use in source and binary forms, with or without modification,
55 * are permitted provided that the following conditions are met:
56 *
57 * 1. Redistributions of source code must retain the above copyright notice, this
58 * list of conditions and the following disclaimer.
59 *
60 * 2. Redistributions in binary form must reproduce the above copyright notice,
61 * this list of conditions and the following disclaimer in the documentation and/or
62 * other materials provided with the distribution.
63 *
64 * 3. Neither the name of the copyright holder nor the names of its contributors
65 * may be used to endorse or promote products derived from this software without
66 * specific prior written permission.
67 *
68 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
69 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
70 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
71 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
72 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
73 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
74 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
75 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
77 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 */
79
80/** @addtogroup CMSIS
81  * @{
82  */
83
84/** @addtogroup stm32h7xx_system
85  * @{
86  */ 
87 
88/** @addtogroup STM32H7xx_System_Private_Includes
89  * @{
90  */
91
92#include "stm32h7xx.h"
93#include <math.h>
94#ifdef __rtems__
95#include <bsp/linker-symbols.h>
96#endif /* __rtems__ */
97#if !defined  (HSE_VALUE)
98#define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
99#endif /* HSE_VALUE */
100
101#if !defined  (CSI_VALUE)
102  #define CSI_VALUE    ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
103#endif /* CSI_VALUE */
104
105#if !defined  (HSI_VALUE)
106  #define HSI_VALUE    ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/
107#endif /* HSI_VALUE */
108
109/**
110  * @}
111  */
112
113/** @addtogroup STM32H7xx_System_Private_TypesDefinitions
114  * @{
115  */
116
117/**
118  * @}
119  */
120
121/** @addtogroup STM32H7xx_System_Private_Defines
122  * @{
123  */
124
125/************************* Miscellaneous Configuration ************************/
126/*!< Uncomment the following line if you need to use external SRAM or SDRAM mounted
127     on EVAL board as data memory  */
128#define DATA_IN_ExtSRAM
129#define DATA_IN_ExtSDRAM
130
131/*!< Uncomment the following line if you need to relocate your vector Table in
132     Internal SRAM. */
133/* #define VECT_TAB_SRAM */
134#define VECT_TAB_OFFSET  0x00000000UL       /*!< Vector Table base offset field.
135                                      This value must be a multiple of 0x200. */
136/******************************************************************************/
137
138/**
139  * @}
140  */
141
142/** @addtogroup STM32H7xx_System_Private_Macros
143  * @{
144  */
145
146/**
147  * @}
148  */
149
150/** @addtogroup STM32H7xx_System_Private_Variables
151  * @{
152  */
153  /* This variable is updated in three ways:
154      1) by calling CMSIS function SystemCoreClockUpdate()
155      2) by calling HAL API function HAL_RCC_GetHCLKFreq()
156      3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
157         Note: If you use this function to configure the system clock; then there
158               is no need to call the 2 first functions listed above, since SystemCoreClock
159               variable is updated automatically.
160  */
161#ifndef __rtems__
162  uint32_t SystemCoreClock = 64000000;
163  uint32_t SystemD2Clock = 64000000;
164#else /* __rtems__ */
165  RTEMS_SECTION(".rtemsstack") uint32_t SystemCoreClock;
166  RTEMS_SECTION(".rtemsstack") uint32_t SystemD2Clock;
167#endif /* __rtems__ */
168  const  uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
169
170/**
171  * @}
172  */
173
174/** @addtogroup STM32H7xx_System_Private_FunctionPrototypes
175  * @{
176  */
177#ifndef __rtems__
178#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
179  static void SystemInit_ExtMemCtl(void);
180#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
181#endif /* __rtems__ */
182
183/**
184  * @}
185  */
186
187/** @addtogroup STM32H7xx_System_Private_Functions
188  * @{
189  */
190
191/**
192  * @brief  Setup the microcontroller system
193  *         Initialize the FPU setting, vector table location and External memory
194  *         configuration.
195  * @param  None
196  * @retval None
197  */
198void SystemInit (void)
199{   
200  /* FPU settings ------------------------------------------------------------*/
201  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
202    SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2)));  /* set CP10 and CP11 Full Access */
203  #endif
204
205    /*SEVONPEND enabled so that an interrupt coming from the CPU(n) interrupt signal is
206     detectable by the CPU after a WFI/WFE instruction.*/
207 SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
208
209#ifdef CORE_CM7
210  /* Reset the RCC clock configuration to the default reset state ------------*/
211  /* Set HSION bit */
212  RCC->CR |= RCC_CR_HSION;
213 
214  /* Reset CFGR register */
215  RCC->CFGR = 0x00000000;
216
217  /* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */
218  RCC->CR &= 0xEAF6ED7FU;
219
220  /* Reset D1CFGR register */
221  RCC->D1CFGR = 0x00000000;
222
223  /* Reset D2CFGR register */
224  RCC->D2CFGR = 0x00000000;
225 
226  /* Reset D3CFGR register */
227  RCC->D3CFGR = 0x00000000;
228
229  /* Reset PLLCKSELR register */
230  RCC->PLLCKSELR = 0x00000000;
231
232  /* Reset PLLCFGR register */
233  RCC->PLLCFGR = 0x00000000;
234  /* Reset PLL1DIVR register */
235  RCC->PLL1DIVR = 0x00000000;
236  /* Reset PLL1FRACR register */
237  RCC->PLL1FRACR = 0x00000000;
238
239  /* Reset PLL2DIVR register */
240  RCC->PLL2DIVR = 0x00000000;
241
242  /* Reset PLL2FRACR register */
243 
244  RCC->PLL2FRACR = 0x00000000;
245  /* Reset PLL3DIVR register */
246  RCC->PLL3DIVR = 0x00000000;
247
248  /* Reset PLL3FRACR register */
249  RCC->PLL3FRACR = 0x00000000;
250 
251  /* Reset HSEBYP bit */
252  RCC->CR &= 0xFFFBFFFFU;
253
254  /* Disable all interrupts */
255  RCC->CIER = 0x00000000;
256
257  /* Enable CortexM7 HSEM EXTI line (line 78)*/
258  EXTI_D2->EMR3 |= 0x4000UL; 
259
260  /* Change  the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
261  if((DBGMCU->IDCODE & 0xFFFF0000U) < 0x20000000U)
262  {
263    /* if stm32h7 revY*/
264    /* Change  the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
265    *((__IO uint32_t*)0x51008108) = 0x00000001U;
266  }
267 
268
269/*
270   * Disable the FMC bank1 (enabled after reset).
271   * This, prevents CPU speculation access on this bank which blocks the use of FMC during
272   * 24us. During this time the others FMC master (such as LTDC) cannot use it!
273   */
274  FMC_Bank1_R->BTCR[0] = 0x000030D2;
275
276#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
277  SystemInit_ExtMemCtl();
278#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
279 
280#endif /* CORE_CM7*/
281
282#ifndef __rtems__
283#ifdef CORE_CM4
284
285  /* Configure the Vector Table location add offset address ------------------*/
286#ifdef VECT_TAB_SRAM
287  SCB->VTOR = D2_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
288#else
289  SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
290#endif 
291
292#else
293#ifdef CORE_CM7
294
295  /* Configure the Vector Table location add offset address ------------------*/
296#ifdef VECT_TAB_SRAM
297  SCB->VTOR = D1_AXISRAM_BASE  | VECT_TAB_OFFSET;       /* Vector Table Relocation in Internal SRAM */
298#else
299  SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET;       /* Vector Table Relocation in Internal FLASH */
300#endif 
301
302#else
303#error Please #define CORE_CM4 or CORE_CM7
304#endif                       
305#endif
306
307#else /* __rtems__ */
308  SCB->VTOR = (uint32_t) bsp_start_vector_table_begin;
309#endif /* __rtems__ */
310
311}
312
313/**
314   * @brief  Update SystemCoreClock variable according to Clock Register Values.
315  *         The SystemCoreClock variable contains the core clock , it can
316  *         be used by the user application to setup the SysTick timer or configure
317  *         other parameters.
318  *           
319  * @note   Each time the core clock changes, this function must be called
320  *         to update SystemCoreClock variable value. Otherwise, any configuration
321  *         based on this variable will be incorrect.         
322  *     
323  * @note   - The system frequency computed by this function is not the real
324  *           frequency in the chip. It is calculated based on the predefined
325  *           constant and the selected clock source:
326  *             
327  *           - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)                                 
328  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
329  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
330  *           - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*),
331  *             HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
332  *
333  *         (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
334  *             4 MHz) but the real value may vary depending on the variations
335  *             in voltage and temperature.       
336  *         (**) HSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
337  *             64 MHz) but the real value may vary depending on the variations
338  *             in voltage and temperature.   
339  *   
340  *         (***)HSE_VALUE is a constant defined in stm32h7xx_hal.h file (default value
341  *              25 MHz), user has to ensure that HSE_VALUE is same as the real
342  *              frequency of the crystal used. Otherwise, this function may
343  *              have wrong result.
344  *               
345  *         - The result of this function could be not correct when using fractional
346  *           value for HSE crystal.
347  * @param  None
348  * @retval None
349  */
350void SystemCoreClockUpdate (void)
351{
352  uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp;
353  uint32_t common_system_clock;
354  float_t fracn1, pllvco;
355
356  /* Get SYSCLK source -------------------------------------------------------*/
357
358  switch (RCC->CFGR & RCC_CFGR_SWS)
359  {
360  case RCC_CFGR_SWS_HSI:  /* HSI used as system clock source */
361    common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
362    break;
363
364  case RCC_CFGR_SWS_CSI:  /* CSI used as system clock  source */
365    common_system_clock = CSI_VALUE;
366    break;
367
368  case RCC_CFGR_SWS_HSE:  /* HSE used as system clock  source */
369    common_system_clock = HSE_VALUE;
370    break;
371
372  case RCC_CFGR_SWS_PLL1:  /* PLL1 used as system clock  source */
373
374    /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
375    SYSCLK = PLL_VCO / PLLR
376    */
377    pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
378    pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4)  ;
379    pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
380    fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
381
382    if (pllm != 0U)
383    {
384      switch (pllsource)
385      {
386        case RCC_PLLCKSELR_PLLSRC_HSI:  /* HSI used as PLL clock source */
387
388        hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
389        pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
390
391        break;
392
393        case RCC_PLLCKSELR_PLLSRC_CSI:  /* CSI used as PLL clock source */
394          pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
395        break;
396
397        case RCC_PLLCKSELR_PLLSRC_HSE:  /* HSE used as PLL clock source */
398          pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
399        break;
400
401      default:
402          pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
403        break;
404      }
405      pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
406      common_system_clock =  (uint32_t)(float_t)(pllvco/(float_t)pllp);
407    }
408    else
409    {
410      common_system_clock = 0U;
411    }
412    break;
413
414  default:
415    common_system_clock = CSI_VALUE;
416    break;
417  }
418
419  /* Compute SystemClock frequency --------------------------------------------------*/
420  tmp = D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos];
421
422  /* common_system_clock frequency : CM7 CPU frequency  */
423  common_system_clock >>= tmp;
424
425  /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency  */
426  SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
427
428#if defined(DUAL_CORE) && defined(CORE_CM4)
429  SystemCoreClock = SystemD2Clock;
430#else
431  SystemCoreClock = common_system_clock;
432#endif /* DUAL_CORE && CORE_CM4 */
433}
434#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
435/**
436  * @brief  Setup the external memory controller.
437  *         Called in startup_stm32h7xx.s before jump to main.
438  *         This function configures the external memories (SRAM/SDRAM)
439  *         This SRAM/SDRAM will be used as program data memory (including heap and stack).
440  * @param  None
441  * @retval None
442  */
443void SystemInit_ExtMemCtl(void)
444{
445  __IO uint32_t tmp = 0;
446 
447#if defined (DATA_IN_ExtSDRAM) && defined (DATA_IN_ExtSRAM)
448  register uint32_t tmpreg = 0, timeout = 0xFFFF;
449  register __IO uint32_t index;
450 
451  /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
452      clock */
453  RCC->AHB4ENR |= 0x000001F8;
454 
455  /* Delay after an RCC peripheral clock enabling */
456  tmp = READ_BIT(RCC->AHB4ENR, RCC_AHB4ENR_GPIOEEN);
457 
458  /* Connect PDx pins to FMC Alternate function */     
459  GPIOD->AFR[0]  = 0x00CC00CC;
460  GPIOD->AFR[1]  = 0xCCCCCCCC;
461  /* Configure PDx pins in Alternate function mode */ 
462  GPIOD->MODER   = 0xAAAAFAFA;
463  /* Configure PDx pins speed to 100 MHz */ 
464  GPIOD->OSPEEDR = 0xFFFF0F0F;
465  /* Configure PDx pins Output type to push-pull */ 
466  GPIOD->OTYPER  = 0x00000000;
467  /* Configure PDx pins in Pull-up */
468  GPIOD->PUPDR   = 0x55550505;
469
470  /* Connect PEx pins to FMC Alternate function */
471  GPIOE->AFR[0]  = 0xC00CC0CC;
472  GPIOE->AFR[1]  = 0xCCCCCCCC;
473  /* Configure PEx pins in Alternate function mode */
474  GPIOE->MODER   = 0xAAAABEBA;
475  /* Configure PEx pins speed to 100 MHz */
476  GPIOE->OSPEEDR = 0xFFFFC3CF;
477  /* Configure PEx pins Output type to push-pull */ 
478  GPIOE->OTYPER  = 0x00000000;
479  /* Configure PEx pins in Pull-up */
480  GPIOE->PUPDR   = 0x55554145;
481
482  /* Connect PFx pins to FMC Alternate function */
483  GPIOF->AFR[0]  = 0x00CCCCCC;
484  GPIOF->AFR[1]  = 0xCCCCC000;
485  /* Configure PFx pins in Alternate function mode */   
486  GPIOF->MODER   = 0xAABFFAAA;
487  /* Configure PFx pins speed to 100 MHz */
488  GPIOF->OSPEEDR = 0xFFC00FFF;
489  /* Configure PFx pins Output type to push-pull */ 
490  GPIOF->OTYPER  = 0x00000000;
491  /* Configure PFx pins in Pull-up */
492  GPIOF->PUPDR   = 0x55400555;
493
494  /* Connect PGx pins to FMC Alternate function */
495  GPIOG->AFR[0]  = 0x00CCCCCC;
496  GPIOG->AFR[1]  = 0xC0000C0C;
497  /* Configure PGx pins in Alternate function mode */
498  GPIOG->MODER   = 0xBFEEFAAA;
499  /* Configure PGx pins speed to 100 MHz */
500  GPIOG->OSPEEDR = 0xC0330FFF;
501  /* Configure PGx pins Output type to push-pull */ 
502  GPIOG->OTYPER  = 0x00000000;
503  /* Configure PGx pins in Pull-up */
504  GPIOG->PUPDR   = 0x40110555;
505 
506  /* Connect PHx pins to FMC Alternate function */
507  GPIOH->AFR[0]  = 0xCCC00000;
508  GPIOH->AFR[1]  = 0xCCCCCCCC;
509  /* Configure PHx pins in Alternate function mode */
510  GPIOH->MODER   = 0xAAAAABFF;
511  /* Configure PHx pins speed to 100 MHz */
512  GPIOH->OSPEEDR = 0xFFFFFC00;
513  /* Configure PHx pins Output type to push-pull */ 
514  GPIOH->OTYPER  = 0x00000000;
515  /* Configure PHx pins in Pull-up */
516  GPIOH->PUPDR   = 0x55555400;
517 
518  /* Connect PIx pins to FMC Alternate function */
519  GPIOI->AFR[0]  = 0xCCCCCCCC;
520  GPIOI->AFR[1]  = 0x00000CC0;
521  /* Configure PIx pins in Alternate function mode */
522  GPIOI->MODER   = 0xFFEBAAAA;
523  /* Configure PIx pins speed to 100 MHz */
524  GPIOI->OSPEEDR = 0x003CFFFF;
525  /* Configure PIx pins Output type to push-pull */ 
526  GPIOI->OTYPER  = 0x00000000;
527  /* Configure PIx pins in Pull-up */
528  GPIOI->PUPDR   = 0x00145555;
529 
530  /* Enable the FMC/FSMC interface clock */
531  (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
532 
533  /* Configure and enable Bank1_SRAM2 */
534  FMC_Bank1_R->BTCR[4]  = 0x00001091;
535  FMC_Bank1_R->BTCR[5]  = 0x00110212;
536  FMC_Bank1E_R->BWTR[4] = 0x0FFFFFFF;
537 
538  /*SDRAM Timing and access interface configuration*/
539  /*LoadToActiveDelay  = 2
540    ExitSelfRefreshDelay = 6
541    SelfRefreshTime      = 4
542    RowCycleDelay        = 6
543    WriteRecoveryTime    = 2
544    RPDelay              = 2
545    RCDDelay             = 2
546    SDBank             = FMC_SDRAM_BANK2
547    ColumnBitsNumber   = FMC_SDRAM_COLUMN_BITS_NUM_9
548    RowBitsNumber      = FMC_SDRAM_ROW_BITS_NUM_12
549    MemoryDataWidth    = FMC_SDRAM_MEM_BUS_WIDTH_32
550    InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4
551    CASLatency         = FMC_SDRAM_CAS_LATENCY_2
552    WriteProtection    = FMC_SDRAM_WRITE_PROTECTION_DISABLE
553    SDClockPeriod      = FMC_SDRAM_CLOCK_PERIOD_2
554    ReadBurst          = FMC_SDRAM_RBURST_ENABLE
555    ReadPipeDelay      = FMC_SDRAM_RPIPE_DELAY_0*/
556 
557  FMC_Bank5_6_R->SDCR[0] = 0x00001800;
558  FMC_Bank5_6_R->SDCR[1] = 0x00000165;
559  FMC_Bank5_6_R->SDTR[0] = 0x00105000;
560  FMC_Bank5_6_R->SDTR[1] = 0x01010351;
561 
562  /* SDRAM initialization sequence */
563  /* Clock enable command */
564  FMC_Bank5_6_R->SDCMR = 0x00000009;
565  tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
566  while((tmpreg != 0) && (timeout-- > 0))
567  {
568    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
569  }
570
571  /* Delay */
572  for (index = 0; index<1000; index++);
573 
574  /* PALL command */
575    FMC_Bank5_6_R->SDCMR = 0x0000000A; 
576  timeout = 0xFFFF;
577  while((tmpreg != 0) && (timeout-- > 0))
578  {
579    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
580  }
581 
582  FMC_Bank5_6_R->SDCMR = 0x000000EB;
583  timeout = 0xFFFF;
584  while((tmpreg != 0) && (timeout-- > 0))
585  {
586    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
587  }
588
589  FMC_Bank5_6_R->SDCMR = 0x0004400C;
590  timeout = 0xFFFF;
591  while((tmpreg != 0) && (timeout-- > 0))
592  {
593    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
594  }
595  /* Set refresh count */
596  tmpreg = FMC_Bank5_6_R->SDRTR;
597  FMC_Bank5_6_R->SDRTR = (tmpreg | (0x00000603<<1));
598
599  /* Disable write protection */
600  tmpreg = FMC_Bank5_6_R->SDCR[1];
601  FMC_Bank5_6_R->SDCR[1] = (tmpreg & 0xFFFFFDFF);
602
603   /*FMC controller Enable*/
604  FMC_Bank1_R->BTCR[0]  |= 0x80000000;
605 
606#elif defined (DATA_IN_ExtSDRAM)
607  register uint32_t tmpreg = 0, timeout = 0xFFFF;
608  register __IO uint32_t index;
609
610  /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
611      clock */
612  RCC->AHB4ENR |= 0x000001F8;
613 
614  /* Connect PDx pins to FMC Alternate function */
615  GPIOD->AFR[0]  = 0x000000CC;
616  GPIOD->AFR[1]  = 0xCC000CCC;
617  /* Configure PDx pins in Alternate function mode */ 
618  GPIOD->MODER   = 0xAFEAFFFA;
619  /* Configure PDx pins speed to 100 MHz */ 
620  GPIOD->OSPEEDR = 0xF03F000F;
621  /* Configure PDx pins Output type to push-pull */ 
622  GPIOD->OTYPER  = 0x00000000;
623  /* Configure PDx pins in Pull-up */
624  GPIOD->PUPDR   = 0x50150005;
625   
626  /* Connect PEx pins to FMC Alternate function */
627  GPIOE->AFR[0]  = 0xC00000CC;
628  GPIOE->AFR[1]  = 0xCCCCCCCC;
629  /* Configure PEx pins in Alternate function mode */
630  GPIOE->MODER   = 0xAAAABFFA;
631  /* Configure PEx pins speed to 100 MHz */
632  GPIOE->OSPEEDR = 0xFFFFC00F;
633  /* Configure PEx pins Output type to push-pull */ 
634  GPIOE->OTYPER  = 0x00000000;
635  /* Configure PEx pins in Pull-up */
636  GPIOE->PUPDR   = 0x55554005;
637 
638  /* Connect PFx pins to FMC Alternate function */
639  GPIOF->AFR[0]  = 0x00CCCCCC;
640  GPIOF->AFR[1]  = 0xCCCCC000;
641  /* Configure PFx pins in Alternate function mode */   
642  GPIOF->MODER   = 0xAABFFAAA;
643  /* Configure PFx pins speed to 100 MHz */
644  GPIOF->OSPEEDR = 0xFFC00FFF;
645  /* Configure PFx pins Output type to push-pull */ 
646  GPIOF->OTYPER  = 0x00000000;
647  /* Configure PFx pins in Pull-up */
648  GPIOF->PUPDR   = 0x55400555;
649 
650  /* Connect PGx pins to FMC Alternate function */
651  GPIOG->AFR[0]  = 0x00CCCCCC;
652  GPIOG->AFR[1]  = 0xC000000C;
653  /* Configure PGx pins in Alternate function mode */
654  GPIOG->MODER   = 0xBFFEFAAA;
655 /* Configure PGx pins speed to 100 MHz */
656  GPIOG->OSPEEDR = 0xC0030FFF;
657  /* Configure PGx pins Output type to push-pull */ 
658  GPIOG->OTYPER  = 0x00000000;
659  /* Configure PGx pins in Pull-up */
660  GPIOG->PUPDR   = 0x40010555;
661 
662  /* Connect PHx pins to FMC Alternate function */
663  GPIOH->AFR[0]  = 0xCCC00000;
664  GPIOH->AFR[1]  = 0xCCCCCCCC;
665  /* Configure PHx pins in Alternate function mode */
666  GPIOH->MODER   = 0xAAAAABFF;
667  /* Configure PHx pins speed to 100 MHz */
668  GPIOH->OSPEEDR = 0xFFFFFC00;
669  /* Configure PHx pins Output type to push-pull */ 
670  GPIOH->OTYPER  = 0x00000000;
671  /* Configure PHx pins in Pull-up */
672  GPIOH->PUPDR   = 0x55555400;
673 
674  /* Connect PIx pins to FMC Alternate function */
675  GPIOI->AFR[0]  = 0xCCCCCCCC;
676  GPIOI->AFR[1]  = 0x00000CC0;
677  /* Configure PIx pins in Alternate function mode */
678  GPIOI->MODER   = 0xFFEBAAAA;
679  /* Configure PIx pins speed to 100 MHz */
680  GPIOI->OSPEEDR = 0x003CFFFF;
681  /* Configure PIx pins Output type to push-pull */ 
682  GPIOI->OTYPER  = 0x00000000;
683  /* Configure PIx pins in Pull-up */
684  GPIOI->PUPDR   = 0x00145555;
685 
686/*-- FMC Configuration ------------------------------------------------------*/
687  /* Enable the FMC interface clock */
688  (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
689  /*SDRAM Timing and access interface configuration*/
690  /*LoadToActiveDelay  = 2
691    ExitSelfRefreshDelay = 6
692    SelfRefreshTime      = 4
693    RowCycleDelay        = 6
694    WriteRecoveryTime    = 2
695    RPDelay              = 2
696    RCDDelay             = 2
697    SDBank             = FMC_SDRAM_BANK2
698    ColumnBitsNumber   = FMC_SDRAM_COLUMN_BITS_NUM_9
699    RowBitsNumber      = FMC_SDRAM_ROW_BITS_NUM_12
700    MemoryDataWidth    = FMC_SDRAM_MEM_BUS_WIDTH_32
701    InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4
702    CASLatency         = FMC_SDRAM_CAS_LATENCY_2
703    WriteProtection    = FMC_SDRAM_WRITE_PROTECTION_DISABLE
704    SDClockPeriod      = FMC_SDRAM_CLOCK_PERIOD_2
705    ReadBurst          = FMC_SDRAM_RBURST_ENABLE
706    ReadPipeDelay      = FMC_SDRAM_RPIPE_DELAY_0*/
707 
708  FMC_Bank5_6_R->SDCR[0] = 0x00001800;
709  FMC_Bank5_6_R->SDCR[1] = 0x00000165;
710  FMC_Bank5_6_R->SDTR[0] = 0x00105000;
711  FMC_Bank5_6_R->SDTR[1] = 0x01010351;
712
713  /* SDRAM initialization sequence */
714  /* Clock enable command */
715  FMC_Bank5_6_R->SDCMR = 0x00000009;
716  tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
717  while((tmpreg != 0) && (timeout-- > 0))
718  {
719    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
720  }
721
722  /* Delay */
723  for (index = 0; index<1000; index++);
724 
725  /* PALL command */
726    FMC_Bank5_6_R->SDCMR = 0x0000000A; 
727  timeout = 0xFFFF;
728  while((tmpreg != 0) && (timeout-- > 0))
729  {
730    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
731  }
732 
733  FMC_Bank5_6_R->SDCMR = 0x000000EB;
734  timeout = 0xFFFF;
735  while((tmpreg != 0) && (timeout-- > 0))
736  {
737    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
738  }
739
740  FMC_Bank5_6_R->SDCMR = 0x0004400C;
741  timeout = 0xFFFF;
742  while((tmpreg != 0) && (timeout-- > 0))
743  {
744    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
745  }
746  /* Set refresh count */
747  tmpreg = FMC_Bank5_6_R->SDRTR;
748  FMC_Bank5_6_R->SDRTR = (tmpreg | (0x00000603<<1));
749
750  /* Disable write protection */
751  tmpreg = FMC_Bank5_6_R->SDCR[1];
752  FMC_Bank5_6_R->SDCR[1] = (tmpreg & 0xFFFFFDFF);
753
754   /*FMC controller Enable*/
755  FMC_Bank1_R->BTCR[0]  |= 0x80000000;
756
757#elif defined(DATA_IN_ExtSRAM)
758/*-- GPIOs Configuration -----------------------------------------------------*/
759   /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
760  RCC->AHB4ENR   |= 0x00000078;
761 
762  /* Connect PDx pins to FMC Alternate function */     
763  GPIOD->AFR[0]  = 0x00CC00CC;
764  GPIOD->AFR[1]  = 0xCCCCCCCC;
765  /* Configure PDx pins in Alternate function mode */ 
766  GPIOD->MODER   = 0xAAAAFABA;
767  /* Configure PDx pins speed to 100 MHz */ 
768  GPIOD->OSPEEDR = 0xFFFF0F0F;
769  /* Configure PDx pins Output type to push-pull */ 
770  GPIOD->OTYPER  = 0x00000000;
771  /* Configure PDx pins in Pull-up */
772  GPIOD->PUPDR   = 0x55550505;
773
774  /* Connect PEx pins to FMC Alternate function */
775  GPIOE->AFR[0]  = 0xC00CC0CC;
776  GPIOE->AFR[1]  = 0xCCCCCCCC;
777  /* Configure PEx pins in Alternate function mode */
778  GPIOE->MODER   = 0xAAAABEBA;
779  /* Configure PEx pins speed to 100 MHz */
780  GPIOE->OSPEEDR = 0xFFFFC3CF;
781  /* Configure PEx pins Output type to push-pull */ 
782  GPIOE->OTYPER  = 0x00000000;
783  /* Configure PEx pins in Pull-up */
784  GPIOE->PUPDR   = 0x55554145;
785
786  /* Connect PFx pins to FMC Alternate function */
787  GPIOF->AFR[0]  = 0x00CCCCCC;
788  GPIOF->AFR[1]  = 0xCCCC0000;
789  /* Configure PFx pins in Alternate function mode */   
790  GPIOF->MODER   = 0xAAFFFAAA;
791  /* Configure PFx pins speed to 100 MHz */
792  GPIOF->OSPEEDR = 0xFF000FFF;
793  /* Configure PFx pins Output type to push-pull */ 
794  GPIOF->OTYPER  = 0x00000000;
795  /* Configure PFx pins in Pull-up */
796  GPIOF->PUPDR   = 0x55000555;
797
798  /* Connect PGx pins to FMC Alternate function */
799  GPIOG->AFR[0]  = 0x00CCCCCC;
800  GPIOG->AFR[1]  = 0x00000C00;
801  /* Configure PGx pins in Alternate function mode */
802  GPIOG->MODER   = 0xFFEFFAAA;
803  /* Configure PGx pins speed to 100 MHz */
804  GPIOG->OSPEEDR = 0x00300FFF;
805  /* Configure PGx pins Output type to push-pull */ 
806  GPIOG->OTYPER  = 0x00000000;
807  /* Configure PGx pins in Pull-up */
808  GPIOG->PUPDR   = 0x00100555;
809 
810/*-- FMC/FSMC Configuration --------------------------------------------------*/                                                                               
811  /* Enable the FMC/FSMC interface clock */
812  (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
813
814  /* Configure and enable Bank1_SRAM2 */
815  FMC_Bank1_R->BTCR[4]  = 0x00001091;
816  FMC_Bank1_R->BTCR[5]  = 0x00110212;
817  FMC_Bank1E_R->BWTR[4] = 0x0FFFFFFF; 
818 
819  /*FMC controller Enable*/
820  FMC_Bank1_R->BTCR[0]  |= 0x80000000; 
821
822#endif /* DATA_IN_ExtSRAM */
823 
824  (void)(tmp);
825}
826#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
827
828 
829/**
830  * @}
831  */
832
833/**
834  * @}
835  */
836
837/**
838  * @}
839  */
Note: See TracBrowser for help on using the repository browser.