Exemple #1
0
/**
  * @brief  Upload a file via serial port.
  * @param  None
  * @retval None
  */
void SerialUpload(void)
{
  uint32_t status = 0; 

  SerialPutString("\n\n\rSelect Receive File ... (press any key to abort)\n\r");

  if (GetKey() == CRC16)
  {
    /* Transmit the flash image through ymodem protocol */
    status = Ymodem_Transmit((uint8_t*)ApplicationAddress, (const uint8_t*)"UploadedFlashImage.bin", FLASH_IMAGE_SIZE);

    if (status != 0) 
    {
      SerialPutString("\n\rError Occured while Transmitting File\n\r");
    }
    else
    {
      SerialPutString("\n\rFile Trasmitted Successfully \n\r");
    }
  }
  else
  {
    SerialPutString("\r\n\nAborted by user.\n\r");  
  }
 
}
/**
  * @brief  Upload a file via serial port.
  * @param  None
  * @retval None
  */
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*)APPLICATION_ADDRESS, (const uint8_t*)"UploadedFlashImage.bin", USER_FLASH_SIZE);

    if (status != 0) 
    {
      SerialPutString("\n\rError Occurred while Transmitting File\n\r");
    }
    else
    {
      SerialPutString("\n\rFile uploaded successfully \n\r");
    }
  }
}
Exemple #3
0
/**
  * @brief  Upload a file via serial port.
  * @param  None
  * @retval None
  */
