]> git.sur5r.net Git - freertos/blob - Demo/ARM7_STR71x_IAR/71x_init.s
UpdUpdate IAR projects to use Embedded Workbench V5.11.
[freertos] / Demo / ARM7_STR71x_IAR / 71x_init.s
1 ;******************** (C) COPYRIGHT 2003 STMicroelectronics ********************\r
2 ;* File Name          : 71x_init.s\r
3 ;* Author             : MCD Application Team\r
4 ;* Date First Issued  : 06/23/2004\r
5 ;* Description        : This is the first code executed after RESET.\r
6 ;*                      This code used to initialize system stacks\r
7 ;*                      and critical peripherals before entering the C code.\r
8 ;*******************************************************************************\r
9 ;* History:\r
10 ;*  13/01/2006 : V3.1\r
11 ;*  24/05/2005 : V3.0\r
12 ;*  30/11/2004 : V2.0\r
13 ;*  14/07/2004 : V1.3\r
14 ;*  01/01/2004 : V1.2\r
15 ;*******************************************************************************\r
16 ; THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH\r
17 ; CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.\r
18 ; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT\r
19 ; OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT\r
20 ; OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION\r
21 ; CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
22 ;*******************************************************************************/\r
23 \r
24 \r
25 ; --- Standard definitions of mode bits and interrupt (I & F) flags in PSRs\r
26 \r
27 Mode_USR           EQU   0x10\r
28 Mode_FIQ           EQU   0x11\r
29 Mode_IRQ           EQU   0x12\r
30 Mode_SVC           EQU   0x13\r
31 Mode_ABT           EQU   0x17\r
32 Mode_UNDEF         EQU   0x1B\r
33 Mode_SYS           EQU   0x1F ; available on ARM Arch 4 and later\r
34 \r
35 I_Bit              EQU   0x80 ; when I bit is set, IRQ is disabled\r
36 F_Bit              EQU   0x40 ; when F bit is set, FIQ is disabled\r
37 \r
38 \r
39 \r
40 EIC_Base_addr      EQU   0xFFFFF800; EIC base address\r
41 ICR_off_addr       EQU   0x00      ; Interrupt Control register offset\r
42 CIPR_off_addr      EQU   0x08      ; Current Interrupt Priority Register offset\r
43 IVR_off_addr       EQU   0x18      ; Interrupt Vector Register offset\r
44 FIR_off_addr       EQU   0x1C      ; Fast Interrupt Register offset\r
45 IER_off_addr       EQU   0x20      ; Interrupt Enable Register offset\r
46 IPR_off_addr       EQU   0x40      ; Interrupt Pending Bit Register offset\r
47 SIR0_off_addr      EQU   0x60      ; Source Interrupt Register 0\r
48 \r
49 EMI_Base_addr      EQU   0x6C000000; EMI base address\r
50 BCON0_off_addr     EQU   0x00      ; Bank 0 configuration register offset\r
51 BCON1_off_addr     EQU   0x04      ; Bank 1 configuration register offset\r
52 BCON2_off_addr     EQU   0x08      ; Bank 2 configuration register offset\r
53 BCON3_off_addr     EQU   0x0C      ; Bank 3 configuration register offset\r
54 \r
55 EMI_ENABLE         EQU   0x8000\r
56 EMI_SIZE_16        EQU   0x0001\r
57 \r
58 GPIO2_Base_addr    EQU   0xE0005000; GPIO2 base address\r
59 PC0_off_addr       EQU   0x00      ; Port Configuration Register 0 offset\r
60 PC1_off_addr       EQU   0x04      ; Port Configuration Register 1 offset\r
61 PC2_off_addr       EQU   0x08      ; Port Configuration Register 2 offset\r
62 PD_off_addr        EQU   0x0C      ; Port Data Register offset\r
63 \r
64 CPM_Base_addr      EQU   0xA0000040; CPM Base Address\r
65 BOOTCR_off_addr    EQU   0x10      ; CPM - Boot Configuration Register\r
66 FLASH_mask         EQU   0x0000    ; to remap FLASH at 0x0\r
67 RAM_mask           EQU   0x0002    ; to remap RAM at 0x0\r
68 \r
69 ;|----------------------------------------------------------------------------------|\r
70 ;| - APB Bridge  (System Peripheral)                                               |\r
71 ;|----------------------------------------------------------------------------------|\r
72 APB1_base_addr     EQU   0xC0000000          ; APB Bridge1 Base Address\r
73 APB2_base_addr     EQU   0xE0000000          ; APB Bridge2 Base Address\r
74 CKDIS_off_addr     EQU   0x10                ; APB Bridge1 - Clock Disable  Register\r
75 SWRES_off_addr     EQU   0x14                ; APB Bridge1 - Software Reset Register\r
76 CKDIS1_config_all  EQU   0x27FB              ; To enable/disable clock of all APB1's peripherals\r
77 SWRES1_config_all  EQU   0x27FB              ; To reset all APB1's peripherals\r
78 CKDIS2_config_all  EQU   0x7FDD              ; To enable/disable clock of all APB2's peripherals\r
79 SWRES2_config_all  EQU   0x7FDD              ; To reset all APB2's peripherals\r
80 \r
81 \r
82 \r
83 ;---------------------------------------------------------------\r
84 ; ?program_start\r
85 ;---------------------------------------------------------------\r
86                 MODULE  ?program_start\r
87                 SECTION IRQ_STACK:DATA:NOROOT(3)\r
88                 SECTION FIQ_STACK:DATA:NOROOT(3)\r
89                 SECTION UND_STACK:DATA:NOROOT(3)\r
90                 SECTION ABT_STACK:DATA:NOROOT(3)        \r
91                 SECTION SVC_STACK:DATA:NOROOT(3)\r
92                 SECTION CSTACK:DATA:NOROOT(3)\r
93                 SECTION .text:CODE(2)\r
94                 PUBLIC  __iar_program_start\r
95                 EXTERN  ?main\r
96                 EXTERN  ?main\r
97                 CODE32\r
98 \r
99 \r
100 ;*******************************************************************************\r
101 ;*******                         -- MACROS --                            *******\r
102 ;*******************************************************************************\r
103 ;*******************************************************************************\r
104 ;* Macro Name     : EMI_INIT\r
105 ;* Description    : This macro Initialize EMI bank 1: 16-bit 7 wait state\r
106 ;* Input          : None.\r
107 ;* Output         : None.\r
108 ;*******************************************************************************\r
109 EMI_INIT  MACRO\r
110         LDR     r0, =GPIO2_Base_addr      ; Configure P2.0 -> 3 in AF_PP mode\r
111         LDR     r2, [r0, #PC0_off_addr]\r
112         ORR     r2, r2,#0x0000000F\r
113         STR     r2, [r0, #PC0_off_addr]\r
114         LDR     r2, [r0, #PC1_off_addr]\r
115         ORR     r2, r2,#0x0000000F\r
116         STR     r2, [r0, #PC1_off_addr]\r
117         LDR     r2, [r0, #PC2_off_addr]\r
118         ORR     r2, r2,#0x0000000F\r
119         STR     r2, [r0, #PC2_off_addr]\r
120         LDR     r0, =EMI_Base_addr\r
121         LDR     r1, =0x18|EMI_ENABLE|EMI_SIZE_16\r
122         STR     r1, [r0, #BCON1_off_addr] ; Enable bank 1 16-bit 7 wait state\r
123         ENDM\r
124 ;*******************************************************************************\r
125 ;* Macro Name     : EIC_INIT\r
126 ;* Description    : This macro Initialize the EIC as following :\r
127 ;                 - IRQ disabled\r
128 ;                 - FIQ disabled\r
129 ;                 - IVR contain the load PC opcode (0xE59FFXXX)\r
130 ;                 - Current priority level equal to 0\r
131 ;                 - All channels are disabled\r
132 ;                 - All channels priority equal to 0\r
133 ;                 - All SIR registers contain offset to the related IRQ\r
134 ;                   table entry\r
135 ;* Input          : None.\r
136 ;* Output         : None.\r
137 ;*******************************************************************************\r
138 EIC_INIT   MACRO\r
139 \r
140         LDR     r3, =EIC_Base_addr\r
141         LDR     r4, =0xE59F0000\r
142         STR     r4, [r3, #IVR_off_addr]; Write the LDR pc,[pc,#offset]\r
143                                        ; instruction code in IVR[31:16]\r
144         LDR     r2, =32                ; 32 Channel to initialize\r
145         LDR     r0, =T0TIMI_Addr       ; Read the address of the IRQs\r
146                                        ; address table\r
147         LDR     r1, =0x00000FFF\r
148         AND     r0,r0,r1\r
149         LDR     r5, =SIR0_off_addr     ; Read SIR0 address\r
150         SUB     r4,r0,#8               ; subtract 8 for prefetch\r
151         LDR     r1, =0xF7E8            ; Add the offset from IVR to 0x00000000\r
152                                        ; address(IVR address + 7E8 = 0x00000000)\r
153                                        ; 0xF7E8 used to complete the\r
154                                        ; LDR pc,[pc,#offset] opcode (0xE59FFXXX)\r
155         ADD     r1,r4,r1               ; Compute the jump offset from IVR to the\r
156                                        ; IRQ table entry.\r
157 EIC_INI MOV     r4, r1, LSL #16        ; Left shift the result\r
158         STR     r4, [r3, r5]           ; Store the result in SIRx register\r
159         ADD     r1, r1, #4             ; Next IRQ address\r
160         ADD     r5, r5, #4             ; Next SIR\r
161         SUBS    r2, r2, #1             ; Decrement the number of SIR registers\r
162                                        ; to initialize\r
163         BNE     EIC_INI                ; If more then continue\r
164         ENDM\r
165 ;*******************************************************************************\r
166 ;* Macro Name     : PERIPHERAL_INIT\r
167 ;* Description    : This macro reset all device peripherals.\r
168 ;* Input          : None.\r
169 ;* Output         : None.\r
170 ;*******************************************************************************\r
171 PERIPHERAL_INIT MACRO\r
172 \r
173         LDR     r1, =APB1_base_addr      ; r0= APB1 base address\r
174         LDR     r2, =APB2_base_addr      ; r0= APB2 base address\r
175         LDR     r0, =CKDIS1_config_all\r
176         STRH    r0, [r1, #CKDIS_off_addr]; Clock Disabling for all APB1 peripherals\r
177         LDR     r0, =CKDIS2_config_all\r
178         STRH    r0, [r2, #CKDIS_off_addr]; Clock Disabling for all APB2 peripherals\r
179         LDR     r0, =SWRES1_config_all\r
180         STRH    r0, [r1, #SWRES_off_addr]; Keep all APB1 peripherals under reset\r
181         LDR     r0, =SWRES2_config_all\r
182         STRH    r0, [r2, #SWRES_off_addr]; Keep all APB2 peripherals under reset\r
183         MOV     r7, #10                  ; Wait that the selected macrocells exit from reset\r
184 loop1   SUBS    r7, r7, #1\r
185         BNE     loop1\r
186         MOV     r0, #0\r
187         STRH    r0, [r1, #SWRES_off_addr]; Enable all all APB1 peripherals\r
188         STRH    r0, [r2, #SWRES_off_addr]; Enable all all APB2 peripherals\r
189         STRH    r0, [r1, #CKDIS_off_addr]; Clock Enabling for all APB1 peripherals\r
190         STRH    r0, [r2, #CKDIS_off_addr]; Clock Enabling for all APB2 peripherals\r
191         MOV     r7, #10                  ; Wait that the selected macrocells exit from reset\r
192 loop2   SUBS    r7, r7, #1\r
193         BNE     loop2\r
194         ENDM\r
195 ;********************************************************************************************\r
196 \r
197 ; define remapping\r
198 ; If you need to remap memory before entring the main program\r
199 ; uncomment next ligne\r
200 ;            #define   remapping\r
201 \r
202 ; Then define which memory to remap to address 0x00000000\r
203 ;  Uncomment next line if you want to remap RAM\r
204 ;         #define  remap_ram\r
205 \r
206 ;  Uncomment next line if you want to remap FLASH\r
207 ;         #define remap_flash\r
208 \r
209 \r
210         IMPORT  T0TIMI_Addr\r
211 __iar_program_start\r
212          LDR     pc, =NextInst\r
213 NextInst\r
214                 NOP             ; Wait for OSC stabilization\r
215                 NOP\r
216                 NOP\r
217                 NOP\r
218                 NOP\r
219                 NOP\r
220                 NOP\r
221                 NOP\r
222                 NOP\r
223 \r
224         MSR     CPSR_c, #Mode_ABT|F_Bit|I_Bit\r
225         ldr      sp,=SFE(ABT_STACK)     ; End of ABT_STACK\r
226 \r
227         MSR     CPSR_c, #Mode_UNDEF|F_Bit|I_Bit\r
228         ldr      sp,=SFE(UND_STACK)     ; End of UNDEF_STACK\r
229 \r
230         MSR     CPSR_c, #Mode_SVC|F_Bit|I_Bit\r
231        ldr      sp,=SFE(SVC_STACK)      ; End of SVC_STACK\r
232 \r
233 \r
234 \r
235 ; Uncomment next ligne if you need to reset all device pripherals\r
236  ;      PERIPHERAL_INIT           ; Reset all device peripherals\r
237 \r
238 ; Uncomment next ligne if you need to enable the EMI Bank 1\r
239    ;    EMI_INIT                  ; Initialize EIM Bank 1\r
240 \r
241 ;Uncomment next ligne if you need to initialize the EIC\r
242         EIC_INIT                  ; Initialize EIC\r
243 \r
244 ;******************************************************************************\r
245 ;REMAPPING\r
246 ;Description  : Remapping  memory whether RAM,FLASH\r
247 ;               at Address 0x0 after the application has started executing.\r
248 ;               Remapping is generally done to allow RAM  to replace FLASH\r
249 ;               at 0x0.\r
250 ;               the remapping of RAM allow copying of vector table into RAM\r
251 ;               To enable the memory remapping uncomment: (see above)\r
252 ;               #define  remapping to enable memory remapping\r
253 ;                  AND\r
254 ;               #define  remap_ram to remap RAM\r
255 ;                  OR\r
256 ;               #define  remap_flash to remap FLASH\r
257 ;******************************************************************************\r
258 #ifdef remapping\r
259     #ifdef remap_flash\r
260         MOV     r0, #FLASH_mask\r
261     #endif\r
262     #ifdef remap_ram\r
263         MOV     r0, #RAM_mask\r
264     #endif\r
265 \r
266         LDR     r1, =CPM_Base_addr\r
267         LDRH    r2, [r1, #BOOTCR_off_addr]; Read BOOTCR Register\r
268         BIC     r2, r2, #0x03             ; Reset the two LSB bits of BOOTCR\r
269         ORR     r2, r2, r0                ; change the two LSB bits of BOOTCR\r
270         STRH    r2, [r1, #BOOTCR_off_addr]; Write BOOTCR Register\r
271 #endif\r
272 \r
273         MSR     CPSR_c, #Mode_FIQ|I_Bit; Change to FIQ mode\r
274         ldr      sp,=SFE(FIQ_STACK)      ; End of FIQ_STACK\r
275 \r
276         MSR     CPSR_c, #Mode_IRQ|I_Bit; Change to IRQ mode\r
277         ldr      sp,=SFE(IRQ_STACK)    ; End of IRQ_STACK\r
278 \r
279         MSR     CPSR_c, #Mode_SYS         ; Change to system mode, Enable IRQ and FIQ\r
280        ldr     sp,=SFE(CSTACK)        ; End of CSTACK(user)\r
281 \r
282 \r
283 \r
284 ; --- Now branches to a C lib function that copies RO data from their\r
285 ;     load region to their execute region, create the RW and ZI regions\r
286 ;     then jumps to user C main program.\r
287 \r
288                 ; main() must be called from Supervisor mode\r
289                 MSR     CPSR_c, #Mode_SVC|F_Bit|I_Bit\r
290 \r
291         b ?main   ; Note : use B not BL, because an application will\r
292                          ; never return this way\r
293 \r
294         LTORG\r
295 \r
296         END\r
297 ;******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****\r