Skip to main content
contact239955_stm1_st
Associate II
October 9, 2012
Question

Customizing Custom HID descriptor

  • October 9, 2012
  • 5 replies
  • 1339 views
Posted on October 10, 2012 at 00:12

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

http://pastebin.com/Wxyc8Dkp

(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?

Thanks

    This topic has been closed for replies.

    5 replies

    tsuneo
    Associate II
    October 10, 2012
    Posted on October 10, 2012 at 17:46

    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
    contact239955_stm1_st
    Associate II
    October 10, 2012
    Posted on October 10, 2012 at 20:59

    Thanks for your answer

    So I changed what you said in the program but it never goes after this line

    if
    ( 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
    contact239955_stm1_st
    Associate II
    October 15, 2012
    Posted on October 15, 2012 at 15:07

    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
    tsuneo
    Associate II
    October 16, 2012
    Posted on October 16, 2012 at 05:39

    > 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.

    Tsuneo

    contact239955_stm1_st
    Associate II
    October 16, 2012
    Posted on October 16, 2012 at 15:28

    Many thanks for your help, I can finally go on with my project