yincheng.zhong
2024-08-20 7744fffacb03dc81cc9dbaf9f5d86a0f21e79c03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/******************************************************************************
 * @file     startup_MK8000.c
 * @brief    CMSIS-Core(M) Device Startup File for MK8000
 * @version  V2.0.3
 * @date     31. March 2020
 ******************************************************************************/
/*
 * Copyright (c) 2009-2020 Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#include "MK800X.h"
 
/*----------------------------------------------------------------------------
  External References
 *----------------------------------------------------------------------------*/
extern uint32_t __INITIAL_SP;
#ifndef STD_LIBC
extern void update_libc_rom_table(void);
#endif
 
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
extern __NO_RETURN void __PROGRAM_START(void);
#endif
 
const struct BOOT_DESC_T mk_boot_desc = {
    .header_marker = BOOT_HEADER_MARKER,
    .boot_flag = APP_BOOT_FLAG,
#if defined(XIP_EN)
    .boot_addr = FLASH_BASE,
#else
    .boot_addr = SRAM_BASE,
#endif
    .cpc = APP_CPC,
    .image_len = (uint32_t)&mk_boot_desc,
    .image_crc = 0,
    .image_ver = APP_VERSION,
    .code_crc = 0,
#if SECURE_EN
    .image_sig = {0},
#endif
    .isp_unprotect_pw = {0},
    .isp_backdoor_pw = {0},
    .copy_len = (uint32_t)&mk_build_inf + sizeof(mk_build_inf),
    .crc = 0,
};
 
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdate-time"
#endif
const char mk_build_inf[80] =
    "\n"
    "Vendor\t: "
    "MKSEMI"
    "\n"
    "Chip\t: "
    "MK8000"
    "\n"
    "Date\t: " __DATE__
    "\n"
    "Version\t: " FIRMWARE_VERSION "\0";
 
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
 
/*----------------------------------------------------------------------------
  Internal References
 *----------------------------------------------------------------------------*/
__NO_RETURN void Reset_Handler(void);
__NO_RETURN void Default_Handler(void);
 
/*----------------------------------------------------------------------------
  Exception / Interrupt Handler
 *----------------------------------------------------------------------------*/
/* Exceptions */
void NMI_Handler(void) __attribute__((weak, alias("Default_Handler")));
void HardFault_Handler(void) __attribute__((weak, alias("Default_Handler")));
void SVC_Handler(void) __attribute__((weak, alias("Default_Handler")));
void PendSV_Handler(void) __attribute__((weak, alias("Default_Handler")));
void SysTick_Handler(void) __attribute__((weak, alias("Default_Handler")));
 
void BOD_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void ACMP0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void ACMP1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void DMA_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void SLEEP_TIMER_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void MAC_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void PHY_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void GPIO_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void AES_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void ADC_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void TRNG_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void FLASH_CTRL_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void LSP_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void WDT_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void RTC_ALARM_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void RTC_TICK_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void PWM_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void TIMER0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void TIMER1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void TIMER2_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void TIMER3_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void I2C0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void SPI0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void SPI1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void UART0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void UART1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void CALIB_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void RCO32K_CAL_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void WAKEUP_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
void PHY_TIMER_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
 
/*----------------------------------------------------------------------------
  Exception / Interrupt Vector table
 *----------------------------------------------------------------------------*/
 
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
 
