1 |
577 |
jeremybenn |
;******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
|
2 |
|
|
;* File Name : 75x_init.s
|
3 |
|
|
;* Author : MCD Application Team
|
4 |
|
|
;* Date First Issued : 03/10/2006
|
5 |
|
|
;* Description : This module performs:
|
6 |
|
|
;* - Memory remapping (if required),
|
7 |
|
|
;* - Stack pointer initialisation for each mode ,
|
8 |
|
|
;* - Interrupt Controller Initialisation
|
9 |
|
|
;* - Branches to ?main in the C library (which eventually
|
10 |
|
|
;* calls main()).
|
11 |
|
|
;* On reset, the ARM core starts up in Supervisor (SVC) mode,
|
12 |
|
|
;* in ARM state,with IRQ and FIQ disabled.
|
13 |
|
|
;*******************************************************************************
|
14 |
|
|
; History:
|
15 |
|
|
; 07/17/2006 : V1.0
|
16 |
|
|
; 03/10/2006 : V0.1
|
17 |
|
|
;*******************************************************************************
|
18 |
|
|
; THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
19 |
|
|
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
20 |
|
|
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
21 |
|
|
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
22 |
|
|
; CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
23 |
|
|
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
24 |
|
|
;*******************************************************************************
|
25 |
|
|
|
26 |
|
|
IMPORT WAKUP_Addr ; imported from 75x_vect.s
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
; Depending on Your Application, Disable or Enable the following Defines
|
32 |
|
|
; ----------------------------------------------------------------------------
|
33 |
|
|
; SMI Bank0 configuration
|
34 |
|
|
; ----------------------------------------------------------------------------
|
35 |
|
|
; If you need to accees the SMI Bank0
|
36 |
|
|
; uncomment next line
|
37 |
|
|
;#define SMI_Bank0_EN
|
38 |
|
|
|
39 |
|
|
; ----------------------------------------------------------------------------
|
40 |
|
|
; Memory remapping
|
41 |
|
|
; ----------------------------------------------------------------------------
|
42 |
|
|
;#define Remap_SRAM ; remap SRAM at address 0x00
|
43 |
|
|
|
44 |
|
|
; ----------------------------------------------------------------------------
|
45 |
|
|
; EIC initialization
|
46 |
|
|
; ----------------------------------------------------------------------------
|
47 |
|
|
#define EIC_INIT ; Configure and Initialize EIC
|
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 |
|
|
|
58 |
|
|
I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
|
59 |
|
|
F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
; MRCC Register
|
63 |
|
|
MRCC_PCLKEN_Addr EQU 0x60000030 ; Peripheral Clock Enable register base address
|
64 |
|
|
|
65 |
|
|
; CFG Register
|
66 |
|
|
CFG_GLCONF_Addr EQU 0x60000010 ; Global Configuration register base address
|
67 |
|
|
SRAM_mask EQU 0x0002 ; to remap RAM at 0x0
|
68 |
|
|
|
69 |
|
|
; GPIO Register
|
70 |
|
|
GPIOREMAP0R_Addr EQU 0xFFFFE420
|
71 |
|
|
SMI_EN_Mask EQU 0x00000001
|
72 |
|
|
|
73 |
|
|
; SMI Register
|
74 |
|
|
SMI_CR1_Addr EQU 0x90000000
|
75 |
|
|
|
76 |
|
|
; EIC Registers offsets
|
77 |
|
|
EIC_Base_addr EQU 0xFFFFF800 ; EIC base address
|
78 |
|
|
ICR_off_addr EQU 0x00 ; Interrupt Control register offset
|
79 |
|
|
CIPR_off_addr EQU 0x08 ; Current Interrupt Priority Register offset
|
80 |
|
|
IVR_off_addr EQU 0x18 ; Interrupt Vector Register offset
|
81 |
|
|
FIR_off_addr EQU 0x1C ; Fast Interrupt Register offset
|
82 |
|
|
IER_off_addr EQU 0x20 ; Interrupt Enable Register offset
|
83 |
|
|
IPR_off_addr EQU 0x40 ; Interrupt Pending Bit Register offset
|
84 |
|
|
SIR0_off_addr EQU 0x60 ; Source Interrupt Register 0
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
;---------------------------------------------------------------
|
88 |
|
|
; ?program_start
|
89 |
|
|
;---------------------------------------------------------------
|
90 |
|
|
MODULE ?program_start
|
91 |
|
|
SECTION IRQ_STACK:DATA:NOROOT(3)
|
92 |
|
|
SECTION FIQ_STACK:DATA:NOROOT(3)
|
93 |
|
|
SECTION UND_STACK:DATA:NOROOT(3)
|
94 |
|
|
SECTION ABT_STACK:DATA:NOROOT(3)
|
95 |
|
|
SECTION SVC_STACK:DATA:NOROOT(3)
|
96 |
|
|
SECTION CSTACK:DATA:NOROOT(3)
|
97 |
|
|
SECTION .text:CODE(2)
|
98 |
|
|
PUBLIC __iar_program_start
|
99 |
|
|
EXTERN ?main
|
100 |
|
|
CODE32
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
__iar_program_start:
|
104 |
|
|
LDR pc, =NextInst
|
105 |
|
|
|
106 |
|
|
NextInst
|
107 |
|
|
; Reset all Peripheral Clocks
|
108 |
|
|
; This is usefull only when using debugger to Reset\Run the application
|
109 |
|
|
|
110 |
|
|
#ifdef SMI_Bank0_EN
|
111 |
|
|
LDR r0, =0x01000000 ; Disable peripherals clock (except GPIO)
|
112 |
|
|
#else
|
113 |
|
|
LDR r0, =0x00000000 ; Disable peripherals clock
|
114 |
|
|
#endif
|
115 |
|
|
LDR r1, =MRCC_PCLKEN_Addr
|
116 |
|
|
STR r0, [r1]
|
117 |
|
|
|
118 |
|
|
#ifdef SMI_Bank0_EN
|
119 |
|
|
LDR r0, =0x1875623F ; Peripherals kept under reset (except GPIO)
|
120 |
|
|
#else
|
121 |
|
|
LDR r0, =0x1975623F ; Peripherals kept under reset
|
122 |
|
|
#endif
|
123 |
|
|
|
124 |
|
|
STR r0, [r1,#4]
|
125 |
|
|
MOV r0, #0
|
126 |
|
|
NOP ; Wait
|
127 |
|
|
NOP
|
128 |
|
|
NOP
|
129 |
|
|
NOP
|
130 |
|
|
STR r0, [r1,#4] ; Disable peripherals reset
|
131 |
|
|
|
132 |
|
|
; Initialize stack pointer registers
|
133 |
|
|
; Enter each mode in turn and set up the stack pointer
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
MSR CPSR_c, #Mode_FIQ|I_Bit|F_Bit ; No interrupts
|
137 |
|
|
ldr sp,=SFE(FIQ_STACK) ; End of FIQ_STACK
|
138 |
|
|
|
139 |
|
|
MSR CPSR_c, #Mode_IRQ|I_Bit|F_Bit ; No interrupts
|
140 |
|
|
ldr sp,=SFE(IRQ_STACK) ; End of IRQ_STACK
|
141 |
|
|
|
142 |
|
|
MSR CPSR_c, #Mode_ABT|I_Bit|F_Bit ; No interrupts
|
143 |
|
|
ldr sp,=SFE(ABT_STACK) ; End of ABT_STACK
|
144 |
|
|
|
145 |
|
|
MSR CPSR_c, #Mode_UND|I_Bit|F_Bit ; No interrupts
|
146 |
|
|
ldr sp,=SFE(UND_STACK) ; End of UND_STACK
|
147 |
|
|
|
148 |
|
|
MSR CPSR_c, #Mode_SVC|I_Bit|F_Bit ; No interrupts
|
149 |
|
|
ldr sp,=SFE(SVC_STACK) ; End of SVC_STACK
|
150 |
|
|
|
151 |
|
|
; ------------------------------------------------------------------------------
|
152 |
|
|
; Description : Enable SMI Bank0: enable GPIOs clock in MRCC_PCLKEN register,
|
153 |
|
|
; enable SMI alternate function in GPIO_REMAP register and enable
|
154 |
|
|
; Bank0 in SMI_CR1 register.
|
155 |
|
|
; ------------------------------------------------------------------------------
|
156 |
|
|
#ifdef SMI_Bank0_EN
|
157 |
|
|
MOV r0, #0x01000000
|
158 |
|
|
LDR r1, =MRCC_PCLKEN_Addr
|
159 |
|
|
STR r0, [r1] ; Enable GPIOs clock
|
160 |
|
|
|
161 |
|
|
LDR r1, =GPIOREMAP0R_Addr
|
162 |
|
|
MOV r0, #SMI_EN_Mask
|
163 |
|
|
LDR r2, [r1]
|
164 |
|
|
ORR r2, r2, r0
|
165 |
|
|
STR r2, [r1] ; Enable SMI alternate function
|
166 |
|
|
|
167 |
|
|
LDR r0, =0x251 ; SMI Bank0 enabled, Prescaler = 2, Deselect Time = 5
|
168 |
|
|
LDR r1, =SMI_CR1_Addr
|
169 |
|
|
STR r0, [r1] ; Configure CR1 register
|
170 |
|
|
LDR r0, =0x00
|
171 |
|
|
STR r0, [r1,#4] ; Reset CR2 register
|
172 |
|
|
#endif
|
173 |
|
|
|
174 |
|
|
; ------------------------------------------------------------------------------
|
175 |
|
|
; Description : Remapping SRAM at address 0x00 after the application has
|
176 |
|
|
; started executing.
|
177 |
|
|
; ------------------------------------------------------------------------------
|
178 |
|
|
#ifdef Remap_SRAM
|
179 |
|
|
MOV r0, #SRAM_mask
|
180 |
|
|
LDR r1, =CFG_GLCONF_Addr
|
181 |
|
|
LDR r2, [r1] ; Read GLCONF Register
|
182 |
|
|
BIC r2, r2, #0x03 ; Reset the SW_BOOT bits
|
183 |
|
|
ORR r2, r2, r0 ; Change the SW_BOOT bits
|
184 |
|
|
STR r2, [r1] ; Write GLCONF Register
|
185 |
|
|
#endif
|
186 |
|
|
|
187 |
|
|
;-------------------------------------------------------------------------------
|
188 |
|
|
;Description : Initialize the EIC as following :
|
189 |
|
|
; - IRQ disabled
|
190 |
|
|
; - FIQ disabled
|
191 |
|
|
; - IVR contains the load PC opcode
|
192 |
|
|
; - All channels are disabled
|
193 |
|
|
; - All channels priority equal to 0
|
194 |
|
|
; - All SIR registers contains offset to the related IRQ table entry
|
195 |
|
|
;-------------------------------------------------------------------------------
|
196 |
|
|
#ifdef EIC_INIT
|
197 |
|
|
LDR r3, =EIC_Base_addr
|
198 |
|
|
LDR r4, =0x00000000
|
199 |
|
|
STR r4, [r3, #ICR_off_addr] ; Disable FIQ and IRQ
|
200 |
|
|
STR r4, [r3, #IER_off_addr] ; Disable all interrupts channels
|
201 |
|
|
|
202 |
|
|
LDR r4, =0xFFFFFFFF
|
203 |
|
|
STR r4, [r3, #IPR_off_addr] ; Clear all IRQ pending bits
|
204 |
|
|
|
205 |
|
|
LDR r4, =0x18
|
206 |
|
|
STR r4, [r3, #FIR_off_addr] ; Disable FIQ channels and clear FIQ pending bits
|
207 |
|
|
|
208 |
|
|
LDR r4, =0x00000000
|
209 |
|
|
STR r4, [r3, #CIPR_off_addr] ; Reset the current priority register
|
210 |
|
|
|
211 |
|
|
LDR r4, =0xE59F0000 ; Write the LDR pc,pc,#offset..
|
212 |
|
|
STR r4, [r3, #IVR_off_addr] ; ..instruction code in IVR[31:16]
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
LDR r2,= 32 ; 32 Channel to initialize
|
216 |
|
|
LDR r0, =WAKUP_Addr ; Read the address of the IRQs address table
|
217 |
|
|
LDR r1, =0x00000FFF
|
218 |
|
|
AND r0,r0,r1
|
219 |
|
|
LDR r5,=SIR0_off_addr ; Read SIR0 address
|
220 |
|
|
SUB r4,r0,#8 ; subtract 8 for prefetch
|
221 |
|
|
LDR r1, =0xF7E8 ; add the offset to the 0x00 address..
|
222 |
|
|
; ..(IVR address + 7E8 = 0x00)
|
223 |
|
|
; 0xF7E8 used to complete the LDR pc,offset opcode
|
224 |
|
|
ADD r1,r4,r1 ; compute the jump offset
|
225 |
|
|
EIC_INI
|
226 |
|
|
MOV r4, r1, LSL #16 ; Left shift the result
|
227 |
|
|
STR r4, [r3, r5] ; Store the result in SIRx register
|
228 |
|
|
ADD r1, r1, #4 ; Next IRQ address
|
229 |
|
|
ADD r5, r5, #4 ; Next SIR
|
230 |
|
|
SUBS r2, r2, #1 ; Decrement the number of SIR registers to initialize
|
231 |
|
|
BNE EIC_INI ; If more then continue
|
232 |
|
|
|
233 |
|
|
#endif
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
; --- Branch to C Library entry point
|
237 |
|
|
|
238 |
|
|
IMPORT ?main
|
239 |
|
|
|
240 |
|
|
B ?main ; use B not BL, because an application will never return this way
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
LTORG
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
END
|
249 |
|
|
;******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE*****
|