码迷,mamicode.com
首页 > 其他好文 > 详细

novoton-启动代码分析

时间:2018-05-20 18:04:58      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:use   system   void   section   war   sele   function   mic   start   

启动文件:startup_M451Series.s

 1 ; Reset Handler
 2 
 3 Reset_Handler   PROC
 4                 EXPORT  Reset_Handler             [WEAK]
 5                 IMPORT  SystemInit
 6                 IMPORT  __main
 7                 
 8                 LDR     R0, =0x40000100
 9                 ; Unlock Register                
10                 LDR     R1, =0x59
11                 STR     R1, [R0]
12                 LDR     R1, =0x16
13                 STR     R1, [R0]
14                 LDR     R1, =0x88
15                 STR     R1, [R0]
16 
17                 ; Init POR
18                 LDR     R2, =0x40000024
19                 LDR     R1, =0x00005AA5
20                 STR     R1, [R2]
21 
22                 ; Select INV Type
23                 LDR     R2, =0x40000200
24                 LDR     R1, [R2]
25                 BIC     R1, R1, #0x1000
26                 STR     R1, [R2]
27 
28                 ; Lock register
29                 MOVS    R1, #0
30                 STR     R1, [R0]                
31                 
32                 
33                 LDR     R0, = SystemInit
34                 BLX     R0
35                 LDR     R0, = __main
36                 BX      R0
37                 ENDP

从复位中断函数可以知道,系统复位后先 执行 SystemInit 函数,后执行 __main 函数,由 __main 转到用户  main()  函数。

 1 /**
 2  * Initialize the system
 3  *
 4  * @param  None
 5  * @return None
 6  *
 7  * @brief  Setup the microcontroller system.
 8  *         Initialize the System.
 9  */
10 void SystemInit(void)
11 {
12     /* ToDo: add code to initialize the system
13              do not use global variables because this function is called before
14              reaching pre-main. RW section maybe overwritten afterwards.          */
15     
16     SYS_UnlockReg();
17     /* One-time POR18 */
18     if((SYS->PDID >> 12) == 0x945)
19     {
20         M32(GCR_BASE+0x14) |= BIT7;
21     }
22     /* Force to use INV type with HXT */
23     CLK->PWRCTL &= ~CLK_PWRCTL_HXTSELTYP_Msk;
24     SYS_LockReg();
25 
26 
27 #ifdef EBI_INIT
28     extern void SYS_Init();
29     extern void EBI_Init();
30     
31     SYS_UnlockReg();
32     SYS_Init();
33     EBI_Init();
34     SYS_LockReg();
35 #endif
36 
37     /* FPU settings ------------------------------------------------------------*/
38 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
39     SCB->CPACR |= ((3UL << 10 * 2) |               /* set CP10 Full Access */
40                    (3UL << 11 * 2));               /* set CP11 Full Access */
41 #endif
42 
43 }

__main 函数 完成C语言加载所需的资源,后执行跳转用户 main 函数。

novoton-启动代码分析

标签:use   system   void   section   war   sele   function   mic   start   

原文地址:https://www.cnblogs.com/llw2017/p/9063641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!