source: rtems/bsps/arm/stm32h7/boards/stm/stm32h747i-disco/system_stm32h7xx.c @ 1a4e78b3

Last change on this file since 1a4e78b3 was 1a4e78b3, checked in by Karel Gardas <karel@…>, on 03/09/23 at 13:15:53

bsps/stm32h7: fix propagation of configured HSE freq. value into the code

Sponsored-By: Precidata

  • Property mode set to 100644
File size: 20.3 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-DISCO/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/blob/master/Projects/STM32H747I-DISCO/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#include <bspopts.h>
97
98#define HSE_VALUE STM32H7_HSE_FREQUENCY
99
100#endif /* __rtems__ */
101#if !defined  (HSE_VALUE)
102#define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
103#endif /* HSE_VALUE */
104
105#if !defined  (CSI_VALUE)
106  #define CSI_VALUE    ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
107#endif /* CSI_VALUE */
108
109#if !defined  (HSI_VALUE)
110  #define HSI_VALUE    ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/
111#endif /* HSI_VALUE */
112
113/**
114  * @}
115  */
116
117/** @addtogroup STM32H7xx_System_Private_TypesDefinitions
118  * @{
119  */
120
121/**
122  * @}
123  */
124
125/** @addtogroup STM32H7xx_System_Private_Defines
126  * @{
127  */
128
129/************************* Miscellaneous Configuration ************************/
130/*!< Uncomment the following line if you need to use external SDRAM mounted
131     on DISCO board as data memory  */
132/*#define DATA_IN_ExtSDRAM*/
133#ifdef __rtems__
134#define DATA_IN_ExtSDRAM
135#endif /* __rtems__ */
136/*!< Uncomment the following line if you need to relocate your vector Table in
137     Internal SRAM. */
138/* #define VECT_TAB_SRAM */
139#define VECT_TAB_OFFSET  0x00000000UL       /*!< Vector Table base offset field.
140                                      This value must be a multiple of 0x200. */
141/******************************************************************************/
142
143/**
144  * @}
145  */
146
147/** @addtogroup STM32H7xx_System_Private_Macros
148  * @{
149  */
150
151/**
152  * @}
153  */
154
155/** @addtogroup STM32H7xx_System_Private_Variables
156  * @{
157  */
158  /* This variable is updated in three ways:
159      1) by calling CMSIS function SystemCoreClockUpdate()
160      2) by calling HAL API function HAL_RCC_GetHCLKFreq()
161      3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
162         Note: If you use this function to configure the system clock; then there
163               is no need to call the 2 first functions listed above, since SystemCoreClock
164               variable is updated automatically.
165  */
166  uint32_t SystemCoreClock = 64000000;
167  uint32_t SystemD2Clock = 64000000;
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_ExtSDRAM)
179  static void SystemInit_ExtMemCtl(void);
180#endif /* DATA_IN_ExtSDRAM */
181#endif /* __rtems__ */
182/**
183  * @}
184  */
185
186/** @addtogroup STM32H7xx_System_Private_Functions
187  * @{
188  */
189
190/**
191  * @brief  Setup the microcontroller system
192  *         Initialize the FPU setting, vector table location and External memory
193  *         configuration.
194  * @param  None
195  * @retval None
196  */
197void SystemInit (void)
198{   
199  /* FPU settings ------------------------------------------------------------*/
200  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
201    SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2)));  /* set CP10 and CP11 Full Access */
202  #endif
203
204  /*SEVONPEND enabled so that an interrupt coming from the CPU(n) interrupt signal is
205    detectable by the CPU after a WFI/WFE instruction.*/
206 SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
207
208#ifdef CORE_CM7
209  /* Reset the RCC clock configuration to the default reset state ------------*/
210  /* Set HSION bit */
211  RCC->CR |= RCC_CR_HSION;
212 
213  /* Reset CFGR register */
214  RCC->CFGR = 0x00000000;
215
216  /* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */
217  RCC->CR &= 0xEAF6ED7FU;
218
219  /* Reset D1CFGR register */
220  RCC->D1CFGR = 0x00000000;
221
222  /* Reset D2CFGR register */
223  RCC->D2CFGR = 0x00000000;
224 
225  /* Reset D3CFGR register */
226  RCC->D3CFGR = 0x00000000;
227
228  /* Reset PLLCKSELR register */
229  RCC->PLLCKSELR = 0x00000000;
230
231  /* Reset PLLCFGR register */
232  RCC->PLLCFGR = 0x00000000;
233  /* Reset PLL1DIVR register */
234  RCC->PLL1DIVR = 0x00000000;
235  /* Reset PLL1FRACR register */
236  RCC->PLL1FRACR = 0x00000000;
237
238  /* Reset PLL2DIVR register */
239  RCC->PLL2DIVR = 0x00000000;
240
241  /* Reset PLL2FRACR register */
242 
243  RCC->PLL2FRACR = 0x00000000;
244  /* Reset PLL3DIVR register */
245  RCC->PLL3DIVR = 0x00000000;
246
247  /* Reset PLL3FRACR register */
248  RCC->PLL3FRACR = 0x00000000;
249 
250  /* Reset HSEBYP bit */
251  RCC->CR &= 0xFFFBFFFFU;
252
253  /* Disable all interrupts */
254  RCC->CIER = 0x00000000;
255
256  /* Enable CortexM7 HSEM EXTI line (line 78)*/
257  EXTI_D2->EMR3 |= 0x4000UL; 
258
259  /* Change  the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
260  if((DBGMCU->IDCODE & 0xFFFF0000U) < 0x20000000U)
261  {
262    /* if stm32h7 revY*/
263    /* Change  the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
264    *((__IO uint32_t*)0x51008108) = 0x00000001U;
265  }
266 
267
268/*
269   * Disable the FMC bank1 (enabled after reset).
270   * This, prevents CPU speculation access on this bank which blocks the use of FMC during
271   * 24us. During this time the others FMC master (such as LTDC) cannot use it!
272   */
273  FMC_Bank1_R->BTCR[0] = 0x000030D2;
274
275#if defined (DATA_IN_ExtSDRAM)
276  SystemInit_ExtMemCtl();
277#endif /* DATA_IN_ExtSDRAM */
278 
279#endif /* CORE_CM7*/
280
281#ifdef CORE_CM4
282
283  /* Configure the Vector Table location add offset address ------------------*/
284#ifdef VECT_TAB_SRAM
285  SCB->VTOR = D2_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
286#else
287  SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
288#endif 
289
290#else
291#ifdef CORE_CM7
292
293  /* Configure the Vector Table location add offset address ------------------*/
294#ifdef VECT_TAB_SRAM
295  SCB->VTOR = D1_AXISRAM_BASE  | VECT_TAB_OFFSET;       /* Vector Table Relocation in Internal SRAM */
296#else
297  SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET;       /* Vector Table Relocation in Internal FLASH */
298#endif 
299
300#else
301#error Please #define CORE_CM4 or CORE_CM7
302#endif                       
303#endif
304
305}
306
307/**
308   * @brief  Update SystemCoreClock variable according to Clock Register Values.
309  *         The SystemCoreClock variable contains the core clock , it can
310  *         be used by the user application to setup the SysTick timer or configure
311  *         other parameters.
312  *           
313  * @note   Each time the core clock changes, this function must be called
314  *         to update SystemCoreClock variable value. Otherwise, any configuration
315  *         based on this variable will be incorrect.         
316  *     
317  * @note   - The system frequency computed by this function is not the real
318  *           frequency in the chip. It is calculated based on the predefined
319  *           constant and the selected clock source:
320  *             
321  *           - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)                                 
322  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
323  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
324  *           - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*),
325  *             HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
326  *
327  *         (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
328  *             4 MHz) but the real value may vary depending on the variations
329  *             in voltage and temperature.       
330  *         (**) HSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
331  *             64 MHz) but the real value may vary depending on the variations
332  *             in voltage and temperature.   
333  *   
334  *         (***)HSE_VALUE is a constant defined in stm32h7xx_hal.h file (default value
335  *              25 MHz), user has to ensure that HSE_VALUE is same as the real
336  *              frequency of the crystal used. Otherwise, this function may
337  *              have wrong result.
338  *               
339  *         - The result of this function could be not correct when using fractional
340  *           value for HSE crystal.
341  * @param  None
342  * @retval None
343  */
344void SystemCoreClockUpdate (void)
345{
346  uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp;
347  uint32_t common_system_clock;
348  float_t fracn1, pllvco;
349
350  /* Get SYSCLK source -------------------------------------------------------*/
351
352  switch (RCC->CFGR & RCC_CFGR_SWS)
353  {
354  case RCC_CFGR_SWS_HSI:  /* HSI used as system clock source */
355    common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
356    break;
357
358  case RCC_CFGR_SWS_CSI:  /* CSI used as system clock  source */
359    common_system_clock = CSI_VALUE;
360    break;
361
362  case RCC_CFGR_SWS_HSE:  /* HSE used as system clock  source */
363    common_system_clock = HSE_VALUE;
364    break;
365
366  case RCC_CFGR_SWS_PLL1:  /* PLL1 used as system clock  source */
367
368    /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
369    SYSCLK = PLL_VCO / PLLR
370    */
371    pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
372    pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4)  ;
373    pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
374    fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
375
376    if (pllm != 0U)
377    {
378      switch (pllsource)
379      {
380        case RCC_PLLCKSELR_PLLSRC_HSI:  /* HSI used as PLL clock source */
381
382        hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
383        pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
384
385        break;
386
387        case RCC_PLLCKSELR_PLLSRC_CSI:  /* CSI used as PLL clock source */
388          pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
389        break;
390
391        case RCC_PLLCKSELR_PLLSRC_HSE:  /* HSE used as PLL clock source */
392          pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
393        break;
394
395      default:
396          pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
397        break;
398      }
399      pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
400      common_system_clock =  (uint32_t)(float_t)(pllvco/(float_t)pllp);
401    }
402    else
403    {
404      common_system_clock = 0U;
405    }
406    break;
407
408  default:
409    common_system_clock = CSI_VALUE;
410    break;
411  }
412
413  /* Compute SystemClock frequency --------------------------------------------------*/
414  tmp = D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos];
415
416  /* common_system_clock frequency : CM7 CPU frequency  */
417  common_system_clock >>= tmp;
418
419  /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency  */
420  SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
421
422#if defined(DUAL_CORE) && defined(CORE_CM4)
423  SystemCoreClock = SystemD2Clock;
424#else
425  SystemCoreClock = common_system_clock;
426#endif /* DUAL_CORE && CORE_CM4 */
427}
428#if defined (DATA_IN_ExtSDRAM)
429/**
430  * @brief  Setup the external memory controller.
431  *         Called in startup_stm32h7xx.s before jump to main.
432  *         This function configures the external memories SDRAM
433  *         This SDRAM will be used as program data memory (including heap and stack).
434  * @param  None
435  * @retval None
436  */
437void SystemInit_ExtMemCtl(void)
438{
439  __IO uint32_t tmp = 0;
440  register uint32_t tmpreg = 0, timeout = 0xFFFF;
441  register __IO uint32_t index;
442
443  /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
444      clock */
445  RCC->AHB4ENR |= 0x000001F8;
446 
447  /* Delay after an RCC peripheral clock enabling */
448  tmp = READ_BIT(RCC->AHB4ENR, RCC_AHB4ENR_GPIOEEN);
449 
450  /* Connect PDx pins to FMC Alternate function */
451  GPIOD->AFR[0]  = 0x000000CC;
452  GPIOD->AFR[1]  = 0xCC000CCC;
453  /* Configure PDx pins in Alternate function mode */ 
454  GPIOD->MODER   = 0xAFEAFFFA;
455  /* Configure PDx pins speed to 100 MHz */ 
456  GPIOD->OSPEEDR = 0xF03F000F;
457  /* Configure PDx pins Output type to push-pull */ 
458  GPIOD->OTYPER  = 0x00000000;
459  /* Configure PDx pins in Pull-up */
460  GPIOD->PUPDR   = 0x50150005;
461   
462  /* Connect PEx pins to FMC Alternate function */
463  GPIOE->AFR[0]  = 0xC00000CC;
464  GPIOE->AFR[1]  = 0xCCCCCCCC;
465  /* Configure PEx pins in Alternate function mode */
466  GPIOE->MODER   = 0xAAAABFFA;
467  /* Configure PEx pins speed to 100 MHz */
468  GPIOE->OSPEEDR = 0xFFFFC00F;
469  /* Configure PEx pins Output type to push-pull */ 
470  GPIOE->OTYPER  = 0x00000000;
471  /* Configure PEx pins in Pull-up */
472  GPIOE->PUPDR   = 0x55554005;
473 
474  /* Connect PFx pins to FMC Alternate function */
475  GPIOF->AFR[0]  = 0x00CCCCCC;
476  GPIOF->AFR[1]  = 0xCCCCC000;
477  /* Configure PFx pins in Alternate function mode */   
478  GPIOF->MODER   = 0xAABFFAAA;
479  /* Configure PFx pins speed to 100 MHz */
480  GPIOF->OSPEEDR = 0xFFC00FFF;
481  /* Configure PFx pins Output type to push-pull */ 
482  GPIOF->OTYPER  = 0x00000000;
483  /* Configure PFx pins in Pull-up */
484  GPIOF->PUPDR   = 0x55400555;
485 
486  /* Connect PGx pins to FMC Alternate function */
487  GPIOG->AFR[0]  = 0x00CCCCCC;
488  GPIOG->AFR[1]  = 0xC000000C;
489  /* Configure PGx pins in Alternate function mode */
490  GPIOG->MODER   = 0xBFFEFAAA;
491 /* Configure PGx pins speed to 100 MHz */
492  GPIOG->OSPEEDR = 0xC0030FFF;
493  /* Configure PGx pins Output type to push-pull */ 
494  GPIOG->OTYPER  = 0x00000000;
495  /* Configure PGx pins in Pull-up */
496  GPIOG->PUPDR   = 0x40010555;
497 
498  /* Connect PHx pins to FMC Alternate function */
499  GPIOH->AFR[0]  = 0xCCC00000;
500  GPIOH->AFR[1]  = 0xCCCCCCCC;
501  /* Configure PHx pins in Alternate function mode */
502  GPIOH->MODER   = 0xAAAAABFF;
503  /* Configure PHx pins speed to 100 MHz */
504  GPIOH->OSPEEDR = 0xFFFFFC00;
505  /* Configure PHx pins Output type to push-pull */ 
506  GPIOH->OTYPER  = 0x00000000;
507  /* Configure PHx pins in Pull-up */
508  GPIOH->PUPDR   = 0x55555400;
509 
510  /* Connect PIx pins to FMC Alternate function */
511  GPIOI->AFR[0]  = 0xCCCCCCCC;
512  GPIOI->AFR[1]  = 0x00000CC0;
513  /* Configure PIx pins in Alternate function mode */
514  GPIOI->MODER   = 0xFFEBAAAA;
515  /* Configure PIx pins speed to 100 MHz */
516  GPIOI->OSPEEDR = 0x003CFFFF;
517  /* Configure PIx pins Output type to push-pull */ 
518  GPIOI->OTYPER  = 0x00000000;
519  /* Configure PIx pins in Pull-up */
520  GPIOI->PUPDR   = 0x00145555;
521 
522/*-- FMC Configuration ------------------------------------------------------*/
523  /* Enable the FMC interface clock */
524  (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
525  /*SDRAM Timing and access interface configuration*/
526  /*LoadToActiveDelay  = 2
527    ExitSelfRefreshDelay = 6
528    SelfRefreshTime      = 4
529    RowCycleDelay        = 6
530    WriteRecoveryTime    = 2
531    RPDelay              = 2
532    RCDDelay             = 2
533    SDBank             = FMC_SDRAM_BANK2
534    ColumnBitsNumber   = FMC_SDRAM_COLUMN_BITS_NUM_9
535    RowBitsNumber      = FMC_SDRAM_ROW_BITS_NUM_12
536    MemoryDataWidth    = FMC_SDRAM_MEM_BUS_WIDTH_32
537    InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4
538    CASLatency         = FMC_SDRAM_CAS_LATENCY_2
539    WriteProtection    = FMC_SDRAM_WRITE_PROTECTION_DISABLE
540    SDClockPeriod      = FMC_SDRAM_CLOCK_PERIOD_2
541    ReadBurst          = FMC_SDRAM_RBURST_ENABLE
542    ReadPipeDelay      = FMC_SDRAM_RPIPE_DELAY_0*/
543 
544  FMC_Bank5_6_R->SDCR[0] = 0x00001800;
545  FMC_Bank5_6_R->SDCR[1] = 0x00000165;
546  FMC_Bank5_6_R->SDTR[0] = 0x00105000;
547  FMC_Bank5_6_R->SDTR[1] = 0x01010351;
548
549  /* SDRAM initialization sequence */
550  /* Clock enable command */
551  FMC_Bank5_6_R->SDCMR = 0x00000009;
552  tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
553  while((tmpreg != 0) && (timeout-- > 0))
554  {
555    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
556  }
557
558  /* Delay */
559  for (index = 0; index<1000; index++);
560 
561  /* PALL command */
562    FMC_Bank5_6_R->SDCMR = 0x0000000A; 
563  timeout = 0xFFFF;
564  while((tmpreg != 0) && (timeout-- > 0))
565  {
566    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
567  }
568 
569  FMC_Bank5_6_R->SDCMR = 0x000000EB;
570  timeout = 0xFFFF;
571  while((tmpreg != 0) && (timeout-- > 0))
572  {
573    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
574  }
575
576  FMC_Bank5_6_R->SDCMR = 0x0004400C;
577  timeout = 0xFFFF;
578  while((tmpreg != 0) && (timeout-- > 0))
579  {
580    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
581  }
582  /* Set refresh count */
583  tmpreg = FMC_Bank5_6_R->SDRTR;
584  FMC_Bank5_6_R->SDRTR = (tmpreg | (0x00000603<<1));
585
586  /* Disable write protection */
587  tmpreg = FMC_Bank5_6_R->SDCR[1];
588  FMC_Bank5_6_R->SDCR[1] = (tmpreg & 0xFFFFFDFF);
589
590   /*FMC controller Enable*/
591  FMC_Bank1_R->BTCR[0]  |= 0x80000000;
592
593  (void)(tmp);
594}
595#endif /* DATA_IN_ExtSDRAM */
596
597 
598/**
599  * @}
600  */
601
602/**
603  * @}
604  */
605
606/**
607  * @}
608  */
Note: See TracBrowser for help on using the repository browser.