Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2112501
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2012-05-22 21:37:20

TQ2440用的内存是2片MT48LC16M16A2 4Meg x 16 x 4 bank组成32位。
从DataSheet中可以看出:MT48LC16M16A2 的
ReFresh_Count=8K 
Row_Addressing = 8K(A0-A12)
Bank_Addressing = 4(BA0-BA1)
Column_Addressing = 512(A0-A8)
一、代码
1.1 start.S

点击(此处)折叠或打开

  1. .text
  2. .global _start
  3. _start:
  4.     ldr r0, =0x53000000    
  5.     mov r1, #0x0
  6.     str r1, [r0]
  7.     
  8. #define COCKTIME    0x4C000000    
  9. #define MPLLCON        0x4C000004
  10. #define UPLLCON        0x4C000008
  11. #define CLKCON        0x4C00000C
  12. #define CLKSLOW        0x4C000010
  13. #define CLKDIVN     0x4C000014
  14. #define CAMDIVN     0x4C000018
  15.     /*FCLK:HCLK:PCLK=1:4:8*/
  16.     ldr r0, =CLKDIVN
  17.     mov r1, #0x05
  18.     str r1, [r0]

  19.     mrc p15, 0, r0, c1, c0, 0
  20.     orr r0, r0, #0xc0000000
  21.     mcr p15, 0, r0, c1, c0,0

  22.     /*MPLL=(2*m*Fin)/(P*(1<<S)), m=(MDIV+8), p=PDIV+2 s=SDIV*/
  23.     ldr r0, =MPLLCON
  24.     ldr r1, =((0x5C<<12)|(0x01<<4)|(0x01))
  25.     str r1, [r0]
  26.     
  27.     ldr r0, =0x10000
  28. 1:
  29.     sub r0, r0, #1
  30.     bne 1b

  31.     /*UPLL=(m*Fin)/(P*(1<<S)), m=(MDIV+8), p=(PDIV+2), s=SDIV*/
  32.     ldr r0, =UPLLCON
  33.     ldr r1, =((0x10<<12)|(0x01<<4)|(0x01))
  34.     str r1, [r0]

  35.     ldr r0, =0x10000
  36. 1:
  37.     sub r0, r0, #1
  38.     bne 1b

  39.     ldr sp, =1024*4
  40.     bl init_sdram ;增加初始化sdram
  41.     bl main

  42. loop:
  43.     b loop

1.2 sdram.c

点击(此处)折叠或打开

  1. #define BWSCON (*(volatile unsigned int *) 0x48000000)
  2. #define BANKCON0 (*(volatile unsigned int *) 0x48000004)
  3. #define BANKCON1 (*(volatile unsigned int *) 0x48000008)
  4. #define BANKCON2 (*(volatile unsigned int *) 0x4800000C)
  5. #define BANKCON3 (*(volatile unsigned int *) 0x48000010)
  6. #define BANKCON4 (*(volatile unsigned int *) 0x48000014)
  7. #define BANKCON5 (*(volatile unsigned int *) 0x48000018)
  8. #define BANKCON6 (*(volatile unsigned int *) 0x4800001C)
  9. #define BANKCON7 (*(volatile unsigned int *) 0x48000020)
  10. #define REFRESH (*(volatile unsigned int *) 0x48000024)
  11. #define BANKSIZE (*(volatile unsigned int *) 0x48000028)
  12. #define MRSRB6 (*(volatile unsigned int *) 0x4800002C)
  13. #define MRSRB7 (*(volatile unsigned int *) 0x48000030)

  14. void init_sdram(void)
  15. {
  16. /* REFRESH parameter */
  17. #define REFEN 0x1 /* Refresh enable */
  18. #define TREFMD 0x0 /* CBR(CAS before RAS)/Auto refresh */
  19. #define Trp          0x0
  20. #define Trc 0x3
  21. #define Tchr 0x2
  22. #define REFCNT 0x4f4

  23.     /* bank1,2-ide bk3,5,7-null bk4-dm9000 bk6-sdram*/
  24.     BWSCON =(0x02<<24);
  25.     BANKCON0 = 0x00000700;
  26.     BANKCON1 = 0x00000700;
  27.     BANKCON2 = 0x00000700;
  28.     BANKCON3 = 0x00000700;
  29.     BANKCON4 = 0x00000700;
  30.     BANKCON5 = 0x00000700;
  31.     BANKCON6 = (0x3<<15)|(0x01<<2)|0x01;
  32.     BANKCON7 = (0x3<<15)|(0x01<<2)|0x01;
  33.     REFRESH = ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT);
  34.     BANKSIZE = 0x32;
  35.     MRSRB6 = 0x30;
  36.     MRSRB7 = 0x30;
  37. }
 初始化内存就是要配置这十三个寄存器:
 BWSCON:
tq2440的bank用途:其中bank1,2用于ide,bank3没用,bank4 是dm9000, bank5没用, bank6-sdram ,bank7没用。现在要初始化内存所以只设定bank6,其它的bank不管。
DW6=0b10; //bus width for bank 6 is 32bit
WS6=0;    //Disable WAIT,不使用wait信号 (这个东东没有搞明白)
ST6=0;    //Not using UB/LB(Upper Byte/Lower Byte) (这个东东没有搞明白,应该是只有SRAM才有的东东)
BANKCON0-BANKCON5
BANKCON6-BANKCON7:
MT=0b11 ;// Sync. DRAM
Trcd = 0b01;//RAS to CAS delay 3clock (这个东东没有搞明白)
SCAN = 0b01;//Column address numbe ;从A0-A8共9根
2.3 main.c

点击(此处)折叠或打开

  1. #define GPBCON (*(volatile unsigned int *) 0x56000010)
  2. #define GPBDAT (*(volatile unsigned int *) 0x56000014)

  3. static inline void delay (unsigned long loops)
  4. {
  5.     __asm__ volatile ("1:\n"
  6.             "subs %0, %1, #1\n"
  7.             "bne 1b":"=r" (loops):"0" (loops));
  8. }

  9. void main(void)
  10. {
  11.     int i = 1;
  12.     int *p = (int*) 0x30000000;
  13.     GPBCON = 0x15400;
  14.     /*测试sdram,向0x30000000写入一个数,并读取,如果没有改变,则说明sdram初始化成功*/
  15.     *p = 0x12345678;
  16.     if(0x12345678 == *p)
  17.     {
  18. /*如果成功,则灯全亮*/
  19.         GPBDAT = 0;
  20.         delay(400000);
  21.     }
  22.     while(1)
  23.     {
  24.         GPBDAT = 0x7FF&(~i<<5);
  25.         i *= 2;
  26.         if(16==i)
  27.             i = 1;
  28.     }
  29.     return ;
  30. }
注:
内存初始化部分是通过天嵌的u-boot中lowlevel_init.S改过来的,有些东东还不是很清楚,完全自己写还有难度。
阅读(3807) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~