2012-10-09 03:12 PM
Hi,
I need to set up a USB connexion between my computer and an STM32 device so I took the Custom HID example provided by ST and I'm trying to make it works as I want. I just want to send and receive up to 8 bytes so I wrote this (inspired by the example of course). I can actually send some data from the computer (to light LEDs) but I can't get the value of the ADC. In my main function I have an infinite loop like this : while (1) { ADC_Value[0] = (ADC_ConvertedValue&0xFF00) >> 8; ADC_Value[1] = ADC_ConvertedValue&0xFF; buff[0]=0x07; buff[1]=ADC_Value[0]; buff[2]=ADC_Value[1]; USB_SIL_Write(EP1_IN, buff, 3); SetEPTxValid(ENDP1); } The USB configuration should be ok because with and old (buggy) descriptor I managed to send data but not receive data correctly Do you see anything wrong in what I'm doing? Thanks2012-10-10 08:46 AM
while (1) {
// wait until the device is configured
if ( bDeviceState != CONFIGURED ) continue;
// wait until the endpoint finishes
// the last transaction
if ( GetEPTxStatus( ENDP1 ) != EP_TX_NAK ) continue;
ADC_Value[0] = (ADC_ConvertedValue&0xFF00) >> 8;
ADC_Value[1] = ADC_ConvertedValue&0xFF;
buff[0]=0x07;
buff[1]=ADC_Value[0];
buff[2]=ADC_Value[1];
// Send 9 bytes,
// report ID (1 byte) + body (8 bytes)
USB_SIL_Write(EP1_IN, buff, 9);
SetEPTxValid(ENDP1);
}
Also, increase the
wMaxPacketSize
of both of the endpoint descriptors.0x08
,
/* wMaxPacketSize: 8 Bytes max */
<--- 0x09 Did you claim 9 bytes at CustomHID_Reset() ?usb_prop.c
void CustomHID_Reset(void)
{
...
...
/* Initialize Endpoint 1 */
SetEPTxCount(ENDP1, 2); // <---- SetEPTxCount(ENDP1, 9)
SetEPRxCount(ENDP1, 2); // <---- SetEPRxCount(ENDP1, 9)
usb_conf.h
/* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x104) // <----(0x10C)
Tsuneo
2012-10-10 11:59 AM
Thanks for your answer
So I changed what you said in the program but it never goes after this lineif
( bDeviceState != CONFIGURED )
continue
;
bDeviceState is equal to 3 (Suspended I think).
Can you explain why should I change the
ENDP1_RXADDR
value?
edit : Well, I don't know why but know it works perfectly! bDeviceState = configure and I can get and send data without any problems.
Thanks a lot for your help
2012-10-15 06:07 AM
just a little up, I really want to know the meaning of
ENDP1_RXADDR
.
Why should I change this? What value to set depending on the context?
Thanks
2012-10-15 08:39 PM
> So I changed what you said in the program but it never goes after this line
Maybe, hardware problem, like connection of port pins to the USB connector.> Can you explain why should I change the ENDP1_RXADDR value? ENDP1_TXADDR and ENDP1_RXADDR macro on usb_conf.h is used to assign packet buffer on USB_RAM to the endpoints. They are starting address of the endpoint buffers. To keep 9 bytes (or more) space for the EP1 TX, the start address of EP1 RX buffer was moved. Because of access limitation of 4 bytes (32bits) boundary on USB_RAM, 0x10C was chosen. This tuning is required just for STM32F102/103. Tsuneo2012-10-16 06:28 AM
Many thanks for your help, I can finally go on with my project