cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID writefile ( output report ) only works under some F103xx board, GetLastError is 31

calltherain
Associate II
Posted on January 25, 2015 at 16:42

I have 5 stm32 boards, 3 with F103RBT6 , 2 with F103C8T6.

I build an USB HID firmware by using USB FS Device Library 4.0, the code is just modified from the custom HID demo in the ST USB device library. the firmware works okay on all of the boards in regards the HID input report. But when I tried using Windows API WriteFile() to write the HID output report to the boards, only 3 of the board works: 2 of the F103RBT6 board and 1 of the F103C8T6 board. For the boards which can't work correctly, the first WriteFile failed with GetLastError the 2nd WriteFile will cause the thread blocked, after a long waiting (30 seconds maybe ) the writeFile failed with GetLastError 9 In the EP1_OUT_callback() in usb_endp.c I set the PB14 to high at the begining of the handler like this:

void EP1_OUT_Callback(void)
{
//read received data ( 64 bytes )
GPIO_SetBits(GPIOB, GPIO_Pin_14 );
USB_SIL_Read( EP1_OUT, OutputDataBuffer );
//deal withe the OUTPUT data
....
SetEPRxStatus(ENDP1, EP_RX_VALID);
GPIO_ResetBits(GPIOB, GPIO_Pin_14 );
}

but I can't find this pulse in oscilloscope. With those board which works okay, I can see the pulse in the scope. So it seems that the EP1_OUT_Callback is not invoked for some reason. I have no idea what should I try to find out the root cause. Any suggestions are appreciated! Thanks in advance. #usb-f10x_md
3 REPLIES 3
tsuneo
Senior
Posted on January 26, 2015 at 18:09

Did you modify ENDP1_RXADDR value in usb_conf.h?

The original example assigns just 4 bytes (0x104 - 0x100) for TX endpoint buffer,

\STM32_USB-FS-Device_Lib_V4.0.0\Projects\Custom_HID\inc\usb_conf.h
/* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x104) // <--- 0x140

If you would put an input report greater than 4 bytes, the RX endpoint buffer, following just after the TX EP buffer, should be overwritten. Tsuneo
calltherain
Associate II
Posted on January 27, 2015 at 06:55 well, I have the buffer defined like this

/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
//rx buffer base address
#define ENDP1_RXADDR (0x140)

the Endpoint is configured in usb_prop.c

/* Initialize Endpoint 1 */
SetEPType(ENDP1, EP_INTERRUPT);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPTxCount(ENDP1, 32);
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPTxCount(ENDP1, 64);
SetEPRxStatus(ENDP1, EP_RX_VALID);
SetEPTxStatus(ENDP1, EP_TX_NAK);

And if the problem is caused by buffer overlap/overrun issue, I believe all the 5 board will not work.
tsuneo
Senior
Posted on January 27, 2015 at 09:24

> And if the problem is caused by buffer overlap/overrun issue, I believe all the 5 board will not work.

 

If it were so, our life could be much easier.

Buffer overrun and uninitialized variables end up unstable results, sometimes succeed, sometimes fail.

After the error on the WriteFile, does ReadFile still succeed?

If ReadFile could succeed, the USB engine would be working; just the OUT endpoint is broken.

Anyway, trace it on a hardware bus analyzer.

And then, you'll get more precise clues to pin the bug down.

Tsuneo