DDR 初始化的一些代码

来源:互联网 发布:日本类似淘宝的网站 编辑:程序博客网 时间:2024/06/16 09:39

这是sta2065芯片的 DDR 初始化时候的一段代码,在bootloader中使用:

[cpp] view plaincopy
  1. int BL_InitDDRMemory(void)  
  2. {  
  3.         uint32_t *i;  
  4.         int k;  
  5.   
  6.         *((uint32_t *)0x101E0000) = 0x00021003;  
  7.   
  8.         // ---------------------  
  9.         // Waiting for slow mode  
  10.         // ---------------------  
  11.         while ((*((volatile uint32_t *)0x101E0000) & 0x78) != 0x10);  
  12.   
  13.         *((uint32_t *)0x101E0014) = PLLFR;  
  14.         *((uint32_t *)0x101E0058) = SCCLKDIVCR;  
  15.         *((uint32_t *)0x101E0010) = 0x10000000; // enable PLL2  
  16.         *((uint32_t *)0x101E0000) = SRCCR;  
  17.   
  18.         // ---------------------------  
  19.         // Waiting for PLL2 stabilized  
  20.         // ---------------------------  
  21.         while (!(*((volatile uint32_t *)0x101E0010) & 0x20000000));  
  22.   
  23.         // --------------------  
  24.         // Wait for normal mode  
  25.         // --------------------  
  26.         while ((*((volatile uint32_t *)0x101E0000) & 0x78) != 0x20);  
  27.   
  28.         k = 0;  
  29.         for (i = (uint32_t *)0x10110000; i < (uint32_t *)0x10110180; i++)        //主要就是这个DDRConfig表,一共180个寄存器。  
  30.                 *i = DDRConfig[k++]; // Load DDR configuration data  
  31.   
  32.         *((uint32_t *)0x10110020) = ENABLE_DDR_CMD; // Used on C+  
  33.   
  34.         // ------------  
  35.         // Remap memory  
  36.         // ------------  
  37.         *((uint32_t *)0x101E0000) = SRCCR | 0x00000100;  
  38.   
  39.         // ------------------------------  
  40.         // Waiting for DRAM init complete  
  41.         // ------------------------------  
  42.         while ((*((volatile uint32_t *)0x101100C0) & 0x04) != 0x04);  
  43.   
  44.         // ---------------------  
  45.         // Waiting for DDLs lock  
  46.         // ---------------------  
  47.         while (!(*((volatile uint32_t *)0x10110144) & 1));  
  48.         while (!(*((volatile uint32_t *)0x10110148) & 1));  
  49.         while (!(*((volatile uint32_t *)0x1011014C) & 1));  
  50.         while (!(*((volatile uint32_t *)0x10110150) & 1));  
  51.   
  52.         // ------------------------------------------------------  
  53.         // Remove remap to ensure a correct wakeup from deepsleep  
  54.         // ------------------------------------------------------  
  55.         *((uint32_t *)0x101E0000) = SRCCR & ~0x00000100;  
  56.   
  57.         return 0;  
  58. }  
DDRConfig表,有DDR controller 模块的寄存器,每个寄存器对应一个值,这样赋值进去:
[cpp] view plaincopy
  1. static const uint32_t DDRConfig[] = {  
  2.                 0x00000101, 0x01000100, 0x00010001, 0x01010100, //  0- 3  
  3.                 0x00000001, 0x01010000, 0x00010001, 0x01000100, //  4- 7  
  4.                 0x01010000, 0x00010001, 0x03030303, 0x01000303, //  8-11  
  5.                 0x02000000, 0x00010201, 0x03000301, 0x03030103, // 12-15  
  6.                 0x03010102, 0x03040300, 0x03030503, 0x00000005, // 16-19  
  7.                 0x04000300, 0x00000003, 0x06060606, 0x06060606, // 20-23  
  8.                 0x05050505, 0x05050505, 0x04040404,     0x04040404, // 24-27  
  9.                 0x03030303,     0x03030303,     0x02020202,     0x02020202, // 28-31  
  10.                 0x01010101,     0x01010101,     0x040a0a0a,     0x00050002, // 32-35  
  11.                 0x00070102,     0x05020002,     0x00040403,     0x00000000, // 36-39  
  12.                 0x100a0000,     0x3f051202,     0x0d04003f,     0x00002805, // 40-43  
  13.                 0x00640064,     0x00640064,     0x00640064,     0x00000000, // 44-47  
  14.                 0x00000000,     0x00200020,     0x00200020,     0x00200020, // 48-51  
  15.                 0x00200020,     0x00200020,     0x00200020,     0x00000000, // 52-55  
  16.                 0x06590000,     0x00040000,     0x00000004,     0x00000000, // 56-59  
  17.                 0x00000000,     0x00000000,     0x00000000,     0x08520852, // 60-63  
  18.                 0x00c8007d,     0x55250002,     0x00c8002b,     0x00000000, // 64-67  
  19.                 0x0000f362,     0x00000000,     0x00000000,     0x00000000, // 68-71  
  20.                 0x00000000,     0x00407803,     0x00407803,     0x00407803, // 72-75  
  21.                 0x00407803,     0x00111e01,     0x00111e01,     0x00111e01, // 76-79  
  22.                 0x00111e01,     0x00000000,     0x00000000,     0x00000000, // 80-83  
  23.                 0x00000000,     0x00000000,     0x0E148401,     0xf4013b27, // 84-87  
  24.                 0xf4013b27,     0xf4013b27,     0xf4013b27,     0x07800301, // 88-91  
  25.                 0x07800301,     0x07800301,     0x07800301,     0x00000005  // 92-95  
  26. };  

这些寄存器的值一定要配置正确,要不然会出问题,内存空间映射会出各种各样的问题。
0 0
原创粉丝点击