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 srst 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} {
46 return [read_memory $register 32 1]
49 proc at91sam9g45_start { } {
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.
57 arm7_9 fast_memory_access disable
58 # Slow-speed oscillator enabled at reset, so run jtag speed slow.
60 # Make sure processor is halted, or error will result in following steps.
63 # RSTC_MR : enable user reset.
64 mww 0xfffffd08 0xa5000501
68 proc at91sam9g45_init { } {
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.
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.
79 # Make sure processor is halted, or error will result in following steps.
81 # RSTC_MR : enable user reset.
82 mww 0xfffffd08 0xa5000501
83 # WDT_MR : disable watchdog.
84 mww 0xfffffd44 0x00008000
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.
89 mww 0xfffffc20 0x00004001
90 while { [expr {[read_register 0xfffffc68] & 0x01}] != 1 } { sleep 1 }
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.
95 #mww 0xfffffc28 0x202a3f01
96 mww 0xfffffc28 0x20c73f03
97 while { [expr {[read_register 0xfffffc68] & 0x02}] != 2 } { sleep 1 }
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.
102 #mww 0xfffffc30 0x00000101
103 mww 0xfffffc30 0x00001301
104 while { [expr {[read_register 0xfffffc68] & 0x08}] != 8 } { sleep 1 }
106 # Now change PMC_MCKR register to select PLLA.
107 # Wait for MCKRDY signal from PMC_SR to assert.
109 mww 0xfffffc30 0x00001302
110 while { [expr {[read_register 0xfffffc68] & 0x08}] != 8 } { sleep 1 }
112 # Processor and master clocks are now operating and stable at maximum frequency possible:
113 # -> MCLK = 132.096 MHz
114 # -> PCLK = 396.288 MHz
116 # Switch over to adaptive clocking.
120 # Enable faster DCC downloads.
122 arm7_9 dcc_downloads enable
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.
129 # mww 0xfffff870 0xffff0000
130 # mww 0xfffff804 0xffff0000
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.
136 # mww 0xffffef1c 0x000100a
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.
142 # mww 0xffffec30 0x00020002
143 # mww 0xffffec34 0x04040404
144 # mww 0xffffec38 0x00070007
145 # mww 0xffffec3c 0x00030003
147 # Identify NandFlash bank 0. Disabled at the moment because a memory driver is not yet complete.
151 # SMC_SETUP0 : Setup SMC for NOR Flash
152 mww 0xffffe800 0x0012000a
154 mww 0xffffe804 0x3b38343b
156 mww 0xffffe808 0x003f003f
158 mww 0xffffe80c 0x00001000
159 # Identify flash bank 0
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.
165 # 0. Enable DDR2 Clock
167 # 1. Program memory device type
168 # 1.1 configure the DDR controller
170 # 1.2 program the DDR controller
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
185 # jim tcl alternative: after ms
193 # 5. set all bank precharge
198 # 6. set EMR operation (EMRS2)
203 # 7. set EMR operation (EMRS3)
208 # 8. set EMR operation (EMRS1)
211 # 8.1 delay 200 cycles (400Mhz -> 5 * 10^-7s)
214 # 9. Enable DLL Reset (set DLL bit)
215 set CR [expr {[read_register 0xffffe608] | 0x80}]
218 # 10. mode register cycle to reset the DLL
221 # 10.1 delay 2 cycles
223 # 11. set all bank precharge
228 # 12. two auto-refresh (CBR) cycles are provided.
231 # 12.1 delay 10 cycles
232 # 12.2 2nd cycle (schreiben des Mode Register sparen wir uns)
234 # 12.3 delay 10 cycles
236 # 13. disable DLL reset (clear DLL bit)
237 set CR [expr {[read_register 0xffffe608] & 0xffffff7f}]
240 # 14. mode register set cycle
244 # 15. program OCD field (set OCD bits)
245 set CR [expr {[read_register 0xffffe608] | 0x7000}]
251 # 16.1 delay 2 cycles
253 # 17. disable OCD field (clear OCD bits)
254 set CR [expr {[read_register 0xffffe608] & 0xffff8fff}]
260 # 18.1 delay 2 cycles
262 # 19. normal mode command
266 # 20. perform write to any address
269 # 21. write refresh rate into the count field of the refresh rate register
271 # 21.1 delay (500 * 6 cycles)
273 arm7_9 fast_memory_access enable