2014-12-02 05:14 AM
Hello guys,
I am working with the new CubeMX lib on a STM32F4 platform and altough I worked a lot with the ST USB HID implementation/stack it still gives me headaches. I am still new to USB.I am developing an HID device which has custom Feature Reports which indicate the device peripherie status or reporting configuration results etc. Because some of this Feature Report requests need interaction with peripherie, and this peripherie could be in use while the interrup occurs, I can not answer these requests directly in the USB interrupt. I wanted to answer the requests on the control endpoint in the main loop, but my test application on the usb host side does not receive any data.Answering the GetFeatureReport in the interrupt works perfectly well, but answering it delayed in the main loop does not. I guess its because the interrupt cleans up the endpoint at the end of the interrupt, but how can i prevent this, what is the correct why to do this? http://pastebin.com/rfwr4wFuuint8_t
reportBuffer[
4
]
=
{
0
}
;
uint8_t
asyncReport=
0
;
void
MainLoop_Tick(
)
{
if
(
asyncReport!=
0
)
{
if
(
asyncReport==
STATUS_REPORT_ID)
{
//DO SENSOR STUFF
reportBuffer
[
0
]
=
STATUS_REPORT_ID;
USBD_CtlSendData
(
&
USB_DEVICE,
reportBuffer,
4
)
;
}
}
}
void
USBD_HID_ProcessGetFeatureEvent(
uint8_t
report_id)
{
switch
(
report_id)
{
case
STATUS_REPORT_ID:
asyncReport
=
STATUS_REPORT_ID;
break
;
default
:
reportBuffer
[
0
]
=
report_id;
USBD_CtlSendData
(
&
USB_DEVICE,
reportBuffer,
4
)
;
break
;
}
}
2014-12-04 09:10 AM
Looks like almost fine,
but you need to drop the flag, ''asyncReport = 0;'', in the ''if'' clause which examines asyncReport, so that the Tick routine puts the DATA stage just once ;)void MainLoop_Tick(){
if(asyncReport != 0){
if(asyncReport == STATUS_REPORT_ID){
asyncReport = 0; // <------------
//DO SENSOR STUFF
reportBuffer[0] = STATUS_REPORT_ID;
USBD_CtlSendData (&USB_DEVICE, reportBuffer, 4);
}
}
}
Tsuneo
2014-12-15 07:43 AM
Hi Tsuneo,
thank you for your hint, I fixed that problem but I still can not send my data buffer to the host.If I remove USBD_CtlSendData out of the main loop I get an timeout on the host because no data gets transfered. But my USB device behaves correctly and answers all follow up requests.If I run it like in the post, I get an STATUS_SUCCESS on the host, but with an TransferBufferLength of 0x00. So it seems the transfer runs trough but no data gets transfered altough the length it is set to 0x04 in USBD_CtlSendData.Additonal to that, my USB device is in an unkown state and the USB host reports errors until I send a SetFeatureReport. Thats really weird and it seems that it is not possible to call any functions outside of (or after) the USB interrupt except USBD_CUSTOM_HID_SendReport.Debugging the usb stack helped me to get more insight into the procedure, but I found no way to solve me problem and I am still stuck here... There has to be something I overlooked.