📄 71x_init_c.s
字号:
MEND
;*******************************************************************************
;* Macro Name : EIC_INIT 初始化向量中断控制器的宏
;* Description : This macro Initialize the EIC as following :
; - IRQ disabled
; - FIQ disabled
; - IVR contain the load PC opcode (0xE59FFXXX)
; - 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.
;*******************************************************************************
MACRO
EIC_INIT
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 from IVR to 0x00000000
; address(IVR address + 7E8 = 0x00000000)
; 0xF7E8 used to complete the
; LDR pc,[pc,#offset] opcode (0xE59FFXXX)
ADD r1,r4,r1 ; Compute the jump offset from IVR to the
; IRQ table entry.
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
MEND
;*******************************************************************************
;* Macro Name : PERIPHERAL_INIT 初始化内部外设总线的宏
;* Description : This macro reset all device peripherals.
;* Input : None.
;* Output : None.
;*******************************************************************************
MACRO
PERIPHERAL_INIT
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 all APB1 peripherals under reset
LDR r0, =SWRES2_config_all
STRH r0, [r2, #SWRES_off_addr]; Keep all APB2 peripherals under reset
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 peripherals
STRH r0, [r2, #SWRES_off_addr]; Enable all all APB2 peripherals
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
MEND
; 定义存储器重新映射的汇编控制变量,也可以在项目的汇编器设定中预定义这些变量
; 若需要重映射,将如下变量去掉注释
; GBLL remapping
; 然后确定哪个地址映射到0x00000000(去掉对应的变量定义前面的注释)
; 重映射片内RAM (0x20000000)
; GBLL remap_ram
; 重映射片内FLASH(0x40000000)
; GBLL remap_flash
; 重映射片外存储器地址0x60000000
; GBLL remap_ext
; =============================================================================
ENTRY
EXPORT Reset_Handler
IMPORT T0TIMI_Addr
; --- 复位处理入口,系统复位时,从复位向量0x00000000的指令跳转到这里
Reset_Handler
;---设定中止、未定义指令和管理模式下的栈指针
MSR CPSR_c, #Mode_ABT:OR:F_Bit:OR:I_Bit
LDR SP, =ABT_Stack
MSR CPSR_c, #Mode_UNDEF:OR:F_Bit:OR:I_Bit
LDR SP,= UNDEF_Stack
MSR CPSR_c, #Mode_SVC:OR:F_Bit:OR:I_Bit
LDR SP, =RAM_Limit
;---初始化系统时钟
SYSCLK_INIT
;--- 初始化关键外设
PERIPHERAL_INIT ; Reset all device peripherals
;--- 初始化外总线接口
EMI_INIT ; Initialize EIM Bank 1
;--- 初始化中断控制器
EIC_INIT ; Initialize EIC
;******************************************************************************
;根据预定义的汇编变量完成存储器地址的重映射REMAPPING
;重映射把位于其他地方的ARM异常向量表映射到0地址
;******************************************************************************
IF :DEF: remapping
IF :DEF: remap_flash
MOV r0, #FLASH_mask
ENDIF
IF :DEF: remap_ram
MOV r0, #RAM_mask
ENDIF
IF :DEF: remap_ext
MOV r0, #EXTMEM_mask
ENDIF
LDR r1, =CPM_Base_addr
LDRH r2, [r1, #BOOTCR_off_addr]; Read BOOTCR Register
BIC r2, r2, #0x03 ; Reset the two LSB bits of BOOTCR
ORR r2, r2, r0 ; change the two LSB bits of BOOTCR
STRH r2, [r1, #BOOTCR_off_addr]; Write BOOTCR Register
ENDIF
; ---设定中断和系统模式下的栈指针
MSR CPSR_c, #Mode_FIQ:OR:I_Bit; Change to FIQ mode
LDR SP, =FIQ_Stack ; Initialize FIQ stack pointer
MSR CPSR_c, #Mode_IRQ:OR:I_Bit; Change to IRQ mode
LDR SP, =IRQ_Stack ; Initialize IRQ stack pointer
; MSR CPSR_c, #Mode_USR ; Change to User mode, Enable IRQ and FIQ
MSR CPSR_c, #Mode_SYS ; Change to User mode, Enable IRQ and FIQ
LDR SP, =USR_Stack ; Initialize USR stack pointer
; --- 注意,处理器将运行在sys模式下
IMPORT __main
; --- 跳转到C运行库初始化入口,其中将把RO数据从其加载域复制到其执行域,并建立RW和ZI区域,
; 然后初始化用到的C库函数,跳转到用户的C语言main()程序.
B __main ; 跳转,不返回
;*************************************************************
; 下面的代码是为了在不使用散列文件时,为C语言运行库的初始化程序__rt_entry提供
; 一个堆的起始位置。对于简单运行时刻映像,heap的起始地址应该放在ZI数据的上面,
; 从|Image$$ZI$$Limit|开始向上增长;而stack已经在前面汇编程序中设定从RAM的
; 最高端向下增长。适用于RO base=0x20000000和RO base =0x00000000,RWbase =0x20000000两种简单映像。
;
; 当使用散列文件时,可以用分散加载文件指定stack.o和heap.o在存储器中的位置。
; 这时要引入IMPORT __use_two_region_memory 定义,因为stack这时不一定在在heap之上;
; 同时代码要把r0,r1,r2,r3分别赋值为SB,HB,SL,HL。
IMPORT |Image$$ZI$$Limit|
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR r0,=|Image$$ZI$$Limit| ; heap base
MOV pc,lr
;*****************************************************************
LTORG
END
;******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -