UM0424STUser manualSTM32USB-FS-DevicedevelopmentkitIntroductionTheSTM32USB-FS-Devicedevelopment kit isa completefirmwareand software packageincludingexamplesanddemosforall UsBtransfertypes(control,interrupt,bulkandisochronous).The aim of the STM32 USB-FS-Device development kit is to use the STM32 USB-FS-Device librarywithat leastonefirmwaredemoperUSB transfertype.Thisdocumentpresentsadescriptionof all thecomponentsof theSTM32USB-FS-Devicedevelopmentkit, including:STM32USB-FS-Devicelibrary:AllprocessesrelatedtodefaultendpointandstandardrequestsDevice firmware upgrade (DFU) demo: Control transferJoystickmousedemo:InterrupttransferCustomHID demo:Interrupt transferMassstoragedemo:Bulktransfer VirtualCOMport:InterruptandbulktransferCDC LoopBackdemo:Interrupt andbulk transferCompositeExample:InterruptandbulktransferUSBvoicespeakerdemo(USBspeaker):IsochronoustransferTable 1.ApplicableproductsTypePartnumbers orproduct categoriesSTM32F102xxandSTM32F103xxseriesMicrocontrollersSTM32 L1 Ultra Low PowerSTM32 F3 SeriesNote:Startingfrom thisrelease,STM32F105/F107arenolongersupported.Thesedevicesaresupportedby theSTM32USBOTGHostandDeviceLibrary.Formoredetails,pleaserefertousermanualUM1021.1/85December2012DocID13465Rev12www.st.com
December 2012 Doc ID 13465 Rev 12 1/85 UM0424 User manual STM32 USB-FS-Device development kit Introduction The STM32 USB-FS-Device development kit is a complete firmware and software package including examples and demos for all USB transfer types (control, interrupt, bulk and isochronous). The aim of the STM32 USB-FS-Device development kit is to use the STM32 USB-FSDevice library with at least one firmware demo per USB transfer type. This document presents a description of all the components of the STM32 USB-FS-Device development kit, including: ■ STM32 USB-FS-Device library: All processes related to default endpoint and standard requests ■ Device firmware upgrade (DFU) demo: Control transfer ■ Joystick mouse demo: Interrupt transfer ■ Custom HID demo: Interrupt transfer ■ Mass storage demo: Bulk transfer ■ Virtual COM port: Interrupt and bulk transfer ■ CDC LoopBack demo: Interrupt and bulk transfer ■ Composite Example: Interrupt and bulk transfer ■ USB voice speaker demo (USB speaker): Isochronous transfer Note: Starting from this release, STM32F105/F107 are no longer supported. These devices are supported by the STM32 USB OTG Host and Device Library. For more details, please refer to user manual UM1021. Table 1. Applicable products Type Part numbers or product categories Microcontrollers STM32F102xx and STM32F103xx series STM32 L1 Ultra Low Power STM32 F3 Series www.st.com
ContentsUM0424Contents18Relateddocuments29STM32microcontrollerfamilyoverview3.10STM32USB-FS-Devicefirmwarelibrary3.110USBapplication hierarchy3.212USB-FS_Deviceperipheral interface.123.2.1usb_reg(.h, .c)3.2.2..17usb_int (.h, .c)3.2.3usb_mem (.h,.c).173.3USB-FS-Device_Driver medium layer173.3.1.17usb init(.h,.c)3.3.2usb_core(.h,.c).173.3.3usb_sil(.h, .c)213.3.4.21usb_type.h/usb_def.h3.3.5.21platform_config.h3.421Applicationinterface3.4.1usb_conf(.h)223.4.2usb_desc (.h,.c).223.4.3.23usb_prop(.h,.c)3.4.4.24usb_endp (.c)3.4.525usb_istr(.c)3.4.625usb_pwr (.h,.c)3.5Implementinga USB-FS_Deviceapplicationusing theSTM32USB-FS-Device library253.5.1...25Implementing a no-data class-specific request3.5.2.25Howto implement adataclass-specificrequest3.5.3.26Howtomanagedatatransfers innon-controlendpoint4. 27Joystickmousedemo4.1.* 27Generaldescription4.227STM32 low-powermanagement in suspendmode4.3Remotewakeup implementation:282/85DocID13465Rev12
Contents UM0424 2/85 Doc ID 13465 Rev 12 Contents 1 Related documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2 STM32 microcontroller family overview . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 STM32 USB-FS-Device firmware library . . . . . . . . . . . . . . . . . . . . . . . . 10 3.1 USB application hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2 USB-FS_Device peripheral interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.2.1 usb_reg(.h, .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.2.2 usb_int (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.2.3 usb_mem (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.3 USB-FS-Device_Driver medium layer . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.3.1 usb_init(.h,.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.3.2 usb_core (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.3.3 usb_sil(.h, .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.3.4 usb_type.h / usb_def.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.3.5 platform_config.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.4 Application interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.4.1 usb_conf(.h) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.4.2 usb_desc (.h, .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.4.3 usb_prop (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.4.4 usb_endp (.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.4.5 usb_istr(.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.4.6 usb_pwr (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.5 Implementing a USB-FS_Device application using the STM32 USB-FSDevice library 25 3.5.1 Implementing a no-data class-specific request . . . . . . . . . . . . . . . . . . . 25 3.5.2 How to implement a data class-specific request . . . . . . . . . . . . . . . . . . 25 3.5.3 How to manage data transfers in non-control endpoint . . . . . . . . . . . . . 26 4 Joystick mouse demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.2 STM32 low-power management in suspend mode . . . . . . . . . . . . . . . . . 27 4.3 Remote wakeup implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
UM0424Contents530CustomHID demo305.1General description5.230Descriptortopology5.331CustomHIDimplementation5.3.12..31LED control5.3.2.32Push-button state report5.3.3.32ADC-converteddatatransfer6:33Massstoragedemo6.133General description6.2..33Mass storage demo overview346.3Mass storage protocol6.3.1.34Bulk-onlytransfer (BOT)6.3.2.38Smallcomputersysteminterface(ScsI)6.4Mass storage demo implementations396.4.1.39Hardwareconfiguration interface6.4.2.40Endpoint configurations and data management.416.4.3Class-specificrequests6.4.4..42Standardrequest requirements6.4.5BOTstatemachine.426.4.6SCSIprotocol implementation436.4.7Memory management.446.4.844Mediumaccessmanagement6.5Howto customize themass storagedemo467Virtual coMport demo497.149Generaldescription7.249Virtual COMportdemoproposal7.350Softwaredriverinstallation7.451Implementation..517.4.1Hardware implementation.517.4.2Firmware implementation8.53VirtualComport_Loopback8.153Generaldescription8.253Demooverview3/85DocID13465Rev12
UM0424 Contents Doc ID 13465 Rev 12 3/85 5 Custom HID demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.2 Descriptor topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.3 Custom HID implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.3.1 LED control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.3.2 Push-button state report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 5.3.3 ADC-converted data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 6 Mass storage demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6.2 Mass storage demo overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6.3 Mass storage protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.3.1 Bulk-only transfer (BOT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.3.2 Small computer system interface (SCSI) . . . . . . . . . . . . . . . . . . . . . . . . 38 6.4 Mass storage demo implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 6.4.1 Hardware configuration interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 6.4.2 Endpoint configurations and data management . . . . . . . . . . . . . . . . . . 40 6.4.3 Class-specific requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 6.4.4 Standard request requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 6.4.5 BOT state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 6.4.6 SCSI protocol implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 6.4.7 Memory management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 6.4.8 Medium access management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 6.5 How to customize the mass storage demo . . . . . . . . . . . . . . . . . . . . . . . 46 7 Virtual COM port demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 7.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 7.2 Virtual COM port demo proposal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 7.3 Software driver installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 7.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 7.4.1 Hardware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 7.4.2 Firmware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 8 VirtualComport_Loopback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 8.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 8.2 Demo overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
ContentsUM04248.354Transferring data8.3.1.54Sendingdatafromdevicetohost8.3.2...54Receivingdata fromhost to device8.454Running the demo955USBvoicespeakerdemo9.1General description559.2.55Isochronoustransferoverview9.356Audiodevice class overview9.4...57STM32USBaudiospeakerdemo9.4.1General characteristics.589.4.2Implementation.591067Device firmware upgrade10.167General description10.268DFU extension protocol10.2.1.68Introduction10.2.2.68Phases10.2.3.69Requests10.369DFUmodeselection.6910.3.1Run-time descriptor set10.3.2DFUmode descriptor set.707410.4Reconfigurationphase10.574Transferphase10.5.1.74Requests10.5.2..75Specialcommand/protocoldescriptions10.5.3DFUstatediagram.7610.5.4Downloadingand uploading.7710.5.5Manifestationphase.777810.6STM32DFUimplementation10.6.1.78Supportedmemories10.6.2.78DFUmodeentrymechanism10.6.3.78DFUfirmwarearchitecture10.6.4AvailableDFU imageforthe STM32.79.7910.6.5CreatingaDFU image4/85DocID13465Rev12
Contents UM0424 4/85 Doc ID 13465 Rev 12 8.3 Transferring data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 8.3.1 Sending data from device to host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 8.3.2 Receiving data from host to device . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 8.4 Running the demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 9 USB voice speaker demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 9.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 9.2 Isochronous transfer overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 9.3 Audio device class overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 9.4 STM32 USB audio speaker demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 9.4.1 General characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 9.4.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 10 Device firmware upgrade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 10.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 10.2 DFU extension protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 10.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 10.2.2 Phases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 10.2.3 Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 10.3 DFU mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 10.3.1 Run-time descriptor set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 10.3.2 DFU mode descriptor set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 10.4 Reconfiguration phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 10.5 Transfer phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 10.5.1 Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 10.5.2 Special command/protocol descriptions . . . . . . . . . . . . . . . . . . . . . . . . 75 10.5.3 DFU state diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 10.5.4 Downloading and uploading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 10.5.5 Manifestation phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 10.6 STM32 DFU implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 10.6.1 Supported memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 10.6.2 DFU mode entry mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 10.6.3 DFU firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 10.6.4 Available DFU image for the STM32 . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 10.6.5 Creating a DFU image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
UM0424Contents11.80Compositeexample11.1.. 80General description..8111.2Architecture11.381USBdevicedescriptor11.4..82Running the demo12...83RevisionhistoryDocID13465Rev125/85
UM0424 Contents Doc ID 13465 Rev 12 5/85 11 Composite example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 11.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 11.2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 11.3 USB device descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 11.4 Running the demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 12 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83