chen
2024-11-01 631a90c1116fa33382a88a747c89bf761bc0fa9b
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
/*
 * Copyright (c) 2019-2023 Mauna Kea Semiconductor Holdings.
 * All rights reserved.
 *
 */
 
#include "mk_wdt.h"
 
#include "_customboot_image.c"
 
#if ((SRAM_BASE + SRAM_SIZE) < _customboot_end_address)
#error no enough space to store customboot
#endif
 
extern const VECTOR_TABLE_Type __VECTOR_TABLE[48];
 
int main(void)
{
    wdt_close(WDT_ID0);
    
    // copy customboot to it's link address
    memcpy((void *)_customboot_start_address, _customboot_image, sizeof(_customboot_image));
    
    // copy vector table from customboot and put it to the right place
    memcpy((void *)SRAM_BASE, (void *)_customboot_start_address, sizeof(__VECTOR_TABLE));
    
    // setup new msp
    __set_MSP(*(uint32_t *)_customboot_start_address);
    
    // jump to customboot
    typedef void (*p_entry_t)(void);
    ((p_entry_t) (*(uint32_t *)(_customboot_start_address + 4)))();
}