STM32 USB Host Library 学习笔记 (2) USBH_InterruptSendData() USBH_ClrFeature()

复制代码
 1 /**
 2   * @brief  USBH_InterruptSendData
 3   *         Sends the data on Interrupt OUT Endpoint
 4   * @param  pdev: Selected device
 5   * @param  buff: Buffer pointer from where the data needs to be copied
 6   * @param  length: Length of the data to be sent
 7   * @param  hc_num: Host channel Number
 8   * @retval Status. 
 9   */
10 USBH_Status USBH_InterruptSendData( USB_OTG_CORE_HANDLE *pdev, 
11                                 uint8_t *buff, 
12                                 uint8_t length,
13                                 uint8_t hc_num)
14 {
15 
16   pdev->host.hc[hc_num].ep_is_in = 0;  
17   pdev->host.hc[hc_num].xfer_buff = buff;
18   pdev->host.hc[hc_num].xfer_len = length;
19   
20   if(pdev->host.hc[hc_num].toggle_in == 0)
21   {
22     pdev->host.hc[hc_num].data_pid = HC_PID_DATA0;
23   }
24   else
25   {
26     pdev->host.hc[hc_num].data_pid = HC_PID_DATA1;
27   }
28 
29   pdev->host.hc[hc_num].toggle_in ^= 1;  
30   
31   HCD_SubmitRequest (pdev , hc_num);  
32   
33   return USBH_OK;
34 }
复制代码

toggle_in or toggle_out ?

复制代码
 1 /**
 2   * @brief  USBH_BulkSendData
 3   *         Sends the Bulk Packet to the device
 4   * @param  pdev: Selected device
 5   * @param  buff: Buffer pointer from which the Data will be sent to Device
 6   * @param  length: Length of the data to be sent
 7   * @param  hc_num: Host channel Number
 8   * @retval Status
 9   */
10 USBH_Status USBH_BulkSendData ( USB_OTG_CORE_HANDLE *pdev, 
11                                 uint8_t *buff, 
12                                 uint16_t length,
13                                 uint8_t hc_num)
14 { 
15   pdev->host.hc[hc_num].ep_is_in = 0;
16   pdev->host.hc[hc_num].xfer_buff = buff;
17   pdev->host.hc[hc_num].xfer_len = length;  
18 
19  /* Set the Data Toggle bit as per the Flag */
20   if ( pdev->host.hc[hc_num].toggle_out == 0)
21   { /* Put the PID 0 */
22       pdev->host.hc[hc_num].data_pid = HC_PID_DATA0;    
23   }
24  else
25  { /* Put the PID 1 */
26       pdev->host.hc[hc_num].data_pid = HC_PID_DATA1 ;
27  }
28 
29   HCD_SubmitRequest (pdev , hc_num);   
30   return USBH_OK;
31 }
复制代码
复制代码
  else if (hcint.b.chhltd) // usb_hcd_int.c
  {
    MASK_HOST_INT_CHH (num);
    
    if(pdev->host.HC_Status[num] == HC_XFRC)
    {
      pdev->host.URB_State[num] = URB_DONE;  
      
      if (hcchar.b.eptype == EP_TYPE_BULK)
      {
        pdev->host.hc[num].toggle_out ^= 1; 
      }
    }
  }

复制代码
 1 /**
 2 * @brief  USBH_ClrFeature
 3 *         This request is used to clear or disable a specific feature.
 4 
 5 * @param  pdev: Selected device
 6 * @param  ep_num: endpoint number 
 7 * @param  hc_num: Host channel number 
 8 * @retval Status
 9 */
10 USBH_Status USBH_ClrFeature(USB_OTG_CORE_HANDLE *pdev,
11                             USBH_HOST *phost,
12                             uint8_t ep_num, 
13                             uint8_t hc_num) 
14 {
15   
16   phost->Control.setup.b.bmRequestType = USB_H2D | 
17                                          USB_REQ_RECIPIENT_ENDPOINT |
18                                          USB_REQ_TYPE_STANDARD;
19   
20   phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE;
21   phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT;
22   phost->Control.setup.b.wIndex.w = ep_num;
23   phost->Control.setup.b.wLength.w = 0;           
24   
25   if ((ep_num & USB_REQ_DIR_MASK ) == USB_D2H)
26   { /* EP Type is IN */
27     pdev->host.hc[hc_num].toggle_in = 0; 
28   }
29   else
30   {/* EP Type is OUT */
31     pdev->host.hc[hc_num].toggle_out = 0; 
32   }
33   
34   return USBH_CtlReq(pdev, phost, 0 , 0 );   
35 }
复制代码

复制代码
posted @   IAmAProgrammer  阅读(3304)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示