aboutsummaryrefslogtreecommitdiff
path: root/tcl/board/icnova_sam9g45_sodimm.cfg
blob: bf70cca9ae7ec55b1e79f254453ee6dc2933ad09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#################################################################################################
#												                                                #
# Author: Lars Poeschel (larsi@wh2.tu-dresden.de)												#
# Generated for In-Circuit ICnova SAM9G45 SODIMM												#
# http://www.ic-board.de/product_info.php?info=p214_ICnova-SAM9G45-SODIMM.html|ICnova			#
#																								#
#################################################################################################

# FIXME use some standard target config, maybe create one from this
#
#	source [find target/...cfg]

source [find target/at91sam9g45.cfg]

# Set reset type.
# reset_config trst_and_srst

# adapter srst delay 200
# jtag_ntrst_delay 200


# If you don't want to execute built-in boot rom code (and there are good reasons at times not to do that) in the
# AT91SAM9 family, the microcontroller is a lump on a log without initialization.  Because this family has
# some powerful features, we want to have a special function that handles "reset init".  To do this we declare
# an event handler where these special activities can take place.

scan_chain
$_TARGETNAME configure -event reset-init {at91sam9g45_init}

# Set fallback clock to 1/6 of worst-case clock speed (which would be the 32.768 kHz slow clock).
# Slow-speed oscillator enabled at reset, so run jtag speed slow.
$_TARGETNAME configure -event reset-start {at91sam9g45_start}


# NandFlash configuration and definition
# Future TBD
# Flash configuration
# flash bank cfi <base> <size> <chip width> <bus width> <target#>
set _FLASHNAME $_CHIPNAME.flash
# set _NANDNAME $_CHIPNAME.nand
flash bank $_FLASHNAME cfi 0x10000000 0x00800000 2 2 $_TARGETNAME
# nand device $_NANDNAME at91sam9 $_TARGETNAME 0x40000000 0xFFFFE800


proc read_register {register} {
        set result ""
        mem2array result 32 $register 1
        return $result(0)
}

proc at91sam9g45_start { } {

	# Make sure that the the jtag is running slow, since there are a number of different ways the board
	# can be configured coming into this state that can cause communication problems with the jtag
	# adapter.  Also since this call can be made following a "reset init" where fast memory accesses
	# are enabled, need to temporarily shut this down so that the RSTC_MR register can be written at slower
	# jtag speed without causing GDB keep alive problem.

	arm7_9 fast_memory_access disable
    # Slow-speed oscillator enabled at reset, so run jtag speed slow.
	adapter speed 4
    # Make sure processor is halted, or error will result in following steps.
	halt
	wait_halt 10000
    # RSTC_MR : enable user reset.
	mww 0xfffffd08 0xa5000501
}


