/* * Copyright (c) 2019-2023 Mauna Kea Semiconductor Holdings. * All rights reserved. * */ #include "mk_flash.h" #include "mk_trace.h" #include "mk_calib.h" #include "mk_wdt.h" #include "mk_clock.h" #include "libc_rom.h" #include "board.h" #include "AppConfig.h" #include "menu.h" #include "aes.h" #include "AppConfig.h" #include "mk_sleep_timer.h" static const uint32_t fw_addr = 0x04004000; static const uint32_t fw_bytes = 14712; extern const VECTOR_TABLE_Type __VECTOR_TABLE[48]; #define TEST_UART_POLL_MODE 0 #define TEST_UART_INTERUPT_MODE 1 #define TEST_UART_DMA_MODE 2 #define TEST_UART_MODE TEST_UART_DMA_MODE volatile unsigned long time_100ms; volatile unsigned long shengji_time_100ms; volatile unsigned long time32_incr; volatile unsigned long time32_reset = 0; volatile unsigned long start_timer; static unsigned char buff[100]; uint8_t key[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; extern int32_t Receive_Byte (uint8_t *c, uint32_t timeout); void usartdata_process( uint8_t data) { static uint8_t state=0; switch(state) { case 0: if(data==0x55) { state = 1; } break; case 1: if(data==0xAA) { state = 2; }else{ state = 0; } break; case 2: if(data==0x03) { state = 3; }else{ state = 0; } break; case 3: if(data==0x06) { state = 4; }else{ state = 0; } break; case 4: if(data==0x02) { state = 5; }else{ state = 0; } break; case 5: if(data==0x64) { state = 6; }else{ state = 0; } break; case 6: if(data==0x01) { state = 7; }else{ state = 0; } break; case 7: if(data==0x01) { state = 8; }else{ state = 0; } break; case 8: if(data==0x8E) { state = 9; }else{ state = 0; } break; case 9: if(data==0xFF) { uint16_t tmp = 0xAAAA,result; flash_erase(FLASH_ID0, APP_CONFIG_IAPFLAG_SECTOR_ADDR, FLASH_SECTOR_SIZE);//²Á³ýAPP flash_write_nbytes(FLASH_ID0,APP_CONFIG_IAPFLAG_MAP,(uint8_t*)&tmp,2); state = 0; } break; } } uint8_t state111; unsigned short int APP_byte = 0; unsigned short int updata_byte = 0; uint8_t trx_buf[10] = {0}; int test1; int aaa; uint16_t finalbag; static unsigned char zhongjian_shuju[128]; uint8_t jiexi_shuju[128]; static void app_wdt_callback(void *dev, uint32_t status) { ASSERT(status, "WDT TIMEOUT£¬³ÌÐò¸´Î»"); //LOG_INFO(TRACE_MODULE_APP, "³ÌÐò¿¨ËÀ£¬¿´ÃŹ·¸´Î»"); } struct WDT_CFG_T app_wdt_cfg = { .timeout = 32768 * 30, .rst_en = true, .int_en = true, .callback = app_wdt_callback, }; static void sleep_timer_callback(void *dev, uint32_t time) { time_100ms++; shengji_time_100ms++; if(shengji_time_100ms>300) { NVIC_SystemReset(); } } uint8_t flagmode;/*0Êǹ¤¿¨£¬1ÊÇÊÖ»·*/ //uint8_t flagshouhuan; int main(void) { uint8_t c; //sys_tick_callback_set(systic_time_callback); board_clock_run(); calib_chip(); gpio_open(); // board_pins_config(); //board_debug_console_open(TRACE_PORT_UART0); // Chip calibration // calib_chip(); // sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback); // sleep_timer_start(__MS_TO_32K_CNT(100));//²âÊÔ // Disable watchdog timer // wdt_close(WDT_ID0); // wdt_open(WDT_ID0,&app_wdt_cfg);//30s¼ì²âι¹· //LOG_INFO(TRACE_MODULE_APP, "½øÈëBootloader´®¿ÚÉý¼¶\r\n"); // gpio_open(); board_configure(); // struct UART_CFG_T test_uart_cfg = // { // .parity = UART_PARITY_NONE, // .stop = UART_STOP_BITS_1, // .data = UART_DATA_BITS_8, // .flow = UART_FLOW_CONTROL_NONE, // .rx_level = UART_RXFIFO_CHAR_1, // .tx_level = UART_TXFIFO_EMPTY, // .baud = BAUD_115200, // .dma_en = true, // .int_rx = false, // .int_tx = false, // }; flash_open(FLASH_ID0, NULL); // uart_open(UART_ID1, &test_uart_cfg); //uart_open(UART_ID0, &test_uart_cfg); //uart_receive(UART_ID1, trx_buf, 1, uart_receive_callback); // SerialPutString("MK8000-BootLoader-V1.1Æô¶¯\r\n"); //Serial0PutString("MK8000-BootLoader-V1.0Æô¶¯\r\n"); // delay_ms(200); // start_timer=time_100ms; // while(time_100ms