Beispiel #1
0
void pyb_usb_dev_deinit(void) {
    usb_device_t *usb_dev = &usb_device;
    if (usb_dev->enabled) {
        USBD_Stop(&usb_dev->hUSBDDevice);
        usb_dev->enabled = false;
    }
}
/**
  * @brief  DFU_Detach
  *         Handles the DFU DETACH request.
  * @param  pdev: device instance
  * @param  req: pointer to the request structure.
  * @retval None.
  */
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
 USBD_DFU_HandleTypeDef   *hdfu;
 
 hdfu = pdev->pClassData;
 
  if (hdfu->dev_state == DFU_STATE_IDLE || hdfu->dev_state == DFU_STATE_DNLOAD_SYNC
      || hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_MANIFEST_SYNC
        || hdfu->dev_state == DFU_STATE_UPLOAD_IDLE )
  {
    /* Update the state machine */
    hdfu->dev_state = DFU_STATE_IDLE;
    hdfu->dev_status[0] = DFU_ERROR_NONE;
    hdfu->dev_status[1] = 0;
    hdfu->dev_status[2] = 0;
    hdfu->dev_status[3] = 0; /*bwPollTimeout=0ms*/
    hdfu->dev_status[4] = hdfu->dev_state;
    hdfu->dev_status[5] = 0; /*iString*/
    hdfu->wblock_num = 0;
    hdfu->wlength = 0;
  } 
  
  /* Check the detach capability in the DFU functional descriptor */
  if ((USBD_DFU_CfgDesc[12 + (9 * USBD_DFU_MAX_ITF_NUM)]) & DFU_DETACH_MASK)
  {
    /* Perform an Attach-Detach operation on USB bus */
    USBD_Stop (pdev);
    USBD_Start (pdev);  
  }
  else
  {
    /* Wait for the period of time specified in Detach request */
    USBD_Delay (req->wValue);  
  }
}
/**
  * @brief  DFU_Leave
  *         Handles the sub-protocol DFU leave DFU mode request (leaves DFU mode
  *         and resets device to jump to user loaded code).
  * @param  pdev: device instance
  * @retval None
  */
void DFU_Leave(USBD_HandleTypeDef *pdev)
{
 USBD_DFU_HandleTypeDef   *hdfu;
 
 hdfu = pdev->pClassData;
 
 hdfu->manif_state = DFU_MANIFEST_COMPLETE;

  if ((USBD_DFU_CfgDesc[(11 + (9 * USBD_DFU_MAX_ITF_NUM))]) & 0x04)
  {
    hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;

    hdfu->dev_status[1] = 0;
    hdfu->dev_status[2] = 0;
    hdfu->dev_status[3] = 0;
    hdfu->dev_status[4] = hdfu->dev_state;       
    return;
  }
  else
  {
    
    hdfu->dev_state = DFU_STATE_MANIFEST_WAIT_RESET;
    
    hdfu->dev_status[1] = 0;
    hdfu->dev_status[2] = 0;
    hdfu->dev_status[3] = 0;
    hdfu->dev_status[4] = hdfu->dev_state;     
    
    /* Disconnect the USB device */
    USBD_Stop (pdev);

    /* DeInitilialize the MAL(Media Access Layer) */
    ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
    
    /* Generate system reset to allow jumping to the user code */
    NVIC_SystemReset();
   
    /* This instruction will not be reached (system reset) */
    for(;;);
  }  
}
Beispiel #4
0
void pyb_usb_dev_stop(void) {
    if (dev_is_enabled) {
        USBD_Stop(&hUSBDDevice);
        dev_is_enabled = 0;
    }
}
Beispiel #5
0
/**
  * @brief  Execute the demo application.
  * @param  None
  * @retval None
  */
static void Demo_Exec(void)
{
    uint8_t togglecounter = 0x00;

    /* Initialize Accelerometer MEMS*/
    if(BSP_ACCELERO_Init() != HAL_OK)
    {
        /* Initialization Error */
        Error_Handler();
    }

    while(1)
    {
        DemoEnterCondition = 0x00;

        /* Reset UserButton_Pressed variable */
        UserButtonPressed = 0x00;

        /* Configure LEDs to be managed by GPIO */
        BSP_LED_Init(LED3);
        BSP_LED_Init(LED4);
        BSP_LED_Init(LED5);
        BSP_LED_Init(LED6);

        /* SysTick end of count event each 10ms */
        SystemCoreClock = HAL_RCC_GetHCLKFreq();
        SysTick_Config(SystemCoreClock / 100);

        /* Turn OFF all LEDs */
        BSP_LED_Off(LED4);
        BSP_LED_Off(LED3);
        BSP_LED_Off(LED5);
        BSP_LED_Off(LED6);

        /* Waiting User Button is pressed */
        while (UserButtonPressed == 0x00)
        {
            /* Toggle LED4 */
            BSP_LED_Toggle(LED4);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED3);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED5);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED6);
            HAL_Delay(10);
            togglecounter ++;
            if (togglecounter == 0x10)
            {
                togglecounter = 0x00;
                while (togglecounter < 0x10)
                {
                    BSP_LED_Toggle(LED4);
                    BSP_LED_Toggle(LED3);
                    BSP_LED_Toggle(LED5);
                    BSP_LED_Toggle(LED6);
                    HAL_Delay(10);
                    togglecounter ++;
                }
                togglecounter = 0x00;
            }
        }

        /* Waiting User Button is Released */
        while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {}
        UserButtonPressed = 0x00;

        /* TIM4 channels configuration */
        TIM4_Config();

        DemoEnterCondition = 0x01;

        /* USB configuration */
        Demo_USBConfig();

        /* Waiting User Button is pressed */
        while (UserButtonPressed == 0x00)
        {}

        /* Waiting User Button is Released */
        while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {}

        /* Disconnect the USB device */
        USBD_Stop(&hUSBDDevice);
        USBD_DeInit(&hUSBDDevice);
        if(HAL_TIM_PWM_DeInit(&htim4) != HAL_OK)
        {
            /* Initialization Error */
            Error_Handler();
        }
    }
}
Beispiel #6
0
/**
  * @brief  Stop USBD
  * @param  None.
  * @retval USBD status.
  */
USBD_ErrorTypdef  USBDSTOR_Disconnect(void)
{
  USBD_Stop(&USBD_Device);  
  
  return USBD_ERROR_NONE;
}
Beispiel #7
0
void pyb_usb_dev_deinit(void) {
    if (pyb_usb_flags & PYB_USB_FLAG_DEV_ENABLED) {
        USBD_Stop(&hUSBDDevice);
        pyb_usb_flags &= ~PYB_USB_FLAG_DEV_ENABLED;
    }
}