Esempio n. 1
0
/*******************************************************************************
* Function Name  : DFU_Status_Out.
* Description    : DFU status OUT routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DFU_Status_Out (void)
{
  DEVICE_INFO *pInfo = &Device_Info;
  uint32_t Addr;

  if (pInfo->USBbRequest == DFU_GETSTATUS)
  {
    if (DeviceState == STATE_dfuDNBUSY)
    {
      if (wBlockNum == 0)   /* Decode the Special Command*/
      {
        if ((MAL_Buffer[0] ==  CMD_GETCOMMANDS) && (wlength == 1))
        {}
        else if  (( MAL_Buffer[0] ==  CMD_SETADDRESSPOINTER ) && (wlength == 5))
        {
          Pointer  = MAL_Buffer[1];
          Pointer += MAL_Buffer[2] << 8;
          Pointer += MAL_Buffer[3] << 16;
          Pointer += MAL_Buffer[4] << 24;
        }
        else if (( MAL_Buffer[0] ==  CMD_ERASE ) && (wlength == 5))
        {
          Pointer  = MAL_Buffer[1];
          Pointer += MAL_Buffer[2] << 8;
          Pointer += MAL_Buffer[3] << 16;
          Pointer += MAL_Buffer[4] << 24;
          MAL_Erase(Pointer);
        }
      }

      else if (wBlockNum > 1)  // Download Command
      {
        Addr = ((wBlockNum - 2) * wTransferSize) + Pointer;
        MAL_Write(Addr, wlength);
      }
      wlength = 0;
      wBlockNum = 0;

      DeviceState =  STATE_dfuDNLOAD_SYNC;
      DeviceStatus[4] = DeviceState;
      DeviceStatus[1] = 0;
      DeviceStatus[2] = 0;
      DeviceStatus[3] = 0;
      return;
    }
    else if (DeviceState == STATE_dfuMANIFEST)/* Manifestation in progress*/
    {
      DFU_write_crc();
      return;
    }
  }
  return;
}
Esempio n. 2
0
/**
  * @brief  EP0_TxSent
  *         Handles the DFU control endpoint data IN stage.
  * @param  pdev: device instance
  * @retval status
  */
static uint8_t  EP0_TxSent (void  *pdev)
{
  uint32_t Addr;
  USB_SETUP_REQ req;

  if (DeviceState == STATE_dfuDNBUSY)
  {
    /* Decode the Special Command*/
    if (wBlockNum == 0)
    {
      if ((MAL_Buffer[0] ==  CMD_GETCOMMANDS) && (wlength == 1))
      {}
      else if  (( MAL_Buffer[0] ==  CMD_SETADDRESSPOINTER ) && (wlength == 5))
      {
        Pointer  = MAL_Buffer[1];
        Pointer += MAL_Buffer[2] << 8;
        Pointer += MAL_Buffer[3] << 16;
        Pointer += MAL_Buffer[4] << 24;
      }
      else if (( MAL_Buffer[0] ==  CMD_ERASE ) && (wlength == 5))
      {
        Pointer  = MAL_Buffer[1];
        Pointer += MAL_Buffer[2] << 8;
        Pointer += MAL_Buffer[3] << 16;
        Pointer += MAL_Buffer[4] << 24;
        MAL_Erase(Pointer);
      }
      else
      {
        /* Reset the global length and block number */
        wlength = 0;
        wBlockNum = 0;
        /* Call the error management function (command will be nacked) */
        req.bmRequest = 0;
        req.wLength = 1;
        USBD_CtlError (pdev, &req);
      }
    }
    /* Regular Download Command */
    else if (wBlockNum > 1)
    {
      /* Decode the required address */
      Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer;

      /* Preform the write operation */
      MAL_Write(Addr, wlength);
    }
    /* Reset the global lenght and block number */
    wlength = 0;
    wBlockNum = 0;

    /* Update the state machine */
    DeviceState =  STATE_dfuDNLOAD_SYNC;
    DeviceStatus[4] = DeviceState;
    DeviceStatus[1] = 0;
    DeviceStatus[2] = 0;
    DeviceStatus[3] = 0;
    return USBD_OK;
  }
  else if (DeviceState == STATE_dfuMANIFEST)/* Manifestation in progress*/
  {
    /* Start leaving DFU mode */
    DFU_LeaveDFUMode(pdev);
  }

  return USBD_OK;
}