SDRAM & mode register

Category: SDRAM
------------------------------------------------------------

Mode register programming is a vital and confusing step in SDRAM initialization.
Vital as mode register is used to define the specific mode of operation. Burst Length, Burst Type, CAS Latency, Operating Mode and Write Burst Mode are programmed through it.
Confusing as a read transaction from the SDRAM programs the mode register! Yes a read transaction.
The address to be issued contains the value to be programmed into mode register...

What we need for this special read operation is the address mapping of SDRAM. Apart from that SDRAM controller issues Row Address first and then Column Address so, the value to programmed into mode register should be decoded into Row Address...enough confusing....let's take a example...

Generally address mapping is as follows:
(Following information is just an example and will vary depending on processor and memory!)
SDRAM configuration with 32-bit data bus, 8-columns and 11-Rows.
64MB, 4M x 16 two chips connected to form a 32-bit data bus.
MT48LC4M16A2 – 1 Meg x 16 x 4 banks
As per datasheet the address table appears as follows:
-----------------------------------
|Row addressing    | 4096(A0-A11) |
-----------------------------------
|Bank addressing   | 4   (BA0-BA1)|
-----------------------------------
|Column addressing | 256 (A0-A7)  |
-----------------------------------

This information is then interpreted from controller point as follows:
-------------------------------------------------------------
| Flat Address |  A23 | A22 | A21 - A10 | A9 - A2 | A1 - A0 |
-------------------------------------------------------------
| Multiplexed  |  BA1 | BA0 | A11 - A0  | A7 - A0 |    -    |
-------------------------------------------------------------
|              | Depends on |    Row    | Column  |    -    |
|              | Controller |  Address  | Address |         |
-------------------------------------------------------------


Note1: BA0 and BA1 should be set to 0 while programming mode register
Note2: A0 and A1 are not used in Flat addressing as we are considering 32-bit data bus

Code snippet: 
Suppose we need to write 0x22 into mode register, then from above table, we can write as:

dummy = *((volatile unsigned int*)(SDRAM_BASE_ADDR | (0x22 << 10)));

Remember a read operation writes to mode register, so the addresses generated by above instruction will actually write into the mode register. In above example, we are left shifting the value by magic number 10! The value 10 is calculated as in Flat addressing table Row address starts from A10.
------------------------------------------------------------

Comments