using USB_DeviceHidSend outside of USB_DeviceHidGenericAction

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

using USB_DeviceHidSend outside of USB_DeviceHidGenericAction

跳至解决方案
2,328 次查看
Seif1
Contributor III

Hi, I use usb HID to send and recive data. I used the sdk to generate the code. the way it is generated,

is when host send data to the micro (interrupt out), it will end up inside USB_DeviceHidGenericAction, then USB_DeviceHidSend is used to send data to host, then USB_DeviceHidRecv , is used to get the data that the host sent. in this case, USB_DeviceHidSend  works fine.

However, I can only send data to host, only, when the host try sent data to the micro and I want to send and receive data separately. So what I tried to do is outside USB_DeviceHidGenericAction, and after specific time pass, I call USB_DeviceHidSend to send data to host. however, first time it return kStatus_USB_Success, then every time after it return kStatus_USB_Busy. it worth knowing that the code does not enter USB_DeviceHidInterruptIn even when it returned  kStatus_USB_Success so it does not clear the busy flag.

Seif1_0-1658164175303.png

so how I can use USB_DeviceHidSend  outside of USB_DeviceHidGenericAction.

any Help is appreciated, thanks in advance.

0 项奖励
回复
1 解答
2,171 次查看
Seif1
Contributor III

Thanks Alice, I was able to make it work Long time ago. the issue was that I thought that by connecting the USB to the PC and after the enumeration, the Hardware will start taking the data from the specified endpoints, which is not true. in order for the usb Hardware to start taking the data from endpoint, in case of HID, I need to createfile for HID in the host side, in my case PC. this will create the pipeline and the hardware will start reading the endpoint every Period, that was specified in the endpoint descriptor.

在原帖中查看解决方案

0 项奖励
回复
5 回复数
2,172 次查看
Seif1
Contributor III

Thanks Alice, I was able to make it work Long time ago. the issue was that I thought that by connecting the USB to the PC and after the enumeration, the Hardware will start taking the data from the specified endpoints, which is not true. in order for the usb Hardware to start taking the data from endpoint, in case of HID, I need to createfile for HID in the host side, in my case PC. this will create the pipeline and the hardware will start reading the endpoint every Period, that was specified in the endpoint descriptor.

0 项奖励
回复
2,315 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello,

It is not possible to send data at any time, only when USB master waiting responds from USB device, also the USB bus is not busy.

You can refer to dev_hid_generic demo under SDK, call this function "USB_DeviceHidSend()" inUSB_DeviceHidGenericCallback() function.

 

BR

Alice

0 项奖励
回复
2,311 次查看
Seif1
Contributor III

Hi Alice, Thanks for your respond.

I understand, that after the polling time that I specified for the end point IN inside the descriptor, host (pc in my case)will check if the end point have data to read (hardware and lower layer do that for me and I do not need to send anything to check the end point).

 

So what I am trying to do is after every specific time I write the data to the end point(using USB_DeviceHidSend), and whenever the poling time pass the host can get the data from the end point. On the host side, when I want to read the received report, I use readfile API to read the received data(pc can keep reading up to around 22 report). so I can let the pc lower layer reading the reports and store them, then I can analyze them when it is needed.

is any part of my understanding is wrong?

Also, 

using readfile does not send any thing to the host. so according to what you said,  I will always need to use writefile from the pc to be able to get inside USB_DeviceInterface0HidGenericCallback then use USB_DeviceHidSend ?

Also, the following function is the one you are speaking about?

 

Seif1_0-1658337448919.png

 

Thank you !

 

 

0 项奖励
回复
2,274 次查看
Seif1
Contributor III

can anyone confirm my understanding?, that would be appreciated. thanks

0 项奖励
回复
2,224 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello,

I think yes, and strongly recommend you debug step by step the HID demo under SDK, you will know the process well.

 

BR

Alice

 

 

0 项奖励
回复