Remove all occurrences of 'mem2array' and 'array2mem'
[fw/openocd] / tcl / board / icnova_sam9g45_sodimm.cfg
1 #################################################################################################
2 #                                                                                                                                               #
3 # Author: Lars Poeschel (larsi@wh2.tu-dresden.de)                                                                                               #
4 # Generated for In-Circuit ICnova SAM9G45 SODIMM                                                                                                #
5 # http://www.ic-board.de/product_info.php?info=p214_ICnova-SAM9G45-SODIMM.html|ICnova                   #
6 #                                                                                                                                                                                               #
7 #################################################################################################
8
9 # FIXME use some standard target config, maybe create one from this
10 #
11 #       source [find target/...cfg]
12
13 source [find target/at91sam9g45.cfg]
14
15 # Set reset type.
16 # reset_config trst_and_srst
17
18 # adapter srst delay 200
19 # jtag_ntrst_delay 200
20
21
22 # 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
23 # AT91SAM9 family, the microcontroller is a lump on a log without initialization.  Because this family has
24 # some powerful features, we want to have a special function that handles "reset init".  To do this we declare
25 # an event handler where these special activities can take place.
26
27 scan_chain
28 $_TARGETNAME configure -event reset-init {at91sam9g45_init}
29
30 # Set fallback clock to 1/6 of worst-case clock speed (which would be the 32.768 kHz slow clock).
31 # Slow-speed oscillator enabled at reset, so run jtag speed slow.
32 $_TARGETNAME configure -event reset-start {at91sam9g45_start}
33
34
35 # NandFlash configuration and definition
36 # Future TBD
37 # Flash configuration
38 # flash bank cfi <base> <size> <chip width> <bus width> <target#>
39 set _FLASHNAME $_CHIPNAME.flash
40 # set _NANDNAME $_CHIPNAME.nand
41 flash bank $_FLASHNAME cfi 0x10000000 0x00800000 2 2 $_TARGETNAME
42 # nand device $_NANDNAME at91sam9 $_TARGETNAME 0x40000000 0xFFFFE800
43
44
45 proc read_register {register} {
46         return [read_memory $register 32 1]
47 }
48
49 proc at91sam9g45_start { } {
50
51         # Make sure that the the jtag is running slow, since there are a number of different ways the board
52         # can be configured coming into this state that can cause communication problems with the jtag
53         # adapter.  Also since this call can be made following a "reset init" where fast memory accesses
54         # are enabled, need to temporarily shut this down so that the RSTC_MR register can be written at slower
55         # jtag speed without causing GDB keep alive problem.
56
57         arm7_9 fast_memory_access disable
58     # Slow-speed oscillator enabled at reset, so run jtag speed slow.
59         adapter speed 4
60     # Make sure processor is halted, or error will result in following steps.
61         halt
62         wait_halt 10000
63     # RSTC_MR : enable user reset.
64         mww 0xfffffd08 0xa5000501
65 }
66
67
68 proc at91sam9g45_init { } {
69
70         # At reset AT91SAM9G45 chip runs on slow clock (32.768 kHz).  To shift over to a normal clock requires
71         # a number of steps that must be carefully performed.  The process outline below follows the
72         # recommended procedure outlined in the AT91SAM9G45 technical manual.
73         #
74         # Several key and very important things to keep in mind:
75         # The SDRAM parts used currently on the board are -75 grade parts.  This
76         # means the master clock (MCLK) must be at or below 133 MHz or timing errors will occur.  The processor
77         # core can operate up to 400 MHz and therefore PCLK must be at or below this to function properly.
78
79         # Make sure processor is halted, or error will result in following steps.
80         halt
81         # RSTC_MR : enable user reset.
82         mww 0xfffffd08 0xa5000501
83         # WDT_MR : disable watchdog.
84         mww 0xfffffd44 0x00008000
85
86         # Enable the main 15.000 MHz oscillator in CKGR_MOR register.
87         # Wait for MOSCS in PMC_SR to assert indicating oscillator is again stable after change to CKGR_MOR.
88
89         mww 0xfffffc20 0x00004001
90         while { [expr {[read_register 0xfffffc68] & 0x01}] != 1 } { sleep 1 }
91
92         # Set PLLA Register for 792.576 MHz (divider: bypass, multiplier: 43).
93         # Wait for LOCKA signal in PMC_SR to assert indicating PLLA is stable.
94
95         #mww 0xfffffc28 0x202a3f01
96         mww 0xfffffc28 0x20c73f03
97         while { [expr {[read_register 0xfffffc68] & 0x02}] != 2 } { sleep 1 }
98
99         # Set master system clock prescaler divide by 6 and processor clock divide by 2 in PMC_MCKR.
100         # Wait for MCKRDY signal from PMC_SR to assert.
101
102         #mww 0xfffffc30 0x00000101
103         mww 0xfffffc30 0x00001301
104         while { [expr {[read_register 0xfffffc68] & 0x08}] != 8 } { sleep 1 }
105
106         # Now change PMC_MCKR register to select PLLA.
107         # Wait for MCKRDY signal from PMC_SR to assert.
108
109         mww 0xfffffc30 0x00001302
110         while { [expr {[read_register 0xfffffc68] & 0x08}] != 8 } { sleep 1 }
111
112         # Processor and master clocks are now operating and stable at maximum frequency possible:
113         #       -> MCLK = 132.096 MHz
114         #       -> PCLK = 396.288 MHz
115
116         # Switch over to adaptive clocking.
117
118         adapter speed 6000
119
120         # Enable faster DCC downloads.
121
122         arm7_9 dcc_downloads enable
123
124         # To be able to use external SDRAM, several peripheral configuration registers must
125         # be modified.  The first change is made to PIO_ASR to select peripheral functions
126         # for D15 through D31.  The second change is made to the PIO_PDR register to disable
127         # this for D15 through D31.
128
129 #       mww 0xfffff870 0xffff0000
130 #       mww 0xfffff804 0xffff0000
131
132         # The EBI chip select register EBI_CS must be specifically configured to enable the internal SDRAM controller
133         # using CS1.  Additionally we want CS3 assigned to NandFlash.  Also VDDIO is connected physically on
134         # the board to the 3.3 VDC power supply so set the appropriate register bit to notify the micrcontroller.
135
136         # mww 0xffffef1c 0x000100a
137
138         # The ICnova SAM9G45 SODIMM has built-in NandFlash.  The exact physical timing characteristics
139         # for the memory type used on the current board (MT29F2G08AACWP) can be established by setting
140         # four registers in order:  SMC_SETUP3, SMC_PULSE3, SMC_CYCLE3, and SMC_MODE3.
141
142         # mww 0xffffec30 0x00020002
143         # mww 0xffffec34 0x04040404
144         # mww 0xffffec38 0x00070007
145         # mww 0xffffec3c 0x00030003
146
147         # Identify NandFlash bank 0.  Disabled at the moment because a memory driver is not yet complete.
148
149 #       nand probe 0
150
151     # SMC_SETUP0 : Setup SMC for NOR Flash
152         mww 0xffffe800 0x0012000a
153     # SMC_PULSE0
154         mww 0xffffe804 0x3b38343b
155     # SMC_CYCLE0
156         mww 0xffffe808 0x003f003f
157     # SMC_MODE0
158         mww 0xffffe80c 0x00001000
159     # Identify flash bank 0
160         flash probe 0
161
162         # Now setup SDRAM.  This is tricky and configuration is very important for reliability!  The current calculations
163         # are based on 2 x Samsung K4T51083QG memory.
164
165         # 0. Enable DDR2 Clock
166         mww 0xfffffc00 0x4
167         # 1. Program memory device type
168         # 1.1 configure the DDR controller
169         mww 0xffffe620 0x16
170         # 1.2 program the DDR controller
171         mww 0xffffe608 0x3d
172
173         # 2. program memory device features
174         # 2.1 assume timings for 7.5ns min clock period
175         mww 0xffffe60c 0x21128226
176         # 2.2 pSDDRC->HDDRSDRC2_T1PR
177         mww 0xffffe610 0x02c8100e
178         # 2.3 pSDDRC->HDDRSDRC2_T2PR
179         mww 0xffffe614 0x01000702
180         # 3. NOP
181         mww 0xffffe600 0x1
182         mww 0x70000000 0x1
183         # 3.1 delay 200us
184         sleep 1
185         # jim tcl alternative: after ms
186         # after 0.2
187
188         # 4. NOP
189         mww 0xffffe600 0x1
190         mww 0x70000000 0x1
191         # 4.1 delay 400ns
192
193         # 5. set all bank precharge
194         mww 0xffffe600 0x2
195         mww 0x70000000 0x1
196         # 5.1 delay 400ns
197
198         # 6. set EMR operation (EMRS2)
199         mww 0xffffe600 0x5
200         mww 0x74000000 0x1
201         # 6.1 delay 2 cycles
202
203         # 7. set EMR operation (EMRS3)
204         mww 0xffffe600 0x5
205         mww 0x76000000 0x1
206         # 7.1 delay 2 cycles
207
208         # 8. set EMR operation (EMRS1)
209         mww 0xffffe600 0x5
210         mww 0x72000000 0x1
211         # 8.1 delay 200 cycles (400Mhz -> 5 * 10^-7s)
212         sleep 1
213
214         # 9. Enable DLL Reset (set DLL bit)
215         set CR  [expr {[read_register 0xffffe608] | 0x80}]
216         mww 0xffffe608 $CR
217
218         # 10. mode register cycle to reset the DLL
219         mww 0xffffe600 0x5
220         mww 0x70000000 0x1
221         # 10.1 delay 2 cycles
222
223         # 11. set all bank precharge
224         mww 0xffffe600 0x2
225         mww 0x70000000 0x1
226         # 11.1 delay 400 ns
227
228         # 12. two auto-refresh (CBR) cycles are provided.
229         mww 0xffffe600 0x4
230         mww 0x70000000 0x1
231         # 12.1 delay 10 cycles
232         # 12.2 2nd cycle (schreiben des Mode Register sparen wir uns)
233         mww 0x70000000 0x1
234         # 12.3 delay 10 cycles
235
236         # 13. disable DLL reset (clear DLL bit)
237         set CR  [expr {[read_register 0xffffe608] & 0xffffff7f}]
238         mww 0xffffe608 $CR
239
240         # 14. mode register set cycle
241         mww 0xffffe600 0x3
242         mww 0x70000000 0x1
243
244         # 15. program OCD field (set OCD bits)
245         set CR  [expr {[read_register 0xffffe608] | 0x7000}]
246         mww 0xffffe608 $CR
247
248         # 16. (EMRS1)
249         mww 0xffffe600 0x5
250         mww 0x72000000 0x1
251         # 16.1 delay 2 cycles
252
253         # 17. disable OCD field (clear OCD bits)
254         set CR  [expr {[read_register 0xffffe608] & 0xffff8fff}]
255         mww 0xffffe608 $CR
256
257         # 18. (EMRS1)
258         mww 0xffffe600 0x5
259         mww 0x76000000 0x1
260         # 18.1 delay 2 cycles
261
262         # 19. normal mode command
263         mww 0xffffe600 0x0
264         mww 0x70000000 0x1
265
266         # 20. perform write to any address
267         #mww 0x70000000 0x1
268
269         # 21. write refresh rate into the count field of the refresh rate register
270         mww 0xffffe604 0x24b
271         # 21.1 delay (500 * 6 cycles)
272
273         arm7_9 fast_memory_access enable
274 }