1 / 41

Programming Microcontrollers USB – Universal Serial Bus Autumn term 2009

Programming Microcontrollers USB – Universal Serial Bus Autumn term 2009. 64K or 96K Byte SRAM. Enter MAC. ARM966E. CORE. w/DSP. USB 2.0FS. 96 MHz. 256K or 512K Byte Burst Flash. PFQ BC. CAN 2.0B. DMA. INTR Cantle. CLK Cantle. 32K Byte Burst Flash. GPIO. OTP Memo.

elon
Download Presentation

Programming Microcontrollers USB – Universal Serial Bus Autumn term 2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Microcontrollers USB – Universal Serial Bus Autumn term 2009 64K or 96K Byte SRAM Enter MAC ARM966E CORE w/DSP USB 2.0FS 96 MHz 256K or 512K Byte Burst Flash PFQ BC CAN 2.0B DMA INTR Cantle CLK Cantle 32K Byte Burst Flash GPIO OTP Memo LVD BOD EXT. Bus JTAG ETM9 PLL RTC TIM ADC SPI I2C UART USB - Universal Serial Bus STR912FAW44

  2. The USB Implements Forum (USB IF) has been founded in 1995 The first standard (USB 1.0) has been specified a year later USB was planned to connect different peripheral devices to a universal interface Mouse, keyboard, printer etc. The USB 2.0 standard follows in 2000 Speed has been enhanced to 480 MBit/s This enables to connect also hard discs, video cameras etc. History USB - Universal Serial Bus

  3. USB is a asymmetrical bus We distinguish between Host (PC) and Device (also called function) The type of transmission is asynchronous serial bit The transmitted speed are 1.5MBit/s (Low-Speed) 12MBit/s (Full-Speed) 480MBit/s (High-Speed, only for USB 2.0) Since USB 2.0, it is also possible to connect the devices between them OTG (On-The-Go) Generality USB - Universal Serial Bus

  4. USB Topology USB - Universal Serial Bus • 127 devices can be connected to the USB bus (incl. Hubs) • Each device receive a unique address from the Host (PC)

  5. Bus-Powered Hubs Supply voltage is furnished by the host/hub The total power consumption of the connected devices must be < 500 mA Self-Powered-Hubs Supply voltage is furnished separately Each device can consume 500 mA USB Power supply USB - Universal Serial Bus

  6. The USB cable contains 4 lines VCC (+5V) GND D+ and D- (0 and 3.3 V), which work in a differential mode Difference bigger than +200 mV represents a logic 1 Difference smaller than -200 mV represents a logic 0 Electrical Interface USB - Universal Serial Bus

  7. USB connectors USB - Universal Serial Bus

  8. The Host/Hub must recognize the devices that are connected to its outputs The Host/Hub begins therefore with the speed investigation Pull up or pull down resistors Connection & speed investigation USB - Universal Serial Bus

  9. SOP (Start-of-Packet) The transition from the “idle” in to the “K” state This change is the first bit of the SYNC field EOP (End-of-Packet) The “SE0” state is kept during 2 cycles followed by the “Idle” state Bus states (1) USB - Universal Serial Bus

  10. Bus Reset SE0 is activated during 2.5 ms Suspend A USB device must enter in to a sleep mode to save energy If there is no activity on the USB bus during 3 ms The High-Speed devices go in to the Full-Speed modes after 3 ms After 100 to 875 µs they go in to the suspend state Resume A suspended device must be wake up with a resume sequence Data lines must be set in to the “K” state during 20 ms followed by a SOF sequence Bus states (2) USB - Universal Serial Bus

  11. State Diagram USB - Universal Serial Bus

  12. The transmission begins with the LSB (Least Significant Bit) The transmitted bits are coded in to NRZI Non-Return-To-Zero-Inverted Data coding USB - Universal Serial Bus

  13. The USB is a polled bus (nobody speaks if not asked. No interrupts) The Host controller initiates all data transfers Transaction type and direction USB address Endpoint (token package) USB protocol USB - Universal Serial Bus

  14. USB Communication flow USB - Universal Serial Bus

  15. Control Transfer The Control transfer enables to configure the Device The Host sends the requests to the Device 10% of the band width is used for this kind of transfer Interrupt Transfer Transfer of a few amount of data, which must be send periodically Mouse, keyboards etc. The Host polls the Endpoints Period is defined in the Endpoint 90% of the Bandwidth is reserved for Interrupt and Isochronous Transfers Transfer type (1) USB - Universal Serial Bus

  16. Bulk Transfer Transfer of great amounts of data, which is not time critical Printers, scanner and memory sticks Transfer are realized with the remaining Bandwidth Isochronous Transfer 90% of the Bandwidth is reserved for Interrupt and Isochronous Transfers The data are transferred one time per frame of 1 ms Transfer type (2) USB - Universal Serial Bus

  17. The data are transmitted within packages Token-Packets SOP Setup IN & OUT Data-Packets Handshake-Packets Special-Packets Data Package USB - Universal Serial Bus

  18. SYNC Each package begins with the SYNC field Synchronization of the Device PLL with the Host one PID The second field is the PID (Packet-Identifier) one The 4 first bits are the complement of the 4 last ones The next fields depend on the package types The CRC (Cyclic Redundancy Check) is often the next-to-last field The EOP is the last field Structure of the packages USB - Universal Serial Bus

  19. SOF (Token-Packet) USB - Universal Serial Bus • Host / Hub sends a SOF every ms (Start-of-Frame) • To avoid that the Device enter into the Suspend mode • Low-Speed • Full-Speed • Frame # : 11-Bit frame number, which is systematically incremented

  20. Setup (Token-Packet) USB - Universal Serial Bus • The Host announces the sending of setup data with this Package • ADDR: 7-Bit Device-Address • ENDP: 4-Bit Endpoint Number

  21. IN & OUT (Token-Packet) USB - Universal Serial Bus • IN: Le Host ask the Device to send him Data • The Device will then send a Data to the Host. • OUT: The Host tells to the Device, that he will send Data to him • The Host will then send a Data to the Device

  22. DATA0 / DATA1 (Data-Packet) USB - Universal Serial Bus • The package DATA0 and DATA1 contain the data to transmit • DATA0 and DATA1 are send alternatively for synchronization purposes • 0..8 Bytes for Low Speed • 0..1023 Bytes for Full Speed • 0..1024 Bytes for High Speed • DATA0 • DATA1

  23. Handshake-Packets USB - Universal Serial Bus • ACK • Confirmation that the package Data has been received without errors • NAK is only send by the device • The package Data could not be treated (OUT) • There are no data to send (IN) • STALL is only send by the device • The device is not activated

  24. The Data transmission is realized during 3 phases The host sends a token package to the device (phase 1) Either the host or the device sends the data (phase 2) The successful reception is confirmed either by the Host or by the Device with a handshake (phase 3) Data transmission USB - Universal Serial Bus

  25. Output transmission example (1) USB - Universal Serial Bus • Transmission without errors • Address: 0x123 • Endpoint: 1 • Data: 0x00, 0x11, 0x22, 0x33 OUT OUT IN

  26. Output transmission example (2) USB - Universal Serial Bus • The FIFO is full • Address: 0x123 • Endpoint: 1 • Data: 0x00, 0x11, 0x22, 0x33 OUT OUT IN

  27. Output transmission example (3) USB - Universal Serial Bus • The USB device is not activated • Address: 0x123 • Endpoint: 1 • Data: 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 OUT OUT IN

  28. Input transmission example (1) USB - Universal Serial Bus • Transmission without errors • Address: 0x123 • Endpoint: 2 • Data: 0x00, 0x11, 0x22, 0x33 OUT IN IN

  29. Input transmission example (2) USB - Universal Serial Bus • The FIFO is full • Address: 0x123 • Endpoint: 2 OUT IN

  30. Input transmission example (3) USB - Universal Serial Bus • The USB device is not activated • Address: 0x123 • Endpoint: 2 OUT IN

  31. USB Device Framework define how to communicate at the driver layer A firmware programmer will be interested basically at this layer USB Device Framework (OSI Layer 7) USB - Universal Serial Bus

  32. The Host sends a “USB Device Request” to the Devices to start an action Endpoint 0 Structure of a Request USB Device Request USB - Universal Serial Bus

  33. Standard Device Requests USB - Universal Serial Bus

  34. Descriptors are predefined structures, which enable to exchange attributes between the host and the device Type of descriptors Standard descriptors Specific descriptors Class or Vendor The descriptors are asked from the Host through the Standard Device Request “GET_DESCRIPTOR” The first Byte contains the size of the descriptor The second the type of the descriptor The standard descriptors describes the standard function and the properties of the USB Device Descriptors USB - Universal Serial Bus

  35. Hierarchy of the Standard descriptors USB - Universal Serial Bus

  36. Device Descriptor Class of the Device The supported standard (USB 1.1 or 2.0) The manufacture A list of the Device Configurations Configuration Descriptor Class of the Device A list of the Configuration Interfaces A list of the Endpoints Interface Descriptor Class of the Device A list of the Endpoints Type of standard descriptors (1) USB - Universal Serial Bus

  37. Endpoint Descriptor Endpoint properties Endpoint number Endpoint direction (IN or OUT) Transfer type Bulk, Interrupt or Isochronous String Descriptor Text description of the Device Class of Vendor-Specific Descriptors Descriptor that are specific to the Device classes Type of standard descriptors (2) USB - Universal Serial Bus

  38. The OS must install the drivers for the new connected Device This task is called Enumeration and it is executed in Windows as follow Host tells Windows that a new Device has been connected Windows calls the Device descriptor of the Device with the temporary address 0 A new address is attributed to the Device The Device descriptor is called for a second time The Configuration descriptor is called without the Interface & Endpoint descriptors The complete Configuration descriptor is called Windows search the corresponding drivers and install them Window configure the Device Enumeration USB - Universal Serial Bus

  39. Example for an application (1) USB - Universal Serial Bus Device Descriptor bLength 0x12 The Descriptor has a length of 18 bytes bDescriptorType 0x01 Device Descriptor bcdUSB 0x0200 USB Specification Number in BCD (2.00) bDeviceClass 0x00 Class is defined in the Interface-Descriptor bDeviceSubClass 0x00 Sub-Class is defined in the Interface-Descriptor bDeviceProtocol 0x00 Protocol is defined in the Interface-Descriptor bMaxPacketSize0 0x40 Size of Endpoint 0: 64 bytes idVendor 0x054C Vendor ID 0x054c (Sony Corporation) idProduct 0x0243 Product ID 0x0243 bcdDevice 0x0100 Device release Number in BCD (1.00) iManufacturer 0x01 iProduct 0x02 iSerialNumber 0x03 bNumConfigurations 0x01 1 configuration

  40. Example for an application (2) USB - Universal Serial Bus Configuration Descriptor bLength 0x09The Descriptor has a length of 9 bytes bDescriptorType 0x02Configuration Descriptor wTotalLength 0x0020 Total size of the Configuration-, Interface-, Endpoint- Descriptors bNumInterfaces 0x01 contains 1 interface bConfigurationValue 0x01 this is configuration 1 iConfiguration 0x00 no string descriptor bmAttributes 0x80 Bus Powered bMaxPower 0x32 50 x 2 mA = 100 mA Interface Descriptor bLength 0x09The Descriptor has a length of 9 bytes bDescriptorType 0x04Interface Descriptor bInterfaceNumber 0x00 this is interface 0 from configuration 1 bAlternateSetting 0x00 no alternate setting bNumEndpoints 0x02 2 Endpoints (1 Bulk-IN, 1 Bulk-OUT) bInterfaceClass 0x08 Mass Storage Device Class bInterfaceSubClass 0x06 SCSI transparent command set bInterfaceProtocol 0x50 Bulk-Only Transport iInterface 0x00 no string descriptor

  41. Example for an application (3) USB - Universal Serial Bus Endpoint Descriptor 1 bLength 0x07The Desc. has a length of 7 bytes bDescriptorType 0x05Endpoint Descriptor bEndpointAddress 0x81 Address 0x81, IN-Endpoint Transfer Type 0x02 Bulk Endpoint wMaxPacketSize 0x0200 FIFO-Size 512 Bytes bInterval 0xFF not used for Bulk endpoints Endpoint Descriptor 2 bLength 0x07The Desc. has a length of 7 bytes bDescriptorType 0x05Endpoint Descriptor bEndpointAddress 0x02Address 0x02, OUT-Endpoint Transfer Type 0x02 Bulk Endpoint wMaxPacketSize 0x0200 FIFO-Size 512 Bytes bInterval 0xFF not used for Bulk endpoints

More Related