#include "menu.h" #include "ymodem.h" #include "mk_flash.h" #include "mk_uart.h" //#include "Usart.h" //#include "SPIFlash.h" //#include "AppConfig.h" #include "HIDO_TypeDef.h" #include "mk_trace.h" //#include "stm32f4xx_hal.h" #include pFunction Jump_To_Application; uint32_t JumpAddress; uint32_t FlashProtection = 0; uint8_t tab_1024[1024] = { 0 }; void Int2Str(uint8_t* str, int32_t intnum) { uint32_t i, Div = 1000000000, j = 0, Status = 0; for (i = 0; i < 10; i++) { str[j++] = (intnum / Div) + 48; intnum = intnum % Div; Div /= 10; if ((str[j-1] == '0') & (Status == 0)) { j = 0; } else { Status++; } } } uint32_t IAP_JumpTo(uint32_t ApplicationAddress) { // if (((*(uint32_t*)ApplicationAddress) & 0x20000000 ) == 0x20000000) // { memcpy((void *)SRAM_BASE, (void *)APP_CONFIG_APPLICATION_ADDRESS, APP_CONFIG_APPLICATION_SIZE);//sizeÌ«´óµ¼Ö¸²¸Çû·¨Ìø×ª __set_MSP(*(uint32_t *)SRAM_BASE); typedef void (*p_entry_t)(void); ((p_entry_t) (*(uint32_t *)(SRAM_BASE + 4) + SRAM_BASE))(); // __set_MSP(*(uint32_t*) ApplicationAddress); //Set MSP MK8000ÐÞ¸Ä // // (*((void(*)(void))JumpAddress))(); // return 1; // } return 0; } uint8_t FileName[FILE_NAME_LENGTH]; /** * @brief Download a file via serial port * @param None * @retval None */ extern uint8_t temp111[256]; extern uint8_t tempchangdu; unsigned char SerialDownload(void) { uint8_t Number[10] = {0}; int32_t Size = 0; Send_Byte(0x33); Size = Ymodem_Receive(&tab_1024[0]);//¿ªÊ¼½ÓÊÕÎļþ,³É¹¦»á·µ»ØÎļþµÄ´óС if (Size > 0) //·µ»Ø³É¹¦ { g_com_map[YAOGEIANC_UPWENJIAN_DAXIAO]=Size; save_com_map_to_flash(); delay_ms(100); memcpy(&g_com_map[YAOGEIANC_UPWENJIAN_NAME],temp111,tempchangdu); delay_ms(100); // SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); // SerialPutString(FileName); // Int2Str(Number, Size); // SerialPutString("\n\r Size: "); // SerialPutString(Number); // SerialPutString(" Bytes\r\n"); // SerialPutString("-------------------\n"); // uart2_up_flag=0; return 0; } else if (Size == -1) { //SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r"); return 1; } else if (Size == -2) { //SerialPutString("\n\n\rVerification failed!\n\r"); return 2; } else if (Size == -3) { //SerialPutString("\r\n\nAborted by user.\n\r"); return 3; } else { // SerialPutString("\n\rFailed to receive the file!\n\r"); return 4; } } /** * @brief Upload a file via serial port. * @param None * @retval None */ uint8_t GetKey(void) { uint8_t key = 0; /* Waiting for user input */ while (1) { if (Serial0KeyPressed((uint8_t*)&key)) break; } return key; } void SerialUpload(void) { uint8_t status = 0 ; SerialPutString("\n\n\rSelect Receive File\n\r"); if (GetKey() == CRC16) { /* Transmit the flash image through ymodem protocol */ status = Ymodem_Transmit((uint8_t*)APP_CONFIG_APPLICATION_ADDRESS, (const uint8_t*)"UploadedFlashImage.bin", APP_CONFIG_APPLICATION_SIZE); if (status != 0) { SerialPutString("\n\rError Occurred while Transmitting File\n\r"); } else { SerialPutString("\n\rFile uploaded successfully \n\r"); } } } /** * @brief Display the Main Menu on HyperTerminal * @param None * @retval None */ //void delay_ms(uint32_t nTimer) //{ // uint32_t i=1000*nTimer; // delay_us(i); //} //void Main_Menu(void) //{ // uint8_t key = 0; // // while (1) // { // //Serial0PutString("Çë´«ÊäÉý¼¶Îļþ\r\n\n"); // /* Download user application in the Flash */ // if(SerialDownload()==0)//Èç¹û´«ÊäÍê³ÉÌø»ØAPP // { // //±êÖ¾Çå³ý // uint16_t tmp = 0xFFFF; // flash_erase(FLASH_ID0, APP_CONFIG_IAPFLAG_SECTOR_ADDR, FLASH_SECTOR_SIZE);//²Á³ýAPPFLAG // flash_write_nbytes(FLASH_ID0,APP_CONFIG_IAPFLAG_MAP,(uint8_t*)&tmp,2); //// SPIFlash_Erase(SPI_FLASH_ID_0, APP_CONFIG_IAPFLAG_MAP,2, SPI_FLASH_SECTOR_ERASE_MODE_4K); MK8000ÐÞ¸Ä //// SPIFlash_Write(SPI_FLASH_ID_0, APP_CONFIG_IAPFLAG_MAP, (HIDO_UINT8*)&tmp, sizeof(tmp)); // //// if (((*(__IO uint32_t*)APP_CONFIG_APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)ÏÈ×¢Ê͵ô¼´Ò»³É¹¦¾ÍÌø×ª //// { // /* Jump to user application */ // //Serial0PutString("Ìø×ªAPP\r\n"); // memcpy((void *)SRAM_BASE, (void *)APP_CONFIG_APPLICATION_ADDRESS, APP_CONFIG_APPLICATION_SIZE); // // setup new msp // __set_MSP(*(uint32_t *)SRAM_BASE); // //Serial0PutString("Ìø×ªAPPºó\r\n"); // typedef void (*p_entry_t)(void); // ((p_entry_t) (*(uint32_t *)(SRAM_BASE + 4) + SRAM_BASE))(); // // //JumpAddress = *(__IO uint32_t*) (SRAM_BASE + 4); // //// Jump_To_Application = (pFunction) JumpAddress; //// //// /* Initialize user application's Stack Pointer */ //// __set_MSP(*(__IO uint32_t*) SRAM_BASE); //// //// /* Jump to application */ //// Jump_To_Application(); // }else{ //// uint16_t tmp = 0xFFFF; //// flash_erase(FLASH_ID0, APP_CONFIG_IAPFLAG_MAP, 2);//²Á³ýAPPFLAG ´Ë´¦Ê§°Ü¾ÍÖØÆôÖØÐ½øÈëbootÀïÃæ´«ÊäÇÒ²»¸Ä±äÒªÉý¼¶µÄ±ê־λ //// flash_write(FLASH_ID0, APP_CONFIG_IAPFLAG_MAP, (uint8_t*)&tmp, sizeof(tmp)); // //SPIFlash_Erase(SPI_FLASH_ID_0, APP_CONFIG_IAPFLAG_MAP,2, SPI_FLASH_SECTOR_ERASE_MODE_4K); ¸ÄдΪMK8000API // //SPIFlash_Write(SPI_FLASH_ID_0, APP_CONFIG_IAPFLAG_MAP, (HIDO_UINT8*)&tmp, sizeof(tmp)); // delay_ms(10); // //LOG_INFO(TRACE_MODULE_APP,"Éý¼¶Ê§°ÜÖØÆô\r\n\n"); // NVIC_SystemReset(); // //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //Èí¸´Î»»Øµ½bootloader MK8000ÐÞ¸Ä // } // // return; // } //// else //// { //// NVIC_SystemReset(); //// return; //// } // ////} //}