Brian Silverman | 2bf644d | 2013-12-06 16:54:59 -0800 | [diff] [blame^] | 1 | /* File: startup_ARMCM3.S |
| 2 | * Purpose: startup file for Cortex-M3 devices. Should use with |
| 3 | * GCC for ARM Embedded Processors |
| 4 | * Version: V1.4 |
| 5 | * Date: 20 Dezember 2012 |
| 6 | * |
| 7 | */ |
| 8 | /* Copyright (c) 2011 - 2012 ARM LIMITED |
| 9 | |
| 10 | All rights reserved. |
| 11 | Redistribution and use in source and binary forms, with or without |
| 12 | modification, are permitted provided that the following conditions are met: |
| 13 | - Redistributions of source code must retain the above copyright |
| 14 | notice, this list of conditions and the following disclaimer. |
| 15 | - Redistributions in binary form must reproduce the above copyright |
| 16 | notice, this list of conditions and the following disclaimer in the |
| 17 | documentation and/or other materials provided with the distribution. |
| 18 | - Neither the name of ARM nor the names of its contributors may be used |
| 19 | to endorse or promote products derived from this software without |
| 20 | specific prior written permission. |
| 21 | * |
| 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
| 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 32 | POSSIBILITY OF SUCH DAMAGE. |
| 33 | ---------------------------------------------------------------------------*/ |
| 34 | |
| 35 | |
| 36 | .syntax unified |
| 37 | .arch armv7-m |
| 38 | |
| 39 | .section .stack |
| 40 | .align 3 |
| 41 | #ifdef __STACK_SIZE |
| 42 | .equ Stack_Size, __STACK_SIZE |
| 43 | #else |
| 44 | .equ Stack_Size, 0x00000400 |
| 45 | #endif |
| 46 | .globl __StackTop |
| 47 | .globl __StackLimit |
| 48 | __StackLimit: |
| 49 | .space Stack_Size |
| 50 | .size __StackLimit, . - __StackLimit |
| 51 | __StackTop: |
| 52 | .size __StackTop, . - __StackTop |
| 53 | |
| 54 | .section .heap |
| 55 | .align 3 |
| 56 | #ifdef __HEAP_SIZE |
| 57 | .equ Heap_Size, __HEAP_SIZE |
| 58 | #else |
| 59 | .equ Heap_Size, 0x00000C00 |
| 60 | #endif |
| 61 | .globl __HeapBase |
| 62 | .globl __HeapLimit |
| 63 | __HeapBase: |
| 64 | .if Heap_Size |
| 65 | .space Heap_Size |
| 66 | .endif |
| 67 | .size __HeapBase, . - __HeapBase |
| 68 | __HeapLimit: |
| 69 | .size __HeapLimit, . - __HeapLimit |
| 70 | |
| 71 | #if 0 |
| 72 | .section .isr_vector |
| 73 | .align 2 |
| 74 | .globl __isr_vector |
| 75 | __isr_vector: |
| 76 | .long __StackTop /* Top of Stack */ |
| 77 | .long Reset_Handler /* Reset Handler */ |
| 78 | .long NMI_Handler /* NMI Handler */ |
| 79 | .long HardFault_Handler /* Hard Fault Handler */ |
| 80 | .long MemManage_Handler /* MPU Fault Handler */ |
| 81 | .long BusFault_Handler /* Bus Fault Handler */ |
| 82 | .long UsageFault_Handler /* Usage Fault Handler */ |
| 83 | .long 0 /* Reserved */ |
| 84 | .long 0 /* Reserved */ |
| 85 | .long 0 /* Reserved */ |
| 86 | .long 0 /* Reserved */ |
| 87 | .long SVC_Handler /* SVCall Handler */ |
| 88 | .long DebugMon_Handler /* Debug Monitor Handler */ |
| 89 | .long 0 /* Reserved */ |
| 90 | .long PendSV_Handler /* PendSV Handler */ |
| 91 | .long SysTick_Handler /* SysTick Handler */ |
| 92 | |
| 93 | /* External interrupts */ |
| 94 | .long WDT_IRQHandler /* 0: Watchdog Timer */ |
| 95 | .long RTC_IRQHandler /* 1: Real Time Clock */ |
| 96 | .long TIM0_IRQHandler /* 2: Timer0 / Timer1 */ |
| 97 | .long TIM2_IRQHandler /* 3: Timer2 / Timer3 */ |
| 98 | .long MCIA_IRQHandler /* 4: MCIa */ |
| 99 | .long MCIB_IRQHandler /* 5: MCIb */ |
| 100 | .long UART0_IRQHandler /* 6: UART0 - DUT FPGA */ |
| 101 | .long UART1_IRQHandler /* 7: UART1 - DUT FPGA */ |
| 102 | .long UART2_IRQHandler /* 8: UART2 - DUT FPGA */ |
| 103 | .long UART4_IRQHandler /* 9: UART4 - not connected */ |
| 104 | .long AACI_IRQHandler /* 10: AACI / AC97 */ |
| 105 | .long CLCD_IRQHandler /* 11: CLCD Combined Interrupt */ |
| 106 | .long ENET_IRQHandler /* 12: Ethernet */ |
| 107 | .long USBDC_IRQHandler /* 13: USB Device */ |
| 108 | .long USBHC_IRQHandler /* 14: USB Host Controller */ |
| 109 | .long CHLCD_IRQHandler /* 15: Character LCD */ |
| 110 | .long FLEXRAY_IRQHandler /* 16: Flexray */ |
| 111 | .long CAN_IRQHandler /* 17: CAN */ |
| 112 | .long LIN_IRQHandler /* 18: LIN */ |
| 113 | .long I2C_IRQHandler /* 19: I2C ADC/DAC */ |
| 114 | .long 0 /* 20: Reserved */ |
| 115 | .long 0 /* 21: Reserved */ |
| 116 | .long 0 /* 22: Reserved */ |
| 117 | .long 0 /* 23: Reserved */ |
| 118 | .long 0 /* 24: Reserved */ |
| 119 | .long 0 /* 25: Reserved */ |
| 120 | .long 0 /* 26: Reserved */ |
| 121 | .long 0 /* 27: Reserved */ |
| 122 | .long CPU_CLCD_IRQHandler /* 28: Reserved - CPU FPGA CLCD */ |
| 123 | .long 0 /* 29: Reserved - CPU FPGA */ |
| 124 | .long UART3_IRQHandler /* 30: UART3 - CPU FPGA */ |
| 125 | .long SPI_IRQHandler /* 31: SPI Touchscreen - CPU FPGA */ |
| 126 | |
| 127 | .size __isr_vector, . - __isr_vector |
| 128 | #else |
| 129 | .macro ISR_HANDLER name= |
| 130 | .section .vectors, "ax" |
| 131 | .word \name |
| 132 | .section .init, "ax" |
| 133 | .thumb_func |
| 134 | .weak \name |
| 135 | \name: |
| 136 | 1: b 1b /* endless loop */ |
| 137 | .endm |
| 138 | |
| 139 | .macro ISR_RESERVED |
| 140 | .section .vectors, "ax" |
| 141 | .word 0 |
| 142 | .endm |
| 143 | |
| 144 | .syntax unified |
| 145 | .global reset_handler |
| 146 | |
| 147 | .section .vectors, "ax" |
| 148 | .code 16 |
| 149 | .global _vectors |
| 150 | |
| 151 | _vectors: |
| 152 | .long __StackTop /* Top of Stack */ |
| 153 | .long Reset_Handler /* Reset Handler */ |
| 154 | ISR_HANDLER NMI_Handler |
| 155 | ISR_HANDLER HardFault_Handler |
| 156 | ISR_HANDLER MemManage_Handler |
| 157 | ISR_HANDLER BusFault_Handler |
| 158 | ISR_HANDLER UsageFault_Handler |
| 159 | ISR_RESERVED |
| 160 | ISR_RESERVED |
| 161 | ISR_RESERVED |
| 162 | ISR_RESERVED |
| 163 | ISR_HANDLER SVC_Handler |
| 164 | ISR_HANDLER DebugMon_Handler |
| 165 | ISR_RESERVED |
| 166 | ISR_HANDLER PendSV_Handler |
| 167 | ISR_HANDLER SysTick_Handler |
| 168 | /* interrupts */ |
| 169 | ISR_HANDLER WWDG_IRQHandler |
| 170 | ISR_HANDLER PVD_IRQHandler |
| 171 | ISR_HANDLER TAMP_STAMP_IRQHandler |
| 172 | ISR_HANDLER RTC_WKUP_IRQHandler |
| 173 | ISR_HANDLER FLASH_IRQHandler |
| 174 | ISR_HANDLER RCC_IRQHandler |
| 175 | ISR_HANDLER EXTI0_IRQHandler |
| 176 | ISR_HANDLER EXTI1_IRQHandler |
| 177 | ISR_HANDLER EXTI2_IRQHandler |
| 178 | ISR_HANDLER EXTI3_IRQHandler |
| 179 | ISR_HANDLER EXTI4_IRQHandler |
| 180 | ISR_HANDLER DMA1_Stream0_IRQHandler |
| 181 | ISR_HANDLER DMA1_Stream1_IRQHandler |
| 182 | ISR_HANDLER DMA1_Stream2_IRQHandler |
| 183 | ISR_HANDLER DMA1_Stream3_IRQHandler |
| 184 | ISR_HANDLER DMA1_Stream4_IRQHandler |
| 185 | ISR_HANDLER DMA1_Stream5_IRQHandler |
| 186 | ISR_HANDLER DMA1_Stream6_IRQHandler |
| 187 | ISR_HANDLER ADC_IRQHandler |
| 188 | ISR_HANDLER CAN1_TX_IRQHandler |
| 189 | ISR_HANDLER CAN1_RX0_IRQHandler |
| 190 | ISR_HANDLER CAN1_RX1_IRQHandler |
| 191 | ISR_HANDLER CAN1_SCE_IRQHandler |
| 192 | ISR_HANDLER EXTI9_5_IRQHandler |
| 193 | ISR_HANDLER TIM1_BRK_TIM9_IRQHandler |
| 194 | ISR_HANDLER TIM1_UP_TIM10_IRQHandler |
| 195 | ISR_HANDLER TIM1_TRG_COM_TIM11_IRQHandler |
| 196 | ISR_HANDLER TIM1_CC_IRQHandler |
| 197 | ISR_HANDLER TIM2_IRQHandler |
| 198 | ISR_HANDLER TIM3_IRQHandler |
| 199 | ISR_HANDLER TIM4_IRQHandler |
| 200 | ISR_HANDLER I2C1_EV_IRQHandler |
| 201 | ISR_HANDLER I2C1_ER_IRQHandler |
| 202 | ISR_HANDLER I2C2_EV_IRQHandler |
| 203 | ISR_HANDLER I2C2_ER_IRQHandler |
| 204 | ISR_HANDLER SPI1_IRQHandler |
| 205 | ISR_HANDLER SPI2_IRQHandler |
| 206 | ISR_HANDLER USART1_IRQHandler |
| 207 | ISR_HANDLER USART2_IRQHandler |
| 208 | ISR_HANDLER USART3_IRQHandler |
| 209 | ISR_HANDLER EXTI15_10_IRQHandler |
| 210 | ISR_HANDLER RTC_Alarm_IRQHandler |
| 211 | ISR_HANDLER OTG_FS_WKUP_IRQHandler |
| 212 | ISR_HANDLER TIM8_BRK_TIM12_IRQHandler |
| 213 | ISR_HANDLER TIM8_UP_TIM13_IRQHandler |
| 214 | ISR_HANDLER TIM8_TRG_COM_TIM14_IRQHandler |
| 215 | ISR_HANDLER TIM8_CC_IRQHandler |
| 216 | ISR_HANDLER DMA1_Stream7_IRQHandler |
| 217 | ISR_HANDLER FSMC_IRQHandler |
| 218 | ISR_HANDLER SDIO_IRQHandler |
| 219 | ISR_HANDLER TIM5_IRQHandler |
| 220 | ISR_HANDLER SPI3_IRQHandler |
| 221 | ISR_HANDLER UART4_IRQHandler |
| 222 | ISR_HANDLER UART5_IRQHandler |
| 223 | ISR_HANDLER TIM6_DAC_IRQHandler |
| 224 | ISR_HANDLER TIM7_IRQHandler |
| 225 | ISR_HANDLER DMA2_Stream0_IRQHandler |
| 226 | ISR_HANDLER DMA2_Stream1_IRQHandler |
| 227 | ISR_HANDLER DMA2_Stream2_IRQHandler |
| 228 | ISR_HANDLER DMA2_Stream3_IRQHandler |
| 229 | ISR_HANDLER DMA2_Stream4_IRQHandler |
| 230 | ISR_HANDLER ETH_IRQHandler |
| 231 | ISR_HANDLER ETH_WKUP_IRQHandler |
| 232 | ISR_HANDLER CAN2_TX_IRQHandler |
| 233 | ISR_HANDLER CAN2_RX0_IRQHandler |
| 234 | ISR_HANDLER CAN2_RX1_IRQHandler |
| 235 | ISR_HANDLER CAN2_SCE_IRQHandler |
| 236 | ISR_HANDLER OTG_FS_IRQHandler |
| 237 | ISR_HANDLER DMA2_Stream5_IRQHandler |
| 238 | ISR_HANDLER DMA2_Stream6_IRQHandler |
| 239 | ISR_HANDLER DMA2_Stream7_IRQHandler |
| 240 | ISR_HANDLER USART6_IRQHandler |
| 241 | ISR_HANDLER I2C3_EV_IRQHandler |
| 242 | ISR_HANDLER I2C3_ER_IRQHandler |
| 243 | ISR_HANDLER OTG_HS_EP1_OUT_IRQHandler |
| 244 | ISR_HANDLER OTG_HS_EP1_IN_IRQHandler |
| 245 | ISR_HANDLER OTG_HS_WKUP_IRQHandler |
| 246 | ISR_HANDLER OTG_HS_IRQHandler |
| 247 | ISR_HANDLER DCMI_IRQHandler |
| 248 | ISR_HANDLER CRYP_IRQHandler |
| 249 | ISR_HANDLER HASH_RNG_IRQHandler |
| 250 | .section .vectors, "ax" |
| 251 | _vectors_end: |
| 252 | |
| 253 | |
| 254 | .section .vectors_ram, "ax" |
| 255 | _vectors_ram: |
| 256 | .space _vectors_end-_vectors, 0 |
| 257 | #endif |
| 258 | |
| 259 | .text |
| 260 | .thumb |
| 261 | .thumb_func |
| 262 | .align 2 |
| 263 | .globl Reset_Handler |
| 264 | .type Reset_Handler, %function |
| 265 | Reset_Handler: |
| 266 | /* Loop to copy data from read only memory to RAM. The ranges |
| 267 | * of copy from/to are specified by following symbols evaluated in |
| 268 | * linker script. |
| 269 | * __etext: End of code section, i.e., begin of data sections to copy from. |
| 270 | * __data_start__/__data_end__: RAM address range that data should be |
| 271 | * copied to. Both must be aligned to 4 bytes boundary. */ |
| 272 | |
| 273 | ldr r1, =__etext |
| 274 | ldr r2, =__data_start__ |
| 275 | ldr r3, =__data_end__ |
| 276 | |
| 277 | subs r3, r2 |
| 278 | ble .LC1 |
| 279 | .LC0: |
| 280 | subs r3, #4 |
| 281 | ldr r0, [r1, r3] |
| 282 | str r0, [r2, r3] |
| 283 | bgt .LC0 |
| 284 | .LC1: |
| 285 | |
| 286 | /* Loop to zero out BSS section, which uses following symbols |
| 287 | * in linker script: |
| 288 | * __bss_start__: start of BSS section. Must align to 4 |
| 289 | * __bss_end__: end of BSS section. Must align to 4 |
| 290 | */ |
| 291 | ldr r1, =__bss_start__ |
| 292 | ldr r2, =__bss_end__ |
| 293 | |
| 294 | movs r0, 0 |
| 295 | .LC2: |
| 296 | cmp r1, r2 |
| 297 | itt lt |
| 298 | strlt r0, [r1], #4 |
| 299 | blt .LC2 |
| 300 | |
| 301 | bl SystemInit |
| 302 | |
| 303 | ldr r0, =__vectors_load_start__ |
| 304 | ldr r1, =__vectors_load_end__ |
| 305 | ldr r2, =_vectors_ram |
| 306 | l0: |
| 307 | cmp r0, r1 |
| 308 | beq l1 |
| 309 | ldr r3, [r0] |
| 310 | str r3, [r2] |
| 311 | adds r0, r0, #4 |
| 312 | adds r2, r2, #4 |
| 313 | b l0 |
| 314 | l1: |
| 315 | |
| 316 | /* Configure vector table offset register */ |
| 317 | ldr r0, =0xE000ED08 |
| 318 | ldr r1, =_vectors_ram |
| 319 | str r1, [r0] |
| 320 | |
| 321 | #ifndef __START |
| 322 | #define __START _start |
| 323 | #endif |
| 324 | bl __START |
| 325 | .pool |
| 326 | .size Reset_Handler, . - Reset_Handler |