start_rvds.S 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  1. ;/*
  2. ; * Copyright (c) 2006-2018, RT-Thread Development Team
  3. ; *
  4. ; * SPDX-License-Identifier: Apache-2.0
  5. ; *
  6. ; * Change Logs:
  7. ; * Date Author Notes
  8. ; */
  9. ;
  10. ;/*****************************************************************************/
  11. ;/* LPC2400.S: Startup file for Philips LPC2400 device series */
  12. ;/*****************************************************************************/
  13. ;/* <<< Use Configuration Wizard in Context Menu >>> */
  14. ;/*****************************************************************************/
  15. ;/* This file is part of the uVision/ARM development tools. */
  16. ;/* Copyright (c) 2007-2008 Keil - An ARM Company. All rights reserved. */
  17. ;/* This software may only be used under the terms of a valid, current, */
  18. ;/* end user licence from KEIL for a compatible version of KEIL software */
  19. ;/* development tools. Nothing else gives you the right to use this software. */
  20. ;/*****************************************************************************/
  21. ;/*
  22. ; * The LPC2400.S code is executed after CPU Reset. This file may be
  23. ; * translated with the following SET symbols. In uVision these SET
  24. ; * symbols are entered under Options - ASM - Define.
  25. ; *
  26. ; * NO_CLOCK_SETUP: when set the startup code will not initialize Clock
  27. ; * (used mostly when clock is already initialized from script .ini
  28. ; * file).
  29. ; *
  30. ; * NO_EMC_SETUP: when set the startup code will not initialize
  31. ; * External Bus Controller.
  32. ; *
  33. ; * RAM_INTVEC: when set the startup code copies exception vectors
  34. ; * from on-chip Flash to on-chip RAM.
  35. ; *
  36. ; * REMAP: when set the startup code initializes the register MEMMAP
  37. ; * which overwrites the settings of the CPU configuration pins. The
  38. ; * startup and interrupt vectors are remapped from:
  39. ; * 0x00000000 default setting (not remapped)
  40. ; * 0x40000000 when RAM_MODE is used
  41. ; * 0x80000000 when EXTMEM_MODE is used
  42. ; *
  43. ; * EXTMEM_MODE: when set the device is configured for code execution
  44. ; * from external memory starting at address 0x80000000.
  45. ; *
  46. ; * RAM_MODE: when set the device is configured for code execution
  47. ; * from on-chip RAM starting at address 0x40000000.
  48. ; */
  49. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  50. Mode_USR EQU 0x10
  51. Mode_FIQ EQU 0x11
  52. Mode_IRQ EQU 0x12
  53. Mode_SVC EQU 0x13
  54. Mode_ABT EQU 0x17
  55. Mode_UND EQU 0x1B
  56. Mode_SYS EQU 0x1F
  57. I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
  58. F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
  59. ;----------------------- Memory Definitions ------------------------------------
  60. ; Internal Memory Base Addresses
  61. FLASH_BASE EQU 0x00000000
  62. RAM_BASE EQU 0x40000000
  63. EXTMEM_BASE EQU 0x80000000
  64. ; External Memory Base Addresses
  65. STA_MEM0_BASE EQU 0x80000000
  66. STA_MEM1_BASE EQU 0x81000000
  67. STA_MEM2_BASE EQU 0x82000000
  68. STA_MEM3_BASE EQU 0x83000000
  69. DYN_MEM0_BASE EQU 0xA0000000
  70. DYN_MEM1_BASE EQU 0xB0000000
  71. DYN_MEM2_BASE EQU 0xC0000000
  72. DYN_MEM3_BASE EQU 0xD0000000
  73. ;----------------------- Stack and Heap Definitions ----------------------------
  74. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  75. ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8>
  76. ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8>
  77. ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8>
  78. ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  79. ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8>
  80. ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8>
  81. ;// </h>
  82. UND_Stack_Size EQU 0x00000000
  83. SVC_Stack_Size EQU 0x00000100
  84. ABT_Stack_Size EQU 0x00000000
  85. FIQ_Stack_Size EQU 0x00000000
  86. IRQ_Stack_Size EQU 0x00000100
  87. USR_Stack_Size EQU 0x00000100
  88. ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
  89. FIQ_Stack_Size + IRQ_Stack_Size)
  90. AREA STACK, NOINIT, READWRITE, ALIGN=3
  91. Stack_Mem SPACE USR_Stack_Size
  92. __initial_sp SPACE ISR_Stack_Size
  93. Stack_Top
  94. ;// <h> Heap Configuration
  95. ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  96. ;// </h>
  97. Heap_Size EQU 0x00000000
  98. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  99. __heap_base
  100. Heap_Mem SPACE Heap_Size
  101. __heap_limit
  102. ;----------------------- Clock Definitions -------------------------------------
  103. ; System Control Block (SCB) Module Definitions
  104. SCB_BASE EQU 0xE01FC000 ; SCB Base Address
  105. PLLCON_OFS EQU 0x80 ; PLL Control Offset
  106. PLLCFG_OFS EQU 0x84 ; PLL Configuration Offset
  107. PLLSTAT_OFS EQU 0x88 ; PLL Status Offset
  108. PLLFEED_OFS EQU 0x8C ; PLL Feed Offset
  109. CCLKCFG_OFS EQU 0x104 ; CPU Clock Divider Reg Offset
  110. USBCLKCFG_OFS EQU 0x108 ; USB Clock Divider Reg Offset
  111. CLKSRCSEL_OFS EQU 0x10C ; Clock Source Sel Reg Offset
  112. SCS_OFS EQU 0x1A0 ; Sys Control and Status Reg Offset
  113. PCLKSEL0_OFS EQU 0x1A8 ; Periph Clock Sel Reg 0 Offset
  114. PCLKSEL1_OFS EQU 0x1AC ; Periph Clock Sel Reg 0 Offset
  115. PCON_OFS EQU 0x0C0 ; Power Mode Control Reg Offset
  116. PCONP_OFS EQU 0x0C4 ; Power Control for Periphs Reg Offset
  117. ; Constants
  118. OSCRANGE EQU (1<<4) ; Oscillator Range Select
  119. OSCEN EQU (1<<5) ; Main oscillator Enable
  120. OSCSTAT EQU (1<<6) ; Main Oscillator Status
  121. PLLCON_PLLE EQU (1<<0) ; PLL Enable
  122. PLLCON_PLLC EQU (1<<1) ; PLL Connect
  123. PLLSTAT_M EQU (0x7FFF<<0) ; PLL M Value
  124. PLLSTAT_N EQU (0xFF<<16) ; PLL N Value
  125. PLLSTAT_PLOCK EQU (1<<26) ; PLL Lock Status
  126. ;// <e> Clock Setup
  127. ;// <h> System Controls and Status Register (SYS)
  128. ;// <o1.4> OSCRANGE: Main Oscillator Range Select
  129. ;// <0=> 1 MHz to 20 MHz
  130. ;// <1=> 15 MHz to 24 MHz
  131. ;// <e1.5> OSCEN: Main Oscillator Enable
  132. ;// </e>
  133. ;// </h>
  134. ;//
  135. ;// <h> PLL Clock Source Select Register (CLKSRCSEL)
  136. ;// <o2.0..1> CLKSRC: PLL Clock Source Selection
  137. ;// <0=> Internal RC oscillator
  138. ;// <1=> Main oscillator
  139. ;// <2=> RTC oscillator
  140. ;// </h>
  141. ;//
  142. ;// <h> PLL Configuration Register (PLLCFG)
  143. ;// <i> PLL_clk = (2* M * PLL_clk_src) / N
  144. ;// <o3.0..14> MSEL: PLL Multiplier Selection
  145. ;// <1-32768><#-1>
  146. ;// <i> M Value
  147. ;// <o3.16..23> NSEL: PLL Divider Selection
  148. ;// <1-256><#-1>
  149. ;// <i> N Value
  150. ;// </h>
  151. ;//
  152. ;// <h> CPU Clock Configuration Register (CCLKCFG)
  153. ;// <o4.0..7> CCLKSEL: Divide Value for CPU Clock from PLL
  154. ;// <1-256><#-1>
  155. ;// </h>
  156. ;//
  157. ;// <h> USB Clock Configuration Register (USBCLKCFG)
  158. ;// <o5.0..3> USBSEL: Divide Value for USB Clock from PLL
  159. ;// <1-16><#-1>
  160. ;// </h>
  161. ;//
  162. ;// <h> Peripheral Clock Selection Register 0 (PCLKSEL0)
  163. ;// <o6.0..1> PCLK_WDT: Peripheral Clock Selection for WDT
  164. ;// <0=> Pclk = Cclk / 4
  165. ;// <1=> Pclk = Cclk
  166. ;// <2=> Pclk = Cclk / 2
  167. ;// <3=> Pclk = Cclk / 8
  168. ;// <o6.2..3> PCLK_TIMER0: Peripheral Clock Selection for TIMER0
  169. ;// <0=> Pclk = Cclk / 4
  170. ;// <1=> Pclk = Cclk
  171. ;// <2=> Pclk = Cclk / 2
  172. ;// <3=> Pclk = Cclk / 8
  173. ;// <o6.4..5> PCLK_TIMER1: Peripheral Clock Selection for TIMER1
  174. ;// <0=> Pclk = Cclk / 4
  175. ;// <1=> Pclk = Cclk
  176. ;// <2=> Pclk = Cclk / 2
  177. ;// <3=> Pclk = Cclk / 8
  178. ;// <o6.6..7> PCLK_UART0: Peripheral Clock Selection for UART0
  179. ;// <0=> Pclk = Cclk / 4
  180. ;// <1=> Pclk = Cclk
  181. ;// <2=> Pclk = Cclk / 2
  182. ;// <3=> Pclk = Cclk / 8
  183. ;// <o6.8..9> PCLK_UART1: Peripheral Clock Selection for UART1
  184. ;// <0=> Pclk = Cclk / 4
  185. ;// <1=> Pclk = Cclk
  186. ;// <2=> Pclk = Cclk / 2
  187. ;// <3=> Pclk = Cclk / 8
  188. ;// <o6.10..11> PCLK_PWM0: Peripheral Clock Selection for PWM0
  189. ;// <0=> Pclk = Cclk / 4
  190. ;// <1=> Pclk = Cclk
  191. ;// <2=> Pclk = Cclk / 2
  192. ;// <3=> Pclk = Cclk / 8
  193. ;// <o6.12..13> PCLK_PWM1: Peripheral Clock Selection for PWM1
  194. ;// <0=> Pclk = Cclk / 4
  195. ;// <1=> Pclk = Cclk
  196. ;// <2=> Pclk = Cclk / 2
  197. ;// <3=> Pclk = Cclk / 8
  198. ;// <o6.14..15> PCLK_I2C0: Peripheral Clock Selection for I2C0
  199. ;// <0=> Pclk = Cclk / 4
  200. ;// <1=> Pclk = Cclk
  201. ;// <2=> Pclk = Cclk / 2
  202. ;// <3=> Pclk = Cclk / 8
  203. ;// <o6.16..17> PCLK_SPI: Peripheral Clock Selection for SPI
  204. ;// <0=> Pclk = Cclk / 4
  205. ;// <1=> Pclk = Cclk
  206. ;// <2=> Pclk = Cclk / 2
  207. ;// <3=> Pclk = Cclk / 8
  208. ;// <o6.18..19> PCLK_RTC: Peripheral Clock Selection for RTC
  209. ;// <0=> Pclk = Cclk / 4
  210. ;// <1=> Pclk = Cclk
  211. ;// <2=> Pclk = Cclk / 2
  212. ;// <3=> Pclk = Cclk / 8
  213. ;// <o6.20..21> PCLK_SSP1: Peripheral Clock Selection for SSP1
  214. ;// <0=> Pclk = Cclk / 4
  215. ;// <1=> Pclk = Cclk
  216. ;// <2=> Pclk = Cclk / 2
  217. ;// <3=> Pclk = Cclk / 8
  218. ;// <o6.22..23> PCLK_DAC: Peripheral Clock Selection for DAC
  219. ;// <0=> Pclk = Cclk / 4
  220. ;// <1=> Pclk = Cclk
  221. ;// <2=> Pclk = Cclk / 2
  222. ;// <3=> Pclk = Cclk / 8
  223. ;// <o6.24..25> PCLK_ADC: Peripheral Clock Selection for ADC
  224. ;// <0=> Pclk = Cclk / 4
  225. ;// <1=> Pclk = Cclk
  226. ;// <2=> Pclk = Cclk / 2
  227. ;// <3=> Pclk = Cclk / 8
  228. ;// <o6.26..27> PCLK_CAN1: Peripheral Clock Selection for CAN1
  229. ;// <0=> Pclk = Cclk / 4
  230. ;// <1=> Pclk = Cclk
  231. ;// <2=> Pclk = Cclk / 2
  232. ;// <3=> Pclk = Cclk / 6
  233. ;// <o6.28..29> PCLK_CAN2: Peripheral Clock Selection for CAN2
  234. ;// <0=> Pclk = Cclk / 4
  235. ;// <1=> Pclk = Cclk
  236. ;// <2=> Pclk = Cclk / 2
  237. ;// <3=> Pclk = Cclk / 6
  238. ;// <o6.30..31> PCLK_ACF: Peripheral Clock Selection for ACF
  239. ;// <0=> Pclk = Cclk / 4
  240. ;// <1=> Pclk = Cclk
  241. ;// <2=> Pclk = Cclk / 2
  242. ;// <3=> Pclk = Cclk / 6
  243. ;// </h>
  244. ;//
  245. ;// <h> Peripheral Clock Selection Register 1 (PCLKSEL1)
  246. ;// <o7.0..1> PCLK_BAT_RAM: Peripheral Clock Selection for the Battery Supported RAM
  247. ;// <0=> Pclk = Cclk / 4
  248. ;// <1=> Pclk = Cclk
  249. ;// <2=> Pclk = Cclk / 2
  250. ;// <3=> Pclk = Cclk / 8
  251. ;// <o7.2..3> PCLK_GPIO: Peripheral Clock Selection for GPIOs
  252. ;// <0=> Pclk = Cclk / 4
  253. ;// <1=> Pclk = Cclk
  254. ;// <2=> Pclk = Cclk / 2
  255. ;// <3=> Pclk = Cclk / 8
  256. ;// <o7.4..5> PCLK_PCB: Peripheral Clock Selection for Pin Connect Block
  257. ;// <0=> Pclk = Cclk / 4
  258. ;// <1=> Pclk = Cclk
  259. ;// <2=> Pclk = Cclk / 2
  260. ;// <3=> Pclk = Cclk / 8
  261. ;// <o7.6..7> PCLK_I2C1: Peripheral Clock Selection for I2C1
  262. ;// <0=> Pclk = Cclk / 4
  263. ;// <1=> Pclk = Cclk
  264. ;// <2=> Pclk = Cclk / 2
  265. ;// <3=> Pclk = Cclk / 8
  266. ;// <o7.10..11> PCLK_SSP0: Peripheral Clock Selection for SSP0
  267. ;// <0=> Pclk = Cclk / 4
  268. ;// <1=> Pclk = Cclk
  269. ;// <2=> Pclk = Cclk / 2
  270. ;// <3=> Pclk = Cclk / 8
  271. ;// <o7.12..13> PCLK_TIMER2: Peripheral Clock Selection for TIMER2
  272. ;// <0=> Pclk = Cclk / 4
  273. ;// <1=> Pclk = Cclk
  274. ;// <2=> Pclk = Cclk / 2
  275. ;// <3=> Pclk = Cclk / 8
  276. ;// <o7.14..15> PCLK_TIMER3: Peripheral Clock Selection for TIMER3
  277. ;// <0=> Pclk = Cclk / 4
  278. ;// <1=> Pclk = Cclk
  279. ;// <2=> Pclk = Cclk / 2
  280. ;// <3=> Pclk = Cclk / 8
  281. ;// <o7.16..17> PCLK_UART2: Peripheral Clock Selection for UART2
  282. ;// <0=> Pclk = Cclk / 4
  283. ;// <1=> Pclk = Cclk
  284. ;// <2=> Pclk = Cclk / 2
  285. ;// <3=> Pclk = Cclk / 8
  286. ;// <o7.18..19> PCLK_UART3: Peripheral Clock Selection for UART3
  287. ;// <0=> Pclk = Cclk / 4
  288. ;// <1=> Pclk = Cclk
  289. ;// <2=> Pclk = Cclk / 2
  290. ;// <3=> Pclk = Cclk / 8
  291. ;// <o7.20..21> PCLK_I2C2: Peripheral Clock Selection for I2C2
  292. ;// <0=> Pclk = Cclk / 4
  293. ;// <1=> Pclk = Cclk
  294. ;// <2=> Pclk = Cclk / 2
  295. ;// <3=> Pclk = Cclk / 8
  296. ;// <o7.22..23> PCLK_I2S: Peripheral Clock Selection for I2S
  297. ;// <0=> Pclk = Cclk / 4
  298. ;// <1=> Pclk = Cclk
  299. ;// <2=> Pclk = Cclk / 2
  300. ;// <3=> Pclk = Cclk / 8
  301. ;// <o7.24..25> PCLK_MCI: Peripheral Clock Selection for MCI
  302. ;// <0=> Pclk = Cclk / 4
  303. ;// <1=> Pclk = Cclk
  304. ;// <2=> Pclk = Cclk / 2
  305. ;// <3=> Pclk = Cclk / 8
  306. ;// <o7.28..29> PCLK_SYSCON: Peripheral Clock Selection for System Control Block
  307. ;// <0=> Pclk = Cclk / 4
  308. ;// <1=> Pclk = Cclk
  309. ;// <2=> Pclk = Cclk / 2
  310. ;// <3=> Pclk = Cclk / 8
  311. ;// </h>
  312. ;// </e>
  313. CLOCK_SETUP EQU 1
  314. SCS_Val EQU 0x00000020
  315. CLKSRCSEL_Val EQU 0x00000001
  316. PLLCFG_Val EQU 0x0000000B
  317. CCLKCFG_Val EQU 0x00000004
  318. USBCLKCFG_Val EQU 0x00000005
  319. PCLKSEL0_Val EQU 0x00000000
  320. PCLKSEL1_Val EQU 0x00000000
  321. ;----------------------- Memory Accelerator Module (MAM) Definitions -----------
  322. MAM_BASE EQU 0xE01FC000 ; MAM Base Address
  323. MAMCR_OFS EQU 0x00 ; MAM Control Offset
  324. MAMTIM_OFS EQU 0x04 ; MAM Timing Offset
  325. ;// <e> MAM Setup
  326. ;// <o1.0..1> MAM Control
  327. ;// <0=> Disabled
  328. ;// <1=> Partially Enabled
  329. ;// <2=> Fully Enabled
  330. ;// <i> Mode
  331. ;// <o2.0..2> MAM Timing
  332. ;// <0=> Reserved <1=> 1 <2=> 2 <3=> 3
  333. ;// <4=> 4 <5=> 5 <6=> 6 <7=> 7
  334. ;// <i> Fetch Cycles
  335. ;// </e>
  336. MAM_SETUP EQU 1
  337. MAMCR_Val EQU 0x00000002
  338. MAMTIM_Val EQU 0x00000004
  339. ;----------------------- Pin Connect Block Definitions -------------------------
  340. PCB_BASE EQU 0xE002C000 ; PCB Base Address
  341. PINSEL0_OFS EQU 0x00 ; PINSEL0 Address Offset
  342. PINSEL1_OFS EQU 0x04 ; PINSEL1 Address Offset
  343. PINSEL2_OFS EQU 0x08 ; PINSEL2 Address Offset
  344. PINSEL3_OFS EQU 0x0C ; PINSEL3 Address Offset
  345. PINSEL4_OFS EQU 0x10 ; PINSEL4 Address Offset
  346. PINSEL5_OFS EQU 0x14 ; PINSEL5 Address Offset
  347. PINSEL6_OFS EQU 0x18 ; PINSEL6 Address Offset
  348. PINSEL7_OFS EQU 0x1C ; PINSEL7 Address Offset
  349. PINSEL8_OFS EQU 0x20 ; PINSEL8 Address Offset
  350. PINSEL9_OFS EQU 0x24 ; PINSEL9 Address Offset
  351. PINSEL10_OFS EQU 0x28 ; PINSEL10 Address Offset
  352. ;----------------------- External Memory Controller (EMC) Definitons -----------
  353. EMC_BASE EQU 0xFFE08000 ; EMC Base Address
  354. EMC_CTRL_OFS EQU 0x000
  355. EMC_STAT_OFS EQU 0x004
  356. EMC_CONFIG_OFS EQU 0x008
  357. EMC_DYN_CTRL_OFS EQU 0x020
  358. EMC_DYN_RFSH_OFS EQU 0x024
  359. EMC_DYN_RD_CFG_OFS EQU 0x028
  360. EMC_DYN_RP_OFS EQU 0x030
  361. EMC_DYN_RAS_OFS EQU 0x034
  362. EMC_DYN_SREX_OFS EQU 0x038
  363. EMC_DYN_APR_OFS EQU 0x03C
  364. EMC_DYN_DAL_OFS EQU 0x040
  365. EMC_DYN_WR_OFS EQU 0x044
  366. EMC_DYN_RC_OFS EQU 0x048
  367. EMC_DYN_RFC_OFS EQU 0x04C
  368. EMC_DYN_XSR_OFS EQU 0x050
  369. EMC_DYN_RRD_OFS EQU 0x054
  370. EMC_DYN_MRD_OFS EQU 0x058
  371. EMC_DYN_CFG0_OFS EQU 0x100
  372. EMC_DYN_RASCAS0_OFS EQU 0x104
  373. EMC_DYN_CFG1_OFS EQU 0x140
  374. EMC_DYN_RASCAS1_OFS EQU 0x144
  375. EMC_DYN_CFG2_OFS EQU 0x160
  376. EMC_DYN_RASCAS2_OFS EQU 0x164
  377. EMC_DYN_CFG3_OFS EQU 0x180
  378. EMC_DYN_RASCAS3_OFS EQU 0x184
  379. EMC_STA_CFG0_OFS EQU 0x200
  380. EMC_STA_WWEN0_OFS EQU 0x204
  381. EMC_STA_WOEN0_OFS EQU 0x208
  382. EMC_STA_WRD0_OFS EQU 0x20C
  383. EMC_STA_WPAGE0_OFS EQU 0x210
  384. EMC_STA_WWR0_OFS EQU 0x214
  385. EMC_STA_WTURN0_OFS EQU 0x218
  386. EMC_STA_CFG1_OFS EQU 0x220
  387. EMC_STA_WWEN1_OFS EQU 0x224
  388. EMC_STA_WOEN1_OFS EQU 0x228
  389. EMC_STA_WRD1_OFS EQU 0x22C
  390. EMC_STA_WPAGE1_OFS EQU 0x230
  391. EMC_STA_WWR1_OFS EQU 0x234
  392. EMC_STA_WTURN1_OFS EQU 0x238
  393. EMC_STA_CFG2_OFS EQU 0x240
  394. EMC_STA_WWEN2_OFS EQU 0x244
  395. EMC_STA_WOEN2_OFS EQU 0x248
  396. EMC_STA_WRD2_OFS EQU 0x24C
  397. EMC_STA_WPAGE2_OFS EQU 0x250
  398. EMC_STA_WWR2_OFS EQU 0x254
  399. EMC_STA_WTURN2_OFS EQU 0x258
  400. EMC_STA_CFG3_OFS EQU 0x260
  401. EMC_STA_WWEN3_OFS EQU 0x264
  402. EMC_STA_WOEN3_OFS EQU 0x268
  403. EMC_STA_WRD3_OFS EQU 0x26C
  404. EMC_STA_WPAGE3_OFS EQU 0x270
  405. EMC_STA_WWR3_OFS EQU 0x274
  406. EMC_STA_WTURN3_OFS EQU 0x278
  407. EMC_STA_EXT_W_OFS EQU 0x880
  408. ; Constants
  409. NORMAL_CMD EQU (0x0 << 7) ; NORMAL Command
  410. MODE_CMD EQU (0x1 << 7) ; MODE Command
  411. PALL_CMD EQU (0x2 << 7) ; Precharge All Command
  412. NOP_CMD EQU (0x3 << 7) ; NOP Command
  413. BUFEN_Const EQU (1 << 19) ; Buffer enable bit
  414. EMC_PCONP_Const EQU (1 << 11) ; PCONP val to enable power for EMC
  415. ; External Memory Pins definitions
  416. ; pin functions for SDRAM, NOR and NAND flash interfacing
  417. EMC_PINSEL5_Val EQU 0x05010115 ; !CAS, !RAS, CLKOUT0, !DYCS0, DQMOUT0, DQMOUT1
  418. EMC_PINSEL6_Val EQU 0x55555555 ; D0 .. D15
  419. EMC_PINSEL8_Val EQU 0x55555555 ; A0 .. A15
  420. EMC_PINSEL9_Val EQU 0x50055555; ; A16 .. A23, !OE, !WE, !CS0, !CS1
  421. ;// External Memory Controller Setup (EMC) ---------------------------------
  422. ;// <e> External Memory Controller Setup (EMC)
  423. EMC_SETUP EQU 0
  424. ;// <h> EMC Control Register (EMCControl)
  425. ;// <i> Controls operation of the memory controller
  426. ;// <o0.2> L: Low-power mode enable
  427. ;// <o0.1> M: Address mirror enable
  428. ;// <o0.0> E: EMC enable
  429. ;// </h>
  430. EMC_CTRL_Val EQU 0x00000001
  431. ;// <h> EMC Configuration Register (EMCConfig)
  432. ;// <i> Configures operation of the memory controller
  433. ;// <o0.8> CCLK: CLKOUT ratio
  434. ;// <0=> 1:1
  435. ;// <1=> 1:2
  436. ;// <o0.0> Endian mode
  437. ;// <0=> Little-endian
  438. ;// <1=> Big-endian
  439. ;// </h>
  440. EMC_CONFIG_Val EQU 0x00000000
  441. ;// Dynamic Memory Interface Setup ---------------------------------------
  442. ;// <e> Dynamic Memory Interface Setup
  443. EMC_DYNAMIC_SETUP EQU 1
  444. ;// <h> Dynamic Memory Refresh Timer Register (EMCDynamicRefresh)
  445. ;// <i> Configures dynamic memory refresh operation
  446. ;// <o0.0..10> REFRESH: Refresh timer <0x000-0x7FF>
  447. ;// <i> 0 = refresh disabled, 0x01-0x7FF: value * 16 CCLKS
  448. ;// </h>
  449. EMC_DYN_RFSH_Val EQU 0x0000001C
  450. ;// <h> Dynamic Memory Read Configuration Register (EMCDynamicReadConfig)
  451. ;// <i> Configures the dynamic memory read strategy
  452. ;// <o0.0..1> RD: Read data strategy
  453. ;// <0=> Clock out delayed strategy
  454. ;// <1=> Command delayed strategy
  455. ;// <2=> Command delayed strategy plus one clock cycle
  456. ;// <3=> Command delayed strategy plus two clock cycles
  457. ;// </h>
  458. EMC_DYN_RD_CFG_Val EQU 0x00000001
  459. ;// <h> Dynamic Memory Timings
  460. ;// <h> Dynamic Memory Percentage Command Period Register (EMCDynamictRP)
  461. ;// <o0.0..3> tRP: Precharge command period <1-16> <#-1>
  462. ;// <i> The delay is in EMCCLK cycles
  463. ;// <i> This value is normally found in SDRAM data sheets as tRP
  464. ;// </h>
  465. ;// <h> Dynamic Memory Active to Precharge Command Period Register (EMCDynamictRAS)
  466. ;// <o1.0..3> tRAS: Active to precharge command period <1-16> <#-1>
  467. ;// <i> The delay is in EMCCLK cycles
  468. ;// <i> This value is normally found in SDRAM data sheets as tRAS
  469. ;// </h>
  470. ;// <h> Dynamic Memory Self-refresh Exit Time Register (EMCDynamictSREX)
  471. ;// <o2.0..3> tSREX: Self-refresh exit time <1-16> <#-1>
  472. ;// <i> The delay is in CCLK cycles
  473. ;// <i> This value is normally found in SDRAM data sheets as tSREX,
  474. ;// <i> for devices without this parameter you use the same value as tXSR
  475. ;// </h>
  476. ;// <h> Dynamic Memory Last Data Out to Active Time Register (EMCDynamictAPR)
  477. ;// <o3.0..3> tAPR: Last-data-out to active command time <1-16> <#-1>
  478. ;// <i> The delay is in CCLK cycles
  479. ;// <i> This value is normally found in SDRAM data sheets as tAPR
  480. ;// </h>
  481. ;// <h> Dynamic Memory Data-in to Active Command Time Register (EMCDynamictDAL)
  482. ;// <o4.0..3> tDAL: Data-in to active command time <1-16> <#-1>
  483. ;// <i> The delay is in CCLK cycles
  484. ;// <i> This value is normally found in SDRAM data sheets as tDAL or tAPW
  485. ;// </h>
  486. ;// <h> Dynamic Memory Write Recovery Time Register (EMCDynamictWR)
  487. ;// <o5.0..3> tWR: Write recovery time <1-16> <#-1>
  488. ;// <i> The delay is in CCLK cycles
  489. ;// <i> This value is normally found in SDRAM data sheets as tWR, tDPL, tRWL, or tRDL
  490. ;// </h>
  491. ;// <h> Dynamic Memory Active to Active Command Period Register (EMCDynamictRC)
  492. ;// <o6.0..4> tRC: Active to active command period <1-32> <#-1>
  493. ;// <i> The delay is in CCLK cycles
  494. ;// <i> This value is normally found in SDRAM data sheets as tRC
  495. ;// </h>
  496. ;// <h> Dynamic Memory Auto-refresh Period Register (EMCDynamictRFC)
  497. ;// <o7.0..4> tRFC: Auto-refresh period and auto-refresh to active command period <1-32> <#-1>
  498. ;// <i> The delay is in CCLK cycles
  499. ;// <i> This value is normally found in SDRAM data sheets as tRFC or tRC
  500. ;// </h>
  501. ;// <h> Dynamic Memory Exit Self-refresh Register (EMCDynamictXSR)
  502. ;// <o8.0..4> tXSR: Exit self-refresh to active command time <1-32> <#-1>
  503. ;// <i> The delay is in CCLK cycles
  504. ;// <i> This value is normally found in SDRAM data sheets as tXSR
  505. ;// </h>
  506. ;// <h> Dynamic Memory Active Bank A to Active Bank B Time Register (EMCDynamicRRD)
  507. ;// <o9.0..3> tRRD: Active bank A to active bank B latency <1-16> <#-1>
  508. ;// <i> The delay is in CCLK cycles
  509. ;// <i> This value is normally found in SDRAM data sheets as tRRD
  510. ;// </h>
  511. ;// <h> Dynamic Memory Load Mode Register to Active Command Time (EMCDynamictMRD)
  512. ;// <o10.0..3> tMRD: Load mode register to active command time <1-16> <#-1>
  513. ;// <i> The delay is in CCLK cycles
  514. ;// <i> This value is normally found in SDRAM data sheets as tMRD or tRSA
  515. ;// </h>
  516. ;// </h>
  517. EMC_DYN_RP_Val EQU 0x00000002
  518. EMC_DYN_RAS_Val EQU 0x00000003
  519. EMC_DYN_SREX_Val EQU 0x00000007
  520. EMC_DYN_APR_Val EQU 0x00000002
  521. EMC_DYN_DAL_Val EQU 0x00000005
  522. EMC_DYN_WR_Val EQU 0x00000001
  523. EMC_DYN_RC_Val EQU 0x00000005
  524. EMC_DYN_RFC_Val EQU 0x00000005
  525. EMC_DYN_XSR_Val EQU 0x00000007
  526. EMC_DYN_RRD_Val EQU 0x00000001
  527. EMC_DYN_MRD_Val EQU 0x00000002
  528. ;// <e> Configure External Bus Behaviour for Dynamic CS0 Area
  529. EMC_DYNCS0_SETUP EQU 1
  530. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig0)
  531. ;// <i> Defines the configuration information for the dynamic memory CS0
  532. ;// <o0.20> P: Write protect
  533. ;// <o0.19> B: Buffer enable
  534. ;// <o0.14> AM 14: External bus data width
  535. ;// <0=> 16 bit
  536. ;// <1=> 32 bit
  537. ;// <o0.12> AM 12: External bus memory type
  538. ;// <0=> High-performance
  539. ;// <1=> Low-power SDRAM
  540. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  541. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  542. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  543. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  544. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  545. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  546. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  547. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  548. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  549. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  550. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  551. ;// <o0.3..4> MD: Memory device
  552. ;// <0=> SDRAM
  553. ;// <1=> Low-power SDRAM
  554. ;// <2=> Micron SyncFlash
  555. ;// </h>
  556. EMC_DYN_CFG0_Val EQU 0x00080680
  557. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS0)
  558. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS0
  559. ;// <o0.8..9> CAS: CAS latency
  560. ;// <1=> One CCLK cycle
  561. ;// <2=> Two CCLK cycles
  562. ;// <3=> Three CCLK cycles
  563. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  564. ;// <1=> One CCLK cycle
  565. ;// <2=> Two CCLK cycles
  566. ;// <3=> Three CCLK cycles
  567. ;// </h>
  568. EMC_DYN_RASCAS0_Val EQU 0x00000303
  569. ;// </e> End of Dynamic Setup for CS0 Area
  570. ;// <e> Configure External Bus Behaviour for Dynamic CS1 Area
  571. EMC_DYNCS1_SETUP EQU 0
  572. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig1)
  573. ;// <i> Defines the configuration information for the dynamic memory CS1
  574. ;// <o0.20> P: Write protect
  575. ;// <o0.19> B: Buffer enable
  576. ;// <o0.14> AM 14: External bus data width
  577. ;// <0=> 16 bit
  578. ;// <1=> 32 bit
  579. ;// <o0.12> AM 12: External bus memory type
  580. ;// <0=> High-performance
  581. ;// <1=> Low-power SDRAM
  582. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  583. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  584. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  585. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  586. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  587. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  588. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  589. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  590. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  591. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  592. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  593. ;// <o0.3..4> MD: Memory device
  594. ;// <0=> SDRAM
  595. ;// <1=> Low-power SDRAM
  596. ;// <2=> Micron SyncFlash
  597. ;// </h>
  598. EMC_DYN_CFG1_Val EQU 0x00000000
  599. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS1)
  600. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS1
  601. ;// <o0.8..9> CAS: CAS latency
  602. ;// <1=> One CCLK cycle
  603. ;// <2=> Two CCLK cycles
  604. ;// <3=> Three CCLK cycles
  605. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  606. ;// <1=> One CCLK cycle
  607. ;// <2=> Two CCLK cycles
  608. ;// <3=> Three CCLK cycles
  609. ;// </h>
  610. EMC_DYN_RASCAS1_Val EQU 0x00000303
  611. ;// </e> End of Dynamic Setup for CS1 Area
  612. ;// <e> Configure External Bus Behaviour for Dynamic CS2 Area
  613. EMC_DYNCS2_SETUP EQU 0
  614. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig2)
  615. ;// <i> Defines the configuration information for the dynamic memory CS2
  616. ;// <o0.20> P: Write protect
  617. ;// <o0.19> B: Buffer enable
  618. ;// <o0.14> AM 14: External bus data width
  619. ;// <0=> 16 bit
  620. ;// <1=> 32 bit
  621. ;// <o0.12> AM 12: External bus memory type
  622. ;// <0=> High-performance
  623. ;// <1=> Low-power SDRAM
  624. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  625. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  626. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  627. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  628. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  629. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  630. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  631. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  632. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  633. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  634. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  635. ;// <o0.3..4> MD: Memory device
  636. ;// <0=> SDRAM
  637. ;// <1=> Low-power SDRAM
  638. ;// <2=> Micron SyncFlash
  639. ;// </h>
  640. EMC_DYN_CFG2_Val EQU 0x00000000
  641. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS2)
  642. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS2
  643. ;// <o0.8..9> CAS: CAS latency
  644. ;// <1=> One CCLK cycle
  645. ;// <2=> Two CCLK cycles
  646. ;// <3=> Three CCLK cycles
  647. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  648. ;// <1=> One CCLK cycle
  649. ;// <2=> Two CCLK cycles
  650. ;// <3=> Three CCLK cycles
  651. ;// </h>
  652. EMC_DYN_RASCAS2_Val EQU 0x00000303
  653. ;// </e> End of Dynamic Setup for CS2 Area
  654. ;// <e> Configure External Bus Behaviour for Dynamic CS3 Area
  655. EMC_DYNCS3_SETUP EQU 0
  656. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig3)
  657. ;// <i> Defines the configuration information for the dynamic memory CS3
  658. ;// <o0.20> P: Write protect
  659. ;// <o0.19> B: Buffer enable
  660. ;// <o0.14> AM 14: External bus data width
  661. ;// <0=> 16 bit
  662. ;// <1=> 32 bit
  663. ;// <o0.12> AM 12: External bus memory type
  664. ;// <0=> High-performance
  665. ;// <1=> Low-power SDRAM
  666. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  667. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  668. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  669. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  670. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  671. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  672. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  673. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  674. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  675. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  676. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  677. ;// <o0.3..4> MD: Memory device
  678. ;// <0=> SDRAM
  679. ;// <1=> Low-power SDRAM
  680. ;// <2=> Micron SyncFlash
  681. ;// </h>
  682. EMC_DYN_CFG3_Val EQU 0x00000000
  683. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS3)
  684. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS3
  685. ;// <o0.8..9> CAS: CAS latency
  686. ;// <1=> One CCLK cycle
  687. ;// <2=> Two CCLK cycles
  688. ;// <3=> Three CCLK cycles
  689. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  690. ;// <1=> One CCLK cycle
  691. ;// <2=> Two CCLK cycles
  692. ;// <3=> Three CCLK cycles
  693. ;// </h>
  694. EMC_DYN_RASCAS3_Val EQU 0x00000303
  695. ;// </e> End of Dynamic Setup for CS3 Area
  696. ;// </e> End of Dynamic Setup
  697. ;// Static Memory Interface Setup ----------------------------------------
  698. ;// <e> Static Memory Interface Setup
  699. EMC_STATIC_SETUP EQU 1
  700. ;// Configure External Bus Behaviour for Static CS0 Area ---------------
  701. ;// <e> Configure External Bus Behaviour for Static CS0 Area
  702. EMC_STACS0_SETUP EQU 1
  703. ;// <h> Static Memory Configuration Register (EMCStaticConfig0)
  704. ;// <i> Defines the configuration information for the static memory CS0
  705. ;// <o0.20> WP: Write protect
  706. ;// <o0.19> B: Buffer enable
  707. ;// <o0.8> EW: Extended wait enable
  708. ;// <o0.7> PB: Byte lane state
  709. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  710. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  711. ;// <o0.6> PC: Chip select polarity
  712. ;// <0=> Active LOW chip select
  713. ;// <1=> Active HIGH chip select
  714. ;// <o0.3> PM: Page mode enable
  715. ;// <o0.0..1> MW: Memory width
  716. ;// <0=> 8 bit
  717. ;// <1=> 16 bit
  718. ;// <2=> 32 bit
  719. ;// </h>
  720. EMC_STA_CFG0_Val EQU 0x00000081
  721. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen0)
  722. ;// <i> Selects the delay from CS0 to write enable
  723. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  724. ;// <i> The delay is in CCLK cycles
  725. ;// </h>
  726. EMC_STA_WWEN0_Val EQU 0x00000002
  727. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen0)
  728. ;// <i> Selects the delay from CS0 or address change, whichever is later, to output enable
  729. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  730. ;// <i> The delay is in CCLK cycles
  731. ;// </h>
  732. EMC_STA_WOEN0_Val EQU 0x00000002
  733. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd0)
  734. ;// <i> Selects the delay from CS0 to a read access
  735. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  736. ;// <i> The delay is in CCLK cycles
  737. ;// </h>
  738. EMC_STA_WRD0_Val EQU 0x0000001F
  739. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage0)
  740. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS0
  741. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  742. ;// <i> The delay is in CCLK cycles
  743. ;// </h>
  744. EMC_STA_WPAGE0_Val EQU 0x0000001F
  745. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr0)
  746. ;// <i> Selects the delay from CS0 to a write access
  747. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  748. ;// <i> The delay is in CCLK cycles
  749. ;// </h>
  750. EMC_STA_WWR0_Val EQU 0x0000001F
  751. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn0)
  752. ;// <i> Selects the number of bus turnaround cycles for CS0
  753. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  754. ;// <i> The delay is in CCLK cycles
  755. ;// </h>
  756. EMC_STA_WTURN0_Val EQU 0x0000000F
  757. ;// </e> End of Static Setup for Static CS0 Area
  758. ;// Configure External Bus Behaviour for Static CS1 Area ---------------
  759. ;// <e> Configure External Bus Behaviour for Static CS1 Area
  760. EMC_STACS1_SETUP EQU 0
  761. ;// <h> Static Memory Configuration Register (EMCStaticConfig1)
  762. ;// <i> Defines the configuration information for the static memory CS1
  763. ;// <o0.20> WP: Write protect
  764. ;// <o0.19> B: Buffer enable
  765. ;// <o0.8> EW: Extended wait enable
  766. ;// <o0.7> PB: Byte lane state
  767. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  768. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  769. ;// <o0.6> PC: Chip select polarity
  770. ;// <0=> Active LOW chip select
  771. ;// <1=> Active HIGH chip select
  772. ;// <o0.3> PM: Page mode enable
  773. ;// <o0.0..1> MW: Memory width
  774. ;// <0=> 8 bit
  775. ;// <1=> 16 bit
  776. ;// <2=> 32 bit
  777. ;// </h>
  778. EMC_STA_CFG1_Val EQU 0x00000000
  779. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen1)
  780. ;// <i> Selects the delay from CS1 to write enable
  781. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  782. ;// <i> The delay is in CCLK cycles
  783. ;// </h>
  784. EMC_STA_WWEN1_Val EQU 0x00000000
  785. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen1)
  786. ;// <i> Selects the delay from CS1 or address change, whichever is later, to output enable
  787. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  788. ;// <i> The delay is in CCLK cycles
  789. ;// </h>
  790. EMC_STA_WOEN1_Val EQU 0x00000000
  791. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd1)
  792. ;// <i> Selects the delay from CS1 to a read access
  793. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  794. ;// <i> The delay is in CCLK cycles
  795. ;// </h>
  796. EMC_STA_WRD1_Val EQU 0x0000001F
  797. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage0)
  798. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS1
  799. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  800. ;// <i> The delay is in CCLK cycles
  801. ;// </h>
  802. EMC_STA_WPAGE1_Val EQU 0x0000001F
  803. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr1)
  804. ;// <i> Selects the delay from CS1 to a write access
  805. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  806. ;// <i> The delay is in CCLK cycles
  807. ;// </h>
  808. EMC_STA_WWR1_Val EQU 0x0000001F
  809. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn1)
  810. ;// <i> Selects the number of bus turnaround cycles for CS1
  811. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  812. ;// <i> The delay is in CCLK cycles
  813. ;// </h>
  814. EMC_STA_WTURN1_Val EQU 0x0000000F
  815. ;// </e> End of Static Setup for Static CS1 Area
  816. ;// Configure External Bus Behaviour for Static CS2 Area ---------------
  817. ;// <e> Configure External Bus Behaviour for Static CS2 Area
  818. EMC_STACS2_SETUP EQU 0
  819. ;// <h> Static Memory Configuration Register (EMCStaticConfig2)
  820. ;// <i> Defines the configuration information for the static memory CS2
  821. ;// <o0.20> WP: Write protect
  822. ;// <o0.19> B: Buffer enable
  823. ;// <o0.8> EW: Extended wait enable
  824. ;// <o0.7> PB: Byte lane state
  825. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  826. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  827. ;// <o0.6> PC: Chip select polarity
  828. ;// <0=> Active LOW chip select
  829. ;// <1=> Active HIGH chip select
  830. ;// <o0.3> PM: Page mode enable
  831. ;// <o0.0..1> MW: Memory width
  832. ;// <0=> 8 bit
  833. ;// <1=> 16 bit
  834. ;// <2=> 32 bit
  835. ;// </h>
  836. EMC_STA_CFG2_Val EQU 0x00000000
  837. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen2)
  838. ;// <i> Selects the delay from CS2 to write enable
  839. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  840. ;// <i> The delay is in CCLK cycles
  841. ;// </h>
  842. EMC_STA_WWEN2_Val EQU 0x00000000
  843. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen2)
  844. ;// <i> Selects the delay from CS2 or address change, whichever is later, to output enable
  845. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  846. ;// <i> The delay is in CCLK cycles
  847. ;// </h>
  848. EMC_STA_WOEN2_Val EQU 0x00000000
  849. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd2)
  850. ;// <i> Selects the delay from CS2 to a read access
  851. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  852. ;// <i> The delay is in CCLK cycles
  853. ;// </h>
  854. EMC_STA_WRD2_Val EQU 0x0000001F
  855. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage2)
  856. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS2
  857. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  858. ;// <i> The delay is in CCLK cycles
  859. ;// </h>
  860. EMC_STA_WPAGE2_Val EQU 0x0000001F
  861. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr2)
  862. ;// <i> Selects the delay from CS2 to a write access
  863. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  864. ;// <i> The delay is in CCLK cycles
  865. ;// </h>
  866. EMC_STA_WWR2_Val EQU 0x0000001F
  867. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn2)
  868. ;// <i> Selects the number of bus turnaround cycles for CS2
  869. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  870. ;// <i> The delay is in CCLK cycles
  871. ;// </h>
  872. EMC_STA_WTURN2_Val EQU 0x0000000F
  873. ;// </e> End of Static Setup for Static CS2 Area
  874. ;// Configure External Bus Behaviour for Static CS3 Area ---------------
  875. ;// <e> Configure External Bus Behaviour for Static CS3 Area
  876. EMC_STACS3_SETUP EQU 0
  877. ;// <h> Static Memory Configuration Register (EMCStaticConfig3)
  878. ;// <i> Defines the configuration information for the static memory CS3
  879. ;// <o0.20> WP: Write protect
  880. ;// <o0.19> B: Buffer enable
  881. ;// <o0.8> EW: Extended wait enable
  882. ;// <o0.7> PB: Byte lane state
  883. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  884. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  885. ;// <o0.6> PC: Chip select polarity
  886. ;// <0=> Active LOW chip select
  887. ;// <1=> Active HIGH chip select
  888. ;// <o0.3> PM: Page mode enable
  889. ;// <o0.0..1> MW: Memory width
  890. ;// <0=> 8 bit
  891. ;// <1=> 16 bit
  892. ;// <2=> 32 bit
  893. ;// </h>
  894. EMC_STA_CFG3_Val EQU 0x00000000
  895. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen3)
  896. ;// <i> Selects the delay from CS3 to write enable
  897. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  898. ;// <i> The delay is in CCLK cycles
  899. ;// </h>
  900. EMC_STA_WWEN3_Val EQU 0x00000000
  901. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen3)
  902. ;// <i> Selects the delay from CS3 or address change, whichever is later, to output enable
  903. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  904. ;// <i> The delay is in CCLK cycles
  905. ;// </h>
  906. EMC_STA_WOEN3_Val EQU 0x00000000
  907. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd3)
  908. ;// <i> Selects the delay from CS3 to a read access
  909. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  910. ;// <i> The delay is in CCLK cycles
  911. ;// </h>
  912. EMC_STA_WRD3_Val EQU 0x0000001F
  913. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage3)
  914. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS3
  915. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  916. ;// <i> The delay is in CCLK cycles
  917. ;// </h>
  918. EMC_STA_WPAGE3_Val EQU 0x0000001F
  919. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr3)
  920. ;// <i> Selects the delay from CS3 to a write access
  921. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  922. ;// <i> The delay is in CCLK cycles
  923. ;// </h>
  924. EMC_STA_WWR3_Val EQU 0x0000001F
  925. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn3)
  926. ;// <i> Selects the number of bus turnaround cycles for CS3
  927. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  928. ;// <i> The delay is in CCLK cycles
  929. ;// </h>
  930. EMC_STA_WTURN3_Val EQU 0x0000000F
  931. ;// </e> End of Static Setup for Static CS3 Area
  932. ;// <h> Static Memory Extended Wait Register (EMCStaticExtendedWait)
  933. ;// <i> Time long static memory read and write transfers
  934. ;// <o.0..9> EXTENDEDWAIT: Extended wait time out <0-1023>
  935. ;// <i> The delay is in (16 * CCLK) cycles
  936. ;// </h>
  937. EMC_STA_EXT_W_Val EQU 0x00000000
  938. ;// </e> End of Static Setup
  939. ;// </e> End of EMC Setup
  940. PRESERVE8
  941. ; Area Definition and Entry Point
  942. ; Startup Code must be linked first at Address at which it expects to run.
  943. AREA RESET, CODE, READONLY
  944. ARM
  945. ; Exception Vectors
  946. ; Mapped to Address 0.
  947. ; Absolute addressing mode must be used.
  948. ; Dummy Handlers are implemented as infinite loops which can be modified.
  949. Vectors LDR PC, Reset_Addr
  950. LDR PC, Undef_Addr
  951. LDR PC, SWI_Addr
  952. LDR PC, PAbt_Addr
  953. LDR PC, DAbt_Addr
  954. NOP ; Reserved Vector
  955. LDR PC, IRQ_Addr
  956. LDR PC, FIQ_Addr
  957. Reset_Addr DCD Reset_Handler
  958. Undef_Addr DCD Undef_Handler
  959. SWI_Addr DCD SWI_Handler
  960. PAbt_Addr DCD PAbt_Handler
  961. DAbt_Addr DCD DAbt_Handler
  962. DCD 0 ; Reserved Address
  963. IRQ_Addr DCD IRQ_Handler
  964. FIQ_Addr DCD FIQ_Handler
  965. ; Exception Handler
  966. IMPORT rt_hw_trap_udef
  967. IMPORT rt_hw_trap_swi
  968. IMPORT rt_hw_trap_pabt
  969. IMPORT rt_hw_trap_dabt
  970. IMPORT rt_hw_trap_fiq
  971. ; Prepare Fatal Context
  972. MACRO
  973. prepare_fatal
  974. STMFD sp!, {r0-r3}
  975. MOV r1, sp
  976. ADD sp, sp, #16
  977. SUB r2, lr, #4
  978. MRS r3, spsr
  979. ; switch to SVC mode and no interrupt
  980. MSR cpsr_c, #I_Bit :OR: F_Bit :OR: Mode_SVC
  981. STMFD sp!, {r0} ; old r0
  982. ; get sp
  983. ADD r0, sp, #4
  984. STMFD sp!, {r3} ; cpsr
  985. STMFD sp!, {r2} ; pc
  986. STMFD sp!, {lr} ; lr
  987. STMFD sp!, {r0} ; sp
  988. STMFD sp!, {r4-r12}
  989. MOV r4, r1
  990. LDMFD r4!, {r0-r3}
  991. STMFD sp!, {r0-r3}
  992. MOV r0, sp
  993. MEND
  994. Undef_Handler
  995. prepare_fatal
  996. BL rt_hw_trap_irq
  997. B .
  998. SWI_Handler
  999. prepare_fatal
  1000. BL rt_hw_trap_swi
  1001. B .
  1002. PAbt_Handler
  1003. prepare_fatal
  1004. BL rt_hw_trap_pabt
  1005. B .
  1006. DAbt_Handler
  1007. prepare_fatal
  1008. BL rt_hw_trap_dabt
  1009. B .
  1010. FIQ_Handler
  1011. prepare_fatal
  1012. BL rt_hw_trap_fiq
  1013. B .
  1014. ; Reset Handler
  1015. EXPORT Reset_Handler
  1016. Reset_Handler
  1017. ; Clock Setup ------------------------------------------------------------------
  1018. IF (:LNOT:(:DEF:NO_CLOCK_SETUP)):LAND:(CLOCK_SETUP != 0)
  1019. LDR R0, =SCB_BASE
  1020. MOV R1, #0xAA
  1021. MOV R2, #0x55
  1022. ; Configure and Enable PLL
  1023. LDR R3, =SCS_Val ; Enable main oscillator
  1024. STR R3, [R0, #SCS_OFS]
  1025. IF (SCS_Val:AND:OSCEN) != 0
  1026. OSC_Loop LDR R3, [R0, #SCS_OFS] ; Wait for main osc stabilize
  1027. ANDS R3, R3, #OSCSTAT
  1028. BEQ OSC_Loop
  1029. ENDIF
  1030. LDR R3, =CLKSRCSEL_Val ; Select PLL source clock
  1031. STR R3, [R0, #CLKSRCSEL_OFS]
  1032. LDR R3, =PLLCFG_Val
  1033. STR R3, [R0, #PLLCFG_OFS]
  1034. STR R1, [R0, #PLLFEED_OFS]
  1035. STR R2, [R0, #PLLFEED_OFS]
  1036. MOV R3, #PLLCON_PLLE
  1037. STR R3, [R0, #PLLCON_OFS]
  1038. STR R1, [R0, #PLLFEED_OFS]
  1039. STR R2, [R0, #PLLFEED_OFS]
  1040. IF (CLKSRCSEL_Val:AND:3) != 2
  1041. ; Wait until PLL Locked (if source is not RTC oscillator)
  1042. PLL_Loop LDR R3, [R0, #PLLSTAT_OFS]
  1043. ANDS R3, R3, #PLLSTAT_PLOCK
  1044. BEQ PLL_Loop
  1045. ELSE
  1046. ; Wait at least 200 cycles (if source is RTC oscillator)
  1047. MOV R3, #(200/4)
  1048. PLL_Loop SUBS R3, R3, #1
  1049. BNE PLL_Loop
  1050. ENDIF
  1051. M_N_Lock LDR R3, [R0, #PLLSTAT_OFS]
  1052. LDR R4, =(PLLSTAT_M:OR:PLLSTAT_N)
  1053. AND R3, R3, R4
  1054. LDR R4, =PLLCFG_Val
  1055. EORS R3, R3, R4
  1056. BNE M_N_Lock
  1057. ; Setup CPU clock divider
  1058. MOV R3, #CCLKCFG_Val
  1059. STR R3, [R0, #CCLKCFG_OFS]
  1060. ; Setup USB clock divider
  1061. LDR R3, =USBCLKCFG_Val
  1062. STR R3, [R0, #USBCLKCFG_OFS]
  1063. ; Setup Peripheral Clock
  1064. LDR R3, =PCLKSEL0_Val
  1065. STR R3, [R0, #PCLKSEL0_OFS]
  1066. LDR R3, =PCLKSEL1_Val
  1067. STR R3, [R0, #PCLKSEL1_OFS]
  1068. ; Switch to PLL Clock
  1069. MOV R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
  1070. STR R3, [R0, #PLLCON_OFS]
  1071. STR R1, [R0, #PLLFEED_OFS]
  1072. STR R2, [R0, #PLLFEED_OFS]
  1073. ENDIF ; CLOCK_SETUP
  1074. ; Setup Memory Accelerator Module ----------------------------------------------
  1075. IF MAM_SETUP != 0
  1076. LDR R0, =MAM_BASE
  1077. MOV R1, #MAMTIM_Val
  1078. STR R1, [R0, #MAMTIM_OFS]
  1079. MOV R1, #MAMCR_Val
  1080. STR R1, [R0, #MAMCR_OFS]
  1081. ENDIF ; MAM_SETUP
  1082. ; Setup External Memory Controller ---------------------------------------------
  1083. IF (:LNOT:(:DEF:NO_EMC_SETUP)):LAND:(EMC_SETUP != 0)
  1084. LDR R0, =EMC_BASE
  1085. LDR R1, =SCB_BASE
  1086. LDR R2, =PCB_BASE
  1087. LDR R4, =EMC_PCONP_Const ; Enable EMC
  1088. LDR R3, [R1, #PCONP_OFS]
  1089. ORR R4, R4, R3
  1090. STR R4, [R1, #PCONP_OFS]
  1091. LDR R4, =EMC_CTRL_Val
  1092. STR R4, [R0, #EMC_CTRL_OFS]
  1093. LDR R4, =EMC_CONFIG_Val
  1094. STR R4, [R0, #EMC_CONFIG_OFS]
  1095. ; Setup pin functions for External Bus functionality
  1096. LDR R4, =EMC_PINSEL5_Val
  1097. STR R4, [R2, #PINSEL5_OFS]
  1098. LDR R4, =EMC_PINSEL6_Val
  1099. STR R4, [R2, #PINSEL6_OFS]
  1100. LDR R4, =EMC_PINSEL8_Val
  1101. STR R4, [R2, #PINSEL8_OFS]
  1102. LDR R4, =EMC_PINSEL9_Val
  1103. STR R4, [R2, #PINSEL9_OFS]
  1104. ; Setup Dynamic Memory Interface
  1105. IF (EMC_DYNAMIC_SETUP != 0)
  1106. LDR R4, =EMC_DYN_RP_Val
  1107. STR R4, [R0, #EMC_DYN_RP_OFS]
  1108. LDR R4, =EMC_DYN_RAS_Val
  1109. STR R4, [R0, #EMC_DYN_RAS_OFS]
  1110. LDR R4, =EMC_DYN_SREX_Val
  1111. STR R4, [R0, #EMC_DYN_SREX_OFS]
  1112. LDR R4, =EMC_DYN_APR_Val
  1113. STR R4, [R0, #EMC_DYN_APR_OFS]
  1114. LDR R4, =EMC_DYN_DAL_Val
  1115. STR R4, [R0, #EMC_DYN_DAL_OFS]
  1116. LDR R4, =EMC_DYN_WR_Val
  1117. STR R4, [R0, #EMC_DYN_WR_OFS]
  1118. LDR R4, =EMC_DYN_RC_Val
  1119. STR R4, [R0, #EMC_DYN_RC_OFS]
  1120. LDR R4, =EMC_DYN_RFC_Val
  1121. STR R4, [R0, #EMC_DYN_RFC_OFS]
  1122. LDR R4, =EMC_DYN_XSR_Val
  1123. STR R4, [R0, #EMC_DYN_XSR_OFS]
  1124. LDR R4, =EMC_DYN_RRD_Val
  1125. STR R4, [R0, #EMC_DYN_RRD_OFS]
  1126. LDR R4, =EMC_DYN_MRD_Val
  1127. STR R4, [R0, #EMC_DYN_MRD_OFS]
  1128. LDR R4, =EMC_DYN_RD_CFG_Val
  1129. STR R4, [R0, #EMC_DYN_RD_CFG_OFS]
  1130. IF (EMC_DYNCS0_SETUP != 0)
  1131. LDR R4, =EMC_DYN_RASCAS0_Val
  1132. STR R4, [R0, #EMC_DYN_RASCAS0_OFS]
  1133. LDR R4, =EMC_DYN_CFG0_Val
  1134. MVN R5, #BUFEN_Const
  1135. AND R4, R4, R5
  1136. STR R4, [R0, #EMC_DYN_CFG0_OFS]
  1137. ENDIF
  1138. IF (EMC_DYNCS1_SETUP != 0)
  1139. LDR R4, =EMC_DYN_RASCAS1_Val
  1140. STR R4, [R0, #EMC_DYN_RASCAS1_OFS]
  1141. LDR R4, =EMC_DYN_CFG1_Val
  1142. MVN R5, =BUFEN_Const
  1143. AND R4, R4, R5
  1144. STR R4, [R0, #EMC_DYN_CFG1_OFS]
  1145. ENDIF
  1146. IF (EMC_DYNCS2_SETUP != 0)
  1147. LDR R4, =EMC_DYN_RASCAS2_Val
  1148. STR R4, [R0, #EMC_DYN_RASCAS2_OFS]
  1149. LDR R4, =EMC_DYN_CFG2_Val
  1150. MVN R5, =BUFEN_Const
  1151. AND R4, R4, R5
  1152. STR R4, [R0, #EMC_DYN_CFG2_OFS]
  1153. ENDIF
  1154. IF (EMC_DYNCS3_SETUP != 0)
  1155. LDR R4, =EMC_DYN_RASCAS3_Val
  1156. STR R4, [R0, #EMC_DYN_RASCAS3_OFS]
  1157. LDR R4, =EMC_DYN_CFG3_Val
  1158. MVN R5, =BUFEN_Const
  1159. AND R4, R4, R5
  1160. STR R4, [R0, #EMC_DYN_CFG3_OFS]
  1161. ENDIF
  1162. LDR R6, =1440000 ; Number of cycles to delay
  1163. Wait_0 SUBS R6, R6, #1 ; Delay ~100 ms proc clk 57.6 MHz
  1164. BNE Wait_0 ; BNE (3 cyc) + SUBS (1 cyc) = 4 cyc
  1165. LDR R4, =(NOP_CMD:OR:0x03) ; Write NOP Command
  1166. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1167. LDR R6, =2880000 ; Number of cycles to delay
  1168. Wait_1 SUBS R6, R6, #1 ; Delay ~200 ms proc clk 57.6 MHz
  1169. BNE Wait_1
  1170. LDR R4, =(PALL_CMD:OR:0x03) ; Write Precharge All Command
  1171. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1172. MOV R4, #2
  1173. STR R4, [R0, #EMC_DYN_RFSH_OFS]
  1174. MOV R6, #64 ; Number of cycles to delay
  1175. Wait_2 SUBS R6, R6, #1 ; Delay
  1176. BNE Wait_2
  1177. LDR R4, =EMC_DYN_RFSH_Val
  1178. STR R4, [R0, #EMC_DYN_RFSH_OFS]
  1179. LDR R4, =(MODE_CMD:OR:0x03) ; Write MODE Command
  1180. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1181. ; Dummy read
  1182. IF (EMC_DYNCS0_SETUP != 0)
  1183. LDR R4, =DYN_MEM0_BASE
  1184. MOV R5, #(0x33 << 12)
  1185. ADD R4, R4, R5
  1186. LDR R4, [R4, #0]
  1187. ENDIF
  1188. IF (EMC_DYNCS1_SETUP != 0)
  1189. LDR R4, =DYN_MEM1_BASE
  1190. MOV R5, #(0x33 << 12)
  1191. ADD R4, R4, R5
  1192. LDR R4, [R4, #0]
  1193. ENDIF
  1194. IF (EMC_DYNCS2_SETUP != 0)
  1195. LDR R4, =DYN_MEM2_BASE
  1196. MOV R5, #(0x33 << 12)
  1197. ADD R4, R4, R5
  1198. LDR R4, [R4, #0]
  1199. ENDIF
  1200. IF (EMC_DYNCS3_SETUP != 0)
  1201. LDR R4, =DYN_MEM3_BASE
  1202. MOV R5, #(0x33 << 12)
  1203. ADD R4, R4, R5
  1204. LDR R4, [R4, #0]
  1205. ENDIF
  1206. LDR R4, =NORMAL_CMD ; Write NORMAL Command
  1207. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1208. ; Enable buffer if requested by settings
  1209. IF (EMC_DYNCS0_SETUP != 0):LAND:((EMC_DYN_CFG0_Val:AND:BUFEN_Const) != 0)
  1210. LDR R4, =EMC_DYN_CFG0_Val
  1211. STR R4, [R0, #EMC_DYN_CFG0_OFS]
  1212. ENDIF
  1213. IF (EMC_DYNCS1_SETUP != 0):LAND:((EMC_DYN_CFG1_Val:AND:BUFEN_Const) != 0)
  1214. LDR R4, =EMC_DYN_CFG1_Val
  1215. STR R4, [R0, #EMC_DYN_CFG1_OFS]
  1216. ENDIF
  1217. IF (EMC_DYNCS2_SETUP != 0):LAND:((EMC_DYN_CFG2_Val:AND:BUFEN_Const) != 0)
  1218. LDR R4, =EMC_DYN_CFG2_Val
  1219. STR R4, [R0, #EMC_DYN_CFG2_OFS]
  1220. ENDIF
  1221. IF (EMC_DYNCS3_SETUP != 0):LAND:((EMC_DYN_CFG3_Val:AND:BUFEN_Const) != 0)
  1222. LDR R4, =EMC_DYN_CFG3_Val
  1223. STR R4, [R0, #EMC_DYN_CFG3_OFS]
  1224. ENDIF
  1225. LDR R6, =14400 ; Number of cycles to delay
  1226. Wait_3 SUBS R6, R6, #1 ; Delay ~1 ms @ proc clk 57.6 MHz
  1227. BNE Wait_3
  1228. ENDIF ; EMC_DYNAMIC_SETUP
  1229. ; Setup Static Memory Interface
  1230. IF (EMC_STATIC_SETUP != 0)
  1231. LDR R6, =1440000 ; Number of cycles to delay
  1232. Wait_4 SUBS R6, R6, #1 ; Delay ~100 ms @ proc clk 57.6 MHz
  1233. BNE Wait_4
  1234. IF (EMC_STACS0_SETUP != 0)
  1235. LDR R4, =EMC_STA_CFG0_Val
  1236. STR R4, [R0, #EMC_STA_CFG0_OFS]
  1237. LDR R4, =EMC_STA_WWEN0_Val
  1238. STR R4, [R0, #EMC_STA_WWEN0_OFS]
  1239. LDR R4, =EMC_STA_WOEN0_Val
  1240. STR R4, [R0, #EMC_STA_WOEN0_OFS]
  1241. LDR R4, =EMC_STA_WRD0_Val
  1242. STR R4, [R0, #EMC_STA_WRD0_OFS]
  1243. LDR R4, =EMC_STA_WPAGE0_Val
  1244. STR R4, [R0, #EMC_STA_WPAGE0_OFS]
  1245. LDR R4, =EMC_STA_WWR0_Val
  1246. STR R4, [R0, #EMC_STA_WWR0_OFS]
  1247. LDR R4, =EMC_STA_WTURN0_Val
  1248. STR R4, [R0, #EMC_STA_WTURN0_OFS]
  1249. ENDIF
  1250. IF (EMC_STACS1_SETUP != 0)
  1251. LDR R4, =EMC_STA_CFG1_Val
  1252. STR R4, [R0, #EMC_STA_CFG1_OFS]
  1253. LDR R4, =EMC_STA_WWEN1_Val
  1254. STR R4, [R0, #EMC_STA_WWEN1_OFS]
  1255. LDR R4, =EMC_STA_WOEN1_Val
  1256. STR R4, [R0, #EMC_STA_WOEN1_OFS]
  1257. LDR R4, =EMC_STA_WRD1_Val
  1258. STR R4, [R0, #EMC_STA_WRD1_OFS]
  1259. LDR R4, =EMC_STA_WPAGE1_Val
  1260. STR R4, [R0, #EMC_STA_WPAGE1_OFS]
  1261. LDR R4, =EMC_STA_WWR1_Val
  1262. STR R4, [R0, #EMC_STA_WWR1_OFS]
  1263. LDR R4, =EMC_STA_WTURN1_Val
  1264. STR R4, [R0, #EMC_STA_WTURN1_OFS]
  1265. ENDIF
  1266. IF (EMC_STACS2_SETUP != 0)
  1267. LDR R4, =EMC_STA_CFG2_Val
  1268. STR R4, [R0, #EMC_STA_CFG2_OFS]
  1269. LDR R4, =EMC_STA_WWEN2_Val
  1270. STR R4, [R0, #EMC_STA_WWEN2_OFS]
  1271. LDR R4, =EMC_STA_WOEN2_Val
  1272. STR R4, [R0, #EMC_STA_WOEN2_OFS]
  1273. LDR R4, =EMC_STA_WRD2_Val
  1274. STR R4, [R0, #EMC_STA_WRD2_OFS]
  1275. LDR R4, =EMC_STA_WPAGE2_Val
  1276. STR R4, [R0, #EMC_STA_WPAGE2_OFS]
  1277. LDR R4, =EMC_STA_WWR2_Val
  1278. STR R4, [R0, #EMC_STA_WWR2_OFS]
  1279. LDR R4, =EMC_STA_WTURN2_Val
  1280. STR R4, [R0, #EMC_STA_WTURN2_OFS]
  1281. ENDIF
  1282. IF (EMC_STACS3_SETUP != 0)
  1283. LDR R4, =EMC_STA_CFG3_Val
  1284. STR R4, [R0, #EMC_STA_CFG3_OFS]
  1285. LDR R4, =EMC_STA_WWEN3_Val
  1286. STR R4, [R0, #EMC_STA_WWEN3_OFS]
  1287. LDR R4, =EMC_STA_WOEN3_Val
  1288. STR R4, [R0, #EMC_STA_WOEN3_OFS]
  1289. LDR R4, =EMC_STA_WRD3_Val
  1290. STR R4, [R0, #EMC_STA_WRD3_OFS]
  1291. LDR R4, =EMC_STA_WPAGE3_Val
  1292. STR R4, [R0, #EMC_STA_WPAGE3_OFS]
  1293. LDR R4, =EMC_STA_WWR3_Val
  1294. STR R4, [R0, #EMC_STA_WWR3_OFS]
  1295. LDR R4, =EMC_STA_WTURN3_Val
  1296. STR R4, [R0, #EMC_STA_WTURN3_OFS]
  1297. ENDIF
  1298. LDR R6, =144000 ; Number of cycles to delay
  1299. Wait_5 SUBS R6, R6, #1 ; Delay ~10 ms @ proc clk 57.6 MHz
  1300. BNE Wait_5
  1301. LDR R4, =EMC_STA_EXT_W_Val
  1302. LDR R5, =EMC_STA_EXT_W_OFS
  1303. ADD R5, R5, R0
  1304. STR R4, [R5, #0]
  1305. ENDIF ; EMC_STATIC_SETUP
  1306. ENDIF ; EMC_SETUP
  1307. ; Copy Exception Vectors to Internal RAM ---------------------------------------
  1308. IF :DEF:RAM_INTVEC
  1309. ADR R8, Vectors ; Source
  1310. LDR R9, =RAM_BASE ; Destination
  1311. LDMIA R8!, {R0-R7} ; Load Vectors
  1312. STMIA R9!, {R0-R7} ; Store Vectors
  1313. LDMIA R8!, {R0-R7} ; Load Handler Addresses
  1314. STMIA R9!, {R0-R7} ; Store Handler Addresses
  1315. ENDIF
  1316. ; Memory Mapping (when Interrupt Vectors are in RAM) ---------------------------
  1317. MEMMAP EQU 0xE01FC040 ; Memory Mapping Control
  1318. IF :DEF:REMAP
  1319. LDR R0, =MEMMAP
  1320. IF :DEF:EXTMEM_MODE
  1321. MOV R1, #3
  1322. ELIF :DEF:RAM_MODE
  1323. MOV R1, #2
  1324. ELSE
  1325. MOV R1, #1
  1326. ENDIF
  1327. STR R1, [R0]
  1328. ENDIF
  1329. ; Setup Stack for each mode ----------------------------------------------------
  1330. LDR R0, =Stack_Top
  1331. ; Enter Undefined Instruction Mode and set its Stack Pointer
  1332. MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  1333. MOV SP, R0
  1334. SUB R0, R0, #UND_Stack_Size
  1335. ; Enter Abort Mode and set its Stack Pointer
  1336. MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  1337. MOV SP, R0
  1338. SUB R0, R0, #ABT_Stack_Size
  1339. ; Enter FIQ Mode and set its Stack Pointer
  1340. MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  1341. MOV SP, R0
  1342. SUB R0, R0, #FIQ_Stack_Size
  1343. ; Enter IRQ Mode and set its Stack Pointer
  1344. MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  1345. MOV SP, R0
  1346. SUB R0, R0, #IRQ_Stack_Size
  1347. ; Enter Supervisor Mode and set its Stack Pointer
  1348. MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  1349. MOV SP, R0
  1350. SUB R0, R0, #SVC_Stack_Size
  1351. IF :DEF:__MICROLIB
  1352. EXPORT __initial_sp
  1353. ELSE
  1354. ENDIF
  1355. ; Enter the C code -------------------------------------------------------------
  1356. IMPORT __main
  1357. LDR R0, =__main
  1358. BX R0
  1359. IMPORT rt_interrupt_enter
  1360. IMPORT rt_interrupt_leave
  1361. IMPORT rt_thread_switch_interrupt_flag
  1362. IMPORT rt_interrupt_from_thread
  1363. IMPORT rt_interrupt_to_thread
  1364. IMPORT rt_hw_trap_irq
  1365. IRQ_Handler PROC
  1366. EXPORT IRQ_Handler
  1367. STMFD sp!, {r0-r12,lr}
  1368. BL rt_interrupt_enter
  1369. BL rt_hw_trap_irq
  1370. BL rt_interrupt_leave
  1371. ; if rt_thread_switch_interrupt_flag set, jump to
  1372. ; rt_hw_context_switch_interrupt_do and don't return
  1373. LDR r0, =rt_thread_switch_interrupt_flag
  1374. LDR r1, [r0]
  1375. CMP r1, #1
  1376. BEQ rt_hw_context_switch_interrupt_do
  1377. LDMFD sp!, {r0-r12,lr}
  1378. SUBS pc, lr, #4
  1379. ENDP
  1380. ; /*
  1381. ; * void rt_hw_context_switch_interrupt_do(rt_base_t flag)
  1382. ; */
  1383. rt_hw_context_switch_interrupt_do PROC
  1384. EXPORT rt_hw_context_switch_interrupt_do
  1385. MOV r1, #0 ; clear flag
  1386. STR r1, [r0]
  1387. LDMFD sp!, {r0-r12,lr}; reload saved registers
  1388. STMFD sp!, {r0-r3} ; save r0-r3
  1389. MOV r1, sp
  1390. ADD sp, sp, #16 ; restore sp
  1391. SUB r2, lr, #4 ; save old task's pc to r2
  1392. MRS r3, spsr ; get cpsr of interrupt thread
  1393. ; switch to SVC mode and no interrupt
  1394. MSR cpsr_c, #I_Bit :OR: F_Bit :OR: Mode_SVC
  1395. STMFD sp!, {r2} ; push old task's pc
  1396. STMFD sp!, {r4-r12,lr}; push old task's lr,r12-r4
  1397. MOV r4, r1 ; Special optimised code below
  1398. MOV r5, r3
  1399. LDMFD r4!, {r0-r3}
  1400. STMFD sp!, {r0-r3} ; push old task's r3-r0
  1401. STMFD sp!, {r5} ; push old task's cpsr
  1402. LDR r4, =rt_interrupt_from_thread
  1403. LDR r5, [r4]
  1404. STR sp, [r5] ; store sp in preempted tasks's TCB
  1405. LDR r6, =rt_interrupt_to_thread
  1406. LDR r6, [r6]
  1407. LDR sp, [r6] ; get new task's stack pointer
  1408. LDMFD sp!, {r4} ; pop new task's cpsr to spsr
  1409. MSR spsr_cxsf, r4
  1410. BIC r4, r4, #0x20 ; must be ARM mode
  1411. MSR cpsr_cxsf, r4
  1412. LDMFD sp!, {r0-r12,lr,pc}^ ; pop new task's r0-r12,lr & pc, copy spsr to cpsr
  1413. ENDP
  1414. IF :DEF:__MICROLIB
  1415. EXPORT __heap_base
  1416. EXPORT __heap_limit
  1417. ELSE
  1418. ; User Initial Stack & Heap
  1419. AREA |.text|, CODE, READONLY
  1420. IMPORT __use_two_region_memory
  1421. EXPORT __user_initial_stackheap
  1422. __user_initial_stackheap
  1423. LDR R0, = Heap_Mem
  1424. LDR R1, =(Stack_Mem + USR_Stack_Size)
  1425. LDR R2, = (Heap_Mem + Heap_Size)
  1426. LDR R3, = Stack_Mem
  1427. BX LR
  1428. ENDIF
  1429. END