Examples

Examples are in the examples folder. You will find:

You might also want to have a look at the testsuite for a more complex example involving multiple configurations.

Writing descriptors

When writing descriptors it is highly recomended to enable endpoint validation and trace mode in usb_config.h.

How to detect when the USB cable is disconnected

Example trace mode printout for device enumeration

++DEV Device RESET
++DEV Suspend request
++DEV Resume request
++DEV Device RESET
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=256 wIndex=0 wLength=64 }
++IN endpoint 0 buffer filled with 18 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
++DEV Device RESET
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x0 bRequest=5 wValue=47 wIndex=0 wLength=0 }
+ EP0 IN irq
++DEV New device state=ADDRESS
+ DEV Host assigned adress 47
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=256 wIndex=0 wLength=18 }
++IN endpoint 0 buffer filled with 18 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=1536 wIndex=0 wLength=10 }
EP0 Unsupported descriptor
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=1536 wIndex=0 wLength=10 }
EP0 Unsupported descriptor
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=1536 wIndex=0 wLength=10 }
EP0 Unsupported descriptor
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=512 wIndex=0 wLength=9 }
++IN endpoint 0 buffer filled with 9 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=512 wIndex=0 wLength=9 }
++IN endpoint 0 buffer filled with 9 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=768 wIndex=0 wLength=255 }
++IN endpoint 0 buffer filled with 4 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=770 wIndex=1033 wLength=255 }
++IN endpoint 0 buffer filled with 14 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=769 wIndex=1033 wLength=255 }
++IN endpoint 0 buffer filled with 18 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x80 bRequest=6 wValue=771 wIndex=1033 wLength=255 }
++IN endpoint 0 buffer filled with 4 bytes
+ EP0 IN irq
+ EP0 OUT irq
+ EP0 IN transaction completed
+ EP0 SETUP irq
++EP0 Setup={ bmRequestType=0x0 bRequest=9 wValue=1 wIndex=0 wLength=0 }
++DEV New device state=CONFIGURED
+ EP0 IN irq
+ EP0 OUT transaction completed