1 ;******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
2 ;* File Name : 71x_init.s
3 ;* Author : MCD Application Team
4 ;* Date First Issued : 06/23/2004
5 ;* Description : This is the first code executed after RESET.
6 ;* This code used to initialize system stacks
7 ;* and critical peripherals before entering the C code.
8 ;*******************************************************************************
15 ;*******************************************************************************
16 ; THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
17 ; CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
18 ; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
19 ; OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
20 ; OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
21 ; CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
22 ;*******************************************************************************/
25 ; --- Standard definitions of mode bits and interrupt (I & F) flags in PSRs
33 Mode_SYS EQU 0x1F ; available on ARM Arch 4 and later
35 I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
36 F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
40 EIC_Base_addr EQU 0xFFFFF800; EIC base address
41 ICR_off_addr EQU 0x00 ; Interrupt Control register offset
42 CIPR_off_addr EQU 0x08 ; Current Interrupt Priority Register offset
43 IVR_off_addr EQU 0x18 ; Interrupt Vector Register offset
44 FIR_off_addr EQU 0x1C ; Fast Interrupt Register offset
45 IER_off_addr EQU 0x20 ; Interrupt Enable Register offset
46 IPR_off_addr EQU 0x40 ; Interrupt Pending Bit Register offset
47 SIR0_off_addr EQU 0x60 ; Source Interrupt Register 0
49 EMI_Base_addr EQU 0x6C000000; EMI base address
50 BCON0_off_addr EQU 0x00 ; Bank 0 configuration register offset
51 BCON1_off_addr EQU 0x04 ; Bank 1 configuration register offset
52 BCON2_off_addr EQU 0x08 ; Bank 2 configuration register offset
53 BCON3_off_addr EQU 0x0C ; Bank 3 configuration register offset
56 EMI_SIZE_16 EQU 0x0001
58 GPIO2_Base_addr EQU 0xE0005000; GPIO2 base address
59 PC0_off_addr EQU 0x00 ; Port Configuration Register 0 offset
60 PC1_off_addr EQU 0x04 ; Port Configuration Register 1 offset
61 PC2_off_addr EQU 0x08 ; Port Configuration Register 2 offset
62 PD_off_addr EQU 0x0C ; Port Data Register offset
64 CPM_Base_addr EQU 0xA0000040; CPM Base Address
65 BOOTCR_off_addr EQU 0x10 ; CPM - Boot Configuration Register
66 FLASH_mask EQU 0x0000 ; to remap FLASH at 0x0
67 RAM_mask EQU 0x0002 ; to remap RAM at 0x0
69 ;|----------------------------------------------------------------------------------|
70 ;| - APB Bridge (System Peripheral) |
71 ;|----------------------------------------------------------------------------------|
72 APB1_base_addr EQU 0xC0000000 ; APB Bridge1 Base Address
73 APB2_base_addr EQU 0xE0000000 ; APB Bridge2 Base Address
74 CKDIS_off_addr EQU 0x10 ; APB Bridge1 - Clock Disable Register
75 SWRES_off_addr EQU 0x14 ; APB Bridge1 - Software Reset Register
76 CKDIS1_config_all EQU 0x27FB ; To enable/disable clock of all APB1's peripherals
77 SWRES1_config_all EQU 0x27FB ; To reset all APB1's peripherals
78 CKDIS2_config_all EQU 0x7FDD ; To enable/disable clock of all APB2's peripherals
79 SWRES2_config_all EQU 0x7FDD ; To reset all APB2's peripherals
83 ;---------------------------------------------------------------
85 ;---------------------------------------------------------------
87 SECTION IRQ_STACK:DATA:NOROOT(3)
88 SECTION FIQ_STACK:DATA:NOROOT(3)
89 SECTION UND_STACK:DATA:NOROOT(3)
90 SECTION ABT_STACK:DATA:NOROOT(3)
91 SECTION SVC_STACK:DATA:NOROOT(3)
92 SECTION CSTACK:DATA:NOROOT(3)
94 PUBLIC __iar_program_start
100 ;*******************************************************************************
101 ;******* -- MACROS -- *******
102 ;*******************************************************************************
103 ;*******************************************************************************
104 ;* Macro Name : EMI_INIT
105 ;* Description : This macro Initialize EMI bank 1: 16-bit 7 wait state
108 ;*******************************************************************************
110 LDR r0, =GPIO2_Base_addr ; Configure P2.0 -> 3 in AF_PP mode
111 LDR r2, [r0, #PC0_off_addr]
112 ORR r2, r2,#0x0000000F
113 STR r2, [r0, #PC0_off_addr]
114 LDR r2, [r0, #PC1_off_addr]
115 ORR r2, r2,#0x0000000F
116 STR r2, [r0, #PC1_off_addr]
117 LDR r2, [r0, #PC2_off_addr]
118 ORR r2, r2,#0x0000000F
119 STR r2, [r0, #PC2_off_addr]
120 LDR r0, =EMI_Base_addr
121 LDR r1, =0x18|EMI_ENABLE|EMI_SIZE_16
122 STR r1, [r0, #BCON1_off_addr] ; Enable bank 1 16-bit 7 wait state
124 ;*******************************************************************************
125 ;* Macro Name : EIC_INIT
126 ;* Description : This macro Initialize the EIC as following :
129 ; - IVR contain the load PC opcode (0xE59FFXXX)
130 ; - Current priority level equal to 0
131 ; - All channels are disabled
132 ; - All channels priority equal to 0
133 ; - All SIR registers contain offset to the related IRQ
137 ;*******************************************************************************
140 LDR r3, =EIC_Base_addr
142 STR r4, [r3, #IVR_off_addr]; Write the LDR pc,[pc,#offset]
143 ; instruction code in IVR[31:16]
144 LDR r2, =32 ; 32 Channel to initialize
145 LDR r0, =T0TIMI_Addr ; Read the address of the IRQs
149 LDR r5, =SIR0_off_addr ; Read SIR0 address
150 SUB r4,r0,#8 ; subtract 8 for prefetch
151 LDR r1, =0xF7E8 ; Add the offset from IVR to 0x00000000
152 ; address(IVR address + 7E8 = 0x00000000)
153 ; 0xF7E8 used to complete the
154 ; LDR pc,[pc,#offset] opcode (0xE59FFXXX)
155 ADD r1,r4,r1 ; Compute the jump offset from IVR to the
157 EIC_INI MOV r4, r1, LSL #16 ; Left shift the result
158 STR r4, [r3, r5] ; Store the result in SIRx register
159 ADD r1, r1, #4 ; Next IRQ address
160 ADD r5, r5, #4 ; Next SIR
161 SUBS r2, r2, #1 ; Decrement the number of SIR registers
163 BNE EIC_INI ; If more then continue
165 ;*******************************************************************************
166 ;* Macro Name : PERIPHERAL_INIT
167 ;* Description : This macro reset all device peripherals.
170 ;*******************************************************************************
171 PERIPHERAL_INIT MACRO
173 LDR r1, =APB1_base_addr ; r0= APB1 base address
174 LDR r2, =APB2_base_addr ; r0= APB2 base address
175 LDR r0, =CKDIS1_config_all
176 STRH r0, [r1, #CKDIS_off_addr]; Clock Disabling for all APB1 peripherals
177 LDR r0, =CKDIS2_config_all
178 STRH r0, [r2, #CKDIS_off_addr]; Clock Disabling for all APB2 peripherals
179 LDR r0, =SWRES1_config_all
180 STRH r0, [r1, #SWRES_off_addr]; Keep all APB1 peripherals under reset
181 LDR r0, =SWRES2_config_all
182 STRH r0, [r2, #SWRES_off_addr]; Keep all APB2 peripherals under reset
183 MOV r7, #10 ; Wait that the selected macrocells exit from reset
184 loop1 SUBS r7, r7, #1
187 STRH r0, [r1, #SWRES_off_addr]; Enable all all APB1 peripherals
188 STRH r0, [r2, #SWRES_off_addr]; Enable all all APB2 peripherals
189 STRH r0, [r1, #CKDIS_off_addr]; Clock Enabling for all APB1 peripherals
190 STRH r0, [r2, #CKDIS_off_addr]; Clock Enabling for all APB2 peripherals
191 MOV r7, #10 ; Wait that the selected macrocells exit from reset
192 loop2 SUBS r7, r7, #1
195 ;********************************************************************************************
198 ; If you need to remap memory before entring the main program
199 ; uncomment next ligne
202 ; Then define which memory to remap to address 0x00000000
203 ; Uncomment next line if you want to remap RAM
206 ; Uncomment next line if you want to remap FLASH
207 ; #define remap_flash
214 NOP ; Wait for OSC stabilization
224 MSR CPSR_c, #Mode_ABT|F_Bit|I_Bit
225 ldr sp,=SFE(ABT_STACK) ; End of ABT_STACK
227 MSR CPSR_c, #Mode_UNDEF|F_Bit|I_Bit
228 ldr sp,=SFE(UND_STACK) ; End of UNDEF_STACK
230 MSR CPSR_c, #Mode_SVC|F_Bit|I_Bit
231 ldr sp,=SFE(SVC_STACK) ; End of SVC_STACK
235 ; Uncomment next ligne if you need to reset all device pripherals
236 ; PERIPHERAL_INIT ; Reset all device peripherals
238 ; Uncomment next ligne if you need to enable the EMI Bank 1
239 ; EMI_INIT ; Initialize EIM Bank 1
241 ;Uncomment next ligne if you need to initialize the EIC
242 EIC_INIT ; Initialize EIC
244 ;******************************************************************************
246 ;Description : Remapping memory whether RAM,FLASH
247 ; at Address 0x0 after the application has started executing.
248 ; Remapping is generally done to allow RAM to replace FLASH
250 ; the remapping of RAM allow copying of vector table into RAM
251 ; To enable the memory remapping uncomment: (see above)
252 ; #define remapping to enable memory remapping
254 ; #define remap_ram to remap RAM
256 ; #define remap_flash to remap FLASH
257 ;******************************************************************************
266 LDR r1, =CPM_Base_addr
267 LDRH r2, [r1, #BOOTCR_off_addr]; Read BOOTCR Register
268 BIC r2, r2, #0x03 ; Reset the two LSB bits of BOOTCR
269 ORR r2, r2, r0 ; change the two LSB bits of BOOTCR
270 STRH r2, [r1, #BOOTCR_off_addr]; Write BOOTCR Register
273 MSR CPSR_c, #Mode_FIQ|I_Bit; Change to FIQ mode
274 ldr sp,=SFE(FIQ_STACK) ; End of FIQ_STACK
276 MSR CPSR_c, #Mode_IRQ|I_Bit; Change to IRQ mode
277 ldr sp,=SFE(IRQ_STACK) ; End of IRQ_STACK
279 MSR CPSR_c, #Mode_SYS ; Change to system mode, Enable IRQ and FIQ
280 ldr sp,=SFE(CSTACK) ; End of CSTACK(user)
284 ; --- Now branches to a C lib function that copies RO data from their
285 ; load region to their execute region, create the RW and ZI regions
286 ; then jumps to user C main program.
288 ; main() must be called from Supervisor mode
289 MSR CPSR_c, #Mode_SVC|F_Bit|I_Bit
291 b ?main ; Note : use B not BL, because an application will
292 ; never return this way
297 ;******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****