/******************************************************************************
|
* @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)
|
{
|
}
|
}
|