proc at91sam9g45_init { } {

	# At reset AT91SAM9G45 chip runs on slow clock (32.768 kHz).  To shift over to a normal clock requires
	# a number of steps that must be carefully performed.  The process outline below follows the
	# recommended procedure outlined in the AT91SAM9G45 technical manual.
	#
	# Several key and very important things to keep in mind:
	# The SDRAM parts used currently on the board are -75 grade parts.  This
	# means the master clock (MCLK) must be at or below 133 MHz or timing errors will occur.  The processor
	# core can operate up to 400 MHz and therefore PCLK must be at or below this to function properly.

	# Make sure processor is halted, or error will result in following steps.
	halt
	# RSTC_MR : enable user reset.
	mww 0xfffffd08 0xa5000501
	# WDT_MR : disable watchdog.
	mww 0xfffffd44 0x00008000

	# Enable the main 15.000 MHz oscillator in CKGR_MOR register.
	# Wait for MOSCS in PMC_SR to assert indicating oscillator is again stable after change to CKGR_MOR.

	mww 0xfffffc20 0x00004001
	while { [expr [read_register 0xfffffc68] & 0x01] != 1 } { sleep 1 }

	# Set PLLA Register for 792.576 MHz (divider: bypass, multiplier: 43).
	# Wait for LOCKA signal in PMC_SR to assert indicating PLLA is stable.

	#mww 0xfffffc28 0x202a3f01
	mww 0xfffffc28 0x20c73f03
	while { [expr [read_register 0xfffffc68] & 0x02] != 2 } { sleep 1 }

	# Set master system clock prescaler divide by 6 and processor clock divide by 2 in PMC_MCKR.
	# Wait for MCKRDY signal from PMC_SR to assert.

	#mww 0xfffffc30 0x00000101
	mww 0xfffffc30 0x00001301
	while { [expr [read_register 0xfffffc68] & 0x08] != 8 } { sleep 1 }

	# Now change PMC_MCKR register to select PLLA.
	# Wait for MCKRDY signal from PMC_SR to assert.

	mww 0xfffffc30 0x00001302
	while { [expr [read_register 0xfffffc68] & 0x08] != 8 } { sleep 1 }

	# Processor and master clocks are now operating and stable at maximum frequency possible:
	#	-> MCLK = 132.096 MHz
	#	-> PCLK = 396.288 MHz

	# Switch over to adaptive clocking.

	adapter speed 6000

	# Enable faster DCC downloads.

	arm7_9 dcc_downloads enable

	# To be able to use external SDRAM, several peripheral configuration registers must
	# be modified.  The first change is made to PIO_ASR to select peripheral functions
	# for D15 through D31.  The second change is made to the PIO_PDR register to disable
	# this for D15 through D31.

#	mww 0xfffff870 0xffff0000
#	mww 0xfffff804 0xffff0000

	# The EBI chip select register EBI_CS must be specifically configured to enable the internal SDRAM controller
	# using CS1.  Additionally we want CS3 assigned to NandFlash.  Also VDDIO is connected physically on
	# the board to the 3.3 VDC power supply so set the appropriate register bit to notify the micrcontroller.

	# mww 0xffffef1c 0x000100a

	# The ICnova SAM9G45 SODIMM has built-in NandFlash.  The exact physical timing characteristics
	# for the memory type used on the current board (MT29F2G08AACWP) can be established by setting
	# four registers in order:  SMC_SETUP3, SMC_PULSE3, SMC_CYCLE3, and SMC_MODE3.

	# mww 0xffffec30 0x00020002
	# mww 0xffffec34 0x04040404
	# mww 0xffffec38 0x00070007
	# mww 0xffffec3c 0x00030003

	# Identify NandFlash bank 0.  Disabled at the moment because a memory driver is not yet complete.

#	nand probe 0

    # SMC_SETUP0 : Setup SMC for NOR Flash
	mww 0xffffe800 0x0012000a
    # SMC_PULSE0
	mww 0xffffe804 0x3b38343b
    # SMC_CYCLE0
	mww 0xffffe808 0x003f003f
    # SMC_MODE0
	mww 0xffffe80c 0x00001000
    # Identify flash bank 0
	flash probe 0

	# Now setup SDRAM.  This is tricky and configuration is very important for reliability!  The current calculations
	# are based on 2 x Samsung K4T51083QG memory.

	# 0. Enable DDR2 Clock
	mww 0xfffffc00 0x4
	# 1. Program memory device type
	# 1.1 configure the DDR controller
	mww 0xffffe620 0x16
	# 1.2 program the DDR controller
	mww 0xffffe608 0x3d

	# 2. program memory device features
	# 2.1 assume timings for 7.5ns min clock period
	mww 0xffffe60c 0x21128226
	# 2.2 pSDDRC->HDDRSDRC2_T1PR
	mww 0xffffe610 0x02c8100e
	# 2.3 pSDDRC->HDDRSDRC2_T2PR
	mww 0xffffe614 0x01000702
	# 3. NOP
	mww 0xffffe600 0x1
	mww 0x70000000 0x1
	# 3.1 delay 200us
	sleep 1
	# jim tcl alternative: after ms
	# after 0.2

	# 4. NOP
	mww 0xffffe600 0x1
	mww 0x70000000 0x1
	# 4.1 delay 400ns

	# 5. set all bank precharge
	mww 0xffffe600 0x2
	mww 0x70000000 0x1
	# 5.1 delay 400ns

	# 6. set EMR operation (EMRS2)
	mww 0xffffe600 0x5
	mww 0x74000000 0x1
	# 6.1 delay 2 cycles

	# 7. set EMR operation (EMRS3)
	mww 0xffffe600 0x5
	mww 0x76000000 0x1
	# 7.1 delay 2 cycles

	# 8. set EMR operation (EMRS1)
	mww 0xffffe600 0x5
	mww 0x72000000 0x1
	# 8.1 delay 200 cycles (400Mhz -> 5 * 10^-7s)
	sleep 1

	# 9. Enable DLL Reset (set DLL bit)
	set CR  [expr [read_register 0xffffe608] | 0x80]
	mww 0xffffe608 $CR

	# 10. mode register cycle to reset the DLL
	mww 0xffffe600 0x5
	mww 0x70000000 0x1
	# 10.1 delay 2 cycles

	# 11. set all bank precharge
	mww 0xffffe600 0x2
	mww 0x70000000 0x1
	# 11.1 delay 400 ns

	# 12. two auto-refresh (CBR) cycles are provided.
	mww 0xffffe600 0x4
	mww 0x70000000 0x1
	# 12.1 delay 10 cycles
	# 12.2 2nd cycle (schreiben des Mode Register sparen wir uns)
	mww 0x70000000 0x1
	# 12.3 delay 10 cycles

	# 13. disable DLL reset (clear DLL bit)
	set CR  [expr [read_register 0xffffe608] & 0xffffff7f]
	mww 0xffffe608 $CR

	# 14. mode register set cycle
	mww 0xffffe600 0x3
	mww 0x70000000 0x1

	# 15. program OCD field (set OCD bits)
	set CR  [expr [read_register 0xffffe608] | 0x7000]
	mww 0xffffe608 $CR

	# 16. (EMRS1)
	mww 0xffffe600 0x5
	mww 0x72000000 0x1
	# 16.1 delay 2 cycles

	# 17. disable OCD field (clear OCD bits)
	set CR  [expr [read_register 0xffffe608] & 0xffff8fff]
	mww 0xffffe608 $CR

	# 18. (EMRS1)
	mww 0xffffe600 0x5
	mww 0x76000000 0x1
	# 18.1 delay 2 cycles

	# 19. normal mode command
	mww 0xffffe600 0x0
	mww 0x70000000 0x1

	# 20. perform write to any address
	#mww 0x70000000 0x1

	# 21. write refresh rate into the count field of the refresh rate register
	mww 0xffffe604 0x24b
	# 21.1 delay (500 * 6 cycles)

	arm7_9 fast_memory_access enable
}