1
0

ADuC702x.s 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. ;/*****************************************************************************/
  2. ;/* STARTUP.S: Startup file for ADI ADuC702x device series */
  3. ;/*****************************************************************************/
  4. ;/* <<< Use Configuration Wizard in Context Menu >>> */
  5. ;/*****************************************************************************/
  6. ;/* This file is part of the uVision/ARM development tools. */
  7. ;/* Copyright (c) 2005-2006 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. ; * The STARTUP.S code is executed after CPU Reset. This file may be
  14. ; * translated with the following SET symbols. In uVision these SET
  15. ; * symbols are entered under Options - ASM - Define.
  16. ; *
  17. ; * RAM_INTVEC: when set the startup code copies exception vectors
  18. ; * from on-chip Flash to on-chip RAM and remaps RAM to address 0.
  19. ; */
  20. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  21. Mode_USR EQU 0x10
  22. Mode_FIQ EQU 0x11
  23. Mode_IRQ EQU 0x12
  24. Mode_SVC EQU 0x13
  25. Mode_ABT EQU 0x17
  26. Mode_UND EQU 0x1B
  27. Mode_SYS EQU 0x1F
  28. I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
  29. F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
  30. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  31. ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8>
  32. ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8>
  33. ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8>
  34. ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  35. ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8>
  36. ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8>
  37. ;// </h>
  38. UND_Stack_Size EQU 0x00000080
  39. SVC_Stack_Size EQU 0x00000080
  40. ABT_Stack_Size EQU 0x00000080
  41. FIQ_Stack_Size EQU 0x00000080
  42. IRQ_Stack_Size EQU 0x00000080
  43. USR_Stack_Size EQU 0x00000400
  44. Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
  45. FIQ_Stack_Size + IRQ_Stack_Size + USR_Stack_Size)
  46. AREA STACK, NOINIT, READWRITE, ALIGN=3
  47. Stack_Mem SPACE Stack_Size
  48. Stack_Top EQU Stack_Mem + Stack_Size
  49. ;// <h> Heap Configuration
  50. ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  51. ;// </h>
  52. Heap_Size EQU 0x00000000
  53. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  54. Heap_Mem SPACE Heap_Size
  55. ; MMR definitions
  56. MMR_BASE EQU 0xFFFF0000 ; MMR Base Address
  57. REMAP_OFFSET EQU 0x0220
  58. POWKEY1_OFFSET EQU 0x0404
  59. POWCON_OFFSET EQU 0x0408
  60. POWKEY2_OFFSET EQU 0x040C
  61. ;// <e> PLL Setup
  62. ;// <o1.0..2> CD: PLL Multiplier Selection
  63. ;// <0-7>
  64. ;// <i> CD Value
  65. ;// <o1.3> FINT: Fast Interrupt
  66. ;// <0-1>
  67. ;// <i> Switches to CD0 for FIQ
  68. ;// </e>
  69. PLL_SETUP EQU 1
  70. PLLCFG_Val EQU 0x00000001
  71. ;// <e> Pin Setup
  72. GPIO_SETUP EQU 0
  73. GPIOBASE EQU 0xFFFFF400
  74. ;// <h> Port 0
  75. ;// <o.0..1> P0.0 <0=> GPIO <1=> CMPOUT <2=> MS2 <3=> PLAI[7]
  76. ;// <o.4..5> P0.1 <0=> GPIO <1=> --- <2=> XBEN0 <3=> ---
  77. ;// <o.8..9> P0.2 <0=> GPIO <1=> --- <2=> XBEN1 <3=> ---
  78. ;// <o.12..13> P0.3 <0=> GPIO <1=> TRST <2=> XA16 <3=> ADCBUSY
  79. ;// <o.16..17> P0.4 <0=> GPIO/IRQ0 <1=> CONVSTART <2=> MS1 <3=> PLAO[1]
  80. ;// <o.20..21> P0.5 <0=> GPIO/IRQ1 <1=> ADCBUSY <2=> MS0 <3=> PLAO[2]
  81. ;// <o.24..25> P0.6 <0=> GPIO <1=> MRST <2=> XAE <3=> PLAO[3]
  82. ;// <o.28..29> P0.7 <0=> GPIO <1=> ECLK <2=> SIN <3=> PLAO[4]
  83. ;// </h>
  84. GP0CON_Val EQU 0x00000000
  85. ;// <h> Port 1
  86. ;// <o.0..1> P1.0 <0=> GPIO <1=> SIN <2=> I2C0SCL <3=> PLAI[0]
  87. ;// <o.4..5> P1.1 <0=> GPIO <1=> SOUT <2=> I2C0SDA <3=> PLAI[1]
  88. ;// <o.8..9> P1.2 <0=> GPIO <1=> RTS <2=> I2C1SCL <3=> PLAI[2]
  89. ;// <o.12..13> P1.3 <0=> GPIO <1=> CTS <2=> I2C1SDA <3=> PLAI[3]
  90. ;// <o.16..17> P1.4 <0=> GPIO/IRQ2 <1=> RI <2=> SPICLK <3=> PLAI[4]
  91. ;// <o.20..21> P1.5 <0=> GPIO/IRQ3 <1=> DCD <2=> SPIMISO <3=> PLAI[5]
  92. ;// <o.24..25> P1.6 <0=> GPIO <1=> DSR <2=> SPIMOSI <3=> PLAI[6]
  93. ;// <o.28..29> P1.7 <0=> GPIO <1=> DTR <2=> SPICSL <3=> PLAO[0]
  94. ;// </h>
  95. GP1CON_Val EQU 0x00000000
  96. ;// <h> Port 2
  97. ;// <o.0..1> P2.0 <0=> GPIO <1=> CONVSTART <2=> SOUT <3=> PLAO[5]
  98. ;// <o.4..5> P2.1 <0=> GPIO <1=> --- <2=> XWS <3=> PLAO[6]
  99. ;// <o.8..9> P2.2 <0=> GPIO <1=> --- <2=> XRS <3=> PLAO[7]
  100. ;// <o.12..13> P2.3 <0=> GPIO <1=> --- <2=> XAE <3=> ---
  101. ;// <o.16..17> P2.4 <0=> GPIO <1=> --- <2=> MS0 <3=> ---
  102. ;// <o.20..21> P2.5 <0=> GPIO <1=> --- <2=> MS1 <3=> ---
  103. ;// <o.24..25> P2.6 <0=> GPIO <1=> --- <2=> MS2 <3=> ---
  104. ;// <o.28..29> P2.7 <0=> GPIO <1=> --- <2=> MS3 <3=> ---
  105. ;// </h>
  106. GP2CON_Val EQU 0x00000000
  107. ;// <h> Port 3
  108. ;// <o.0..1> P3.0 <0=> GPIO <1=> PWM0H <2=> XAD0 <3=> PLAI[8]
  109. ;// <o.4..5> P3.1 <0=> GPIO <1=> PWM0L <2=> XAD1 <3=> PLAI[9]
  110. ;// <o.8..9> P3.2 <0=> GPIO <1=> PWM1H <2=> XAD2 <3=> PLAI[10]
  111. ;// <o.12..13> P3.3 <0=> GPIO <1=> PWM1L <2=> XAD3 <3=> PLAI[11]
  112. ;// <o.16..17> P3.4 <0=> GPIO <1=> PWM2H <2=> XAD4 <3=> PLAI[12]
  113. ;// <o.20..21> P3.5 <0=> GPIO <1=> PWM2L <2=> XAD5 <3=> PLAI[13]
  114. ;// <o.24..25> P3.6 <0=> GPIO <1=> PWMTRIP <2=> XAD6 <3=> PLAI[14]
  115. ;// <o.28..29> P3.7 <0=> GPIO <1=> PWMSYNC <2=> XAD7 <3=> PLAI[15]
  116. ;// </h>
  117. GP3CON_Val EQU 0x00000000
  118. ;// <h> Port 4
  119. ;// <o.0..1> P4.0 <0=> GPIO <1=> --- <2=> XAD8 <3=> PLAO[8]
  120. ;// <o.4..5> P4.1 <0=> GPIO <1=> --- <2=> XAD9 <3=> PLAO[9]
  121. ;// <o.8..9> P4.2 <0=> GPIO <1=> --- <2=> XAD10 <3=> PLAO[10]
  122. ;// <o.12..13> P4.3 <0=> GPIO <1=> --- <2=> XAD11 <3=> PLAO[11]
  123. ;// <o.16..17> P4.4 <0=> GPIO <1=> --- <2=> XAD12 <3=> PLAO[12]
  124. ;// <o.20..21> P4.5 <0=> GPIO <1=> --- <2=> XAD13 <3=> PLAO[13]
  125. ;// <o.24..25> P4.6 <0=> GPIO <1=> --- <2=> XAD14 <3=> PLAO[14]
  126. ;// <o.28..29> P4.7 <0=> GPIO <1=> --- <2=> XAD15 <3=> PLAO[15]
  127. ;// </h>
  128. GP4CON_Val EQU 0x00000000
  129. ;// </e>
  130. ;// <e> External Memory Interface
  131. XM_SETUP EQU 0
  132. XMBASE EQU 0xFFFFF000
  133. ;// <e.0> Enable Memory Region 0
  134. ;// <o.1> Data Bus Width <0=> 8-bit <1=> 16-bit
  135. ;// <o1.11> Enable Dynamic Addressing
  136. ;// <o1.15> Byte Enabled Write Strobe
  137. ;// <o1.10> Disable extra Address Latch Hold Cycle
  138. ;// <o1.8> Disable extra Write Address Hold Cycle
  139. ;// <o1.9> Disable Read Bus Turn Cycle
  140. ;// <o1.12..14> Address Wait States <0-7>
  141. ;// <i> Number of Wait States added for AE
  142. ;// <o1.0..3> Read Wait States <0-15>
  143. ;// <i> Number of Wait States added for RS
  144. ;// <o1.4..7> Write Wait States <0-15>
  145. ;// <i> Number of Wait States added for WS
  146. ;// </e>
  147. XM0CON_Val EQU 0x00000000
  148. XM0PAR_Val EQU 0x000070FF
  149. ;// <e.0> Enable Memory Region 1
  150. ;// <o.1> Data Bus Width <0=> 8-bit <1=> 16-bit
  151. ;// <o1.11> Enable Dynamic Addressing
  152. ;// <o1.15> Byte Enabled Write Strobe
  153. ;// <o1.10> Disable extra Address Latch Hold Cycle
  154. ;// <o1.8> Disable extra Write Address Hold Cycle
  155. ;// <o1.9> Disable Read Bus Turn Cycle
  156. ;// <o1.12..14> Address Wait States <0-7>
  157. ;// <i> Number of Wait States added for AE
  158. ;// <o1.0..3> Read Wait States <0-15>
  159. ;// <i> Number of Wait States added for RS
  160. ;// <o1.4..7> Write Wait States <0-15>
  161. ;// <i> Number of Wait States added for WS
  162. ;// </e>
  163. XM1CON_Val EQU 0x00000000
  164. XM1PAR_Val EQU 0x000070FF
  165. ;// <e.0> Enable Memory Region 2
  166. ;// <o.1> Data Bus Width <0=> 8-bit <1=> 16-bit
  167. ;// <o1.11> Enable Dynamic Addressing
  168. ;// <o1.15> Byte Enabled Write Strobe
  169. ;// <o1.10> Disable extra Address Latch Hold Cycle
  170. ;// <o1.8> Disable extra Write Address Hold Cycle
  171. ;// <o1.9> Disable Read Bus Turn Cycle
  172. ;// <o1.12..14> Address Wait States <0-7>
  173. ;// <i> Number of Wait States added for AE
  174. ;// <o1.0..3> Read Wait States <0-15>
  175. ;// <i> Number of Wait States added for RS
  176. ;// <o1.4..7> Write Wait States <0-15>
  177. ;// <i> Number of Wait States added for WS
  178. ;// </e>
  179. XM2CON_Val EQU 0x00000000
  180. XM2PAR_Val EQU 0x000070FF
  181. ;// <e.0> Enable Memory Region 3
  182. ;// <o.1> Data Bus Width <0=> 8-bit <1=> 16-bit
  183. ;// <o1.11> Enable Dynamic Addressing
  184. ;// <o1.15> Byte Enabled Write Strobe
  185. ;// <o1.10> Disable extra Address Latch Hold Cycle
  186. ;// <o1.8> Disable extra Write Address Hold Cycle
  187. ;// <o1.9> Disable Read Bus Turn Cycle
  188. ;// <o1.12..14> Address Wait States <0-7>
  189. ;// <i> Number of Wait States added for AE
  190. ;// <o1.0..3> Read Wait States <0-15>
  191. ;// <i> Number of Wait States added for RS
  192. ;// <o1.4..7> Write Wait States <0-15>
  193. ;// <i> Number of Wait States added for WS
  194. ;// </e>
  195. XM3CON_Val EQU 0x00000000
  196. XM3PAR_Val EQU 0x000070FF
  197. ;// <e.0> Memory Muxed Mode
  198. XMCFG_Val EQU 0x00000001
  199. ;// </e>
  200. ;// </e>
  201. PRESERVE8
  202. ; Area Definition and Entry Point
  203. ; Startup Code must be linked first at Address at which it expects to run.
  204. AREA Reset, CODE, READONLY
  205. ARM
  206. ; Exception Vectors
  207. ; Mapped to Address 0.
  208. ; Absolute addressing mode must be used.
  209. ; Dummy Handlers are implemented as infinite loops which can be modified.
  210. Vectors LDR PC, Reset_Addr
  211. LDR PC, Undef_Addr
  212. LDR PC, SWI_Addr
  213. LDR PC, PAbt_Addr
  214. LDR PC, DAbt_Addr
  215. DCD 0xFFFFFFFF ; Reserved Vector
  216. LDR PC, IRQ_Addr
  217. LDR PC, FIQ_Addr
  218. EXTERN Undef_Handler
  219. EXTERN SWI_Handler
  220. EXTERN PAbt_Handler
  221. EXTERN DAbt_Handler
  222. EXTERN IRQ_Handler
  223. EXTERN FIQ_Handler
  224. Reset_Addr DCD Reset_Handler
  225. Undef_Addr DCD Undef_Handler
  226. SWI_Addr DCD SWI_Handler
  227. PAbt_Addr DCD PAbt_Handler
  228. DAbt_Addr DCD DAbt_Handler
  229. DCD 0xFFFFFFFF ; Reserved Address
  230. IRQ_Addr DCD IRQ_Handler
  231. FIQ_Addr DCD FIQ_Handler
  232. ; Reset Handler
  233. EXPORT Reset_Handler
  234. Reset_Handler
  235. ; Setup PLL
  236. IF PLL_SETUP <> 0
  237. LDR R0, =MMR_BASE
  238. MOV R1, #0x01
  239. STR R1, [R0,#POWKEY1_OFFSET]
  240. MOV R1, #PLLCFG_Val
  241. STR R1, [R0,#POWCON_OFFSET]
  242. MOV R1, #0xF4
  243. STR R1, [R0,#POWKEY2_OFFSET]
  244. ENDIF ; PLL_SETUP
  245. ; Setup Pins
  246. IF GPIO_SETUP <> 0
  247. ADR R10, GPIO_CFG ; Pointer to GPIO CFG
  248. LDMIA R10, {R0-R5} ; Load GPIO Configuration
  249. STMIA R0, {R1-R5} ; Store GPxCON
  250. B GPIO_END
  251. GPIO_CFG DCD GPIOBASE
  252. DCD GP0CON_Val
  253. DCD GP1CON_Val
  254. DCD GP2CON_Val
  255. DCD GP3CON_Val
  256. DCD GP4CON_Val
  257. GPIO_END
  258. ENDIF ; GPIO_SETUP
  259. ; Setup External Memory Interface
  260. IF XM_SETUP <> 0
  261. ADR R10, XM_CFG ; Pointer to XM CFG
  262. LDMIA R10, {R0-R9} ; Load XM Configuration
  263. STR R1, [R0],#0x10 ; Store XMCFG
  264. STMIA R0, {R2-R9} ; Store XMxCON & XMxPAR
  265. B XM_END
  266. XM_CFG DCD XMBASE
  267. DCD XMCFG_Val
  268. DCD XM0CON_Val
  269. DCD XM1CON_Val
  270. DCD XM2CON_Val
  271. DCD XM3CON_Val
  272. DCD XM0PAR_Val
  273. DCD XM1PAR_Val
  274. DCD XM2PAR_Val
  275. DCD XM3PAR_Val
  276. XM_END
  277. ENDIF ; XM_SETUP
  278. ; Copy Exception Vectors to Internal RAM and Remap Memory
  279. ; (when Interrupt Vectors are in RAM)
  280. IF :DEF:RAM_INTVEC
  281. ADR R8, Vectors ; Source
  282. LDR R9, =0x00010000 ; Destination
  283. LDMIA R8!, {R0-R7} ; Load Vectors
  284. STMIA R9!, {R0-R7} ; Store Vectors
  285. LDMIA R8!, {R0-R7} ; Load Handler Addresses
  286. STMIA R9!, {R0-R7} ; Store Handler Addresses
  287. LDR R0, =MMR_BASE
  288. MOV R1, #1
  289. STR R1, [R0,#REMAP_OFFSET]
  290. ENDIF
  291. ; Setup Stack for each mode
  292. LDR R0, =Stack_Top
  293. ; Enter Undefined Instruction Mode and set its Stack Pointer
  294. MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  295. MOV SP, R0
  296. SUB R0, R0, #UND_Stack_Size
  297. ; Enter Abort Mode and set its Stack Pointer
  298. MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  299. MOV SP, R0
  300. SUB R0, R0, #ABT_Stack_Size
  301. ; Enter FIQ Mode and set its Stack Pointer
  302. MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  303. MOV SP, R0
  304. SUB R0, R0, #FIQ_Stack_Size
  305. ; Enter IRQ Mode and set its Stack Pointer
  306. MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  307. MOV SP, R0
  308. SUB R0, R0, #IRQ_Stack_Size
  309. ; Enter Supervisor Mode and set its Stack Pointer
  310. MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  311. MOV SP, R0
  312. SUB R0, R0, #SVC_Stack_Size
  313. ; Enter User Mode and set its Stack Pointer
  314. MSR CPSR_c, #Mode_USR
  315. MOV SP, R0
  316. SUB SL, SP, #USR_Stack_Size
  317. ; Enter the C code
  318. IMPORT __main
  319. LDR R0, =__main
  320. BX R0
  321. ; User Initial Stack & Heap
  322. AREA |.text|, CODE, READONLY
  323. IMPORT __use_two_region_memory
  324. EXPORT __user_initial_stackheap
  325. __user_initial_stackheap
  326. LDR R0, = Heap_Mem
  327. LDR R1, =(Stack_Mem + USR_Stack_Size)
  328. LDR R2, = (Heap_Mem + Heap_Size)
  329. LDR R3, = Stack_Mem
  330. BX LR
  331. END