extern const VECTOR_TABLE_Type __VECTOR_TABLE[48];
const VECTOR_TABLE_Type __VECTOR_TABLE[48] __VECTOR_TABLE_ATTRIBUTE = {
    (VECTOR_TABLE_Type)(&__INITIAL_SP),           /*     Initial Stack Pointer */
    Reset_Handler,                                /*     Reset Handler */
    NMI_Handler,                                  /* -14 NMI Handler */
    HardFault_Handler,                            /* -13 Hard Fault Handler */
    0,                                            /*     Reserved */
    0,                                            /*     Reserved */
    0,                                            /*     Reserved */
    0,                                            /*     Reserved */
    0,                                            /*     Reserved */
    (VECTOR_TABLE_Type)((uint32_t)&mk_boot_desc), /*     Pointer of boot descriptor */
    (VECTOR_TABLE_Type)((uint32_t)&mk_build_inf), /*     Pointer of build information */
    SVC_Handler,                                  /*  -5 SVCall Handler */
    0,                                            /*     Reserved */
    0,                                            /*     Reserved */
    PendSV_Handler,                               /*  -2 PendSV Handler */
    SysTick_Handler,                              /*  -1 SysTick Handler */
 
    /* Interrupts */
    BOD_IRQHandler,         /*   0 BOD */
    ACMP0_IRQHandler,       /*   1 ACMP0 */
    ACMP1_IRQHandler,       /*   2 ACMP1 */
    SLEEP_TIMER_IRQHandler, /*   3 SLEEP_TIMER */
    MAC_IRQHandler,         /*   4 MAC */
    PHY_IRQHandler,         /*   5 PHY */
    DMA_IRQHandler,         /*   6 DMA */
    GPIO_IRQHandler,        /*   7 GPIO */
    AES_IRQHandler,         /*   8 AES */
    ADC_IRQHandler,         /*   9 ADC */
    TRNG_IRQHandler,        /*  10 TRNG */
    FLASH_CTRL_IRQHandler,  /*  11 FLASH_CTRL */
    LSP_IRQHandler,         /*  12 LSP */
    WDT_IRQHandler,         /*  13 WDT */
    RTC_ALARM_IRQHandler,   /*  14 RTC ALARM */
    RTC_TICK_IRQHandler,    /*  15 RTC TICK */
    PWM_IRQHandler,         /*  16 PWM */
    TIMER0_IRQHandler,      /*  17 TIMER0 */
    TIMER1_IRQHandler,      /*  18 TIMER1 */
    TIMER2_IRQHandler,      /*  19 TIMER2 */
    TIMER3_IRQHandler,      /*  20 TIMER3 */
    I2C0_IRQHandler,        /*  21 I2C0 */
    SPI0_IRQHandler,        /*  22 SPI0 */
    SPI1_IRQHandler,        /*  23 SPI1 */
    UART0_IRQHandler,       /*  24 UART0 */
    UART1_IRQHandler,       /*  25 UART1 */
    CALIB_IRQHandler,       /*  26 CALIBRATION */
    RCO32K_CAL_IRQHandler,  /*  27 RCO32K CAL */
    WAKEUP_IRQHandler,      /*  28 WAKEUP */
    PHY_TIMER_IRQHandler,   /*  29 PHY TIMER */
 
    /* Interrupts 30..31 are left out */
};
 
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
 
/*----------------------------------------------------------------------------
  Reset Handler called on controller reset
 *----------------------------------------------------------------------------*/
 
#if defined(__CC_ARM)
/* ARM RVDS or Keil MDK */
__asm void start_main_asm(void)
{
    IMPORT __PROGRAM_START;
    LDR R0, = __PROGRAM_START;
    BX R0;
}
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
/* ARM CLANG */
__NO_RETURN void start_main_asm(void) __attribute__((naked));
void start_main_asm(void)
{
    __ASM volatile(
        "ldr r0, = __main\n"
        "bx r0\n");
}
#elif defined(__ICCARM__)
/* IAR */
__NO_RETURN void start_main_asm(void) __attribute__((naked));
extern void __iar_program_start(void);
void start_main_asm(void)
{
    __ASM volatile(
        "ldr r0, = __iar_program_start\n"
        "bx r0\n");
    while (1)
    {
    }
}
#else
/* GCC */
__NO_RETURN void start_main_asm(void) __attribute__((naked));
__NO_RETURN void __cmsis_start_(void)
{
    __cmsis_start();
}
 
void start_main_asm(void)
{
    __ASM volatile(
        "ldr r0, = __cmsis_start_\n"
        "bx r0\n");
}
#endif
 
__NO_RETURN void Reset_Handler(void)
{
#if defined(XIP_EN)
    // Remap FLASH
    SYSCON->SYS_CTRL &= ~(SYSCON_SYS_CTRL_REMAP_MSK);
    SYSCON->SYS_CTRL |= SYSCON_SYS_CTRL_REMAP(0x02);
#else
    // Remap SRAM
    SYSCON->SYS_CTRL &= ~(SYSCON_SYS_CTRL_REMAP_MSK);
    SYSCON->SYS_CTRL |= SYSCON_SYS_CTRL_REMAP(0x01);
#endif
#ifndef STD_LIBC
    update_libc_rom_table();
#endif
    SystemInit();     /* CMSIS System Initialization */
    start_main_asm(); /* Enter PreMain (C library entry point) */
}
 
/*----------------------------------------------------------------------------
  Default Handler for Exceptions / Interrupts
 *----------------------------------------------------------------------------*/
__NO_RETURN void Default_Handler(void)
{
    while (1)
    {
    }
}