]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D3x_Xplained_IAR/AtmelFiles/libboard_sama5d3x-ek/source/board_memories.c
Start of SAMA5D3 XPlained demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D3x_Xplained_IAR / AtmelFiles / libboard_sama5d3x-ek / source / board_memories.c
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2014, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /** \addtogroup ddrd_module \r
31  *\r
32  * The DDR/SDR SDRAM Controller (DDRSDRC) is a multiport memory controller. It comprises\r
33  * four slave AHB interfaces. All simultaneous accesses (four independent AHB ports) are interleaved\r
34  * to maximize memory bandwidth and minimize transaction latency due to SDRAM protocol.\r
35  * \r
36  * \section ddr2 Configures DDR2\r
37  *\r
38  * The DDR2-SDRAM devices are initialized by the following sequence:\r
39  * <ul>\r
40  * <li> EBI Chip Select 1 is assigned to the DDR2SDR Controller, Enable DDR2 clock x2 in PMC.</li>\r
41  * <li> Step 1: Program the memory device type</li>\r
42  * <li> Step 2:\r
43  *  -# Program the features of DDR2-SDRAM device into the Configuration Register.\r
44  *  -# Program the features of DDR2-SDRAM device into the Timing Register HDDRSDRC2_T0PR.\r
45  *  -# Program the features of DDR2-SDRAM device into the Timing Register HDDRSDRC2_T1PR.\r
46  *  -# Program the features of DDR2-SDRAM device into the Timing Register HDDRSDRC2_T2PR. </li>\r
47  * <li> Step 3: An NOP command is issued to the DDR2-SDRAM to enable clock. </li>\r
48  * <li> Step 4:  An NOP command is issued to the DDR2-SDRAM </li>\r
49  * <li> Step 5: An all banks precharge command is issued to the DDR2-SDRAM. </li>\r
50  * <li> Step 6: An Extended Mode Register set (EMRS2) cycle is  issued to chose between commercialor high  temperature operations.</li>\r
51  * <li> Step 7: An Extended Mode Register set (EMRS3) cycle is issued to set all registers to 0. </li>\r
52  * <li> Step 8:  An Extended Mode Register set (EMRS1) cycle is issued to enable DLL.</li>\r
53  * <li> Step 9:  Program DLL field into the Configuration Register.</li>\r
54  * <li> Step 10: A Mode Register set (MRS) cycle is issued to reset DLL.</li>\r
55  * <li> Step 11: An all banks precharge command is issued to the DDR2-SDRAM.</li>\r
56  * <li> Step 12: Two auto-refresh (CBR) cycles are provided. Program the auto refresh command (CBR) into the Mode Register.</li>\r
57  * <li> Step 13: Program DLL field into the Configuration Register to low(Disable DLL reset).</li>\r
58  * <li> Step 14: A Mode Register set (MRS) cycle is issued to program the parameters of the DDR2-SDRAM devices.</li>\r
59  * <li> Step 15: Program OCD field into the Configuration Register to high (OCD calibration default). </li>\r
60  * <li> Step 16: An Extended Mode Register set (EMRS1) cycle is issued to OCD default value.</li>\r
61  * <li> Step 17: Program OCD field into the Configuration Register to low (OCD calibration mode exit).</li>\r
62  * <li> Step 18: An Extended Mode Register set (EMRS1) cycle is issued to enable OCD exit.</li>\r
63  * <li> Step 19,20: A mode Normal command is provided. Program the Normal mode into Mode Register.</li>\r
64  * <li> Step 21: Write the refresh rate into the count field in the Refresh Timer register. The DDR2-SDRAM device requires a refresh every 15.625 or 7.81. </li>\r
65  * </ul>\r
66 */\r
67 /*@{*/\r
68 /*@}*/\r
69 \r
70 /** \addtogroup sdram_module\r
71  *\r
72  * \section sdram Configures SDRAM\r
73  *\r
74  * The SDR-SDRAM devices are initialized by the following sequence:\r
75  * <ul>\r
76  * <li> EBI Chip Select 1 is assigned to the DDR2SDR Controller, Enable DDR2 clock x2 in PMC.</li>\r
77  * <li> Step 1. Program the memory device type into the Memory Device Register</li>\r
78  * <li> Step 2. Program the features of the SDR-SDRAM device into the Timing Register and into the Configuration Register.</li>\r
79  * <li> Step 3. For low-power SDRAM, temperature-compensated self refresh (TCSR), drive strength (DS) and partial array self refresh (PASR) must be set in the Low-power Register.</li>\r
80  * <li> Step 4. A NOP command is issued to the SDR-SDRAM. Program NOP command into Mode Register, the application must \r
81  * set Mode to 1 in the Mode Register. Perform a write access to any SDR-SDRAM address to acknowledge this command. \r
82  * Now the clock which drives SDR-SDRAM device is enabled.</li>\r
83  * <li> Step 5. An all banks precharge command is issued to the SDR-SDRAM. Program all banks precharge command into Mode Register, the application must set Mode to 2 in the\r
84  * Mode Register . Perform a write access to any SDRSDRAM address to acknowledge this command.</li>\r
85  * <li> Step 6. Eight auto-refresh (CBR) cycles are provided. Program the auto refresh command (CBR) into Mode Register, the application must set Mode to 4 in the Mode Register.\r
86  * Once in the idle state, two AUTO REFRESH cycles must be performed.</li>\r
87  * <li> Step 7. A Mode Register set (MRS) cycle is issued to program the parameters of the SDRSDRAM\r
88  * devices, in particular CAS latency and burst length. </li>\r
89  * <li> Step 8. For low-power SDR-SDRAM initialization, an Extended Mode Register set (EMRS) cycle is issued to program the SDR-SDRAM parameters (TCSR, PASR, DS). The write\r
90  * address must be chosen so that BA[1] is set to 1 and BA[0] is set to 0 </li>\r
91  * <li> Step 9. The application must go into Normal Mode, setting Mode to 0 in the Mode Register and perform a write access at any location in the SDRAM to acknowledge this command.</li>\r
92  * <li> Step 10. Write the refresh rate into the count field in the DDRSDRC Refresh Timer register </li>\r
93 * </ul>\r
94 */\r
95 /*@{*/\r
96 /*@}*/\r
97 \r
98  \r
99  \r
100 /**\r
101  * \file\r
102  *\r
103  * Implementation of memories configuration on board.\r
104  *\r
105  */\r
106 \r
107  \r
108 /*----------------------------------------------------------------------------\r
109  *        Headers\r
110  *----------------------------------------------------------------------------*/\r
111 #include "board.h"\r
112 \r
113 /*----------------------------------------------------------------------------\r
114  *        Definiation\r
115  *----------------------------------------------------------------------------*/\r
116  \r
117 \r
118 #define DDRC2_MODE_NORMAL_CMD       (0x0) // (HDDRSDRC2) Normal Mode\r
119 #define DDRC2_MODE_NOP_CMD          (0x1) // (HDDRSDRC2) Issue a NOP Command at every access\r
120 #define DDRC2_MODE_PRCGALL_CMD      (0x2) // (HDDRSDRC2) Issue a All Banks Precharge Command at every access\r
121 #define DDRC2_MODE_LMR_CMD          (0x3) // (HDDRSDRC2) Issue a Load Mode Register at every access\r
122 #define DDRC2_MODE_RFSH_CMD         (0x4) // (HDDRSDRC2) Issue a Refresh\r
123 #define DDRC2_MODE_EXT_LMR_CMD      (0x5) // (HDDRSDRC2) Issue an Extended Load Mode Register\r
124 #define DDRC2_MODE_DEEP_CMD         (0x6) // (HDDRSDRC2) Enter Deep Power Mode\r
125 #define DDRC2_MODE_Reserved         (0x7) // (HDDRSDRC2) Reserved value\r
126 \r
127 \r
128 /*----------------------------------------------------------------------------\r
129  *        Exported functions\r
130  *----------------------------------------------------------------------------*/\r
131 \r
132 /**\r
133  * \brief Changes the mapping of the chip so that the remap area mirrors the\r
134  * internal ROM or the EBI CS0.\r
135  */\r
136 void BOARD_RemapRom( void )\r
137 {\r
138     MATRIX->MATRIX_MRCR = MATRIX_MRCR_RCB0;\r
139     AXIMX->AXIMX_REMAP = 0;\r
140 }\r
141 \r
142 /**\r
143  * \brief Changes the mapping of the chip so that the remap area mirrors the\r
144  * internal RAM.\r
145  */\r
146 \r
147 void BOARD_RemapRam( void )\r
148 {\r
149     MATRIX->MATRIX_MRCR = MATRIX_MRCR_RCB0;\r
150     AXIMX->AXIMX_REMAP = AXIMX_REMAP_REMAP0;\r
151 }\r
152 \r
153 /**\r
154  * \brief Initialize Vdd EBI drive\r
155  * \param 0: 1.8V 1: 3.3V\r
156  */\r
157 void BOARD_ConfigureVddMemSel( uint8_t VddMemSel )\r
158 {\r
159     ( void ) VddMemSel;\r
160 }\r
161  \r
162 #define DDR2_BA0(r) (1 << (25 + r))\r
163 #define DDR2_BA1(r) (1 << (26 + r))\r
164 \r
165 /* -------- MPDDRC_DLL_SOR : (MPDDRC Offset: 0x74) MPDDRC DLL Slave Offset Register -------- */\r
166 // SxOFF: DLL Slave x Delay Line Offset ([x=0..1][x=0..3])\r
167 #define MPDDRC_DLL_SOR_S0_OFF_Pos 0\r
168 #define MPDDRC_DLL_SOR_S0_OFF_Msk (0x1fu << MPDDRC_DLL_SOR_S0_OFF_Pos) /**< \brief (MPDDRC_DLL_SOR) DLL Slave 0 Delay Line Offset */\r
169 #define MPDDRC_DLL_SOR_S0_OFF(value) ((MPDDRC_DLL_SOR_S0_OFF_Msk & ((value) << MPDDRC_DLL_SOR_S0_OFF_Pos)))\r
170 #define MPDDRC_DLL_SOR_S1_OFF_Pos 8\r
171 #define MPDDRC_DLL_SOR_S1_OFF_Msk (0x1fu << MPDDRC_DLL_SOR_S1_OFF_Pos) /**< \brief (MPDDRC_DLL_SOR) DLL Slave 1 Delay Line Offset */\r
172 #define MPDDRC_DLL_SOR_S1_OFF(value) ((MPDDRC_DLL_SOR_S1_OFF_Msk & ((value) << MPDDRC_DLL_SOR_S1_OFF_Pos)))\r
173 #define MPDDRC_DLL_SOR_S2_OFF_Pos 16\r
174 #define MPDDRC_DLL_SOR_S2_OFF_Msk (0x1fu << MPDDRC_DLL_SOR_S2_OFF_Pos) /**< \brief (MPDDRC_DLL_SOR) DLL Slave 2 Delay Line Offset */\r
175 #define MPDDRC_DLL_SOR_S2_OFF(value) ((MPDDRC_DLL_SOR_S2_OFF_Msk & ((value) << MPDDRC_DLL_SOR_S2_OFF_Pos)))\r
176 #define MPDDRC_DLL_SOR_S3_OFF_Pos 24\r
177 #define MPDDRC_DLL_SOR_S3_OFF_Msk (0x1fu << MPDDRC_DLL_SOR_S3_OFF_Pos) /**< \brief (MPDDRC_DLL_SOR) DLL Slave 3 Delay Line Offset */\r
178 #define MPDDRC_DLL_SOR_S3_OFF(value) ((MPDDRC_DLL_SOR_S3_OFF_Msk & ((value) << MPDDRC_DLL_SOR_S3_OFF_Pos)))\r
179 \r
180 \r
181 /**\r
182  * \brief Configures DDR2 (MT47H128M16RT 128MB/ MT47H64M16HR)\r
183  MT47H64M16HR : 8 Meg x 16 x 8 banks\r
184  Refresh count: 8K\r
185  Row address: A[12:0] (8K)\r
186  Column address A[9:0] (1K)\r
187  Bank address BA[2:0] a(24,25) (8) \r
188  */\r
189 \r
190 void BOARD_ConfigureDdram( uint8_t device )\r
191 {\r
192     volatile uint8_t *pDdr = (uint8_t *) DDR_CS_ADDR;\r
193     volatile uint32_t i;\r
194     volatile uint32_t cr = 0;\r
195     volatile uint32_t dummy_value;\r
196 \r
197     dummy_value = 0x00000000;\r
198    \r
199     /* Enable DDR2 clock x2 in PMC */\r
200     PMC->PMC_PCER1 = (1 << (ID_MPDDRC-32));\r
201     PMC->PMC_SCER  |= PMC_SCER_DDRCK;\r
202     MPDDRC->MPDDRC_LPR = 0;\r
203 \r
204     MPDDRC->MPDDRC_DLL_SOR = 0x101 | MPDDRC_DLL_SOR_S1_OFF(0x0) | MPDDRC_DLL_SOR_S2_OFF(0x1) | MPDDRC_DLL_SOR_S3_OFF(0x1);\r
205     MPDDRC->MPDDRC_DLL_MOR = (0xC5000000) | MPDDRC_DLL_MOR_MOFF(7) | MPDDRC_DLL_MOR_CLK90OFF(0x1F)  | MPDDRC_DLL_MOR_SELOFF;  // Key = 0xc5000000 \r
206     dummy_value  =  MPDDRC->MPDDRC_IO_CALIBR;\r
207     dummy_value &= ~MPDDRC_IO_CALIBR_RDIV_Msk;\r
208     dummy_value &= ~MPDDRC_IO_CALIBR_TZQIO_Msk;\r
209     dummy_value |= MPDDRC_IO_CALIBR_RDIV_RZQ_48;\r
210     dummy_value |= MPDDRC_IO_CALIBR_TZQIO(3);\r
211     MPDDRC->MPDDRC_IO_CALIBR = dummy_value;\r
212     *(uint32_t *)0xFFFFEA80 = 0x1100;\r
213     *(uint32_t *)0xFFFFEA84 = 0x1100;\r
214     *(uint32_t *)0xFFFFEA88 = 0x1100;\r
215     *(uint32_t *)0xFFFFEA8C = 0x1100;\r
216 \r
217 /* Step 1: Program the memory device type */\r
218     /* DBW = 0 (32 bits bus wide); Memory Device = 6 = DDR2-SDRAM = 0x00000006*/\r
219     MPDDRC->MPDDRC_MD = MPDDRC_MD_MD_DDR2_SDRAM;\r
220  \r
221 /* Step 2: Program the features of DDR2-SDRAM device into the Timing Register.*/\r
222     if (device == DDRAM_MT47H128M16RT)\r
223     {\r
224         MPDDRC->MPDDRC_CR = MPDDRC_CR_NR_14  | \r
225                             MPDDRC_CR_NC_10  | \r
226                             MPDDRC_CR_CAS_4_DDR2 | \r
227                             MPDDRC_CR_NB_8 |\r
228                             MPDDRC_CR_DLL_RESET_DISABLED |\r
229                             MPDDRC_CR_DQMS_NOT_SHARED |\r
230                             MPDDRC_CR_ENRDM_OFF |\r
231                             MPDDRC_CR_UNAL_SUPPORTED |\r
232                             MPDDRC_CR_NDQS_DISABLED |\r
233                             MPDDRC_CR_OCD(0x0);\r
234     }\r
235     if (device == DDRAM_MT47H64M16HR)\r
236     {\r
237         MPDDRC->MPDDRC_CR = MPDDRC_CR_NR_13 | \r
238                             MPDDRC_CR_NC_10 | \r
239                             MPDDRC_CR_CAS_3_DDR2| \r
240                             MPDDRC_CR_NB_8 |\r
241                             MPDDRC_CR_DLL_RESET_DISABLED |\r
242                             MPDDRC_CR_DQMS_NOT_SHARED |\r
243                             MPDDRC_CR_ENRDM_OFF |\r
244                             MPDDRC_CR_UNAL_SUPPORTED |\r
245                             MPDDRC_CR_NDQS_DISABLED |\r
246                             MPDDRC_CR_OCD(0x0);\r
247     }\r
248 \r
249     MPDDRC->MPDDRC_TPR0 = MPDDRC_TPR0_TRAS(6)    //  6 * 7.5 = 45 ns\r
250                         | MPDDRC_TPR0_TRCD(2)    //  2 * 7.5 = 15 ns\r
251                         | MPDDRC_TPR0_TWR(3)     //  3 * 7.5 = 22.5 ns\r
252                         | MPDDRC_TPR0_TRC(8)     //  8 * 7.5 = 60 ns\r
253                         | MPDDRC_TPR0_TRP(2)     //  2 * 7.5 = 15 ns\r
254                         | MPDDRC_TPR0_TRRD(2)    //  2 * 7.5 = 15 ns\r
255                         | MPDDRC_TPR0_TWTR(2)    //  2 clock cycle\r
256                         | MPDDRC_TPR0_TMRD(2);   //  2 clock cycles\r
257 \r
258     MPDDRC->MPDDRC_TPR1 = MPDDRC_TPR1_TRFC(0x1A)   // 18 * 7.5 = 135 ns (min 127.5 ns for 1Gb DDR)\r
259                         | MPDDRC_TPR1_TXSNR(0x1C)  // 20 * 7.5 > 142.5ns TXSNR: Exit self refresh delay to non read command\r
260                         | MPDDRC_TPR1_TXSRD(0xC8) // min 200 clock cycles, TXSRD: Exit self refresh delay to Read command\r
261                         | MPDDRC_TPR1_TXP(0x2);    //  2 * 7.5 = 15 ns\r
262 \r
263     MPDDRC->MPDDRC_TPR2 = MPDDRC_TPR2_TXARD(8)   //  min 2 clock cycles\r
264                           | MPDDRC_TPR2_TXARDS(7)//  min 7 clock cycles\r
265                           | MPDDRC_TPR2_TRPA(2)  //  min 18ns\r
266                           | MPDDRC_TPR2_TRTP(2)  //  2 * 7.5 = 15 ns (min 7.5ns)\r
267                           | MPDDRC_TPR2_TFAW(7) ;\r
268 \r
269     /* DDRSDRC Low-power Register */\r
270     for (i = 0; i < 13300; i++) {\r
271         asm("nop");\r
272     } \r
273     MPDDRC->MPDDRC_LPR = MPDDRC_LPR_LPCB_DISABLED | \r
274                          MPDDRC_LPR_CLK_FR_DISABLED | \r
275                          MPDDRC_LPR_TIMEOUT_0 | \r
276                          MPDDRC_LPR_APDE_SLOW ;\r
277 \r
278 /* Step 3: An NOP command is issued to the DDR2-SDRAM. Program the NOP command into\r
279     the Mode Register, the application must set MODE to 1 in the Mode Register. */\r
280     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_NOP_CMD;\r
281     /* Perform a write access to any DDR2-SDRAM address to acknowledge this command */\r
282     *pDdr = 0;  /* Now clocks which drive DDR2-SDRAM device are enabled.*/\r
283    \r
284     /* A minimum pause of 200 ¦Ìs is provided to precede any signal toggle. (6 core cycles per iteration, core is at 396MHz: min 13200 loops) */\r
285     for (i = 0; i < 13300; i++) {\r
286         asm("nop");\r
287     } \r
288  \r
289 /* Step 4:  An NOP command is issued to the DDR2-SDRAM */\r
290     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_NOP_CMD;\r
291     /* Perform a write access to any DDR2-SDRAM address to acknowledge this command.*/\r
292     *pDdr = 0; /* Now CKE is driven high.*/\r
293     /* wait 400 ns min */\r
294     for (i = 0; i < 100; i++) {\r
295         asm("nop");\r
296     }\r
297  \r
298 /* Step 5: An all banks precharge command is issued to the DDR2-SDRAM. */\r
299     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_PRCGALL_CMD;\r
300     /* Perform a write access to any DDR2-SDRAM address to acknowledge this command.*/\r
301     *pDdr = 0;\r
302     /* wait 400 ns min */\r
303     for (i = 0; i < 100; i++) {\r
304         asm("nop");\r
305     }\r
306 \r
307 /* Step 6: An Extended Mode Register set (EMRS2) cycle is  issued to chose between commercialor high  temperature operations. */\r
308     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_EXT_LMR_CMD;\r
309     *((uint8_t *)(pDdr + DDR2_BA1(device))) = 0; /* The write address must be chosen so that BA[1] is set to 1 and BA[0] is set to 0. */\r
310     /* wait 2 cycles min */\r
311     for (i = 0; i < 100; i++) {\r
312         asm("nop");\r
313     }\r
314 \r
315 /* Step 7: An Extended Mode Register set (EMRS3) cycle is issued to set all registers to 0. */\r
316     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_EXT_LMR_CMD;\r
317     *((uint8_t *)(pDdr + DDR2_BA1(device) + DDR2_BA0(device))) = 0;  /* The write address must be chosen so that BA[1] is set to 1 and BA[0] is set to 1.*/\r
318     /* wait 2 cycles min */\r
319     for (i = 0; i < 100; i++) {\r
320         asm("nop");\r
321     }\r
322 \r
323  /* Step 8:  An Extended Mode Register set (EMRS1) cycle is issued to enable DLL. */\r
324     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_EXT_LMR_CMD;\r
325     *((uint8_t *)(pDdr + DDR2_BA0(device))) = 0;  /* The write address must be chosen so that BA[1] is set to 0 and BA[0] is set to 1. */\r
326     /* An additional 200 cycles of clock are required for locking DLL */\r
327     for (i = 0; i < 10000; i++) {\r
328         asm("nop");\r
329     }\r
330 \r
331 /* Step 9:  Program DLL field into the Configuration Register.*/\r
332     cr = MPDDRC->MPDDRC_CR;\r
333     MPDDRC->MPDDRC_CR = cr | MPDDRC_CR_DLL_RESET_ENABLED;\r
334 \r
335 /* Step 10: A Mode Register set (MRS) cycle is issued to reset DLL. */\r
336     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_LMR_CMD;\r
337     *(pDdr) = 0;  /* The write address must be chosen so that BA[1:0] bits are set to 0. */\r
338     /* wait 2 cycles min */\r
339     for (i = 0; i < 100; i++) {\r
340         asm("nop");\r
341     }\r
342  \r
343 /* Step 11: An all banks precharge command is issued to the DDR2-SDRAM. */\r
344     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_PRCGALL_CMD;\r
345     *(pDdr) = 0;  /* Perform a write access to any DDR2-SDRAM address to acknowledge this command */\r
346     /* wait 2 cycles min */\r
347     for (i = 0; i < 100; i++) {\r
348         asm("nop");\r
349     }\r
350 \r
351 /* Step 12: Two auto-refresh (CBR) cycles are provided. Program the auto refresh command (CBR) into the Mode Register. */\r
352     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_RFSH_CMD;\r
353     *(pDdr) = 0;  /* Perform a write access to any DDR2-SDRAM address to acknowledge this command */\r
354     /* wait 2 cycles min */\r
355     for (i = 0; i < 100; i++) {\r
356         asm("nop");\r
357     }\r
358     /* Configure 2nd CBR. */\r
359     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_RFSH_CMD;\r
360     *(pDdr) = 0;  /* Perform a write access to any DDR2-SDRAM address to acknowledge this command */\r
361     /* wait 2 cycles min */\r
362     for (i = 0; i < 100; i++) {\r
363         asm("nop");\r
364     }\r
365 \r
366 /* Step 13: Program DLL field into the Configuration Register to low(Disable DLL reset). */\r
367     cr = MPDDRC->MPDDRC_CR;\r
368     MPDDRC->MPDDRC_CR = cr & (~MPDDRC_CR_DLL_RESET_ENABLED);\r
369 \r
370 /* Step 14: A Mode Register set (MRS) cycle is issued to program the parameters of the DDR2-SDRAM devices. */\r
371     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_LMR_CMD;\r
372     *(pDdr) = 0;  /* The write address must be chosen so that BA[1:0] are set to 0. */\r
373     /* wait 2 cycles min */\r
374     for (i = 0; i < 100; i++) {\r
375         asm("nop");\r
376     }\r
377 \r
378 /* Step 15: Program OCD field into the Configuration Register to high (OCD calibration default). */\r
379     cr = MPDDRC->MPDDRC_CR;\r
380     MPDDRC->MPDDRC_CR = cr | MPDDRC_CR_OCD(0x07);\r
381 \r
382 /* Step 16: An Extended Mode Register set (EMRS1) cycle is issued to OCD default value. */\r
383     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_EXT_LMR_CMD;\r
384     *((uint8_t *)(pDdr + DDR2_BA0(device))) = 0;  /* The write address must be chosen so that BA[1] is set to 0 and BA[0] is set to 1.*/\r
385     /* wait 2 cycles min */\r
386     for (i = 0; i < 100; i++) {\r
387         asm("nop");\r
388     }\r
389 \r
390 /* Step 17: Program OCD field into the Configuration Register to low (OCD calibration mode exit). */\r
391    // cr = MPDDRC->MPDDRC_CR;\r
392    // MPDDRC->MPDDRC_CR = cr  & (~ MPDDRC_CR_OCD(0x07));\r
393 \r
394 /* Step 18: An Extended Mode Register set (EMRS1) cycle is issued to enable OCD exit.*/\r
395     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_EXT_LMR_CMD;\r
396     *((uint8_t *)(pDdr + DDR2_BA0(device))) = 0;  /* The write address must be chosen so that BA[1] is set to 0 and BA[0] is set to 1.*/\r
397     /* wait 2 cycles min */\r
398     for (i = 0; i < 100; i++) {\r
399         asm("nop");\r
400     }\r
401 \r
402 /* Step 19,20: A mode Normal command is provided. Program the Normal mode into Mode Register. */\r
403     MPDDRC->MPDDRC_MR = MPDDRC_MR_MODE_NORMAL_CMD;\r
404     *(pDdr) = 0;\r
405 \r
406 /* Step 21: Write the refresh rate into the count field in the Refresh Timer register. The DDR2-SDRAM device requires a refresh every 15.625 ¦Ìs or 7.81 ¦Ìs. \r
407    With a 100MHz frequency, the refresh timer count register must to be set with (15.625 /100 MHz) = 1562 i.e. 0x061A or (7.81 /100MHz) = 781 i.e. 0x030d. */\r
408     /* For MT47H64M16HR, The refresh period is 64ms (commercial), This equates to an average\r
409        refresh rate of 7.8125¦Ìs (commercial), To ensure all rows of all banks are properly \r
410        refreshed, 8192 REFRESH commands must be issued every 64ms (commercial) */\r
411     /* ((64 x 10(^-3))/8192) x133 x (10^6) */\r
412     //MPDDRC->MPDDRC_RTR = MPDDRC_RTR_COUNT(300); /* Set Refresh timer 7.8125 us*/\r
413     MPDDRC->MPDDRC_RTR = 0x00300408;\r
414     /* OK now we are ready to work on the DDRSDR */\r
415     /* wait for end of calibration */\r
416     for (i = 0; i < 500; i++) {\r
417         asm("    nop");\r
418     }\r
419 }\r
420 \r
421 \r
422 /**\r
423  * \brief Configures the EBI for Sdram (LPSDR Micron MT48H8M16) access.\r
424  */\r
425 void BOARD_ConfigureSdram( void )\r
426 {\r
427 }\r
428 \r
429 /** \brief Configures the EBI for NandFlash access at 133Mhz.\r
430  */\r
431 void BOARD_ConfigureNandFlash( uint8_t busWidth )\r
432 {\r
433     PMC_EnablePeripheral(ID_SMC);\r
434     SMC->SMC_CS_NUMBER[3].SMC_SETUP = 0\r
435                     | SMC_SETUP_NWE_SETUP(1)\r
436                     | SMC_SETUP_NCS_WR_SETUP(1)\r
437                     | SMC_SETUP_NRD_SETUP(2)\r
438                     | SMC_SETUP_NCS_RD_SETUP(1);\r
439 \r
440     SMC->SMC_CS_NUMBER[3].SMC_PULSE = 0\r
441                     | SMC_PULSE_NWE_PULSE(5)\r
442                     | SMC_PULSE_NCS_WR_PULSE(7)\r
443                     | SMC_PULSE_NRD_PULSE(5)\r
444                     | SMC_PULSE_NCS_RD_PULSE(7);\r
445 \r
446     SMC->SMC_CS_NUMBER[3].SMC_CYCLE = 0\r
447                     | SMC_CYCLE_NWE_CYCLE(8)\r
448                     | SMC_CYCLE_NRD_CYCLE(9);\r
449 \r
450     SMC->SMC_CS_NUMBER[3].SMC_TIMINGS = SMC_TIMINGS_TCLR(3)\r
451                                        | SMC_TIMINGS_TADL(10)\r
452                                        | SMC_TIMINGS_TAR(3)\r
453                                        | SMC_TIMINGS_TRR(4)\r
454                                        | SMC_TIMINGS_TWB(5)\r
455                                        | SMC_TIMINGS_RBNSEL(3)\r
456                                        |(SMC_TIMINGS_NFSEL);\r
457     SMC->SMC_CS_NUMBER[3].SMC_MODE = SMC_MODE_READ_MODE | \r
458                                      SMC_MODE_WRITE_MODE | \r
459                                      ((busWidth == 8 )? SMC_MODE_DBW_BIT_8 :SMC_MODE_DBW_BIT_16) | \r
460                                      SMC_MODE_TDF_CYCLES(1);\r
461 }\r
462 \r
463 void BOARD_ConfigureNorFlash( uint8_t busWidth )\r
464 {\r
465     uint32_t dbw;\r
466     PMC_EnablePeripheral(ID_SMC);\r
467     if (busWidth == 8) \r
468     {\r
469         dbw = SMC_MODE_DBW_BIT_8;\r
470     }\r
471     else {\r
472         dbw = SMC_MODE_DBW_BIT_16;\r
473     }\r
474     /* Configure SMC, NCS0 is assigned to a norflash */\r
475     SMC->SMC_CS_NUMBER[0].SMC_SETUP = 0x00020001;\r
476     SMC->SMC_CS_NUMBER[0].SMC_PULSE = 0x0B0B0A0A;\r
477     SMC->SMC_CS_NUMBER[0].SMC_CYCLE = 0x000E000B;\r
478     SMC->SMC_CS_NUMBER[0].SMC_TIMINGS = 0x00000000;\r
479     SMC->SMC_CS_NUMBER[0].SMC_MODE  = SMC_MODE_WRITE_MODE\r
480                                     | SMC_MODE_READ_MODE\r
481                                     | dbw\r
482                                     | SMC_MODE_EXNW_MODE_DISABLED\r
483                                     | SMC_MODE_TDF_CYCLES(1);\r
484 \r
485 }\r
486 \r
487 // -----------------------------------------------------------------------------\r
488 //  Function Name       : LPDDR2_Initialize\r
489 //  Object              : \r
490 // -----------------------------------------------------------------------------\r
491 \r
492 void BOARD_ConfigureLpDdram( void)  \r
493 {\r
494     volatile uint32_t i;\r
495     volatile uint32_t dummy_value;\r
496     PMC->PMC_PCER1 = (1 << (ID_MPDDRC-32));\r
497     PMC->PMC_SCER  |= PMC_SCER_DDRCK;\r
498     /* -------------------- Additional DDR2 setting ------------------------ */\r
499 \r
500     MPDDRC->MPDDRC_DLL_SOR = MPDDRC_DLL_SOR_S0_OFF(0x4) | MPDDRC_DLL_SOR_S1_OFF(0x3) | MPDDRC_DLL_SOR_S2_OFF(0x4) | MPDDRC_DLL_SOR_S3_OFF(0x4);  // design recommendation\r
501     MPDDRC->MPDDRC_DLL_MOR = (0xC5000000) | MPDDRC_DLL_MOR_MOFF(7) | MPDDRC_DLL_MOR_CLK90OFF(0x1F)  | MPDDRC_DLL_MOR_SELOFF;  // Key = 0xc5000000 \r
502 \r
503     dummy_value  =  MPDDRC->MPDDRC_IO_CALIBR;\r
504     dummy_value &= ~MPDDRC_IO_CALIBR_RDIV_Msk;\r
505     dummy_value &= ~MPDDRC_IO_CALIBR_TZQIO_Msk;\r
506     dummy_value |= (0x4 << 0);\r
507     dummy_value |= MPDDRC_IO_CALIBR_TZQIO(3);\r
508 \r
509     MPDDRC->MPDDRC_IO_CALIBR = dummy_value;\r
510     /* DDRSDRC High Speed Register (MPDDRC_HS)  : hidden option -> calibration during autorefresh */\r
511     *(uint32_t *)0xFFFFEA24 |= (1 << 5);\r
512     \r
513     /* SFR_DDRCFG  DDR Configuration  Force DDR_DQ and DDR_DQS input buffer always on */   \r
514     *(uint32_t *)0xF0038004 |= (0x3 << 16);\r
515    \r
516     /*                   Initialization sequence STEP 1\r
517       Program the memory device type into the Memory Device Register */\r
518 \r
519     /*   Memory device = LPDDR2 => MPDDRC_MD_MD_LPDDR2_SDRAM\r
520       Data bus width = 32 bits => 0x0 (The system is in 64 bits, thus memory data bus width should be 32 bits) */\r
521     MPDDRC->MPDDRC_MD = MPDDRC_MD_MD_LPDDR2_SDRAM;\r
522 \r
523 \r
524 /*                   Initialization sequence STEP 2\r
525     Program the features of Low-power DDR2-SDRAM device into the Timing Register \r
526     (asynchronous timing, trc, tras, etc.) and into the Configuration Register (number of\r
527     columns, rows, banks, CAS latency and output drive strength) (see Section 8.3 on\r
528     page 35, Section 8.4 on page 39 and Section 80.5 on page 41). */ \r
529     MPDDRC->MPDDRC_CR =  MPDDRC_CR_NC_10 |\r
530                          MPDDRC_CR_NR_14 |\r
531                          MPDDRC_CR_CAS_5_LPDDR2   |\r
532                          MPDDRC_CR_NB_8           |\r
533                          MPDDRC_CR_UNAL_SUPPORTED |\r
534                          MPDDRC_CR_ENRDM_ON;\r
535     MPDDRC->MPDDRC_LPDDR2_LPR |= MPDDRC_LPDDR2_LPR_DS(0x3);\r
536 \r
537     MPDDRC->MPDDRC_TPR0 = MPDDRC_TPR0_TRAS (6)    | // 03 - TRAS tRAS Row active time\r
538                           MPDDRC_TPR0_TRCD (2)    | // 04 - TRC tRCD RAS-to-CAS delay\r
539                           MPDDRC_TPR0_TWR  (3)    | // 05 - TWR tWR WRITE recovery time\r
540                           MPDDRC_TPR0_TRC  (8)    | // 06 - TRC tRC ACTI-to-ACTIVT command period\r
541                           MPDDRC_TPR0_TRP  (3)    | // 07 - TRP tRPpb  Row precharge time\r
542                           MPDDRC_TPR0_TRRD (2)    | // 08 - TRRD tRRD Active bank a to active bank b\r
543                           MPDDRC_TPR0_TWTR (2)    | // 09 - TWTR-tWTR Internal WRITE-to-READcommand delay\r
544                           MPDDRC_TPR0_TMRD (3);    // 10 - TMRD-tMRD\r
545 \r
546     MPDDRC->MPDDRC_TPR1 = MPDDRC_TPR1_TRFC  (17)  | // 11 - TRFC tRFCab Refresh cycle time\r
547                           MPDDRC_TPR1_TXSNR (18)  | // 12 - TXSNR   SELF REFRESH exit to next valid delay\r
548                           MPDDRC_TPR1_TXSRD (14)  | // 13 - TXSRD Exit Self Refresh\r
549                           MPDDRC_TPR1_TXP   (2);    // 14 - TXP-tXP Exit power-down\r
550 \r
551     MPDDRC->MPDDRC_TPR2 = MPDDRC_TPR2_TXARD  (1)  | // 15 - TXARD-txARD\r
552                           MPDDRC_TPR2_TXARDS (1)  | // 16 - TXARDS-txARDs\r
553                           MPDDRC_TPR2_TRPA   (3)  | // 17 - TRPA-tRPpab Row precharge time (all banks)\r
554                           MPDDRC_TPR2_TRTP   (2)  | // 18 - TRTP-tRTP\r
555                           MPDDRC_TPR2_TFAW   (8);   // 19 - TFAW-tFAW\r
556 \r
557 /*  Initialization sequence STEP 3\r
558     An NOP command is issued to the Low-power DDR2-SDRAM. Program the NOP\r
559     command into the Mode Register, the application must set the MODE (MDDRC Command\r
560     Mode) field to 1 in the Mode Register (see Section 8.1 on page 32). Perform a\r
561     write access to any Low-power DDR2-SDRAM address to acknowledge this command.\r
562     Now, clocks which drive Low-power DDR2-SDRAM devices are enabled.\r
563     A minimum pause of 100 ns must be observed to precede any signal toggle. */\r
564 \r
565     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_NOP_CMD;   // NOP to ENABLE CLOCK output\r
566     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
567     for (i = 0; i < 100; i++) {\r
568         asm("    nop");\r
569     } // Delay loop (at least 100 ns)\r
570 \r
571 /*  Initialization sequence STEP 4\r
572     An NOP command is issued to the Low-power DDR2-SDRAM. Program the NOP\r
573     command into the Mode Register, the application must set MODE to 1 in the Mode\r
574     Register (see Section 8.1 on page 32). Perform a write access to any Low-power\r
575     DDR2-SDRAM address to acknowledge this command. Now, CKE is driven high.\r
576     A minimum pause of 200 us must be satisfied before Reset Command.\r
577 */\r
578 \r
579     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_NOP_CMD;   // NOP to drive CKE high\r
580     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
581     for (i = 0; i < 10000; i++) {\r
582         asm("    nop");\r
583     }                                                        // Delay loop (at least 200 us)\r
584 \r
585 /*  Initialization sequence STEP 5\r
586     A reset command is issued to the Low-power DDR2-SDRAM. Program\r
587     LPDDR2_CMD in the MODE (MDDRC Command Mode) and MRS (Mode Register\r
588     Select LPDDR2) field of the Mode Register, the application must set MODE to 7 and\r
589     MRS to 63. (see Section 8.1 on page 32). Perform a write access to any Low-power\r
590     DDR2-SDRAM address to acknowledge this command. Now, the reset command is issued.\r
591     A minimum pause of 1us must be satisfied before any commands. */\r
592 \r
593     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MRS(0x3F) | MPDDRC_MR_MODE_LPDDR2_CMD;  \r
594     *(unsigned int *)DDR_CS_ADDR  = 0x00000000; \r
595     for (i = 0; i < 500; i++) { asm("    nop"); } \r
596 \r
597 /*  Initialization sequence STEP 6\r
598     A Mode Register Read command is issued to the Low-power DDR2-SDRAM. Program\r
599     LPPDR2_CMD in the MODE and MRS field of the Mode Register, the\r
600     application must set MODE to 7 and must set MRS field to 0. (see Section 8.1 on\r
601     page 32). Perform a write access to any Low-power DDR2-SDRAM address to\r
602     acknowledge this command. Now, the Mode Register Read command is issued.\r
603     A minimum pause of 10 us must be satisfied before any commands. */\r
604 \r
605     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_LPDDR2_CMD | MPDDRC_MR_MRS(0x00);\r
606     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
607     for (i = 0; i < 5000; i++) {asm("    nop"); } \r
608 \r
609 /*  Initialization sequence STEP 7\r
610     A calibration command is issued to the Low-power DDR2-SDRAM. Program the type\r
611     of calibration into the Configuration Register, ZQ field, RESET value (see Section 8.3\r
612     \94MPDDRC Configuration Register?on page 37). In the Mode Register, program the\r
613     MODE field to LPDDR2_CMD value, and the MRS field; the application must set\r
614     MODE to 7 and MRS to 10 (see Section 8.1 LPDDRC Mode Register?on page 34).\r
615     Perform a write access to any Low-power DDR2-SDRAM address to acknowledge\r
616     this command. Now, the ZQ Calibration command is issued. Program the type of calibration\r
617     into the Configuration Register, ZQ field */\r
618 \r
619     MPDDRC->MPDDRC_CR            &= ~MPDDRC_CR_ZQ_Msk;\r
620     MPDDRC->MPDDRC_CR            |=  MPDDRC_CR_ZQ_RESET;\r
621     MPDDRC->MPDDRC_MR             =  MPDDRC_MR_MODE_LPDDR2_CMD | MPDDRC_MR_MRS(0x0A);\r
622                                                              // Mode Register Read  command. MODE = 0x7 and MRS = 0x0A\r
623     *(unsigned int *)DDR_CS_ADDR = 0x00000000;                // Access to memory\r
624     for (i = 0; i < 500; i++) {asm("    nop"); }\r
625     MPDDRC->MPDDRC_CR            &= ~MPDDRC_CR_ZQ_Msk;\r
626     MPDDRC->MPDDRC_CR            |=  MPDDRC_CR_ZQ_SHORT;\r
627 \r
628 /*  Initialization sequence STEP 8\r
629     A Mode Register Write command is issued to the Low-power DDR2-SDRAM. Program\r
630     LPPDR2_CMD in the MODE and MRS field in the Mode Register, the\r
631     application must set MODE to 7 and must set MRS field to 0.5 (see Section 8.1 on\r
632     page 32). The Mode Register Write command cycle is issued to program the parameters\r
633     of the Low-power DDR2-SDRAM devices, in particular burst length. Perform a\r
634     write access to any Low-power DDR2-SDRAM address to acknowledge this command.\r
635     Now, the Mode Register Write command is issued. */\r
636 \r
637     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_LPDDR2_CMD | MPDDRC_MR_MRS(0x01);\r
638     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
639     for (i = 0; i < 500; i++) {\r
640         asm("    nop");\r
641     }\r
642 \r
643 /*  Initialization sequence STEP 9\r
644     Mode Register Write Command is issued to the Low-power DDR2-SDRAM. Program\r
645     LPPDR2_CMD in the MODE and MRS field in the Mode Register, the\r
646     application must set MODE to 7 and must set MRS field to 2. (see Section 8.1 on\r
647     page 32). The Mode Register Write command cycle is issued to program the parameters\r
648     of the Low-power DDR2-SDRAM devices, in particular CAS latency. Perform a\r
649     write access to any Low-power DDR2-SDRAM address to acknowledge this command.\r
650     Now, the Mode Register Write command is issued. */\r
651 \r
652     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_LPDDR2_CMD | MPDDRC_MR_MRS(0x02);\r
653     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
654     for (i = 0; i < 500; i++) {\r
655         asm("    nop");\r
656     }\r
657 \r
658 /*  Initialization sequence STEP 10\r
659     A Mode Register Write Command is issued to the Low-power DDR2-SDRAM. Program\r
660     LPPDR2_CMD in the MODE and MRS field of the Mode Register, the\r
661     application must set MODE to 7 and must set MRS field to 3. (see Section 8.1 on\r
662     page 32). The Mode Register Write command cycle is issued to program the parameters\r
663     of the Low-power DDR2-SDRAM devices, in particular Drive Strength and Slew\r
664     Rate. Perform a write access to any Low-power DDR2-SDRAM address to acknowledge\r
665     this command. Now, the Mode Register Write command is issued. */\r
666 \r
667     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_LPDDR2_CMD | MPDDRC_MR_MRS(0x03); //0x00000307;\r
668     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
669     for (i = 0; i < 500; i++) {\r
670         asm("    nop");\r
671     }\r
672 \r
673 /*                   Initialization sequence STEP 11\r
674     A Mode Register Write Command is issued to the Low-power DDR2-SDRAM. Program\r
675     LPPDR2_CMD in the MODE and MRS field of the Mode Register, the\r
676     application must set MODE to 7 and must set MRS field to 16. (see Section 8.1 on\r
677     page 32). Mode Register Write command cycle is issued to program the parameters\r
678     of the Low-power DDR2-SDRAM devices, in particular Partial Array Self Refresh\r
679    (PASR). Perform a write access to any Low-power DDR2-SDRAM address to\r
680     acknowledge this command. Now, the Mode Register Write command is issued.*/\r
681 \r
682     MPDDRC->MPDDRC_MR             = MPDDRC_MR_MODE_LPDDR2_CMD | MPDDRC_MR_MRS(0x10);// 0x00001007;\r
683     *(unsigned int *)DDR_CS_ADDR  = 0x00000000;               // Access to memory\r
684     for (i = 0; i < 500; i++) {\r
685         asm("    nop");\r
686     }\r
687 \r
688 /*  Initialization sequence STEP 12\r
689     Write the refresh rate into the COUNT field in the Refresh Timer register (see page\r
690     33). (Refresh rate = delay between refresh cycles). The Low-power DDR2-SDRAM\r
691     device requires a refresh every 7.81 ìs. With a 100 MHz frequency, the refresh timer\r
692     count register must to be set with (7.81/100 MHz) = 781 i.e. 0x030d. */\r
693     MPDDRC->MPDDRC_RTR           &= ~MPDDRC_RTR_COUNT_Msk;\r
694     MPDDRC->MPDDRC_RTR           |=  MPDDRC_RTR_COUNT(1030);\r
695     MPDDRC->MPDDRC_MR             =  0x00000000;              // Set Normal mode\r
696     *(unsigned int *)DDR_CS_ADDR  =  0x00000000;              // Perform \r
697       for (i = 0; i < 500; i++) {\r
698         asm("    nop");\r
699     }\r
700     /* Launch short ZQ calibration */\r
701     MPDDRC->MPDDRC_CR            &= ~MPDDRC_CR_ZQ_Msk;                   // Enable short calibration in the CR\r
702     MPDDRC->MPDDRC_CR            |=  MPDDRC_CR_ZQ_SHORT;\r
703     MPDDRC->MPDDRC_CR            |=  MPDDRC_CR_DLL_RESET_ENABLED;\r
704     *(unsigned int *)DDR_CS_ADDR  =  0x00000000;              // Perform\r
705 \r
706     /* Calculate ZQS: search for tZQCS in the memory datasheet => tZQCS = 180 ns*/\r
707    MPDDRC->MPDDRC_LPDDR2_TIM_CAL =  MPDDRC_LPDDR2_TIM_CAL_ZQCS(12);\r
708 }\r