Page 2 of 3

Re: STM32F103 LibUsb

Posted: Mon Aug 20, 2012 11:12 pm
by goahunter
So i modified the line from bulk transfer to packet transfer and everything seems to work flawlessly. On to autobinding winusb to the stm32.

Re: STM32F103 LibUsb

Posted: Tue Aug 21, 2012 1:09 pm
by Mathias
I'm not sure what line you changed and what works now, but did you install the libUSBx driver for the device? Like described here?

Re: STM32F103 LibUsb

Posted: Tue Aug 21, 2012 3:05 pm
by goahunter
I Changed

Code: Select all

/**
 * @brief   EP1 initialization structure (IN only).
 */
static const USBEndpointConfig ep1config = {
  USB_EP_MODE_PACKET,    //Type and mode of the endpoint


to USB_EP_MODE_PACKET from USB_EP_MODE_TYPE_BULK

I am using Zadig for driver installation, as of right now but my ultimate goal is to autobind the driver so that i do not have to use zadig.

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 5:38 pm
by goahunter
So just a bump on this thread. Having some troubles with the usb receive callback. Currently I have a C# program that is used for basic communication and I'm sending a packet to the stm32, for example I may send the packet 0x31 to the receiveBuf[0] position. Using a packet sniffer I can see that the packet is indeed being sent and is 0x31 (ascii character 1) and if I use the following code:

Code: Select all

   void dataReceived(USBDriver *usbp, usbep_t ep){
       (void) usbp;
       (void) ep;

        switch(receiveBuf[0]){
            case 'V':
                palTogglePad(GPIOD, 4);
                break;
            case '1':
                palTogglePad(GPIOD, 4);
                break;
            case '3':
                palTogglePad(GPIOD, 4);
                break;
            case '4':
                palTogglePad(GPIOD, 4);
                break;
            default:
      palTogglePad(GPIOD, 5);
      break;
       }


the default case is triggered instead of case '1'.
Been pounding my head on the keyboard for two days now. Any ideas why the receiveBuf is not matching case '1'?

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 6:54 pm
by Giovanni
Not enough code to see, is the callback actually invoked or it is just the character that is not matched?

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 7:35 pm
by goahunter
I'll show the whole data received code.

Code: Select all

/* IN EP1 state */
   static USBInEndpointState ep1instate;

/* EP1 initialization structure (IN only) */
   static const USBEndpointConfig ep1config = {
     USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET,    //Type and mode of the endpoint
     NULL,                     //Setup packet notification callback (NULL for non-control EPs)
     dataTransmitted,          //IN endpoint notification callback
     NULL,                     //OUT endpoint notification callback
     IN_PACKETSIZE,            //IN endpoint maximum packet size
     0x0000,                   //OUT endpoint maximum packet size
     &ep1instate,              //USBEndpointState associated to the IN endpoint
     NULL                      //USBEndpointState associated to the OUTendpoint
   };

/*
 * Data Received Callback
 * it writes the received Data to the output buffer
 * to have an echo effect
 */
   void dataReceived(USBDriver *usbp, usbep_t ep){
       (void) usbp;
       (void) ep;

        switch(receiveBuf[0]){
            case 'V':
                palTogglePad(GPIOD, 4);
                break;
            case '1':
                palTogglePad(GPIOD, 4);
                break;
            case '3':
                palTogglePad(GPIOD, 4);
                break;
            case '4':
                palTogglePad(GPIOD, 4);
                break;
          default:
            palTogglePad(GPIOD, 5);
            break;
       }

      /* Initiate next receive */
       usbPrepareReceive(usbp, EP_OUT, receiveBuf, 64);
       chSysLockFromIsr();
       usbStartReceiveI(usbp, EP_OUT);
       chSysUnlockFromIsr();
   }

/* OUT EP2 state */
   USBOutEndpointState ep2outstate;

/*
 * @brief   EP2 initialization structure (OUT only).
 */
   static const USBEndpointConfig ep2config = {
     USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET,
     NULL,
     NULL,
     dataReceived,
     0x0000,
     OUT_PACKETSIZE,
     NULL,
     &ep2outstate
   }

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 7:36 pm
by goahunter
The call back is being invoked. It appears that the character isn't being matched. When any data is sent is goes to the default and bypasses all other cases as if the character doesn't match. The default case does toggle.

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 7:39 pm
by Giovanni
Is that a "one" or a "letter L"? alternatively a stack corruption by overflow or a compiler bug.

Giovanni

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 7:41 pm
by Giovanni
Another question, do received packets have a size of at least 1?

Re: STM32F103 LibUsb

Posted: Fri Sep 07, 2012 7:59 pm
by goahunter
It is a numeric 1 and not L.
packetsniffer.png
packetsniffer.png (103.54 KiB) Viewed 7187 times

usbprogram.png
usbprogram.png (22.8 KiB) Viewed 7187 times