The USB topic

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

Re: The USB topic

Post by Giovanni »

Hi,

Probably the operation will be embedded in usbConnect() and usbDisconnect(), is a separate API really required?

Giovanni
gniibe
Posts: 14
Joined: Tue Jan 18, 2011 1:13 am

Re: The USB topic

Post by gniibe »

I observe stall of USB CDC output for my NeuG application. I am using trunk.

I think that SERIAL_USB_BUFFERS_SIZE in chibios/os/hal/include/serial_usb.h
should be 63, if we use USB_EP_MODE_PACKET for the endpoint.

When host receive 64-byte DATA0/DATA1, it expects more packet(s).
If size is 64-byte, device should send 0-sized DATA0/DATA1 to finish transaction.

That's my thought. Any comments will be appreciated.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: The USB topic

Post by Giovanni »

It is possible you are right, I have to read the specification more carefully.

Giovanni
linvinus
Posts: 19
Joined: Mon Sep 19, 2011 9:09 am

Re: USB enable connection API

Post by linvinus »

gniibe wrote:Hello,

Thanks a lot for USB driver. This is a feedback from a user.

I think that it would be better to provide a API to enable USB connection.

In STM32 example, there is a line like:

Code: Select all

     palClearPad(GPIOC, GPIOC_USB_DISC);

but, in case of my board (STBee Mini), it's GPIOA which controls USB line.

Some abstraction is needed.
--

For USB 1.1 and USB 2.0 full speed device.
In general to inform host about new device, we should shutdown usb line D+ for 500ms and then release.
Some boards have separate transistor, which control pull-up resistor on line D+.
But same job can be done without that transistor, only by the controller .
For example:

Code: Select all

  //first reset USB D+
  palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_OUTPUT_PUSHPULL);
  palClearPad(GPIOA, GPIOA_USBDP);
  chThdSleepMilliseconds(500);
  palSetPad(GPIOA, GPIOA_USBDP);
  palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_INPUT);

  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);

it working for me.

So, driver should have call back function, through which user can configure what to do.
Or, maybe, just a driver property, which IO-line controls D+, and property state - "normal on" or "normal off".


Also, probably, driver should know when host is available, usual through usb power line, so it should have property what io-line to sniff for that.
gniibe
Posts: 14
Joined: Tue Jan 18, 2011 1:13 am

Re: The USB topic

Post by gniibe »

For ZLP (zero length packet) and CDC, here is a reference:
http://www.microchip.com/forums/m325655-print.aspx

Just for your information, I needed ZLP for USB CCID/ICCD function too (my application Gnuk).

For control transfer, it is clearly described in the spec (I'm reading the section 8.5.3.2 of the USB 2.0 specification).
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: The USB topic

Post by Giovanni »

Thanks,

I will soon start a revision of the USB driver, the API will probably change a bit because there are some things I don't like (like copying buffers while interrupts are disabled).

Possible changes:
- API revision.
- Correct handling of the zero packet.
- Handling the pull-up from inside the driver.
- Support for double buffering.
- Investigate if it is possible to use a DMA to copy buffers.
- Other?

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

Re: The USB topic

Post by Giovanni »

Hi,

A small update about this.

I implemented the following points (in the repository):
- API revision.
- Handling the pull-up from inside the driver.
- Investigate if it is possible to use a DMA to copy buffers (yes it should be possible using the DMA driver copy function, not tested it yet).

In addition I also fixed several problems in USB and SERIAL_USB drivers.

I am still working on the other open points.

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

Re: The USB topic

Post by Giovanni »

gniibe wrote:For ZLP (zero length packet) and CDC, here is a reference:
http://www.microchip.com/forums/m325655-print.aspx

Just for your information, I needed ZLP for USB CCID/ICCD function too (my application Gnuk).

For control transfer, it is clearly described in the spec (I'm reading the section 8.5.3.2 of the USB 2.0 specification).


Hi,

After reading this discussion I think that probably the zero sized packet is not needed in a CDC application. This is my reasoning:

1) If the packet size is equal to the maximum size then the host processes the packet and assumes that there is more data incoming so it waits for more data (within the same bulk transaction).
2) If the packet size is *not* equal to the maximum size then the host processes the packet and... then waits for more data anyway (by starting another bulk transaction).

This behavior should be compatible with the specification you mentioned.

Am I missing something?

Giovanni
Xamusk
Posts: 81
Joined: Sat Mar 05, 2011 10:47 pm

Re: The USB topic

Post by Xamusk »

Is it possible to use two virtual serial ports through USB? It would be great to have a "data" port and a "debug" or shell port.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: The USB topic

Post by Giovanni »

I never tryed it but it should be possible, it is just matter of defining the correct descriptors and allocate another endpoint (devil is in details of course).

Giovanni
Post Reply