STR71x.s
上传用户:yyyd609
上传日期:2022-07-18
资源大小:183k
文件大小:18k
源码类别:

微处理器开发

开发平台:

C/C++

  1. ;/*****************************************************************************/
  2. ;/* STARTUP.S: Startup file for ST STR71x 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. ; *  REMAP: when set the startup code initializes the register BOOTCR 
  18. ; *  which overwrites the settings of the CPU configuration pins. The 
  19. ; *  startup and interrupt vectors are remapped from:
  20. ; *     0x40000000  default setting
  21. ; *     0x60000000  when EXTMEM_MODE is used
  22. ; *     0x20000000  when RAM_MODE is used
  23. ; *
  24. ; *  EXTMEM_MODE: when set the device is configured for code execution
  25. ; *  from external memory starting at address 0x60000000. The startup
  26. ; *  vectors are located to 0x60000000.
  27. ; *
  28. ; *  RAM_MODE: when set the device is configured for code execution
  29. ; *  from on-chip RAM starting at address 0x20000000. The startup
  30. ; *  vectors are located to 0x20000000.
  31. ; */
  32. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  33. Mode_USR        EQU     0x10
  34. Mode_FIQ        EQU     0x11
  35. Mode_IRQ        EQU     0x12
  36. Mode_SVC        EQU     0x13
  37. Mode_ABT        EQU     0x17
  38. Mode_UND        EQU     0x1B
  39. Mode_SYS        EQU     0x1F
  40. I_Bit           EQU     0x80            ; when I bit is set, IRQ is disabled
  41. F_Bit           EQU     0x40            ; when F bit is set, FIQ is disabled
  42. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  43. ;//   <o0> Undefined Mode      <0x0-0xFFFFFFFF:8>
  44. ;//   <o1> Supervisor Mode     <0x0-0xFFFFFFFF:8>
  45. ;//   <o2> Abort Mode          <0x0-0xFFFFFFFF:8>
  46. ;//   <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  47. ;//   <o4> Interrupt Mode      <0x0-0xFFFFFFFF:8>
  48. ;//   <o5> User/System Mode    <0x0-0xFFFFFFFF:8>
  49. ;// </h>
  50. UND_Stack_Size  EQU     0x00000000
  51. SVC_Stack_Size  EQU     0x00000008
  52. ABT_Stack_Size  EQU     0x00000000
  53. FIQ_Stack_Size  EQU     0x00000000
  54. IRQ_Stack_Size  EQU     0x00000100
  55. USR_Stack_Size  EQU     0x00000400
  56. ISR_Stack_Size  EQU     (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + 
  57.                          FIQ_Stack_Size + IRQ_Stack_Size)
  58.                 AREA    STACK, NOINIT, READWRITE, ALIGN=3
  59. Stack_Mem       SPACE   USR_Stack_Size
  60. __initial_sp    SPACE   ISR_Stack_Size
  61. Stack_Top
  62. ;// <h> Heap Configuration
  63. ;//   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  64. ;// </h>
  65. Heap_Size       EQU     0x00000000
  66.                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
  67. __heap_base
  68. Heap_Mem        SPACE   Heap_Size
  69. __heap_limit
  70. ; APB Bridge 1 & 2 definitions (Peripherals)
  71. APB1_BASE       EQU     0xC0000000      ; APB Bridge 1 Base Address
  72. APB2_BASE       EQU     0xE0000000      ; APB Bridge 2 Base Address
  73. CKDIS_OFS       EQU     0x10            ; Clock Disable Register Offset
  74. SWRES_OFS       EQU     0x14            ; Software Reset Register Offset
  75. APB1_Mask       EQU     0x27FB          ; APB1 Peripherals Mask
  76. APB2_Mask       EQU     0x7FDD          ; APB2 Peripherals Mask
  77. ;// <e> Reset all Device Peripherals
  78. PERIPH_RESET    EQU     1
  79. ;// </e>
  80. ; External Memory Interface (EMI) definitions
  81. EMI_BASE        EQU     0x6C000000      ; EMI Base Address
  82. BCON0_OFS       EQU     0x00            ; BCON0 Offset
  83. BCON1_OFS       EQU     0x04            ; BCON1 Offset
  84. BCON2_OFS       EQU     0x08            ; BCON2 Offset
  85. BCON3_OFS       EQU     0x0C            ; BCON3 Offset
  86. ;// <e> External Memory Interface (EMI)
  87. EMI_SETUP       EQU     0
  88. ;//   <h> Bank Configuration 0 (BCON0)
  89. ;//     <o.15>    BE: Bank Enable
  90. ;//     <o.0..1>  B_SIZE: Bus Size  <0=>  8-bit    <1=> 16-bit
  91. ;//                                 <2=> Reserved  <3=> Reserved
  92. ;//     <o.2..5>  C_LENGTH: Cycle Length <0-15>
  93. ;//               <i> Number of Wait States
  94. ;//   </h>
  95. BCON0_Val       EQU     0x0000801D
  96. ;//   <h> Bank Configuration 1 (BCON1)
  97. ;//     <o.15>    BE: Bank Enable
  98. ;//     <o.0..1>  B_SIZE: Bus Size  <0=>  8-bit    <1=> 16-bit
  99. ;//                                 <2=> Reserved  <3=> Reserved
  100. ;//     <o.2..5>  C_LENGTH: Cycle Length <0-15>
  101. ;//               <i> Number of Wait States
  102. ;//   </h>
  103. BCON1_Val       EQU     0x0000801D
  104. ;//   <h> Bank Configuration 2 (BCON2)
  105. ;//     <o.15>    BE: Bank Enable
  106. ;//     <o.0..1>  B_SIZE: Bus Size  <0=>  8-bit    <1=> 16-bit
  107. ;//                                 <2=> Reserved  <3=> Reserved
  108. ;//     <o.2..5>  C_LENGTH: Cycle Length <0-15>
  109. ;//               <i> Number of Wait States
  110. ;//   </h>
  111. BCON2_Val       EQU     0x0000001D
  112. ;//   <h> Bank Configuration 3 (BCON3)
  113. ;//     <o.15>    BE: Bank Enable
  114. ;//     <o.0..1>  B_SIZE: Bus Size  <0=>  8-bit    <1=> 16-bit
  115. ;//                                 <2=> Reserved  <3=> Reserved
  116. ;//     <o.2..5>  C_LENGTH: Cycle Length <0-15>
  117. ;//               <i> Number of Wait States
  118. ;//   </h>
  119. BCON3_Val       EQU     0x0000001D
  120. ;// </e> End of EMI
  121. ; GPIO Port 2 definitions (for External Memory Interface setup)
  122. GPIO2_BASE      EQU     0xE0005000      ; GPIO2 Base Address
  123. PC0_OFS         EQU     0x00            ; PC0 Offset
  124. PC1_OFS         EQU     0x04            ; PC1 Offset
  125. PC2_OFS         EQU     0x08            ; PC2 Offset
  126. PD_OFS          EQU     0x0C            ; PD Offset
  127. ; Enhanced Interrupt Controller (EIC) definitions
  128. EIC_BASE        EQU     0xFFFFF800      ; EIC Base Address
  129. ICR_OFS         EQU     0x00            ; Interrupt Control Reg. Offset
  130. CIPR_OFS        EQU     0x08            ; Curr. Int. Priority R. Offset
  131. IVR_OFS         EQU     0x18            ; Interrupt Vector Reg. Offset
  132. FIR_OFS         EQU     0x1C            ; Fast Interrupt Reg. Offset
  133. IER_OFS         EQU     0x20            ; Interrupt Enable Reg. Offset
  134. IPR_OFS         EQU     0x40            ; Interrupt Pending Reg. Offset
  135. SIR0_OFS        EQU     0x60            ; Source Interrupt Reg. 0 Offset
  136. ;// <e> Setup EIC and Exception Handlers
  137. EIC_SETUP       EQU     1
  138. ;// </e>
  139.                 PRESERVE8
  140.                 
  141. ; Area Definition and Entry Point
  142. ;  Startup Code must be linked first at Address at which it expects to run.
  143. EXPORT  Vectors
  144.                 AREA    Reset, CODE, READONLY
  145.                 ARM
  146.                 IF      EIC_SETUP <> 0
  147.                 ; Import Exceptions Handlers
  148.                 IMPORT  UndefHandler
  149.                 IMPORT  SWIHandler
  150.                 IMPORT  PAbtHandler
  151.                 IMPORT  DAbtHandler
  152.                 IMPORT  IRQHandler
  153.                 IMPORT  FIQHandler
  154.                 ; Import IRQ Handlers
  155.                 IMPORT  T0TIMIIRQHandler
  156.                 IMPORT  FLASHIRQHandler
  157.                 IMPORT  RCCUIRQHandler
  158.                 IMPORT  RTCIRQHandler
  159.                 IMPORT  WDGIRQHandler
  160.                 IMPORT  XTIIRQHandler
  161.                 IMPORT  USBHPIRQHandler
  162.                 IMPORT  I2C0ITERRIRQHandler
  163.                 IMPORT  I2C1ITERRIRQHandler
  164.                 IMPORT  UART0IRQHandler
  165.                 IMPORT  UART1IRQHandler
  166.                 IMPORT  UART2IRQHandler
  167.                 IMPORT  UART3IRQHandler
  168.                 IMPORT  BSPI0IRQHandler
  169.                 IMPORT  BSPI1IRQHandler
  170.                 IMPORT  I2C0IRQHandler
  171.                 IMPORT  I2C1IRQHandler
  172.                 IMPORT  CANIRQHandler
  173.                 IMPORT  ADC12IRQHandler
  174.                 IMPORT  T1TIMIIRQHandler
  175.                 IMPORT  T2TIMIIRQHandler
  176.                 IMPORT  T3TIMIIRQHandler
  177.                 IMPORT  HDLCIRQHandler
  178.                 IMPORT  USBLPIRQHandler
  179.                 IMPORT  T0TOIIRQHandler
  180.                 IMPORT  T0OC1IRQHandler
  181.                 IMPORT  T0OC2IRQHandler
  182.                 ENDIF
  183. ; Exception Vectors
  184. ;  Mapped to Address 0.
  185. ;  Absolute addressing mode must be used.
  186. ;  Dummy Handlers are implemented as infinite loops which can be modified.
  187. ; ENTRY
  188. Vectors         
  189.   ; ENTRY
  190.                 LDR     PC, Reset_Addr         
  191.                 LDR     PC, Undef_Addr
  192.                 LDR     PC, SWI_Addr
  193.                 LDR     PC, PAbt_Addr
  194.                 LDR     PC, DAbt_Addr
  195.                 NOP                         ; Reserved Vector 
  196.                 IF      EIC_SETUP <> 0                
  197.                 LDR     PC,IRQ_Addr
  198.                 ELSE
  199.                 LDR     PC,[PC, #-0x0808]   ; Vector from EIC_IVR
  200.                 ENDIF
  201.                 LDR     PC, FIQ_Addr
  202. Reset_Addr      DCD     Reset_Handler
  203. Undef_Addr      DCD     UndefHandler
  204. SWI_Addr        DCD     SWIHandler
  205. PAbt_Addr       DCD     PAbtHandler
  206. DAbt_Addr       DCD     DAbtHandler
  207.                 DCD     0                   ; Reserved Address 
  208. IRQ_Addr        DCD     IRQHandler
  209. FIQ_Addr        DCD     FIQHandler
  210.                 IF      EIC_SETUP = 0
  211. UndefHandler    B       UndefHandler
  212. SWIHandler      B       SWIHandler
  213. PAbtHandler     B       PAbtHandler
  214. DAbtHandler     B       DAbtHandler
  215. IRQHandler      B       IRQHandler
  216. FIQHandler      B       FIQHandler
  217.                 ELSE
  218.                 ; Peripherals IRQ Handlers Address Table
  219.                 EXPORT  T0TIMI_Addr
  220. T0TIMI_Addr     DCD     T0TIMIIRQHandler
  221. FLASH_Addr      DCD     FLASHIRQHandler
  222. RCCU_Addr       DCD     RCCUIRQHandler
  223. RTC_Addr        DCD     RTCIRQHandler
  224. WDG_Addr        DCD     WDGIRQHandler
  225. XTI_Addr        DCD     XTIIRQHandler
  226. USBHP_Addr      DCD     USBHPIRQHandler
  227. I2C0ITERR_Addr  DCD     I2C0ITERRIRQHandler
  228. I2C1ITERR_Addr  DCD     I2C1ITERRIRQHandler
  229. UART0_Addr      DCD     UART0IRQHandler
  230. UART1_Addr      DCD     UART1IRQHandler
  231. UART2_Addr      DCD     UART2IRQHandler
  232. UART3_Addr      DCD     UART3IRQHandler
  233. BSPI0_Addr      DCD     BSPI0IRQHandler
  234. BSPI1_Addr      DCD     BSPI1IRQHandler
  235. I2C0_Addr       DCD     I2C0IRQHandler
  236. I2C1_Addr       DCD     I2C1IRQHandler
  237. CAN_Addr        DCD     CANIRQHandler
  238. ADC12_Addr      DCD     ADC12IRQHandler
  239. T1TIMI_Addr     DCD     T1TIMIIRQHandler
  240. T2TIMI_Addr     DCD     T2TIMIIRQHandler
  241. T3TIMI_Addr     DCD     T3TIMIIRQHandler
  242.                 DCD     0                   ; Reserved
  243.                 DCD     0                   ; Reserved
  244.                 DCD     0                   ; Reserved
  245. HDLC_Addr       DCD     HDLCIRQHandler
  246. USBLP_Addr      DCD     USBLPIRQHandler
  247.                 DCD     0                   ; Reserved
  248.                 DCD     0                   ; Reserved
  249. T0TOI_Addr      DCD     T0TOIIRQHandler
  250. T0OC1_Addr      DCD     T0OC1IRQHandler
  251. T0OC2_Addr      DCD     T0OC2IRQHandler
  252.                 ENDIF
  253. ; Reset Handler
  254.                 EXPORT  Reset_Handler
  255. Reset_Handler   
  256.                 NOP     ; Wait for OSC stabilization
  257.                 NOP
  258.                 NOP
  259.                 NOP
  260.                 NOP
  261.                 NOP
  262.                 NOP
  263.                 NOP
  264. ; Reset Peripherals
  265.                 IF      PERIPH_RESET <> 0
  266.                 LDR     R1, =APB1_BASE
  267.                 LDR     R2, =APB2_BASE
  268.                 LDR     R3, =APB1_Mask
  269.                 LDR     R4, =APB2_Mask
  270.                 STRH    R3, [R1, #CKDIS_OFS]   ; Disable Clock for APB1 periph.
  271.                 STRH    R4, [R2, #CKDIS_OFS]   ; Disable Clock for APB2 periph.
  272.                 STRH    R3, [R1, #SWRES_OFS]   ; Keep under Reset APB1 periph.
  273.                 STRH    R4, [R2, #SWRES_OFS]   ; Keep under Reset APB2 periph.
  274.                 MOV     R0, #10
  275. PR_Loop1        SUBS    R0, R0, #1             ; Wait that selected macrocells
  276.                 BNE     PR_Loop1               ; enter reset
  277.                 STRH    R0, [R1, #SWRES_OFS]   ; Release Reset of APB1 periph.
  278.                 STRH    R0, [R2, #SWRES_OFS]   ; Relase Reset of APB2 periph.
  279.                 STRH    R0, [R1, #CKDIS_OFS]   ; Enable Clock for APB1 periph.
  280.                 STRH    R0, [R2, #CKDIS_OFS]   ; Enable Clock for APB2 periph.
  281.                 MOV     R0, #10
  282. PR_Loop2        SUBS    R0, R0, #1             ; Wait that selected macrocells
  283.                 BNE     PR_Loop2               ; exit from reset
  284.                 ENDIF
  285. ; Setup External Memory Interface (EMI)
  286.                 IF      EMI_SETUP <> 0
  287.                 LDR     R0, =GPIO2_BASE        ; Configure P2.0..7 for Ext. Bus
  288.                 LDR     R1, [R0, #PC0_OFS]
  289.                 ORR     R1, R1, #0x0000000F
  290.                 STR     R1, [R0, #PC0_OFS]
  291.                 LDR     R1, [R0, #PC1_OFS]
  292.                 ORR     R1, R1, #0x0000000F
  293.                 STR     R1, [R0, #PC1_OFS]
  294.                 LDR     R1, [R0, #PC2_OFS]
  295.                 ORR     R1, R1, #0x0000000F
  296.                 STR     R1, [R0, #PC2_OFS]
  297.                 LDR     R0, =EMI_BASE          ; Configure EMI
  298.                 LDR     R1, =BCON0_Val
  299.                 STR     R1, [R0, #BCON0_OFS]
  300.                 LDR     R1, =BCON1_Val
  301.                 STR     R1, [R0, #BCON1_OFS]
  302.                 LDR     R1, =BCON2_Val
  303.                 STR     R1, [R0, #BCON2_OFS]
  304.                 LDR     R1, =BCON3_Val
  305.                 STR     R1, [R0, #BCON3_OFS]
  306.                 ENDIF
  307. ; Setup Enhanced Interrupt Controller
  308.                 IF      EIC_SETUP <> 0
  309.                 LDR     R0, =EIC_BASE
  310.                 LDR     R1, =0xE59F0000     ; LDR PC,[PC,#ofs] (High 16-bits)
  311.                 STR     R1, [R0, #IVR_OFS]  ; Store into IVR[31:16]
  312.                 LDR     R1, =T0TIMI_Addr    ; IRQ Address Table
  313.                 LDR     R2, =0x0FFF         ; Offset Mask
  314.                 AND     R1, R1, R2          ; Mask Offset
  315.                 LDR     R2, =0xF7E0         ; Jump Offset = 0x07E0
  316.                                             ; 0xFXXX is used to complete the
  317.                                             ; LDR PC,[PC,#ofs]
  318.                                             ; 0x07E0 = 0x07E8 - 8 (Prefetch)
  319.                                             ; 0 = IVR Address + 0x7E8
  320.                 ADD     R1, R1, R2          ; Add Jump Offset
  321.                 MOV     R2, #32             ; Number of Channels
  322.                 MOV     R3, #SIR0_OFS       ; Offset to SIR0
  323. EIC_Loop        MOV     R4, R1, LSL #16     ; Use High 16-bits
  324.                 STR     R4, [R0, R3]        ; Store into SIRx
  325.                 ADD     R1, R1, #4          ; Next IRQ Address
  326.                 ADD     R3, R3, #4          ; Next SIRx
  327.                 SUBS    R2, R2, #1          ; Decrement Counter
  328.                 BNE     EIC_Loop                               
  329.                 ENDIF
  330. ; Memory Remapping
  331. BOOTCR          EQU     0xA0000050          ; Boot Configuration Register
  332. FLASH_BM        EQU     0x01                ; Boot Mode: Flash at 0
  333. RAM_BM          EQU     0x02                ; Boot Mode: RAM at 0
  334. EXTMEM_BM       EQU     0x03                ; Boot Mode: EXTMEM at 0
  335.                 IF      :DEF:REMAP
  336.                 MOV     R1, #FLASH_BM
  337.                 IF      :DEF:EXTMEM_MODE
  338.                 MOV     R1, #EXTMEM_BM
  339.                 ENDIF
  340.                 IF      :DEF:RAM_MODE
  341.                 MOV     R1, #RAM_BM
  342.                 ENDIF
  343.                 LDR     R0, =BOOTCR
  344.                 LDRH    R2, [R0]            ; Read BOOTCR
  345.                 BIC     R2, R2, #0x03       ; Clear two LSB bits
  346.                 ORR     R2, R2, R1          ; Setup two LSB bits
  347.                 STRH    R2, [R0]            ; Write BOOTCR
  348.                 ENDIF
  349. ; Setup Stack for each mode
  350.                 LDR     R0, =Stack_Top
  351. ;  Enter Undefined Instruction Mode and set its Stack Pointer
  352.                 MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  353.                 MOV     SP, R0
  354.                 SUB     R0, R0, #UND_Stack_Size
  355. ;  Enter Abort Mode and set its Stack Pointer
  356.                 MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  357.                 MOV     SP, R0
  358.                 SUB     R0, R0, #ABT_Stack_Size
  359. ;  Enter FIQ Mode and set its Stack Pointer
  360.                 MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  361.                 MOV     SP, R0
  362.                 SUB     R0, R0, #FIQ_Stack_Size
  363. ;  Enter IRQ Mode and set its Stack Pointer
  364.                 MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  365.                 MOV     SP, R0
  366.                 SUB     R0, R0, #IRQ_Stack_Size
  367. ;  Enter Supervisor Mode and set its Stack Pointer
  368.                 MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  369.                 MOV     SP, R0
  370.                 SUB     R0, R0, #SVC_Stack_Size
  371. ;  Enter User Mode and set its Stack Pointer
  372.                 MSR     CPSR_c, #Mode_USR
  373.                 IF      :DEF:__MICROLIB
  374.                 EXPORT __initial_sp
  375.                 ELSE
  376.                 MOV     SP, R0
  377.                 SUB     SL, SP, #USR_Stack_Size
  378.                 ENDIF
  379. ; Enter the C code
  380.                 IMPORT  __main
  381.                 LDR     R0, =__main
  382.                 BX      R0
  383.                 IF      :DEF:__MICROLIB
  384.                 EXPORT  __heap_base
  385.                 EXPORT  __heap_limit
  386.                 ELSE
  387. ; User Initial Stack & Heap
  388.                 AREA    |.text|, CODE, READONLY
  389.                 IMPORT  __use_two_region_memory
  390.                 EXPORT  __user_initial_stackheap
  391. __user_initial_stackheap
  392.                 LDR     R0, =  Heap_Mem
  393.                 LDR     R1, =(Stack_Mem + USR_Stack_Size)
  394.                 LDR     R2, = (Heap_Mem +      Heap_Size)
  395.                 LDR     R3, = Stack_Mem
  396.                 BX      LR
  397.                 ENDIF
  398.                 END