1 #################################################################################################
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 #
7 #################################################################################################
9 # FIXME use some standard target config, maybe create one from this
11 # source [find target/...cfg]
13 source [find target/at91sam9g45.cfg]
16 # reset_config trst_and_srst
18 # adapter_nsrst_delay 200
19 # jtag_ntrst_delay 200
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.
28 $_TARGETNAME configure -event reset-init {at91sam9g45_init}
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}
35 # NandFlash configuration and definition
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
45 proc read_register {register} {
47 mem2array result 32 $register 1
51 proc at91sam9g45_start { } {
53 # Make sure that the the jtag is running slow, since there are a number of different ways the board
54 # can be configured coming into this state that can cause communication problems with the jtag
55 # adapter. Also since this call can be made following a "reset init" where fast memory accesses
56 # are enabled, need to temporarily shut this down so that the RSTC_MR register can be written at slower
57 # jtag speed without causing GDB keep alive problem.
59 arm7_9 fast_memory_access disable
60 # Slow-speed oscillator enabled at reset, so run jtag speed slow.
62 # Make sure processor is halted, or error will result in following steps.
65 # RSTC_MR : enable user reset.
66 mww 0xfffffd08 0xa5000501
70 proc at91sam9g45_init { } {
72 # At reset AT91SAM9G45 chip runs on slow clock (32.768 kHz). To shift over to a normal clock requires
73 # a number of steps that must be carefully performed. The process outline below follows the
74 # recommended procedure outlined in the AT91SAM9G45 technical manual.
76 # Several key and very important things to keep in mind:
77 # The SDRAM parts used currently on the board are -75 grade parts. This
78 # means the master clock (MCLK) must be at or below 133 MHz or timing errors will occur. The processor
79 # core can operate up to 400 MHz and therefore PCLK must be at or below this to function properly.
81 # Make sure processor is halted, or error will result in following steps.
83 # RSTC_MR : enable user reset.
84 mww 0xfffffd08 0xa5000501
85 # WDT_MR : disable watchdog.
86 mww 0xfffffd44 0x00008000
88 # Enable the main 15.000 MHz oscillator in CKGR_MOR register.
89 # Wait for MOSCS in PMC_SR to assert indicating oscillator is again stable after change to CKGR_MOR.
91 mww 0xfffffc20 0x00004001
92 while { [expr [read_register 0xfffffc68] & 0x01] != 1 } { sleep 1 }
94 # Set PLLA Register for 792.576 MHz (divider: bypass, multiplier: 43).
95 # Wait for LOCKA signal in PMC_SR to assert indicating PLLA is stable.
97 #mww 0xfffffc28 0x202a3f01
98 mww 0xfffffc28 0x20c73f03
99 while { [expr [read_register 0xfffffc68] & 0x02] != 2 } { sleep 1 }
101 # Set master system clock prescaler divide by 6 and processor clock divide by 2 in PMC_MCKR.
102 # Wait for MCKRDY signal from PMC_SR to assert.
104 #mww 0xfffffc30 0x00000101
105 mww 0xfffffc30 0x00001301
106 while { [expr [read_register 0xfffffc68] & 0x08] != 8 } { sleep 1 }
108 # Now change PMC_MCKR register to select PLLA.
109 # Wait for MCKRDY signal from PMC_SR to assert.
111 mww 0xfffffc30 0x00001302
112 while { [expr [read_register 0xfffffc68] & 0x08] != 8 } { sleep 1 }
114 # Processor and master clocks are now operating and stable at maximum frequency possible:
115 # -> MCLK = 132.096 MHz
116 # -> PCLK = 396.288 MHz
118 # Switch over to adaptive clocking.
122 # Enable faster DCC downloads.
124 arm7_9 dcc_downloads enable
126 # To be able to use external SDRAM, several peripheral configuration registers must
127 # be modified. The first change is made to PIO_ASR to select peripheral functions
128 # for D15 through D31. The second change is made to the PIO_PDR register to disable
129 # this for D15 through D31.
131 # mww 0xfffff870 0xffff0000
132 # mww 0xfffff804 0xffff0000
134 # The EBI chip select register EBI_CS must be specifically configured to enable the internal SDRAM controller
135 # using CS1. Additionally we want CS3 assigned to NandFlash. Also VDDIO is connected physically on
136 # the board to the 3.3 VDC power supply so set the appropriate register bit to notify the micrcontroller.
138 # mww 0xffffef1c 0x000100a
140 # The ICnova SAM9G45 SODIMM has built-in NandFlash. The exact physical timing characteristics
141 # for the memory type used on the current board (MT29F2G08AACWP) can be established by setting
142 # four registers in order: SMC_SETUP3, SMC_PULSE3, SMC_CYCLE3, and SMC_MODE3.
144 # mww 0xffffec30 0x00020002
145 # mww 0xffffec34 0x04040404
146 # mww 0xffffec38 0x00070007
147 # mww 0xffffec3c 0x00030003
149 # Identify NandFlash bank 0. Disabled at the moment because a memory driver is not yet complete.
153 # SMC_SETUP0 : Setup SMC for NOR Flash
154 mww 0xffffe800 0x0012000a
156 mww 0xffffe804 0x3b38343b
158 mww 0xffffe808 0x003f003f
160 mww 0xffffe80c 0x00001000
161 # Identify flash bank 0
164 # Now setup SDRAM. This is tricky and configuration is very important for reliability! The current calculations
165 # are based on 2 x Samsung K4T51083QG memory.
167 # 0. Enable DDR2 Clock
169 # 1. Program memory device type
170 # 1.1 configure the DDR controller
172 # 1.2 program the DDR controller
175 # 2. program memory device features
176 # 2.1 assume timings for 7.5ns min clock period
177 mww 0xffffe60c 0x21128226
178 # 2.2 pSDDRC->HDDRSDRC2_T1PR
179 mww 0xffffe610 0x02c8100e
180 # 2.3 pSDDRC->HDDRSDRC2_T2PR
181 mww 0xffffe614 0x01000702
187 # jim tcl alternative: after ms
195 # 5. set all bank precharge
200 # 6. set EMR operation (EMRS2)
205 # 7. set EMR operation (EMRS3)
210 # 8. set EMR operation (EMRS1)
213 # 8.1 delay 200 cycles (400Mhz -> 5 * 10^-7s)
216 # 9. Enable DLL Reset (set DLL bit)
217 set CR [expr [read_register 0xffffe608] | 0x80]
220 # 10. mode register cycle to reset the DLL
223 # 10.1 delay 2 cycles
225 # 11. set all bank precharge
230 # 12. two auto-refresh (CBR) cycles are provided.
233 # 12.1 delay 10 cycles
234 # 12.2 2nd cycle (schreiben des Mode Register sparen wir uns)
236 # 12.3 delay 10 cycles
238 # 13. disable DLL reset (clear DLL bit)
239 set CR [expr [read_register 0xffffe608] & 0xffffff7f]
242 # 14. mode register set cycle
246 # 15. program OCD field (set OCD bits)
247 set CR [expr [read_register 0xffffe608] | 0x7000]
253 # 16.1 delay 2 cycles
255 # 17. disable OCD field (clear OCD bits)
256 set CR [expr [read_register 0xffffe608] & 0xffff8fff]
262 # 18.1 delay 2 cycles
264 # 19. normal mode command
268 # 20. perform write to any address
271 # 21. write refresh rate into the count field of the refresh rate register
273 # 21.1 delay (500 * 6 cycles)
275 arm7_9 fast_memory_access enable