1 | ;/*****************************************************************************/
|
2 | ;/* STARTUP.S: Startup file for Philips LPC2000 */
|
3 | ;/*****************************************************************************/
|
4 | ;/* <<< Use Configuration Wizard in Context Menu >>> */
|
5 | ;/*****************************************************************************/
|
6 | ;/* This file is part of the uVision/ARM development tools. */
|
7 | ;/* Copyright (c) 2005-2007 Keil Software. All rights reserved. */
|
8 | ;/* This software may only be used under the terms of a valid, current, */
|
9 | ;/* end user licence from KEIL for a compatible version of KEIL software */
|
10 | ;/* development tools. Nothing else gives you the right to use this software. */
|
11 | ;/*****************************************************************************/
|
12 |
|
13 |
|
14 | ;/*
|
15 | ; * The STARTUP.S code is executed after CPU Reset. This file may be
|
16 | ; * translated with the following SET symbols. In uVision these SET
|
17 | ; * symbols are entered under Options - ASM - Define.
|
18 | ; *
|
19 | ; * REMAP: when set the startup code initializes the register MEMMAP
|
20 | ; * which overwrites the settings of the CPU configuration pins. The
|
21 | ; * startup and interrupt vectors are remapped from:
|
22 | ; * 0x00000000 default setting (not remapped)
|
23 | ; * 0x80000000 when EXTMEM_MODE is used
|
24 | ; * 0x40000000 when RAM_MODE is used
|
25 | ; *
|
26 | ; * EXTMEM_MODE: when set the device is configured for code execution
|
27 | ; * from external memory starting at address 0x80000000.
|
28 | ; *
|
29 | ; * RAM_MODE: when set the device is configured for code execution
|
30 | ; * from on-chip RAM starting at address 0x40000000.
|
31 | ; *
|
32 | ; * EXTERNAL_MODE: when set the PIN2SEL values are written that enable
|
33 | ; * the external BUS at startup.
|
34 | ; */
|
35 |
|
36 |
|
37 | ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
|
38 |
|
39 | Mode_USR EQU 0x10
|
40 | Mode_FIQ EQU 0x11
|
41 | Mode_IRQ EQU 0x12
|
42 | Mode_SVC EQU 0x13
|
43 | Mode_ABT EQU 0x17
|
44 | Mode_UND EQU 0x1B
|
45 | Mode_SYS EQU 0x1F
|
46 |
|
47 | I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
|
48 | F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
|
49 |
|
50 |
|
51 | ;// <h> Stack Configuration (Stack Sizes in Bytes)
|
52 | ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8>
|
53 | ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8>
|
54 | ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8>
|
55 | ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
|
56 | ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8>
|
57 | ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8>
|
58 | ;// </h>
|
59 |
|
60 | UND_Stack_Size EQU 0x00000000
|
61 | SVC_Stack_Size EQU 0x00000008
|
62 | ABT_Stack_Size EQU 0x00000000
|
63 | FIQ_Stack_Size EQU 0x00000000
|
64 | IRQ_Stack_Size EQU 0x00000080
|
65 | USR_Stack_Size EQU 0x00000400
|
66 |
|
67 | ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
|
68 | FIQ_Stack_Size + IRQ_Stack_Size)
|
69 |
|
70 | AREA STACK, NOINIT, READWRITE, ALIGN=3
|
71 |
|
72 | Stack_Mem SPACE USR_Stack_Size
|
73 | __initial_sp SPACE ISR_Stack_Size
|
74 |
|
75 | Stack_Top
|
76 |
|
77 |
|
78 | ;// <h> Heap Configuration
|
79 | ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF>
|
80 | ;// </h>
|
81 |
|
82 | Heap_Size EQU 0x00000000
|
83 |
|
84 | AREA HEAP, NOINIT, READWRITE, ALIGN=3
|
85 | __heap_base
|
86 | Heap_Mem SPACE Heap_Size
|
87 | __heap_limit
|
88 |
|
89 |
|
90 | ; VPBDIV definitions
|
91 | VPBDIV EQU 0xE01FC100 ; VPBDIV Address
|
92 |
|
93 | ;// <e> VPBDIV Setup
|
94 | ;// <i> Peripheral Bus Clock Rate
|
95 | ;// <o1.0..1> VPBDIV: VPB Clock
|
96 | ;// <0=> VPB Clock = CPU Clock / 4
|
97 | ;// <1=> VPB Clock = CPU Clock
|
98 | ;// <2=> VPB Clock = CPU Clock / 2
|
99 | ;// <o1.4..5> XCLKDIV: XCLK Pin
|
100 | ;// <0=> XCLK Pin = CPU Clock / 4
|
101 | ;// <1=> XCLK Pin = CPU Clock
|
102 | ;// <2=> XCLK Pin = CPU Clock / 2
|
103 | ;// </e>
|
104 | VPBDIV_SETUP EQU 0
|
105 | VPBDIV_Val EQU 0x00000000
|
106 |
|
107 |
|
108 | ; Phase Locked Loop (PLL) definitions
|
109 | PLL_BASE EQU 0xE01FC080 ; PLL Base Address
|
110 | PLLCON_OFS EQU 0x00 ; PLL Control Offset
|
111 | PLLCFG_OFS EQU 0x04 ; PLL Configuration Offset
|
112 | PLLSTAT_OFS EQU 0x08 ; PLL Status Offset
|
113 | PLLFEED_OFS EQU 0x0C ; PLL Feed Offset
|
114 | PLLCON_PLLE EQU (1<<0) ; PLL Enable
|
115 | PLLCON_PLLC EQU (1<<1) ; PLL Connect
|
116 | PLLCFG_MSEL EQU (0x1F<<0) ; PLL Multiplier
|
117 | PLLCFG_PSEL EQU (0x03<<5) ; PLL Divider
|
118 | PLLSTAT_PLOCK EQU (1<<10) ; PLL Lock Status
|
119 |
|
120 | ;// <e> PLL Setup
|
121 | ;// <o1.0..4> MSEL: PLL Multiplier Selection
|
122 | ;// <1-32><#-1>
|
123 | ;// <i> M Value
|
124 | ;// <o1.5..6> PSEL: PLL Divider Selection
|
125 | ;// <0=> 1 <1=> 2 <2=> 4 <3=> 8
|
126 | ;// <i> P Value
|
127 | ;// </e>
|
128 | PLL_SETUP EQU 1
|
129 | PLLCFG_Val EQU 0x00000024
|
130 |
|
131 |
|
132 | ; Memory Accelerator Module (MAM) definitions
|
133 | MAM_BASE EQU 0xE01FC000 ; MAM Base Address
|
134 | MAMCR_OFS EQU 0x00 ; MAM Control Offset
|
135 | MAMTIM_OFS EQU 0x04 ; MAM Timing Offset
|
136 |
|
137 | ;// <e> MAM Setup
|
138 | ;// <o1.0..1> MAM Control
|
139 | ;// <0=> Disabled
|
140 | ;// <1=> Partially Enabled
|
141 | ;// <2=> Fully Enabled
|
142 | ;// <i> Mode
|
143 | ;// <o2.0..2> MAM Timing
|
144 | ;// <0=> Reserved <1=> 1 <2=> 2 <3=> 3
|
145 | ;// <4=> 4 <5=> 5 <6=> 6 <7=> 7
|
146 | ;// <i> Fetch Cycles
|
147 | ;// </e>
|
148 | MAM_SETUP EQU 1
|
149 | MAMCR_Val EQU 0x00000002
|
150 | MAMTIM_Val EQU 0x00000004
|
151 |
|
152 |
|
153 | ; External Memory Controller (EMC) definitions
|
154 | EMC_BASE EQU 0xFFE00000 ; EMC Base Address
|
155 | BCFG0_OFS EQU 0x00 ; BCFG0 Offset
|
156 | BCFG1_OFS EQU 0x04 ; BCFG1 Offset
|
157 | BCFG2_OFS EQU 0x08 ; BCFG2 Offset
|
158 | BCFG3_OFS EQU 0x0C ; BCFG3 Offset
|
159 |
|
160 | ;// <e> External Memory Controller (EMC)
|
161 | EMC_SETUP EQU 0
|
162 |
|
163 | ;// <e> Bank Configuration 0 (BCFG0)
|
164 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
165 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
166 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
167 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
168 | ;// <o1.26> WP: Write Protect
|
169 | ;// <o1.27> BM: Burst ROM
|
170 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
171 | ;// <2=> 32-bit <3=> Reserved
|
172 | ;// </e>
|
173 | BCFG0_SETUP EQU 0
|
174 | BCFG0_Val EQU 0x0000FBEF
|
175 |
|
176 | ;// <e> Bank Configuration 1 (BCFG1)
|
177 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
178 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
179 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
180 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
181 | ;// <o1.26> WP: Write Protect
|
182 | ;// <o1.27> BM: Burst ROM
|
183 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
184 | ;// <2=> 32-bit <3=> Reserved
|
185 | ;// </e>
|
186 | BCFG1_SETUP EQU 0
|
187 | BCFG1_Val EQU 0x0000FBEF
|
188 |
|
189 | ;// <e> Bank Configuration 2 (BCFG2)
|
190 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
191 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
192 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
193 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
194 | ;// <o1.26> WP: Write Protect
|
195 | ;// <o1.27> BM: Burst ROM
|
196 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
197 | ;// <2=> 32-bit <3=> Reserved
|
198 | ;// </e>
|
199 | BCFG2_SETUP EQU 0
|
200 | BCFG2_Val EQU 0x0000FBEF
|
201 |
|
202 | ;// <e> Bank Configuration 3 (BCFG3)
|
203 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
204 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
205 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
206 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
207 | ;// <o1.26> WP: Write Protect
|
208 | ;// <o1.27> BM: Burst ROM
|
209 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
210 | ;// <2=> 32-bit <3=> Reserved
|
211 | ;// </e>
|
212 | BCFG3_SETUP EQU 0
|
213 | BCFG3_Val EQU 0x0000FBEF
|
214 |
|
215 | ;// </e> End of EMC
|
216 |
|
217 |
|
218 | ; External Memory Pins definitions
|
219 | PINSEL2 EQU 0xE002C014 ; PINSEL2 Address
|
220 | PINSEL2_Val EQU 0x0E6149E4 ; CS0..3, OE, WE, BLS0..3,
|
221 | ; D0..31, A2..23, JTAG Pins
|
222 |
|
223 |
|
224 | PRESERVE8
|
225 |
|
226 |
|
227 | ; Area Definition and Entry Point
|
228 | ; Startup Code must be linked first at Address at which it expects to run.
|
229 |
|
230 | AREA RESET, CODE, READONLY
|
231 | ARM
|
232 |
|
233 |
|
234 | ; Exception Vectors
|
235 | ; Mapped to Address 0.
|
236 | ; Absolute addressing mode must be used.
|
237 | ; Dummy Handlers are implemented as infinite loops which can be modified.
|
238 |
|
239 | Vectors LDR PC, Reset_Addr
|
240 | LDR PC, Undef_Addr
|
241 | LDR PC, SWI_Addr
|
242 | LDR PC, PAbt_Addr
|
243 | LDR PC, DAbt_Addr
|
244 | NOP ; Reserved Vector
|
245 | ; LDR PC, IRQ_Addr
|
246 | LDR PC, [PC, #-0x0FF0] ; Vector from VicVectAddr
|
247 | LDR PC, FIQ_Addr
|
248 |
|
249 | Reset_Addr DCD Reset_Handler
|
250 | Undef_Addr DCD Undef_Handler
|
251 | SWI_Addr DCD SWI_Handler
|
252 | PAbt_Addr DCD PAbt_Handler
|
253 | DAbt_Addr DCD DAbt_Handler
|
254 | DCD 0 ; Reserved Address
|
255 | IRQ_Addr DCD IRQ_Handler
|
256 | FIQ_Addr DCD FIQ_Handler
|
257 |
|
258 | Undef_Handler B Undef_Handler
|
259 | SWI_Handler B SWI_Handler
|
260 | PAbt_Handler B PAbt_Handler
|
261 | DAbt_Handler B DAbt_Handler
|
262 | IRQ_Handler B IRQ_Handler
|
263 | FIQ_Handler B FIQ_Handler
|
264 |
|
265 |
|
266 | ; Reset Handler
|
267 |
|
268 | EXPORT Reset_Handler
|
269 | Reset_Handler
|
270 |
|
271 |
|
272 | ; Setup External Memory Pins
|
273 | IF :DEF:EXTERNAL_MODE
|
274 | LDR R0, =PINSEL2
|
275 | LDR R1, =PINSEL2_Val
|
276 | STR R1, [R0]
|
277 | ENDIF
|
278 |
|
279 |
|
280 | ; Setup External Memory Controller
|
281 | IF EMC_SETUP <> 0
|
282 | LDR R0, =EMC_BASE
|
283 |
|
284 | IF BCFG0_SETUP <> 0
|
285 | LDR R1, =BCFG0_Val
|
286 | STR R1, [R0, #BCFG0_OFS]
|
287 | ENDIF
|
288 |
|
289 | IF BCFG1_SETUP <> 0
|
290 | LDR R1, =BCFG1_Val
|
291 | STR R1, [R0, #BCFG1_OFS]
|
292 | ENDIF
|
293 |
|
294 | IF BCFG2_SETUP <> 0
|
295 | LDR R1, =BCFG2_Val
|
296 | STR R1, [R0, #BCFG2_OFS]
|
297 | ENDIF
|
298 |
|
299 | IF BCFG3_SETUP <> 0
|
300 | LDR R1, =BCFG3_Val
|
301 | STR R1, [R0, #BCFG3_OFS]
|
302 | ENDIF
|
303 |
|
304 | ENDIF ; EMC_SETUP
|
305 |
|
306 |
|
307 | ; Setup VPBDIV
|
308 | IF VPBDIV_SETUP <> 0
|
309 | LDR R0, =VPBDIV
|
310 | LDR R1, =VPBDIV_Val
|
311 | STR R1, [R0]
|
312 | ENDIF
|
313 |
|
314 |
|
315 | ; Setup PLL
|
316 | IF PLL_SETUP <> 0
|
317 | LDR R0, =PLL_BASE
|
318 | MOV R1, #0xAA
|
319 | MOV R2, #0x55
|
320 |
|
321 | ; Configure and Enable PLL
|
322 | MOV R3, #PLLCFG_Val
|
323 | STR R3, [R0, #PLLCFG_OFS]
|
324 | MOV R3, #PLLCON_PLLE
|
325 | STR R3, [R0, #PLLCON_OFS]
|
326 | STR R1, [R0, #PLLFEED_OFS]
|
327 | STR R2, [R0, #PLLFEED_OFS]
|
328 |
|
329 | ; Wait until PLL Locked
|
330 | PLL_Loop LDR R3, [R0, #PLLSTAT_OFS]
|
331 | ANDS R3, R3, #PLLSTAT_PLOCK
|
332 | BEQ PLL_Loop
|
333 |
|
334 | ; Switch to PLL Clock
|
335 | MOV R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
|
336 | STR R3, [R0, #PLLCON_OFS]
|
337 | STR R1, [R0, #PLLFEED_OFS]
|
338 | STR R2, [R0, #PLLFEED_OFS]
|
339 | ENDIF ; PLL_SETUP
|
340 |
|
341 |
|
342 | ; Setup MAM
|
343 | IF MAM_SETUP <> 0
|
344 | LDR R0, =MAM_BASE
|
345 | MOV R1, #MAMTIM_Val
|
346 | STR R1, [R0, #MAMTIM_OFS]
|
347 | MOV R1, #MAMCR_Val
|
348 | STR R1, [R0, #MAMCR_OFS]
|
349 | ENDIF ; MAM_SETUP
|
350 |
|
351 |
|
352 | ; Memory Mapping (when Interrupt Vectors are in RAM)
|
353 | MEMMAP EQU 0xE01FC040 ; Memory Mapping Control
|
354 | IF :DEF:REMAP
|
355 | LDR R0, =MEMMAP
|
356 | IF :DEF:EXTMEM_MODE
|
357 | MOV R1, #3
|
358 | ELIF :DEF:RAM_MODE
|
359 | MOV R1, #2
|
360 | ELSE
|
361 | MOV R1, #1
|
362 | ENDIF
|
363 | STR R1, [R0]
|
364 | ENDIF
|
365 |
|
366 |
|
367 | ; Initialise Interrupt System
|
368 | ; ...
|
369 |
|
370 |
|
371 | ; Setup Stack for each mode
|
372 |
|
373 | LDR R0, =Stack_Top
|
374 |
|
375 | ; Enter Undefined Instruction Mode and set its Stack Pointer
|
376 | MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
|
377 | MOV SP, R0
|
378 | SUB R0, R0, #UND_Stack_Size
|
379 |
|
380 | ; Enter Abort Mode and set its Stack Pointer
|
381 | MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
|
382 | MOV SP, R0
|
383 | SUB R0, R0, #ABT_Stack_Size
|
384 |
|
385 | ; Enter FIQ Mode and set its Stack Pointer
|
386 | MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
|
387 | MOV SP, R0
|
388 | SUB R0, R0, #FIQ_Stack_Size
|
389 |
|
390 | ; Enter IRQ Mode and set its Stack Pointer
|
391 | MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
|
392 | MOV SP, R0
|
393 | SUB R0, R0, #IRQ_Stack_Size
|
394 |
|
395 | ; Enter Supervisor Mode and set its Stack Pointer
|
396 | MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
|
397 | MOV SP, R0
|
398 | SUB R0, R0, #SVC_Stack_Size
|
399 |
|
400 | ; Enter User Mode and set its Stack Pointer
|
401 | MSR CPSR_c, #Mode_USR
|
402 | IF :DEF:__MICROLIB
|
403 |
|
404 | EXPORT __initial_sp
|
405 |
|
406 | ELSE
|
407 |
|
408 | MOV SP, R0
|
409 | SUB SL, SP, #USR_Stack_Size
|
410 |
|
411 | ENDIF
|
412 |
|
413 |
|
414 | ; Enter the C code
|
415 |
|
416 | IMPORT __main
|
417 | LDR R0, =__main
|
418 | BX R0
|
419 |
|
420 |
|
421 | IF :DEF:__MICROLIB
|
422 |
|
423 | EXPORT __heap_base
|
424 | EXPORT __heap_limit
|
425 |
|
426 | ELSE
|
427 | ; User Initial Stack & Heap
|
428 | AREA |.text|, CODE, READONLY
|
429 |
|
430 | IMPORT __use_two_region_memory
|
431 | EXPORT __user_initial_stackheap
|
432 | __user_initial_stackheap
|
433 |
|
434 | LDR R0, = Heap_Mem
|
435 | LDR R1, =(Stack_Mem + USR_Stack_Size)
|
436 | LDR R2, = (Heap_Mem + Heap_Size)
|
437 | LDR R3, = Stack_Mem
|
438 | BX LR
|
439 | ENDIF
|
440 |
|
441 |
|
442 | END
|