4412学习日记 - DDR3初始化

4412的动态存储控制器有80多个寄存器,挨个看寄存器说明设置伤不起啊,最后决定参考u-boot中的代码,搞明白它设置了哪些东西。

先来看看时序图


DQ:

为数据信号

DQS:

是内存和内存控制器之间信号同步用的。
由DQ信号发出端发出DQS,信号接收端根据DQS的上、下沿来触发数据的接收。
简单点说,如果是从内存中读取信号,那么内存控制器根据内存发出的DQS来判断在什么时候接收读出来的数据。如果是写的话,就正好相反,内存根据
内存控制器发出的DQS来触发数据的接收。
DDR3是有读和写两个DQS(2个DQS的好处是,不必等待DQS反向)。


再看看4412手册动态存储管理器那章关于DDR3初始化的说明

18.3 Initialization
You must power up and initialize SDRAM devices in a predefined manner. Other non-specific operational procedures may result in undefined operation. An initialization procedure consists of three procedures:
1. PHY DLL initialization
2. Setting controller register
3. Memory initialization
For initializing memory, refer to JEDEC specifications and datasheets of memory devices for more details. According to the memory types, initialization sequences are as follows.
18.3.1 DDR3
Use the sequence given here to initialize DDR3 devices. Unless specified otherwise, these steps are mandatory.
1. Apply power. RESET# needs to be maintained for minimum 200us with stable power. CKE is pulled “Low” anytime before RESET# being de-asserted (min. time 10ns)
2. If on die termination is required, enable PhyControl1.term_write_en, PhyControl1.term_read_en.
3. If ZQ calibration is required, disable PhyZQControl.ctrl_zq_mode_noterm and enable PhyZQCon-trol.ctrl_zq_start so that the PHY automatically calibrates the I/Os to match the driving and termination impedance by referencing resistor value of an external resistor and updates the matched value during auto re-fresh cycles.
4. Set the PhyControl0.ctrl_start_point and PhyControl0.ctrl_inc bit-fields to correct value according to clock frequency. Set the PhyControl0.ctrl_dll_on bit-field to „1‟ to activate the PHY DLL.
5. DQS Cleaning: set the PhyControl1.ctrl_shiftc and PhyControl1.ctrl_offsetc bit-fields to the proper value according to clock frequency, board delay and memory tDQSCK parameter.
6. Set the PhyControl0.ctrl_start bit-field to "1".
7. Set the ConControl. At this moment, an auto refresh counter should be off.
8. Set the MemControl. At this moment, all power down modes and periodic ZQ(pzq_en) should be off.
9. Set the MemConfig0 register. If there are two external memory chips, also set the MemConfig1 register.
10. Set the PrechConfig and PwrdnConfig registers.
11. Set the TimingAref, TimingRow, TimingData and TimingPower registers according to memory AC parame-ters.
12. If QoS scheme is required, set the QosControl0~15 and QosConfig0~15 registers.
13. Wait for the PhyStatus0.ctrl_clock and PhyStatus0.ctrl_flock bit-fields to change to „1‟. Check whether PHY DLL is locked.
14. PHY DLL compensates the changes of delay amount caused by PVT variation during memory operation. Therefore, it should not be off for reliable operation. It can be off except runs at low frequency. If off mode is used, set the PhyControl0.ctrl_force bit-field to the correct value according to the PhySta-tus0.ctrl_lock_value[9:2] bit-field for fix delay amount. Clear the PhyControl0.ctrl_dll_on bit-field to turn off PHY DLL.
15. Set the PhyControl1.fp_resync bit-field to „1‟ to update DLL information.
16. Set the PhyControl1.fp_resync bit-field to „0‟.
17. Confirm that after RESET# is de-asserted, 500 us have passed before CKE becomes active.
18. Confirm that clocks(CK, CK#) need to be started and stabilized for at least 10 ns or 5 tCK (which is larger) before CKE goes active.
19. Issue a NOP command using the DirectCmd register to assert and to hold CKE to a logic high level.
20. Wait for tXPR(max(5nCK,tRFC(min)+10ns)) or set tXP to tXPR value before step 17. If the system set tXP to tXPR, then the system must set tXP to proper value before normal memory operation.
21. Issue an EMRS2 command using the DirectCmd register to program the operating parameters. Dynamic ODT should be disabled. A10 and A9 should be low.
22. Issue an EMRS3 command using the DirectCmd register to program the operating parameters.
23. Issue an EMRS command using the DirectCmd register to enable the memory DLL.
24. Issue a MRS command using the DirectCmd register to reset the memory DLL.
25. Issues a MRS command using the DirectCmd register to program the operating parameters without resetting the memory DLL.
26. Issues a ZQINIT commands using the DirectCmd register.
27. If there are two external memory chips, perform steps 19 ~ 26 procedures for chip1 memory device.
28. Set the ConControl to turn on an auto refresh counter.
29. If power down modes or periodic ZQ(pzq_en) are required, set the MemControl register.


将u-boot中的代码对照操作规程,弄明白每一句代表哪一步

/*
 * (C) Copyright 2011 Samsung Electronics Co. Ltd
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

#include <config.h>
#include <asm/arch/cpu.h>

#define MCLK_400


	.globl mem_ctrl_asm_init
mem_ctrl_asm_init:

	/* Async bridge configuration at CPU_core:
	 * 1: half_sync
	 * 0: full_sync */
	ldr	r0, =0x10010350
	mov	r1, #1
	str	r1, [r0]
	/*实验了下这段省略了也可以运行*/



/*****************************************************************/
/*DREX0***********************************************************/
/*****************************************************************/

	ldr	r0, =APB_DMC_0_BASE

	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]
	/*2. If on die termination is required, enable PhyControl1.term_write_en, 
	PhyControl1.term_read_en.*/

	ldr	r1, =0xE3854C03
	str	r1, [r0, #DMC_PHYZQCONTROL]
	/*3. If ZQ calibration is required, disable PhyZQControl.
	ctrl_zq_mode_noterm and enable PhyZQCon-trol.
	ctrl_zq_start so that the PHY automatically calibrates 
	the I/Os to match the driving and termination impedance 
	by referencing resistor value of an external resistor 
	and updates the matched value during auto re-fresh cycles.*/

	mov	r2, #0x100000
1:	subs	r2, r2, #1
	bne	1b


	ldr	r1, =0x7110100A
	str	r1, [r0, #DMC_PHYCONTROL0]	
	/*4. Set the PhyControl0.ctrl_start_point and PhyControl0.
	ctrl_inc bit-fields to correct value according to clock frequency. 
	Set the PhyControl0.ctrl_dll_on bit-field to "1" to activate the PHY DLL.*/

	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]
	/*5. DQS Cleaning: set the PhyControl1.ctrl_shiftc and PhyControl1.
	ctrl_offsetc bit-fields to the proper value according to clock frequency, 
	board delay and memory tDQSCK parameter.*/
	
	ldr	r1, =0x7110100B
	str	r1, [r0, #DMC_PHYCONTROL0]
	/*6. Set the PhyControl0.ctrl_start bit-field to "1".*/

	ldr	r1, =0x00000000
	str	r1, [r0, #DMC_PHYCONTROL2]
	/*DQS offset*/
	/*实验了一下可以省略,默认值就是全零*/
	
	ldr	r1, =0x0FFF301A
	str	r1, [r0, #DMC_CONCONTROL]
	/*7. Set the ConControl. At this moment, 
	an auto refresh counter should be off.*/
	
	ldr	r1, =0x00312640
	str	r1, [r0, #DMC_MEMCONTROL]
	/*8. Set the MemControl. At this moment,
	all power down modes and periodic ZQ(pzq_en) should be off.*/

	ldr	r1, =0x40e01323
	str	r1, [r0, #DMC_MEMCONFIG0]
	ldr	r1, =0x60e01323
	str	r1, [r0, #DMC_MEMCONFIG1]
	/*9. Set the MemConfig0 register. If there are two external memory chips, 
	also set the MemConfig1 register.*/

	ldr	r1, =(0x80000000 | CONFIG_IV_SIZE)
	str	r1, [r0, #DMC_IVCONTROL]
	/*Memory Channel Interleaving*/
	/*实验了一下可以省略,用默认值就可以*/

	ldr	r1, =0xff000000
	str	r1, [r0, #DMC_PRECHCONFIG]
	/*10. Set the PrechConfig and PwrdnConfig registers.*/

	ldr	r1, =0x000000BB
	str	r1, [r0, #DMC_TIMINGAREF] @TimingAref
	ldr	r1, =0x4046654f
	str	r1, [r0, #DMC_TIMINGROW] @TimingRow
	ldr	r1, =0x46400506
	str	r1, [r0, #DMC_TIMINGDATA] @TimingData
	ldr	r1, =0x52000a3c
	str	r1, [r0, #DMC_TIMINGPOWER] @TimingPower
	/*11. Set the TimingAref, TimingRow, TimingData and 
	TimingPower registers according to memory AC parame-ters.*/



	/* chip 0 */
	ldr	r1, =0x07000000
	str	r1, [r0, #DMC_DIRECTCMD]
	/*19. Issue a NOP command using the DirectCmd register to assert and to hold CKE to a logic high level.*/

	mov	r2, #0x100000
2:	subs	r2, r2, #1
	bne	2b
	/*20. Wait for tXPR(max(5nCK,tRFC(min)+10ns)) or set tXP to tXPR value before step 17. If the system set tXP to tXPR, then the system must set tXP to proper value before normal memory operation.*/

	ldr	r1, =0x00020000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00030000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00010002
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00000328
	str	r1, [r0, #DMC_DIRECTCMD]
	/*没搞明白这里发的什么指令*/
	
	mov	r2, #0x100000
3:	subs	r2, r2, #1
	bne	3b

	ldr	r1, =0x0a000000
	str	r1, [r0, #DMC_DIRECTCMD]
	/*26. Issues a ZQINIT commands using the DirectCmd register.*/

	mov	r2, #0x100000
4:	subs	r2, r2, #1
	bne	4b




/*27. If there are two external memory chips, perform steps 19 ~ 26 procedures for chip1 memory device.*/
#if 1
	/* chip 1 */
	ldr	r1, =0x07100000
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
5:	subs	r2, r2, #1
	bne	5b

	ldr	r1, =0x00120000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00130000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00110002
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00100328
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
6:	subs	r2, r2, #1
	bne	6b

	ldr	r1, =0x0a100000
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
7:	subs	r2, r2, #1
	bne	7b
#endif

	ldr	r1, =0xe000008e
	str	r1, [r0, #DMC_PHYCONTROL1]
	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]

	mov	r2, #0x100000
8:	subs	r2, r2, #1
	bne	8b


/*****************************************************************/
/*DREX1***********************************************************/
/*****************************************************************/

	ldr	r0, =APB_DMC_1_BASE

	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]

	ldr	r1, =0xE3854C03
	str	r1, [r0, #DMC_PHYZQCONTROL]

	mov	r2, #0x100000
1:	subs	r2, r2, #1
	bne	1b

	ldr	r1, =0xe000008e
	str	r1, [r0, #DMC_PHYCONTROL1]
	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]

	ldr	r1, =0x71101008
	str	r1, [r0, #DMC_PHYCONTROL0]
	ldr	r1, =0x7110100A
	str	r1, [r0, #DMC_PHYCONTROL0]

	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]
	ldr	r1, =0x7110100B
	str	r1, [r0, #DMC_PHYCONTROL0]

	ldr	r1, =0x00000000
	str	r1, [r0, #DMC_PHYCONTROL2]

	ldr	r1, =0x0FFF301A
	str	r1, [r0, #DMC_CONCONTROL]
	ldr	r1, =0x00312640
	str	r1, [r0, #DMC_MEMCONTROL]

	ldr	r1, =0x40e01323			@Interleaved?
	str	r1, [r0, #DMC_MEMCONFIG0]
	ldr	r1, =0x60e01323
	str	r1, [r0, #DMC_MEMCONFIG1]

	ldr	r1, =(0x80000000 | CONFIG_IV_SIZE)
	
	str	r1, [r0, #DMC_IVCONTROL]

	ldr	r1, =0xff000000
	str	r1, [r0, #DMC_PRECHCONFIG]

	ldr	r1, =0x000000BB
	str	r1, [r0, #DMC_TIMINGAREF] @TimingAref

	ldr	r1, =0x4046654f
	str	r1, [r0, #DMC_TIMINGROW] @TimingRow
	ldr	r1, =0x46400506
	str	r1, [r0, #DMC_TIMINGDATA] @TimingData
	ldr	r1, =0x52000a3c
	str	r1, [r0, #DMC_TIMINGPOWER] @TimingPower

	/* chip 0 */
	ldr	r1, =0x07000000
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
2:	subs	r2, r2, #1
	bne	2b

	ldr	r1, =0x00020000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00030000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00010002
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00000328
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
3:	subs	r2, r2, #1
	bne	3b

	ldr	r1, =0x0a000000
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
4:	subs	r2, r2, #1
	bne	4b

#if 1
	/* chip 1 */
	ldr	r1, =0x07100000
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
5:	subs	r2, r2, #1
	bne	5b

	ldr	r1, =0x00120000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00130000
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00110002
	str	r1, [r0, #DMC_DIRECTCMD]
	ldr	r1, =0x00100328
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
6:	subs	r2, r2, #1
	bne	6b

	ldr	r1, =0x0a100000
	str	r1, [r0, #DMC_DIRECTCMD]

	mov	r2, #0x100000
7:	subs	r2, r2, #1
	bne	7b
#endif

	ldr	r1, =0xe000008e
	str	r1, [r0, #DMC_PHYCONTROL1]
	ldr	r1, =0xe0000086
	str	r1, [r0, #DMC_PHYCONTROL1]

	mov	r2, #0x100000
8:	subs	r2, r2, #1
	bne	8b


/*****************************************************************/
/*Finalize********************************************************/
/*****************************************************************/

	ldr	r0, =APB_DMC_0_BASE
	ldr	r1, =0x0FFF303A
	str	r1, [r0, #DMC_CONCONTROL]
	/*28. Set the ConControl to turn on an auto refresh counter.*/

	ldr	r0, =APB_DMC_1_BASE
	ldr	r1, =0x0FFF303A
	str	r1, [r0, #DMC_CONCONTROL]
	/*28. Set the ConControl to turn on an auto refresh counter.*/

	mov	pc, lr

整个过程迷迷糊糊的到最后也没弄明白怎么回事,网上也没这方面的资料,唉,留着以后求甚解吧











  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值