| 1 | /*********************************************************************
|
|---|
| 2 | * SEGGER Microcontroller GmbH *
|
|---|
| 3 | * The Embedded Experts *
|
|---|
| 4 | **********************************************************************
|
|---|
| 5 | * *
|
|---|
| 6 | * (c) 2014 - 2019 SEGGER Microcontroller GmbH *
|
|---|
| 7 | * *
|
|---|
| 8 | * www.segger.com Support: support@segger.com *
|
|---|
| 9 | * *
|
|---|
| 10 | **********************************************************************
|
|---|
| 11 | * *
|
|---|
| 12 | * All rights reserved. *
|
|---|
| 13 | * *
|
|---|
| 14 | * Redistribution and use in source and binary forms, with or *
|
|---|
| 15 | * without modification, are permitted provided that the following *
|
|---|
| 16 | * conditions are met: *
|
|---|
| 17 | * *
|
|---|
| 18 | * - Redistributions of source code must retain the above copyright *
|
|---|
| 19 | * notice, this list of conditions and the following disclaimer. *
|
|---|
| 20 | * *
|
|---|
| 21 | * - Neither the name of SEGGER Microcontroller GmbH *
|
|---|
| 22 | * nor the names of its contributors may be used to endorse or *
|
|---|
| 23 | * promote products derived from this software without specific *
|
|---|
| 24 | * prior written permission. *
|
|---|
| 25 | * *
|
|---|
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
|---|
| 27 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
|---|
| 28 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
|---|
| 29 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
|---|
| 30 | * DISCLAIMED. *
|
|---|
| 31 | * IN NO EVENT SHALL SEGGER Microcontroller GmbH BE LIABLE FOR *
|
|---|
| 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
|---|
| 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
|---|
| 34 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
|---|
| 35 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
|---|
| 36 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
|---|
| 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
|---|
| 38 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
|---|
| 39 | * DAMAGE. *
|
|---|
| 40 | * *
|
|---|
| 41 | *********************************************************************/
|
|---|
| 42 |
|
|---|
| 43 | /*****************************************************************************
|
|---|
| 44 | * Preprocessor Definitions *
|
|---|
| 45 | * ------------------------ *
|
|---|
| 46 | * NO_STACK_INIT *
|
|---|
| 47 | * *
|
|---|
| 48 | * If defined, the stack pointer will not be initialised. *
|
|---|
| 49 | * *
|
|---|
| 50 | * NO_SYSTEM_INIT *
|
|---|
| 51 | * *
|
|---|
| 52 | * If defined, the SystemInit() function will not be called. By default *
|
|---|
| 53 | * SystemInit() is called after reset to enable the clocks and memories to *
|
|---|
| 54 | * be initialised prior to any C startup initialisation. *
|
|---|
| 55 | * *
|
|---|
| 56 | * NO_VTOR_CONFIG *
|
|---|
| 57 | * *
|
|---|
| 58 | * If defined, the vector table offset register will not be configured. *
|
|---|
| 59 | * *
|
|---|
| 60 | * MEMORY_INIT *
|
|---|
| 61 | * *
|
|---|
| 62 | * If defined, the MemoryInit() function will be called. By default *
|
|---|
| 63 | * MemoryInit() is called after SystemInit() to enable an external memory *
|
|---|
| 64 | * controller. *
|
|---|
| 65 | * *
|
|---|
| 66 | * STACK_INIT_VAL *
|
|---|
| 67 | * *
|
|---|
| 68 | * If defined, specifies the initial stack pointer value. If undefined, *
|
|---|
| 69 | * the stack pointer will be initialised to point to the end of the *
|
|---|
| 70 | * RAM segment. *
|
|---|
| 71 | * *
|
|---|
| 72 | * VECTORS_IN_RAM *
|
|---|
| 73 | * *
|
|---|
| 74 | * If defined, the exception vectors will be copied from Flash to RAM. *
|
|---|
| 75 | * *
|
|---|
| 76 | *****************************************************************************/
|
|---|
| 77 |
|
|---|
| 78 | .syntax unified
|
|---|
| 79 |
|
|---|
| 80 | .global Reset_Handler
|
|---|
| 81 | .extern _vectors
|
|---|
| 82 |
|
|---|
| 83 | .section .init, "ax"
|
|---|
| 84 | .thumb_func
|
|---|
| 85 |
|
|---|
| 86 | .equ VTOR_REG, 0xE000ED08
|
|---|
| 87 |
|
|---|
| 88 | #ifndef STACK_INIT_VAL
|
|---|
| 89 | #define STACK_INIT_VAL __RAM_segment_end__
|
|---|
| 90 | #endif
|
|---|
| 91 |
|
|---|
| 92 | Reset_Handler:
|
|---|
| 93 | #ifndef NO_STACK_INIT
|
|---|
| 94 | /* Initialize main stack */
|
|---|
| 95 | ldr r0, =STACK_INIT_VAL
|
|---|
| 96 | ldr r1, =0x7
|
|---|
| 97 | bics r0, r1
|
|---|
| 98 | mov sp, r0
|
|---|
| 99 | #endif
|
|---|
| 100 |
|
|---|
| 101 | #ifndef NO_SYSTEM_INIT
|
|---|
| 102 | /* Initialize system */
|
|---|
| 103 | ldr r0, =SystemInit
|
|---|
| 104 | blx r0
|
|---|
| 105 | .pushsection .init_array, "aw", %init_array
|
|---|
| 106 | .align 2
|
|---|
| 107 | .word SystemCoreClockUpdate
|
|---|
| 108 | .popsection
|
|---|
| 109 | #endif
|
|---|
| 110 |
|
|---|
| 111 | #ifdef MEMORY_INIT
|
|---|
| 112 | ldr r0, =MemoryInit
|
|---|
| 113 | blx r0
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|
| 116 | #ifdef VECTORS_IN_RAM
|
|---|
| 117 | /* Copy exception vectors into RAM */
|
|---|
| 118 | ldr r0, =__vectors_start__
|
|---|
| 119 | ldr r1, =__vectors_end__
|
|---|
| 120 | ldr r2, =__vectors_ram_start__
|
|---|
| 121 | 1:
|
|---|
| 122 | cmp r0, r1
|
|---|
| 123 | beq 2f
|
|---|
| 124 | ldr r3, [r0]
|
|---|
| 125 | str r3, [r2]
|
|---|
| 126 | adds r0, r0, #4
|
|---|
| 127 | adds r2, r2, #4
|
|---|
| 128 | b 1b
|
|---|
| 129 | 2:
|
|---|
| 130 | #endif
|
|---|
| 131 |
|
|---|
| 132 | #ifndef NO_VTOR_CONFIG
|
|---|
| 133 | /* Configure vector table offset register */
|
|---|
| 134 | ldr r0, =VTOR_REG
|
|---|
| 135 | #ifdef VECTORS_IN_RAM
|
|---|
| 136 | ldr r1, =_vectors_ram
|
|---|
| 137 | #else
|
|---|
| 138 | ldr r1, =_vectors
|
|---|
| 139 | #endif
|
|---|
| 140 | str r1, [r0]
|
|---|
| 141 | #endif
|
|---|
| 142 |
|
|---|
| 143 | /* Jump to program start */
|
|---|
| 144 | b _start
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|