📄 71x_init.s1
字号:
;-----------------------------------------------------------------------------
; This file contains the startup code used by the ICCARM C compiler.
;
; The modules in this file are included in the libraries, and may be replaced
; by any user-defined modules that define the PUBLIC symbol _program_start or
; a user defined start symbol.
; To override the cstartup defined in the library, simply add your modified
; version to the workbench project.
;
; All code in the modules (except ?RESET) will be placed in the ICODE segment.
;
; $Revision: 1.2 $
;
;-----------------------------------------------------------------------------
;
; Naming covention of labels in this file:
;
; ?xxx - External labels only accessed from assembler.
; __xxx - External labels accessed from or defined in C.
; xxx - Labels local to one module (note: this file contains
; several modules).
; main - The starting point of the user program.
;
;---------------------------------------------------------------
; Macros and definitions for the whole file
;---------------------------------------------------------------
; --- Standard definitions of mode bits and interrupt (I & F) flags in PSRs
Mode_USR DEFINE 0x10
Mode_FIQ DEFINE 0x11
Mode_IRQ DEFINE 0x12
Mode_SVC DEFINE 0x13
Mode_ABT DEFINE 0x17
Mode_UNDEF DEFINE 0x1B
Mode_SYS DEFINE 0x1F ; available on ARM Arch 4 and later
I_Bit DEFINE 0x80 ; when I bit is set, IRQ is disabled
F_Bit DEFINE 0x40 ; when F bit is set, FIQ is disabled
EIC_Base_addr DEFINE 0xFFFFF800; EIC base address
ICR_off_addr DEFINE 0x00 ; Interrupt Control register offset
CIPR_off_addr DEFINE 0x08 ; Current Interrupt Priority Register offset
IVR_off_addr DEFINE 0x18 ; Interrupt Vector Register offset
FIR_off_addr DEFINE 0x1C ; Fast Interrupt Register offset
IER_off_addr DEFINE 0x20 ; Interrupt Enable Register offset
IPR_off_addr DEFINE 0x40 ; Interrupt Pending Bit Register offset
SIR0_off_addr DEFINE 0x60 ; Source Interrupt Register 0
EMI_Base_addr DEFINE 0x6C000000; EMI base address
BCON0_off_addr DEFINE 0x00 ; Bank 0 configuration register offset
BCON1_off_addr DEFINE 0x04 ; Bank 1 configuration register offset
BCON2_off_addr DEFINE 0x08 ; Bank 2 configuration register offset
BCON3_off_addr DEFINE 0x0C ; Bank 3 configuration register offset
EMI_ENABLE DEFINE 0x8000
EMI_SIZE_16 DEFINE 0x0001
GPIO2_Base_addr DEFINE 0xE0005000; GPIO2 base address
PC0_off_addr DEFINE 0x00 ; Port Configuration Register 0 offset
PC1_off_addr DEFINE 0x04 ; Port Configuration Register 1 offset
PC2_off_addr DEFINE 0x08 ; Port Configuration Register 2 offset
PD_off_addr DEFINE 0x0C ; Port Data Register offset
CPM_Base_addr DEFINE 0xA0000040; CPM Base Address
BOOTCR_off_addr DEFINE 0x10 ; CPM - Boot Configuration Register
FLASH_mask DEFINE 0x0000 ; to remap FLASH at 0x0
RAM_mask DEFINE 0x0002 ; to remap RAM at 0x0
;|----------------------------------------------------------------------------------|
;| - APB Bridge (System Peripheral) |
;|----------------------------------------------------------------------------------|
APB1_base_addr DEFINE 0xC0000000 ; APB Bridge1 Base Address
APB2_base_addr DEFINE 0xE0000000 ; APB Bridge2 Base Address
CKDIS_off_addr DEFINE 0x10 ; APB Bridge1 - Clock Disable Register
SWRES_off_addr DEFINE 0x14 ; APB Bridge1 - Software Reset Register
CKDIS1_config_all DEFINE 0x27FB ; To enable/disable clock of all APB1's peripherals
SWRES1_config_all DEFINE 0x27FB ; To reset all APB1's peripherals
CKDIS2_config_all DEFINE 0x7FDD ; To enable/disable clock of all APB2's peripherals
SWRES2_config_all DEFINE 0x7FDD ; To reset all APB2's peripherals
;---------------------------------------------------------------
; ?program_start
;---------------------------------------------------------------
MODULE ?program_start ; Begins a library module
RSEG IRQ_STACK:DATA(2)
RSEG FIQ_STACK:DATA(2)
RSEG UND_STACK:DATA(2)
RSEG ABT_STACK:DATA(2)
RSEG SVC_STACK:DATA(2)
RSEG CSTACK:DATA(2)
RSEG ICODE:CODE:NOROOT(2) ; NOROOT指定此段中如果没有代码,在连接时可抛弃
PUBLIC __program_start ; Export symbles to other module
EXTERN ?main ; Import an external symble
CODE32 ; Generate 32-bit ARM instruction
;*******************************************************************************
;******* -- MACROS -- *******
;*******************************************************************************
;*******************************************************************************
;* Macro Name : EIC_INIT
;* Description : This macro Initialize the EIC as following :
; - IRQ disabled
; - FIQ disabled
; - IVR contain the load PC opcode (0xF59FF00)
; - Current priority level equal to 0
; - All channels are disabled
; - All channels priority equal to 0
; - All SIR registers contain offset to the related IRQ
; table entry
;* Input : None.
;* Output : None.
;*******************************************************************************
EIC_INIT MACRO
LDR r3, =EIC_Base_addr
LDR r4, =0xE59F0000
STR r4, [r3, #IVR_off_addr]; Write the LDR pc,[pc,#offset]
; instruction code in IVR[31:16]
LDR r2, =32 ; 32 Channel to initialize
LDR r0, =T0TIMI_Addr ; Read the address of the IRQs
; address table
LDR r1, =0x00000FFF
AND r0,r0,r1
LDR r5, =SIR0_off_addr ; Read SIR0 address
SUB r4,r0,#8 ; subtract 8 for prefetch
LDR r1, =0xF7E8 ; add the offset to the 0x00000000
; address(IVR address + 7E8 = 0x00000000)
; 0xF7E8 used to complete the
; LDR pc,[pc,#offset] opcode
ADD r1,r4,r1 ; compute the jump offset
EIC_INI MOV r4, r1, LSL #16 ; Left shift the result
STR r4, [r3, r5] ; Store the result in SIRx register
ADD r1, r1, #4 ; Next IRQ address
ADD r5, r5, #4 ; Next SIR
SUBS r2, r2, #1 ; Decrement the number of SIR registers
; to initialize
BNE EIC_INI ; If more then continue
ENDM
;*******************************************************************************
;* Macro Name : PERIPHERAL_INIT
;* Description : This macro reset all device peripherals.
;* Input : None.
;* Output : None.
;*******************************************************************************
PERIPHERAL_INIT MACRO
LDR r1, =APB1_base_addr ; r0= APB1 base address
LDR r2, =APB2_base_addr ; r0= APB2 base address
LDR r0, =CKDIS1_config_all
STRH r0, [r1, #CKDIS_off_addr]; Clock Disabling for all APB1 peripherals
LDR r0, =CKDIS2_config_all
STRH r0, [r2, #CKDIS_off_addr]; Clock Disabling for all APB2 peripherals
LDR r0, =SWRES1_config_all
STRH r0, [r1, #SWRES_off_addr]; Keep under reset all APB1 peropherals
LDR r0, =SWRES2_config_all
STRH r0, [r2, #SWRES_off_addr]; Keep under reset all APB2 peropherals
MOV r7, #10 ; Wait that the selected macrocells exit from reset
loop1 SUBS r7, r7, #1
BNE loop1
MOV r0, #0
STRH r0, [r1, #SWRES_off_addr]; Enable all all APB1 peropherals
STRH r0, [r2, #SWRES_off_addr]; Enable all all APB2 peropherals
STRH r0, [r1, #CKDIS_off_addr]; Clock Enabling for all APB1 peripherals
STRH r0, [r2, #CKDIS_off_addr]; Clock Enabling for all APB2 peripherals
MOV r7, #10 ; Wait that the selected macrocells exit from reset
loop2 SUBS r7, r7, #1
BNE loop2
ENDM
;********************************************************************************************
; define remapping
; If you need to remap memory before entring the main program
; uncomment next ligne
#define remapping
; Then define which memory to remap to address 0x00000000
; Uncomment next line if you want to remap RAM
; #define remap_ram
; Uncomment next line if you want to remap FLASH
#define remap_flash
IMPORT T0TIMI_Addr
__program_start
LDR pc, =NextInst
NextInst
NOP ; Wait for OSC stabilization
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
;******************************************************************************
; ARM处理器支持7种运行模式,其中6种是特权模式,一种是用户模式。除用户模式和系统
; 模式外其他都是异常模式。每种处理器模式使用不同的寄存器组,并有自己独立的物理
; 寄存器R13(SP)。所以在初始化时要将SP指向其运行模式的栈空间。
;******************************************************************************
MSR CPSR_c, #Mode_ABT|F_Bit|I_Bit
ldr sp,=SFE(ABT_STACK) & 0xFFFFFFF8 ; End of ABT_STACK
MSR CPSR_c, #Mode_UNDEF|F_Bit|I_Bit
ldr sp,=SFE(UND_STACK) & 0xFFFFFFF8 ; End of UND_STACK
MSR CPSR_c, #Mode_SVC|F_Bit|I_Bit
ldr sp,=SFE(SVC_STACK) & 0xFFFFFFF8 ; End of SVC_STACK
; Uncomment next ligne if you need to reset all device pripherals
; PERIPHERAL_INIT ; Reset all device peripherals
; Uncomment next ligne if you need to initialize the EIC
EIC_INIT ; Initialize EIC
;******************************************************************************
;REMAPPING
;Description : Remapping memory whether RAM,FLASH
; at Address 0x0 after the application has started executing.
; Remapping is generally done to allow RAM to replace FLASH
; at 0x0.
; the remapping of RAM allow copying of vector table into RAM
;
; CPM_Base_addr基地址指向 PCU_MDIVR (0xA0000040)。其[1:0]的状态决定主时钟=MCLK除1,2,4或8。
; BOOTCR寄存器的地址=0xA0000050,它的[1:0]决定Boot Mode。这2位在上电时锁存BOOT0和BOOT1两个引脚
; 的状态,但是也可以用下面的程序修改BOOTCR[1:0]的内容。
;******************************************************************************
#ifdef remapping
#ifdef remap_flash
MOV r0, #FLASH_mask
#endif
#ifdef remap_ram
MOV r0, #RAM_mask
#endif
LDR r1, =CPM_Base_addr
LDRH r2, [r1, #BOOTCR_off_addr]; Read BOOTCR Register addr=0xA0000050,[1:0]=Boot Mode
BIC r2, r2, #0x03 ; Reset the two LSB bits of BOOTCR
ORR r2, r2, r0 ; change the two LSB bits of BOOTCR according to R0
STRH r2, [r1, #BOOTCR_off_addr]; Write BOOTCR Register
#endif
MSR CPSR_c, #Mode_FIQ|I_Bit ; Change to FIQ mode
ldr sp,=SFE(FIQ_STACK) & 0xFFFFFFF8 ; End of FIQ_STACK
MSR CPSR_c, #Mode_IRQ|I_Bit; Change to IRQ mode
ldr sp,=SFE(IRQ_STACK) & 0xFFFFFFF8 ; End of IRQ_STACK
MSR CPSR_c, #Mode_USR ; Change to User mode, Enable IRQ and FIQ
ldr sp,=SFE(CSTACK) & 0xFFFFFFF8 ; End of CSTACK(user)
; --- Now branches to a C lib function
b ?main ; Note : use B not BL, because an application will
; never return this way
LTORG
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -