菜鸟&新手 发表于 2017-3-9 17:01:40

stm32f407用cubmx生成HID,改成自定义设备遇到问题

   各位大神,我用的是STM32F407,先用CUBMX生成了一个HID设备,然后改成自定义的设备,现在是接收数据正常,发送数据不正常,发送用的是这个函数USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);接收用的是这个函数USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8);
static uint8_tUSBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev,
                              uint8_t epnum)
{
          uint8_t i;
                USBD_CUSTOM_HID_HandleTypeDef   *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
          
                if((rxbuff2==0xfe)&&(rxbuff2==0xa1))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfc;
                        txbuff2=0xa1;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                        HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_RESET);
                }
                else if((rxbuff2==0xfd)&&(rxbuff2==0x00))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfb;
                        txbuff2=0x00;
                        txbuff2=0x01;
                        txbuff2=0x00;
                        txbuff2=0x01;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0x17;
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                        HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);
                }
                else if((rxbuff2==0xfd)&&(rxbuff2==0x01))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfb;
                        txbuff2=0x00;
                        txbuff2=0x02;
                        txbuff2=0x00;
                        txbuff2=0x00;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0x17;       
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                        HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET);
                }
                else if((rxbuff2==0xfd)&&(rxbuff2==0x02))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfb;
                        txbuff2=0x00;
                        txbuff2=0x03;
                        txbuff2=0x00;
                        txbuff2=0x02;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0x17;
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                        HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET);
                }
                else if((rxbuff2==0xfd)&&(rxbuff2==0x03))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfb;
                        txbuff2=0x00;
                        txbuff2=0x04;
                        txbuff2=0x09;
                        txbuff2=0x0b;
                        txbuff2=0x03;
                        txbuff2=0x72;
                        txbuff2=0x17;
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                }
                else if((rxbuff2==0xfd)&&(rxbuff2==0x04))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfb;
                        txbuff2=0x00;
                        txbuff2=0x05;
                        txbuff2=0x00;
                        txbuff2=0x64;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0x17;
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                }
                else if((rxbuff2==0xfd)&&(rxbuff2==0x05))
                {
                        for(i=0;i<8;i++)
                        {
                                rxbuff=rxbuff2;
                        }
                        txbuff2=0xfb;
                        txbuff2=0x00;
                        txbuff2=0x06;
                        txbuff2=0x00;
                        txbuff2=0x00;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0x17;
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                }
                else if((rxbuff2==0xfe)&&(rxbuff2==0xa0))
                {
                        txbuff2=0xfc;
                        txbuff2=0xa0;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;
                        txbuff2=0xff;               
                        if (pdev->dev_state == USBD_STATE_CONFIGURED )
                        {
                                if(hhid->state == CUSTOM_HID_IDLE)
                                {
                                        hhid->state = CUSTOM_HID_BUSY;
                                        USBD_LL_Transmit(pdev, 0x82, txbuff2, 8);
                                }
                        }               
                }
               
               

                if (pdev->dev_state == USBD_STATE_CONFIGURED )
                {
                        while(hhid->state != CUSTOM_HID_IDLE);
                       
                        hhid->state = CUSTOM_HID_BUSY;
                        USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8);

                }       
//                USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8);
               
//USBD_CUSTOM_HID_HandleTypeDef   *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
//
//((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf,
//                                                            hhid->Report_buf);
//   
//USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf,
//                         USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);

return USBD_OK;
}

以上是处理过程

只发出一个?

菜鸟&新手 发表于 2017-3-15 15:09:36

现在已经解解决了,是应为FIFO没有配置好,因为我用了两个端口HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40);
        HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40);

菜鸟&新手 发表于 2017-3-9 17:02:06

自己顶一下

无薪税绵 发表于 2017-3-14 08:52:55

楼主检查一下,发送HID有没有错。

boboo-23776 发表于 2017-3-14 10:09:15

budong cun bang ding

chen00000009 发表于 2017-3-14 10:38:13

你底层的那些东西怎么改的?

cldym 发表于 2017-3-14 14:13:57

你底层的那些东西怎么改的?

tgwfcc 发表于 2017-3-14 14:47:49

没搞过,纯粹是来赚ST币的,虽然不多,日积月累嘛

我的颈 发表于 2017-3-14 17:13:48

首先我没有用过cubemx,但是我对你的有点疑问
先用CUBMX生成了一个HID设备,然后改成自定义的设备,
设备描述符接口描述符 HID描述符 端点描述符之类都是cubemx给你生成的?

菜鸟&新手 发表于 2017-3-15 15:07:47

我的颈 发表于 2017-3-14 17:13
首先我没有用过cubemx,但是我对你的有点疑问
先用CUBMX生成了一个HID设备,然后改成自定义的设备,
设备描 ...

不是,自己在基础上修改的
页: [1] 2
查看完整版本: stm32f407用cubmx生成HID,改成自定义设备遇到问题