/** * @brief Download a file via serial port * @param None * @retval None */ void SerialDownload(mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize) { char Number[10] = " "; int32_t Size = 0; printf("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); Size = Ymodem_Receive(&tab_1024[0], flash, flashdestination, maxRecvSize); if (Size > 0) { printf("\n\n\r Programming Successfully!\n\r\r\n Name: "); printf("%s", FileName); Int2Str((uint8_t *)Number, Size); printf("\n\r Size: "); printf("%s", Number); printf(" Bytes\r\n"); } else if (Size == -1) { printf("\n\n\rThe image size is higher than memory!\n\r"); } else if (Size == -2) { printf("\n\n\rVerification failed!\n\r"); } else if (Size == -3) { printf("\r\n\nAborted by user.\n\r"); } else { printf("\n\rFailed to receive file!\n\r"); } }
/** * @brief Download a file via serial port * @param None * @retval None */ void SerialDownload(void) { uint8_t Number[10] = " "; int32_t Size = 0; SerialPutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); Size = Ymodem_Receive(&tab_1024[0]); if (Size > 0) { SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); SerialPutString(file_name); Int2Str(Number, Size); SerialPutString("\n\r Size: "); SerialPutString(Number); SerialPutString(" Bytes\r\n"); SerialPutString("-------------------\n"); } else if (Size == -1) { SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r"); } else if (Size == -2) { SerialPutString("\n\n\rVerification failed!\n\r"); } else if (Size == -3) { SerialPutString("\r\n\nAborted by user.\n\r"); } else { SerialPutString("\n\rFailed to receive the file!\n\r"); } }
/** * @brief Download a file via serial port * @param None * @retval None */ void SerialDownload(void) { uint8_t number[11] = {0}; uint32_t size = 0; COM_StatusTypeDef result; Serial_PutString((uint8_t *)"Waiting for the file to be sent ... (press 'a' to abort)\n\r"); result = Ymodem_Receive( &size ); if (result == COM_OK) { Serial_PutString((uint8_t *)"\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); Serial_PutString(aFileName); Int2Str(number, size); Serial_PutString((uint8_t *)"\n\r Size: "); Serial_PutString(number); Serial_PutString((uint8_t *)" Bytes\r\n"); Serial_PutString((uint8_t *)"-------------------\n"); } else if (result == COM_LIMIT) { Serial_PutString((uint8_t *)"\n\n\rThe image size is higher than the allowed space memory!\n\r"); } else if (result == COM_DATA) { Serial_PutString((uint8_t *)"\n\n\rVerification failed!\n\r"); } else if (result == COM_ABORT) { Serial_PutString((uint8_t *)"\r\n\nAborted by user.\n\r"); } else { Serial_PutString((uint8_t *)"\n\rFailed to receive the file!\n\r"); } }
//================================== static int file_recv( lua_State* L ) { int32_t fsize = 0; uint8_t c, gnm; char fnm[SPIFFS_OBJ_NAME_LEN]; char buff[LUAL_BUFFERSIZE]; spiffs_DIR d; struct spiffs_dirent e; struct spiffs_dirent *pe = &e; uint32_t total, used; SPIFFS_info(&fs, &total, &used); if(total>2000000 || used>2000000 || used > total) { return luaL_error(L, "file system error");; } gnm = 0; if (lua_gettop(L) == 1 && lua_type( L, 1 ) == LUA_TSTRING) { size_t len; const char *fname = luaL_checklstring( L, 1, &len ); if (len > 0 && len < SPIFFS_OBJ_NAME_LEN) { // use given file name for (c=0; c<len; c++) { fnm[c] = fname[c]; } fnm[len] = '\0'; gnm = 1; } } if (FILE_NOT_OPENED != file_fd) { SPIFFS_close(&fs,file_fd); file_fd = FILE_NOT_OPENED; } l_message(NULL,"Start Ymodem file transfer..."); while (MicoUartRecv( MICO_UART_1, &c, 1, 10 ) == kNoErr) {} fsize = Ymodem_Receive(fnm, total-used-10000, gnm); luaWdgReload(); mico_thread_msleep(500); while (MicoUartRecv( MICO_UART_1, &c, 1, 10 ) == kNoErr) {} if (FILE_NOT_OPENED != file_fd) { SPIFFS_fflush(&fs,file_fd); SPIFFS_close(&fs,file_fd); file_fd = FILE_NOT_OPENED; } mico_thread_msleep(500); if (fsize > 0) { sprintf(buff,"\r\nReceived successfully, %d\r\n",fsize); l_message(NULL,buff); } else if (fsize == -1) { l_message(NULL,"\r\nFile write error!\r\n"); } else if (fsize == -2) { l_message(NULL,"\r\nFile open error!\r\n"); } else if (fsize == -3) { l_message(NULL,"\r\nAborted.\r\n"); } else if (fsize == -4) { l_message(NULL,"\r\nFile size too big, aborted.\r\n"); } else { l_message(NULL,"\r\nReceive failed!"); } if (fsize > 0) { SPIFFS_opendir(&fs, "/", &d); while ((pe = SPIFFS_readdir(&d, pe))) { sprintf(buff," %-32s size: %i", pe->name, pe->size); l_message(NULL,buff); } SPIFFS_closedir(&d); } return 0; }
/******************************************************************************* * 函数名称: refresh_flash * 输入参数: * 输出参数: * --返回值: * 函数功能: -- *******************************************************************************/ static void refresh_flash(void) { uint8_t Number[10] = " "; int32_t Size = 0; MFS_UARTSWRst(UartUSBCh); //reset UART UARTConfigMode(UartUSBCh, &tUARTModeConfigT); MFS_UARTEnableTX(UartUSBCh); MFS_UARTEnableRX(UartUSBCh); SerialPutString("Waiting for the file to be sent ...\n\r"); Size = Ymodem_Receive(&tab_1024[0]); // MFS_UARTDisableRX(UartUSBCh); // MFS_UARTDisableTX(UartUSBCh); if (Size > 0) { SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); SerialPutString(file_name); Int2Str(Number, Size); SerialPutString("\n\r Size: "); SerialPutString(Number); SerialPutString(" Bytes\r\n"); SerialPutString("--------------------------------\r\n"); //oneSound(10,0); /* read extern Flash(MX25L4006) verify image */ //#define TEST_IMAGE #ifdef TEST_IMAGE uint32_t i = 0; uint32_t j = ApplicationAddress; memset(&tab_1024[0], 0, PACKET_SIZE); for (i=0u; i<1056; i++) /* (132*1024)/128 0-32 sector */ { MX25L3206_Read((uint8_t *)tab_1024, j, PACKET_SIZE); j += PACKET_SIZE; printHex(tab_1024,PACKET_SIZE); } #endif /* check CRC32 */ //... /* updata image complete, jump application routine */ //Jump_To_app(); //while (1); } else if (Size == -1) { SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r"); } else if (Size == -2) { SerialPutString("\n\n\rVerification failed!\n\r"); } else if (Size == -3) { SerialPutString("\r\n\nAborted by user.\n\r"); } else { SerialPutString("\n\rFailed to receive the file!\n\r"); }/* end if (Size > 0) Ymodem Rev */ if (Size > 0) { oneSound(10,0); } else { oneSound(10, 300); /* BUZZER 201 error buzz */ } bFM3_GPIO_PDOR0_PD = 1u; /* LED 201 light off */ bFM3_GPIO_PDOR0_PC = 1u; /* LED 202 light off */ }
/******************************************************************************* * 函数名称: boot * 输入参数: null * 输出参数: printf information * --返回值: null * 函数功能: -- IAP Ymodem * warning: updata -- updata ing must in Flash high address (0x0001FF04) * updata_OK -- updata compelet must in Flash low address (0x00001004) *******************************************************************************/ void boot(void) { uint8_t j; //SysTick_Config(SystemCoreClock/20); __disable_irq();//关闭总中断 #ifdef TEST LED_IO_init(); bFM3_GPIO_PDOR5_P5 = 1; /* LED off */ #endif /* read appointed address value 16 bit */ /* 0x80(128 byte) if frame isn't 128 byte compensation 0x1A*/ updata = MFlash_Read16bit ((uint16_t*)0x0001FF84); updata_OK = MFlash_Read16bit ((uint16_t*)0x0001FFA4); #ifdef TEST bFM3_GPIO_PDOR5_P5 = 0; /* LED light */ #endif // Jump_To_app(); // while (1); /* updata_OK == 0 updata == 0xFFFF stand for updata OK */ if ( ((0xFFFF==updata) && (0u==updata_OK)) ) { #ifdef TEST bFM3_GPIO_PDOR5_P5 = 0; /* LED4 light */ Delay_ms(1000u); //test bFM3_GPIO_PDOR5_P5 = 1; Delay_ms(1000u); //test #endif Jump_To_app(); /* updata image complete, jump application routine */ } else /* updata is not complete, need to updta image */ { UART_Port_init(); /* UART IO init */ UARTConfigMode(&tUARTModeConfigT); /* UART setup */ UARTPollTX_string("\n\n\rbootloader begin!!!\r\n"); while (1) { //UARTPollTX_string("Waiting for the file to be sent ... (press 'C' to abort)\r\n"); UARTPollTX_string("1...\r\n"); MFS_UARTEnableRX(InUseCh); MFS_UARTEnableTX(InUseCh); Size = Ymodem_Receive(&tab_128[0u]); if (Size > 0) { UARTPollTX_string("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); UARTPollTX_string(FileName); Int2Str(Number, Size); UARTPollTX_string("\n\r Size: "); UARTPollTX_string(Number); UARTPollTX_string(" Bytes\r\n"); UARTPollTX_string("--------------------------------\n"); //write appointed address value updata OK flag MFlash_Write((uint16_t*) 0x0001FFA4,(uint32_t) 0x00000000); /* 必须强制转换 写 32bit */ NVIC_SystemReset(); /* system reset, also soft reset */ while(1); } else if (Size == -1) { UARTPollTX_string("\n\n\rThe image size is higher than the allowed space memory!\n\r"); break; } else if (Size == -2) { UARTPollTX_string("\n\n\rVerification failed!\n\r"); break; } else if (Size == -3) { UARTPollTX_string("\r\n\nAborted by user.\n\r"); break; } else /* SecureCRT Ctrl + C CAN , Size = 0 */ { UARTPollTX_string("\n\rFailed to receive the file!\n\r"); break; } }//end while }//end if #ifdef TEST for (j=0; j<5; j++) { bFM3_GPIO_PDOR5_P5 = 0; /* LED4 light */ Delay_ms(1000u); //test bFM3_GPIO_PDOR5_P5 = 1; Delay_ms(1000u); //test } #endif NVIC_SystemReset(); /* system reset, also soft reset */ /* */ while(1); /* routine fatal error */ }