STM32F103 LibUsb

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
goahunter
Posts: 29
Joined: Thu Aug 16, 2012 10:59 pm

Re: STM32F103 LibUsb

Post 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.
Mathias
Posts: 43
Joined: Thu Jun 28, 2012 6:19 pm

Re: STM32F103 LibUsb

Post 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?
goahunter
Posts: 29
Joined: Thu Aug 16, 2012 10:59 pm

Re: STM32F103 LibUsb

Post 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.
goahunter
Posts: 29
Joined: Thu Aug 16, 2012 10:59 pm

Re: STM32F103 LibUsb

Post 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'?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F103 LibUsb

Post by Giovanni »

Not enough code to see, is the callback actually invoked or it is just the character that is not matched?
goahunter
Posts: 29
Joined: Thu Aug 16, 2012 10:59 pm

Re: STM32F103 LibUsb

Post 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
   }
goahunter
Posts: 29
Joined: Thu Aug 16, 2012 10:59 pm

Re: STM32F103 LibUsb

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F103 LibUsb

Post by Giovanni »

Is that a "one" or a "letter L"? alternatively a stack corruption by overflow or a compiler bug.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F103 LibUsb

Post by Giovanni »

Another question, do received packets have a size of at least 1?
goahunter
Posts: 29
Joined: Thu Aug 16, 2012 10:59 pm

Re: STM32F103 LibUsb

Post by goahunter »

It is a numeric 1 and not L.
packetsniffer.png
packetsniffer.png (103.54 KiB) Viewed 7184 times

usbprogram.png
usbprogram.png (22.8 KiB) Viewed 7184 times
Post Reply