handling USB vendor requests with a data stage in KSDK 2.2 on K64

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

handling USB vendor requests with a data stage in KSDK 2.2 on K64

ソリューションへジャンプ
1,935件の閲覧回数
ryanlush
Contributor IV

I am rewriting some USB firmware that needs to play nicely with an existing windows library. The library uses setup packets to exchange an encryption key with the device. Other than that I'm doing nothing more than bulk transfers so I started with the dev_cdc_vcom_bm example and created my own cdc bulk class.

The way the old firmware works is to call a vendor request callback with the setup packet and the data that went along with it.

In KSDK 2.2, setup packets are handled in USB_DeviceControlCallback in usb_device_ch9.c. What doesnt make sense to me is it calls USB_DeviceClassCallback(handle, kUSB_DeviceEventVendorRequest, &controlRequest); before the data stage. USB_DeviceClassCallback is actually expecting the vendor requests callback to update a buffer pointer in &controlRequest so it knows where to put the data from the data stage.

What is the correct way to handle setup packets of type vendor, that include a data stage, given the existing KSDK 2.2 USB framework?

0 件の賞賛
返信
1 解決策
1,607件の閲覧回数
danielchen
NXP TechSupport
NXP TechSupport

Hi Ryan:

The vendor request setup packet is handled at line815(with setup OUT data stage and setup flag is set) and line853(with setup IN data stage and setup flag is set) in function  USB_DeviceControlCallback of file usb_device_ch9.c. For setup OUT data stage, after the data is received, the data is handled at line902(setup flag is clear and the data buffer is saved in controlRequest.buffer) in function  USB_DeviceControlCallback of file usb_device_ch9.c.

 

The following is the vendor request with setup OUT data stage work flow

pastedImage_1.png

 

The following is the vendor request with setup IN data stage work flow:

pastedImage_1.png

Regards

Daniel

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,608件の閲覧回数
danielchen
NXP TechSupport
NXP TechSupport

Hi Ryan:

The vendor request setup packet is handled at line815(with setup OUT data stage and setup flag is set) and line853(with setup IN data stage and setup flag is set) in function  USB_DeviceControlCallback of file usb_device_ch9.c. For setup OUT data stage, after the data is received, the data is handled at line902(setup flag is clear and the data buffer is saved in controlRequest.buffer) in function  USB_DeviceControlCallback of file usb_device_ch9.c.

 

The following is the vendor request with setup OUT data stage work flow

pastedImage_1.png

 

The following is the vendor request with setup IN data stage work flow:

pastedImage_1.png

Regards

Daniel

0 件の賞賛
返信
1,607件の閲覧回数
ryanlush
Contributor IV

Daniel,

Thank you so much for the detailed response. Your line numbers don't seem to match mine but I've spent a lot of time with this code and understand where the data is retrieved. What throws me off is the data is not retrieved until after the vendor request callback. I want to handle the data in the vendor request callback.

So I added a call to USB_DeviceRecvRequest() inside of my callback and everything seems to be working.

I still dont understand why the data is not retrieved until after the callback. What kinds of things are done in the callback without having the data?

0 件の賞賛
返信