void SerialUpload(mico_flash_t flash, uint32_t flashdestination, char *fileName, int32_t maxRecvSize)
{
  uint8_t status = 0;
  uint8_t key;

  printf("Select Receive File\n\r");
  MicoUartRecv( STDIO_UART, &key, 1, MICO_NEVER_TIMEOUT );

  if (key == CRC16)
  {
    /* Transmit the flash image through ymodem protocol */
    status = Ymodem_Transmit(flash, flashdestination, (uint8_t *)fileName, maxRecvSize);

    if (status != 0)
    {
      printf("\n\rError Occurred while Transmitting File\n\r");
    }
    else
    {
      printf("\n\rFile uploaded successfully \n\r");
    }
  }
}
Exemple #4
0
//==================================
static int file_send( lua_State* L )
{
  int8_t res = 0;
  int8_t newname = 0;
  uint8_t c;
  spiffs_stat s;
  const char *fname;
  const char *newfname;
  size_t len;
  char buff[LUAL_BUFFERSIZE];

  fname = luaL_checklstring( L, 1, &len );
  
  if( len > SPIFFS_OBJ_NAME_LEN )
    return luaL_error(L, "filename too long");
  
  if(FILE_NOT_OPENED!=file_fd){
    SPIFFS_close(&fs,file_fd);
    file_fd = FILE_NOT_OPENED;
  }
  
  if (lua_gettop(L) == 2 && lua_type( L, 2 ) == LUA_TSTRING) {
    size_t len;
    newfname = luaL_checklstring( L, 2, &len );
    newname = 1;
  }

  // Open the file
  file_fd = SPIFFS_open(&fs,(char*)fname,mode2flag("r"),0);
  if(file_fd < FILE_NOT_OPENED){
    file_fd = FILE_NOT_OPENED;
    l_message(NULL,"Error opening file.");
    return 0;
  }

  // Get file size
  SPIFFS_fstat(&fs, file_fd, &s);
  if (newname == 1) {
    sprintf(buff,"sending \"%s\" as \"%s\"\r\n", fname, newfname);
    l_message(NULL,buff);
    fname = newfname;
  }
  
  l_message(NULL,"Start Ymodem file transfer...");

  while (MicoUartRecv( MICO_UART_1, &c, 1, 10 ) == kNoErr) {}
  
  res = Ymodem_Transmit(fname, s.size);
  
  luaWdgReload();
  mico_thread_msleep(500);
  while (MicoUartRecv( MICO_UART_1, &c, 1, 10 ) == kNoErr) {}

  if(FILE_NOT_OPENED!=file_fd){
    SPIFFS_close(&fs,file_fd);
    file_fd = FILE_NOT_OPENED;
  }

  if (res == 0) {
    l_message(NULL,"\r\nFile sent successfuly.");
  }
  else if (res == 99) {
    l_message(NULL,"\r\nNo response.");
  }
  else if (res == 98) {
    l_message(NULL,"\r\nAborted.");
  }
  else {
    l_message(NULL,"\r\nError sending file.");
  }
  return 0;
}
Exemple #5
0
/*******************************************************************************
* 函数名称: download_program_to_meter
* 输入参数: 
* 输出参数: 
* --返回值: 
* 函数功能: --
*******************************************************************************/
static void download_program_to_meter(void)
{
    uint32_t status = 0u; 
    uint8_t tick_C = 0u;
    uint8_t Rev_flag = 0u;
    uint8_t read_flash_check_flag = 0u;
    uint8_t file_size[FILE_SIZE_LENGTH] = {0};
    
    /* wait for meter send 'C', meter printf something before send 'C' */
    delay_ms(5000);  /* 存在很低的概率, 会出现在进入升级的时候会停滞几秒 */
    
    MFS_UARTErrorClr(UartUSBCh);  //CLR error flag
    MFS_UARTSWRst(UART52_Ch);  //reset UART
    UARTConfigMode(UART52_Ch, &tUARTModeConfigT);
    MFS_UARTEnableRX(UART52_Ch);
    MFS_UARTEnableTX(UART52_Ch);
    
    //SerialPutString("\n\n\rSelect Receive File ... \n\r");
    
    Rev_flag = Receive_Byte(UART52_Ch , &tick_C, Rev_timeout); 
    if (0u == Rev_flag)
    {
        if (tick_C == CRC16)
        {
            printf("Rev C. \r\n");
        }    
    }    
    else
    {
		SerialPutString("\r\n no Rev 'C' .\r\n");  
    }    
    
    if (tick_C == CRC16)
    {
        SerialPutString("downlod image .bin ... \r\n");
        
        read_flash_check_flag = 0u;
        read_flash_check_flag = MX25L3206_Read((uint8_t*)(file_size),
                                               (uint32_t)FLASH_IMAGE_SIZE_ADDRESS,
                                               FILE_SIZE_LENGTH);
        if (OK != read_flash_check_flag)
        {
            __NOP();
        }  
        else
        {
            Str2Int(file_size, &flash_image_size);  /* str to hex */

            /* Transmit the flash image through ymodem protocol */
            status = Ymodem_Transmit((uint8_t*)ApplicationAddress,   //!!!!Note
                     (const uint8_t*)"DownloadFlashImage.bin",
                     flash_image_size);  /* , ,FLASH_IMAGE_MAX_SIZE */

            MFS_UARTDisableRX(UART52_Ch);  //

            if (status != 0) 
            {
                SerialPutString("\n\rError Occured while Transmitting File\n\r");
                oneSound(10, 300);  /* BUZZER 201 error buzz */
            }
            else
            {
                SerialPutString("\n\rFile Trasmitted Successfully \n\r");
                oneSound(10, 0);  /* BUZZER 201 buzz */
            }
        }//end if flash check    
    }
    else
    {
        SerialPutString("\r\n\nAborted by user or no Rev 'C' .\n\r");  
        oneSound(10, 300);  /* BUZZER 201 error buzz */
        //while(1);  //test!!! 
    }
    
    bFM3_GPIO_PDOR0_PD = 1u; /* LED 201 light off */
    bFM3_GPIO_PDOR0_PC = 1u; /* LED 202 light off */
    MFS_UARTDisableRX(UART52_Ch);
    MFS_UARTDisableTX(UART52_Ch);
}