Home

STM32 USB-FS-Device development kit

image

Contents

1. 37 Hardware and firmware interaction diagram 39 Medium access layer 45 NAND write operation 45 Virtual COM port demo as USB to USART bridge 49 Communication example 50 Device manager window 50 VirtualComport Loopback application overview 53 Window HyperTerminal message display 54 Isochronous OUT transfer 56 STM32 USB FS Device audio speaker demo data flow 57 Audio playback flow seraa adi eeri enei e a 58 Hardware and firmware interaction diagram 60 Interface state transition diagram 76 DFU firmware architecture 79 USB composite device with two interface functions 80 HID MSC composite architecture 81 USB device descriptor 81 STM32 device enumerated as composite 82 Doc ID 13465 Rev 12 7 85
2. UMO424 Custom HID demo Figure 4 Custom HID topology Device descriptor Configuration descriptor Interface descriptor Endpoint 1 OUT Endpoint 1 IN HID descriptor descriptor descriptor Report descriptors 7 ai15156 Each report descriptor is related to a specific component in the evaluation board LEDs Push buttons or ADC The following section describes the functionality of these reports 5 3 Custom HID implementation 5 3 1 LED control The STM32 evaluation boards have four LEDs In the custom HID demo each LED corresponds to a specific report reports 1 to 4 and the LED states ON OFF are set by the PC applet Reports generated by the host to the device are transmitted through either the interrupt OUT endpoint or the default endpoint Control using the Set_Report request In the PC applet the output mode is set by default to SET_REPORT and interrupt transfer is applied When the device receives data on endpoint 1 OUT the EP1 OUT Callback function is called to dispatch the received state to the corresponding LED according to the report number When switching to the SET FEATURE mode control transfer is applied The CustomHID_SetReport_Feature function is called and the host initiates a control endpoint transfer which causes IN and OUT reports to be sent and received Report Buf contains both the report and the number of bytes to transmit The data received has the format shown i
3. 12 Common register functions 12 USB FS Device Driver medium layer modules 17 Power management functions 25 Eval board power consumption related jumpers 28 Key push button assignment 28 Eval board memory support 34 CBW packet fields 35 CSW packet fields 36 Command block status values 36 SCSI command set 38 Device descriptor 46 Configuration descriptor 47 Interface descriptors 47 Endpoint descriptors 48 USART connector number for each evaluation board 51 Device descriptors eoru dan Sue NN ieee PARRA RR ares hehe 62 Configuration descriptors 62 Interface descriptors 62 Endpoint descriptors
4. 65 Flash memory used by DFU o oocccccccc teens 67 Summary of DFU class specific requests 69 DFU mode device descriptor 70 DFU mode interface descriptor 71 DFU functional descriptor 73 Summary of DFU upgrade upload requests 74 Special command descriptions 75 Document revision history 83 Doc ID 13465 Rev 12 UMO424 List of figures List of figures Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 Figure 7 Figure 8 Figure 9 Figure 10 Figure 11 Figure 12 Figure 13 Figure 14 Figure 15 Figure 16 Figure 17 Figure 18 Figure 19 Figure 20 Figure 21 Figure 22 Figure 23 Figure 24 Figure 25 Figure 26 USB application hierarchy 2 10 USB FS Device library package organization 11 Format of the four data bytes 27 Custom HID topology isse mm mmm da ae Run nu RR a ae 31 Data OUT format ud ap puo doe RR ds is ia ame ALAGA 32 Data IN Format el rn 32 New removable disk in Windows 33 BOT state machine
5. 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 2 85 Doc ID 13465 Rev 12 UM0424 Contents 5 Custom HID demo 22 re eens eee te sete rete Pen ee E 30 5 1 General description 30 5 2 Descriptor topology a ta GRE tee 30 5 3 Custom HID implementation 31 5 3 1 LED CONTON 22 siete ogame deste ve ae tete 2 a ala EE 31 5 3 2 Push button state report 32 5 3 3 ADC converted data transfer 32 6 Mass storage demo 0 0 00 ene ee RR RI 33 6 1 General description 33 6 2 Mass storage demo overview 33 6 3 Mass storage protocol i et opum RE tee ARE 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
6. Interrupt Interrupt IN OUT EP1 EP1 Device MSv31510V1 USB device descriptor bNuminterfaces tells the host how many interfaces the device uses An interface is a point of contact where the host and the device exchange data This demo uses two interfaces in all Figure 25 shows how the USB descriptor was changed in the project to add another MSC interface Figure 25 USB device descriptor ft All Descriptors Configuration Interface Endpoint Class Vendor const uint8 t Composite ConfigDescriptor Composite SIZ CONFIG DESC A ee 0x09 bLength Configuration Descriptor size USB CONFIGURATION DESCRIPTOR TYPE bDescriptorType Configuration Composite SIZ CONFIG DESC wTotalLength Bytes returned 0x00 x01 bConfigurationValue Configuration value 0x00 iConfiguration Index of string descriptor describing the configuration OxCO bmAttributes Self powered Dx 32 MaxPower 100 mA this current is used for detecting Vbus MSv31511V1 Doc ID 13465 Rev 12 81 85 Composite example UMO424 Note 82 85 After modifying the number of interfaces the interface s descriptor of a Mass Storage application is added When even one of the device s interface classes is changed Windows should handle it differently However Windows doesn t recognize the modification To avoid conflict on Windows assign another VID PID to the device idProduct 0x5750
7. 40 6 4 3 Class specific requests 41 6 4 4 Standard request requirements 42 6 4 5 BOT state machine pansi rer cee eee ER m 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 d mo iii AAA 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 o ne ae CR gw PT 53 Doc ID 13465 Rev 12 3 85 Contents UMO424 8 3 Transfering Gala csa gines Samer ed Maley e po O Bee 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 deri it A hee Bad Be 54 9 USB voice speaker demo
8. UMO424 STM32 USB FS Device firmware library 3 4 5 usb_istr c USB_istr module provides a function named USB_Istr which handles all USB interrupts For each USB interrupt source a callback routine named XXX Callback for example RESET Callback is provided in order to implement a user interrupt handler To enable the processing of each callback routines a preprocessor switch named XXX Callback must be defined in the USB configuration file USB_conf h 3 4 6 usb_pwr h c This module manages the power management of the USB device It provides the functions shown in Table 8 Table 8 Power management functions Function name Description RESULT Power_on void Handle switch on conditions RESULT Power off void Handle switch off conditions void Suspend void Sets suspend mode operation conditions void Resume RESUME STATE eResumeSetVal Handle wakeup operations 3 5 Implementing a USB FS Device application using the STM32 USB FS Device library 3 5 1 Implementing a no data class specific request All class specific requests without a data transfer phase implement the field RESULT Class NoData Setup uint8 t RequestNo ofthe structure device property The USBbRequest of the request is available in the RequestNo parameter and all other request fields are stored in the device info structure The user has to test all request fields If the request is compliant with the class to implement the function returns the USB SUCCESS result How
9. Define the interrupts to enable them through the interrupt mask IMR_MSK usb desc h c The usb desc c file should contain all the USB descriptors related to the application The user has to set these descriptors according to the application proprieties and class In all available demos in the STM32 USB FS Device developer kit there is an example implementing a unique serial number string descriptor based on the STM32 Device Unique ID register 12 digits The default value of the serial number string descriptor is STM32 and during the USB initialization the Get SerialNum function reads the Device Unique ID register and sets the serial number string descriptor For more details regarding the Device Unique ID register please refer to Table 4 Doc ID 13465 Rev 12 ky UM0424 STM32 USB FS Device firmware library 3 4 3 usb prop h c The usb prop module is used for implementing the Device Property Device Table and USER STANDARD REQUEST structures used by the USB core Device property implementation The device property structure fields are described below void Init void Init procedure of the USB FS Device peripheral It is called once at the start of the application to manage the initialization process void Reset void Reset procedure of the USB peripheral It is called when the macrocell receives a RESET signal from the bus The user program should set up the endpoints in this procedure in
10. define EP BULK 0x0000 Endpoint BULK define EP CONTROL 0x0200 Endpoint CONTROL define EP ISOCHRNOUS 0x0400 Endpoint ISOCHRONOUS define EP INTERRUPT 0x0600 Endpoint INTERRUPT SetEPType void SetEPType uint8 t bEpNum uint16 t wtype bEpNum Endpoint number wtype Endpoint type value from the above define s GetEPType uint16 t GetEPType uint8 t bEpNum bEpNum Endpoint number return value a value from the above define s c Endpoint STATUS field The STAT TX STAT RX fields of the endpoint register can assume the defined values below define EP TX DIS 0x0000 Endpoint TX DISabled define EP TX STALL 0x0010 Endpoint TX STALLed define EP TX NAK 0x0020 Endpoint TX NAKed define EP TX VALID 0x0030 Endpoint TX VALID define EP RX DIS 0x0000 Endpoint RX DISabled define EP RX STALL 0x1000 Endpoint RX STALLed define EP RX NAK 0x2000 Endpoint RX NAKed define EP RX VALID 0x3000 Endpoint RX VALID SetEPTxStatus void SetEPTxStatus uint8 t bEpNum uint16 t wState SetEPRxStatus void SetEPRxStatus uint8 t bEpNum uintl16 t wState bEpNum Endpoint number wState a value from the above define s GetEPTxStatus uint16 t GetEPTxStatus uint8 t bEpNum GetEPRxStatus uint16 t GetEPRxStatus uint8 t bEpNum bEpNum endpoint number return value a value from the above define s
11. 55 9 1 General description 55 9 2 Isochronous transfer overview 2 55 9 3 Audio device class overview 42 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 4 Introduction eerta noce em nana eae Reg 68 10 2 2 Phases yaang ENTE DAGAN a he xw haat ta arte X punta 68 10 23 Requests uuo Na ans te Dep a BAGS durite i 69 102 IDEFUMOde selection cs i Vener SP RR EP Roo RE ORC Rod 69 10 3 4 Run time descriptor set 69 10 3 2 DFU mode descriptor set 70 10 4 Reconfiguration phase Ro ka tex de cora bor ea Re 74 10 5 Transfer phase 74 10 54 Requests it AMEL Ne heat e dob ee oe EN 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
12. Virtual COM port demo UMO424 Note 52 85 Hardware configuration interface The hardware configuration interface hw_config c and h in the Virtual COM port manages the following routines Configure the system and peripheral USB amp USART clock and interrupts Initialize the USART to default values Configure the USART with the parameters received by the SET_LINE_CODING request Send the data received by the USART to the PC through USB Send the data received by the USB through USART For the STM32 the supported data formats are 7 8 bits in the HyperTerminal and the bandwidth range is from 1200 to 115200 Doc ID 13465 Rev 12 ky UM0424 VirtualComport Loopback 8 8 1 8 2 VirtualComport Loopback This demo runs on the following STMicroelectronics evaluation boards and can be easily tailored to any other hardware e STM3210B EVAL STM3210E EVAL STM32L152 EVAL STM32373C EVAL STM32303C EVAL STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description The purpose of this example is to send and receive data over USB using the CDC protocol The USB Device VCP Example is used for this For further details on this demo please refer to Chapter 7 Virtual COM port demo In this example NO serial cable connector is needed and you can see the data transferred to and from USB This exam
13. 66 85 Table 24 Endpoint descriptors continued Field Value Description bLockDelayUnits 0x00 Unused wLockDelay 0x0000 Unused Doc ID 13465 Rev 12 UM0424 Device firmware upgrade 10 10 1 Device firmware upgrade This demo runs on the following STMicroelectronics evaluation boards and can be easily tailored to any other hardware e STM3210B EVAL STM3210E EVAL STM32L152 EVAL STM32373C EVAL STM32303C EVAL STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description This part of the document presents the implementation of a device firmware upgrade DFU capability in the STM32 microcontroller It follows the DFU class specification defined by the USB Implementers Forum for reprogramming an application through USB The DFU principle is particularly well suited to USB applications that need to be reprogrammed in the field The same USB connector can be used for both the standard operating mode and the reprogramming process This operation is made possible by the IAP capability featured by most of the STMicroelectronics USB Flash microcontrollers which allows a Flash MCU to be reprogrammed by any communication channel The DFU process like any other IAP process is based on the execution of firmware located in one small part of the Flash memory and that manages the erase and p
14. Table 28 DFU mode interface descriptor Offset Field Size Value Description 0 bLength 1 0x09 Size of this descriptor in bytes 1 bDescriptorType 1 0x04 INTERFACE descriptor type 2 bInterfaceNumber 1 0x00 Number of this interface 3 bAlternateSetting 1 Number Alternate setting 4 bNumEndpoints 1 0x00 Only the control pipe is used 5 bInterfaceClass 1 OxFE Application Specific Class Code 6 bInterfaceSubClass 1 0x01 Device Firmware Upgrade Code 7 bInterfaceProtocol 1 0x00 kasia Hagai Ada deL 8 ilnterface 1 Index Index of string descriptor for this interface There is an STMicroelectronics implementation for Alternate settings with a corresponding string descriptor set which is not specified by the standard DFU specification in Section 10 2 3 Requests Alternate settings have to be used to access additional memory segments and other memories Flash memory RAM EEPROM which may or may not be physically implemented in the CPU memory mapping such as external serial SPI Flash memory or external NOR NAND Flash memory In this case each alternate setting employs a string descriptor to indicate the target memory segment as shown below Target Memory Name Start Address Sector 1 Count Sector 1 Size Sector 1 Type Sector 2 Count Sector 2 SizeSector 2 Type Sector n Count Sector n SizeSector n Type Another example for STM32 Flash microcontroller is shown below Internal Flash
15. v UMO424 77 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 FS Device 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 m 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 Table 1 Applicable products Type Part numbers or product categories STM32F102xx and STM32F103xx series Microcontrollers STM32 L1 Ultra Low Power STM32 F3 Series 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 December 2012 Doc ID 13465 Rev 12 1 85 www st com Contents UMO424
16. Contents 1 Related documents x 0 esa IE ae 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 WE si KAO ode ese Euer eR dor UR UE RR a ed 12 3 2 2 usb int 1 7 6 sob VER ERR AA ties 17 3 2 3 USD mem 15 26 is ctetu A po Tiu ex Pago iden 17 3 3 USB FS Device Driver medium layer 17 3 3 1 usb INIA O irm eee er te eee ecd a ete dU ed ees 17 3 3 2 usb core 2h 7C vos see EAE a iw Ea EX RM 17 3 3 3 sbssil hia acto es os done T ite ug tot 21 3 3 4 usb type h usb defh 21 3 3 5 platform Config hi nios ebb npg dda SUP eMe EP adu 21 3 4 Application interface 21 3 4 1 USD COM D es en nn re fons Mer eda eon Deia ATE eue 22 3 4 2 usb desc HC sec ei eeu ey de v ed ds 22 3 4 3 usb prop hi LC ea exea ai tat wernt RS ee A 23 3 4 4 sb sendp 6 4 5 tec Ne eese tee edi es 24 3 4 5 USD IStr 6 en D ERR Ne ede Gat nls REN ede ATE 25 3 4 6 usb pwt CIrse esos tek week RD Ah DU x x a o 25 3 5 Implementing a USB FS Device application using the STM32 USB FS Device library 25 3 5 1 Implementing a no data class specific request 25 3 5 2 How to implement a data class specific request
17. Reference to UMO412 added to Section 10 Device firmware upgrade Note added in Section 6 2 Mass storage demo overview 22 May 2008 STM3210E EVAL added user manual updated accordingly Small text changes 30 May 2008 Section 1 5 2 Tusb_desc h c on page 21 and Section 5 Custom HID demo on page 30 added Section 4 Joystick mouse demo on page 27 modified Section 10 6 STM32 DFU implementation on page 78 modified Section 6 4 8 Medium access management on page 44 added 13 Jun 2008 Caution on page 45 reference to firmware license agreement removed 03 Apr 2009 USB replaced by USB FS_Device STM32 Firmware Library upgraded to the standard peripheral library 07 May 2009 Corrupted paf version replaced 10 Nov 2009 Added support for OTG full speed device peripherals Introduction modified Section 3 1 USB application hierarchy and Section 3 2 USB FS_Device peripheral interface modified Enhancement of the library architecture GetEPAdress modified in Endpoint register functions Section 10 6 5 Creating a DFU image modified Section 6 2 Mass storage demo overview modified Figure 14 Device manager window modified Section 8 USB audio streaming demo added BYTE replaced by uint8_t WORD replaced by uint16_t Small text changes 31 May 2010 Modified Section 3 3 2 usb core h c on page 17 device property structure and Section 3 4 1 usb_conf h on page 22 3
18. c This module sets initialization routines and global variables that will be used in the library 3 3 2 usb core h c This module is the kernel of the library It implements all the functions described in Chapter 9 of the USB 2 0 specification Doc ID 13465 Rev 12 17 85 STM32 USB FS Device firmware library UMO424 The available subroutines cover handling of USB standard requests related to the control endpoint ENDPO offering the necessary code to accomplish the sequence of enumeration phase A state machine is implemented in order to process the different stages of the setup transactions The USB core module also implements a dynamic interface between the standard request and the user implementation using the structure User_Standard_Requests The USB core dispatches the class specific requests and some bus events to user program whenever it is necessary User handling procedures are given in the Device Property structure The different data and function structures used by the kernel are described in the following paragraphs 1 Device table structure The core keeps device level information in the Device_Table structure Device_Table is of the type DEVICE typedef struct DEVICE uint8 t Total Endpoint uint8 t Total Configuration DEVICE 2 Device information structure The USB core keeps the setup packet from the host for the implemented USB Device in the Device Info structure This structure has the ty
19. or delete the device instance from the device manager Running the demo When attaching a device to the STM32 eval board the composite appears in the device manager window as shown in Figure 26 You can now use your board as a removable disk and for custom HID applications You can see two applications appear in the device manager each of which can be used in stand alone mode This is the purpose of the composite device 1 USB Mass Storage removable disk a new removable disk appears and write read and format operations can be performed as with any other removable drive Refer to Chapter 6 Mass storage demo for more information 2 HID device refer to Chapter 5 Custom HID demo Figure 26 STM32 device enumerated as composite USB Composite Device Properties EE P General Driver Details gt USB Composite Device Device type Universal Serial Bus controllers Manufacturer Standard USB Host Contralle Location Device status This device is working properly If you are having problems with this device click Troubleshoot to start the troubleshooter Troubleshoot Device usage Use this device enable v OK JC Cancel MSv31512V1 Doc ID 13465 Rev 12 ky UMO424 Revision history 12 Revision history Table 32 Document revision history Date 28 May 2007 Revision 4 Changes Initial release 04 Oct 2007 Evaluation board name corrected
20. 0x08000000 12 001 Ka 116 001 Kg in case of STM3210B EVAL board Internal Flash 0x08000000 6 002 Ka 250 002 Kg in case of STM3210E EVAL board Internal Flash 0x08000000 48 256 Ka 464 256 Kg in case of STM32L152 EVAL board Internal Flash 0x08000000 48 256 Ka 1488 256 Kg in case of STM32L152D EVAL board Internal Flash 0x08000000 12 001 Ka 116 001 Kg in case of STM32373C EVAL and STM32303C EVAL boards Doc ID 13465 Rev 12 71 85 Device firmware upgrade UMO424 Note 72 85 Each Alternate setting string descriptor must follow this memory mapping so that the PC Host Software can decode the right mapping for the selected device To detect that this is a special mapping descriptor to avoid decoding standard descriptor for separator between zones Maximum 8 digits per address starting by 0x for separator between zones Maximum of 2 digits for the number of sectors For separator between number of sectors and sector size Maximum 3 digits for sector size between 0 and 999 1 digit for the sector size multiplier Valid entries are B byte K Kilo M Mega 1 digit for the sector type as follows a 0x41 Readable b 0x42 Erasable c 0x43 Readable and Erasabled 0x44 Writeable e 0x45 Readable and Writeable f 0x46 Erasable and Writeable g 0x47 Readable Erasable and Writeable If the target memory is not conti
21. 12 ky UMO424 Virtual COM port demo 7 Virtual COM port demo This demo runs on the following STMicroelectronics evaluation boards and can be easily tailored to any other hardware e STM3210B EVAL e STM3210E EVAL e STM32L152 EVAL e STM32373C EVAL e STM32303C EVAL e STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file 7 1 General description In modern PCs USB is the standard communication port for almost all peripherals However many industrial software applications still use the classic COM Port UART The Virtual COM Port Demo provides a simple solution to bypass this problem lt uses the USB device as a COM port by affecting the legacy PC application designed for COM Port communication The Virtual COM Port demo provides the firmware examples for the STM32 family and the PC driver This section provides a brief description of the implementation and shows how to run the demo 7 2 Virtual COM port demo proposal The demo proposal is to use the STM32 evaluation board as a USB to USART bridge and to provide communication between a laptop without RS 232 port and a standard PC workstation as shown in Figure 12 Figure 12 Virtual COM port demo as USB to USART bridge Communication MSv31506V1 The PC application used for communication is Windows HyperTerminal See Figure 13 Doc ID 13465 Rev 12 49 85 Virtua
22. 19 85 STM32 USB FS Device firmware library UMO424 20 85 Device property structure The USBcore dispatches the control to the user program whenever it is necessary User handling procedures are given in an array of Device_Property The structure has the type DEVICE_PROP typedef struct DEVICE PROP void Init void Reset void void Process Status IN void void void Process Status OUT void RESULT Class Data Setup uint8 t RequestNo RESULT Class NoData Setup uint8 t RequestNo RESULT Class Get Interface Setting uint8 t Interface uint8 t AlternateSetting uint8 t GetDeviceDescriptor uint16 t Length uint8 t GetConfigDescriptor uint16 t Length uint8 t GetStringDescriptor uintl16 t Length void RxEP buffer This field is not used in current library version It is kept only for compatibility with previous versions uint8 t MaxPacketSize DEVICE PROP User standard request structure The User Standard Request Structure is the interface between the user code and the management of the standard request The structure has the type USER_STANDARD_REQUESTS typedef struct USER STANDARD REQUESTS void User GetConfiguration void void User SetConfiguration void void User GetInterface void void User SetInterface void void User GetStatus voi
23. HyperTerminal message display CDC_LoopBack HyperTerminal DS 35 Y HHEELLOO Connected 0 01 32 ANSIW 115200 8 N 1 NUM MSv31508V1 Character echo is ON Doc ID 13465 Rev 12 1677 UM0424 USB voice speaker demo 9 9 1 9 2 USB voice speaker demo This demo runs on the following STMicroelectronics evaluation boards e STM3210B EVAL e STM3210E EVAL e STM32L152 EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description The USB voice speaker demo gives examples of how to use the STM32 USB peripheral to communicate with the PC host in the isochronous transfer mode They provide a demonstration of the correct method for configuring an isochronous endpoint receiving or transmitting data from to the host They also show how to use the data in a real time application The available voice demo described in this user guide is a USB speaker Isochronous transfer overview The isochronous transfer is used when the application needs to guarantee the access to the USB bandwidth with bounded latency constant data rate and without attempting a new data transfer operation in case of failure In fact an isochronous transaction does not have a handshake phase and no ACK packet is expected or sent after the data packet Figure 17 shows an example of an isochronous OUT transfer wit
24. Related documents UM0424 1 Related documents For more information on using the microcontroller devices listed in Table 1 Applicable products please refer to the reference manuals below Table 2 Reference manual name related to each STM32 device Device name Reference manual STM32L151xx and STM32L152xx RM0038 STM32F102xx and STM32F103xx RM0008 STM32F302xx and STM32F303xx RM0316 STM32F372xx and STM32F373xx RM0313 The STM32 USB FS Device library is designed for use with the following evaluation boards Table 3 User manual name related to each evaluation board Eval board name User manual Device name STM3210E EVAL UM0488 STM32F103ZGT6 STM3210B EVAL UMO426 STM32F103VBT6 STM32L152 EVAL UM1018 STM32L152VBT6 STM32L152D EVAL UM1521 STM32L152ZDT6 STM32373C EVAL UM1564 STM32F373VCT6 STM32303C EVAL UM1567 STM32F303VCT6 8 85 Doc ID 13465 Rev 12 ky UMO424 STM32 microcontroller family overview 2 STM32 microcontroller family overview In this document STM32 refers to the following devices Low density devices STM32F101xx STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes Medium density devices STM32F101xx STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes High density devices STM32F101xx and STM32F103xx microcontrollers where the Fla
25. The fields of this structure are e void User GetConfiguration void Called after receiving the Get Configuration Standard request e void User SetConfiguration void Called after receiving the Set Configuration Standard request e void User Getlnterface void Called after receiving the Get interface Standard request e void User Setlnterface void Called after receiving the Set interface Standard request e void User GetStatus void Called after receiving the Get interface Standard request e void User ClearFeature void Called after receiving the Clear Feature Standard request e void User SetEndPointFeature void Called after receiving the set Feature Standard request only for endpoint recipient e void User_SetDeviceFeature void Called after receiving the set Feature Standard request only for Device recipient e void User SetDeviceAddress void Called after receiving the set Address Standard request usb endp c USB endp module is used for e Handling the CTR correct transfer routines for endpoints other than endpoint O EPO for the USB FS Device peripheral For enabling the processing of these callback handlers a pre processor switch named EPx IN Callback for IN transfer or EPx OUT Callback for OUT transfer or EPx RX ISOC CALLBACK for Isochronous Out transfer must be defined in the USB conf h file Doc ID 13465 Rev 12 ky
26. e Low priority interrupt managed by the function CTR LP and used for control interrupt and bulk in simple buffer mode e High priority interrupt managed by the function CTR HP and used for faster transfer mode like Isochronous and bulk in double buffer mode 3 2 3 usb mem h c The usb mem copies a buffer data from the user memory area to the packet memory area PMA and vice versa It provides two different functions e void UserTOPMABufferCopy uint8 t pbUsrBuf uint6 t wPMABufAddr uint16 t wNBytes e void PMAToUserBufferCopy uint8 t pbUsrBuf uint16_twPMABufAdar uint16 t wNBytes Where e pbUsrBufis the pointer to the user memory area generally in the products SRAM e wPMABufAddr is the address in PMA 512 byte packet memory area dedicated to USB e wNBytes is the number of bytes to be copied 3 3 USB FS Device Driver medium layer Table 6 presents the USB FS Device Driver medium layer modules Table 6 USB FS Device Driver medium layer modules File Description usb init h c USB device initialization global variables usb core h c USB protocol management compliant with chapter 9 of the USB 2 0 specification Simplified functions for read amp write accesses to the endpoints abstraction usb sil h c layer for the USB FS Device peripheral usb def h usb type h USB definitions and types used in the library platform config h Defines the hardware depending on the evaluation board used 3 3 1 usb init h
27. fi ti h teristics bmAttributes 0x80 Configuration characteristics Bus powered Maxpower 0x32 Maximum power consumption through USB bus 100 mA Table 18 Interface descriptors Field Value Description bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x04 Descriptor type Interface descriptor binterfaceNumber 0x00 Interface number bAlternateSetting 0x00 Alternate Setting number bNumEndpoints 0x02 Number of used Endpoints 2 binterfaceClass 0x08 Interface class Mass Storage class binterfaceSubClass 0x06 Interface subclass SCSI transparent binterfaceProtocl Ox50 Interface protocol 0x50 interface 106 Index of the interface String descriptor ky Doc ID 13465 Rev 12 47 85 Mass storage demo UMO424 Table 19 Endpoint descriptors Field Value Description IN endpoint bLength 0x07 Size of this descriptor in bytes bDescriptortype 0x05 Descriptor type endpoint descriptor bEndpointAddress 0x81 IN endpoint address 1 bmAttributes 0x02 Bulk endpoint wMaxPacketSize 0x40 64 bytes binterval 0x00 Does not apply for bulk endpoints OUT endpoint bLength 0x07 Size of this descriptor in bytes bDescriptortype 0x05 Descriptor type endpoint descriptor bEndpointAddress 0x02 Out endpoint address 2 bmAttributes 0x02 Bulk endpoint wMaxPacketSize 0x40 64 bytes binterval 0x00 Does not apply for bulk endpoints 48 85 Doc ID 13465 Rev
28. format operations can be performed as with any other removable drive see Figure 7 Figure 7 New removable disk in Windows _ Hard Disk Drives lt a Local Disk C Devices with Removable Storage Network Drives ai14300 Table 11 gives details of the memory support used for each eval board Doc ID 13465 Rev 12 33 85 Mass storage demo UMO424 Table 11 Eval board memory support Eval board Memory support IP interface STM3210E EVAL MicroSD and NAND Flash SDIO and FSMC STM3210B EVAL MicroSD SPI STM32L152 EVAL MicroSD SPI STM32L152D EVAL MicroSD SDIO STM32373C EVAL MicroSD SPI STM32303C EVAL MicroSD SPI Note All related firmware used to initialize read from and write to the media are available in the sim32xxx_eval_sdio_sd c c h sim32xxx_eval_spi_sd c h and fsmc nand c h files Note For mass storage class the device firmware does not need to know or take into account the file system the host is using The firmware just stores and sends blocks of data as requested by the host 6 3 Mass storage protocol 6 3 1 Bulk only transfer BOT The BOT protocol uses only bulk pipes to transfer command s status and data no interrupt or control pipes The default pipe pipe O or in other words Endpoint 0 is only used to clear the bulk pipe status clear STALL status and to issue the two class specific requests Mass Storage reset and Get Max LUN 34 85 Doc ID 13465 Re
29. interrupt see usb istr c file SOF Callback function to avoid overflowing the Stream Buffer Doc ID 13465 Rev 12 61 85 USB voice speaker demo UMO424 Audio speaker descriptors Table 21 Device descriptors Field Value Description bLength 0x12 Size of this descriptor in bytes bDescriptortype 0x01 Descriptor type Device descriptor bcdUSB 0x0200 USB specification Release number 2 0 bDeviceClass 0x00 Device class bDeviceSubClass 0x00 Device subclass bDeviceProtocol 0x00 Device protocol bMaxPacketSize0 0x40 Max packet size of Endpoint 0 64 bytes idVendor 0x0483 Vendor identifier STMicroelectronics idProduct 0x5730 Product identifier bcdDevice 0x0100 Device release number 1 00 iManufacturer 0x01 Index of the manufacturer string descriptor 1 iProduct 0x02 Index of the product string descriptor 2 iSerialNumber 0x03 Index of the serial number string descriptor 3 bNumConfigurations 0x01 Number of possible configurations 1 Table 22 Configuration descriptors Field Value Description bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x02 Descriptor type Configuration descriptor wTotalLength 0x006D Total length in bytes of the returned data by this descriptor including interface endpoint descriptors Number of interfaces supported by this configuration two bNuminterfaces 0x02 interfaces bConfigurationValue 0x01
30. management consists of the transfer of the needed data directly from the specified data buffer address in the USB memory according to the related endpoint IN ENDP1TXADDR OUT ENDP2RXADDR For these transfers the following two functions are used usb sil c file e USB SIL Read this function transfers the received bytes from the USB memory to the internal RAM This function is used to copy the data sent by the host to the device The number of received data bytes is determined into the function not passed as parameter and this value is returned by the function at the end of the operation e USB SIL Write this function transfers the specified number of bytes from the internal RAM to the USB memory This function is used to send the data from the device to the host Class specific requests The Mass Storage Class specification describes two class specific requests Bulk only mass storage reset This request is used to reset the Mass Storage device and its associated interface This class specific request makes the device ready for the next CBW sent by the PC host To issue the bulk only mass storage reset the host issues a device request on the default pipe endpoint 0 of bmhequestType Class Interface Host to device bRequest field set to OXFF wValue field set to O windex field set to the interface number 0 for this implementation wLength field set to O This request is implemented as a no data class specific reques
31. order to set the default control endpoint and enable it to receive void Process Status IN void Callback procedure it is called when a status in a stage is finished The user program can take control with this callback to perform class and application related processes void Process Status OUT void Callback procedure it is called when a status out stage is finished As with Process Status IN the user program can perform actions after a status out stage RESULT see note below Class Data Setup uint8 t RequestNo Callback procedure it is called when a class request is recognized and this request needs a data stage The core cannot process such requests In this case the user program gets the chance to use custom procedures to analyze the request prepare the data and pass the data to the USB FS Device core for exchange with the host The parameter RequestNo indicates the request number The return parameter of this function has the type RESULT It indicates the result of the request processing to the core RESULT Class NoData Setup uint8 t RequestNo Callback procedure it is called when a non standard device request is recognized that does not need a data stage The core cannot process such requests The user program can have the chance to use custom procedures to analyze the request and take action The return parameter of this function has type RESULT It indicates the result of the request processing to the core RESU
32. shows the package organization of the USB FS Device library with all the demonstrations and subfolders Figure 2 USB FS Device library package organization 4 STM32 USB FS Device Lib J _htmresc m Libraries Contains the USB FS Device driver and the standard 4 Libraries i peripherals libraries CMSIS STM32 USB FS Device Driver STM32F10x StdPeriph Driver STM32F30x StdPeriph Driver STM32F37x StdPeriph Driver STM32L1xx StdPeriph Driver 4 Projects E Projects Contains the workspaces and the sources files for the CDC_LoopBack Composite Example J Custom HID L Device Firmware Upgrade JoyStickMouse Mass Storage J Virtual COM Port J Utilities mom Romo pr y Utilities Contains the STM32 drivers relative to the used boards SD card buttons joystick etc MSv31505V1 Doc ID 13465 Rev 12 11 85 STM32 USB FS Device firmware library UMO424 3 2 3 2 1 Note 12 85 USB FS_Device peripheral interface Table 4 presents the USB FS_Device peripheral interface modules Table 4 USB FS_Device peripheral interface modules File Description usb_reg h c Hardware abstraction layer usb_int c Correct transfer interrupt service routine usb_mem h c Data transfer management from to packet memory area usb_reg h c The usb_regs module implements the hardware abstraction layer it offers a set of basic functions for accessing the USB FS_Devi
33. the class specific AudioControl interface descriptor The AudioControl interface of an audio function may support multiple alternate settings Alternate settings of the AudioControl interface could for instance be used to implement audio functions that support multiple topologies by presenting different class specific AudioControl interface descriptors for each alternate setting e AudioStreaming Interface Subclass AS AudioStreaming interfaces are used to interchange digital audio data streams between the host and the audio function They are optional An audio function can have zero or more AudioStreaming interfaces associated with it each possibly carrying data of a different nature and format Each AudioStreaming interface can have at most one isochronous data endpoint e MiDiStreaming Interface Subclass MIDIS MIDIStreaming interfaces are used to transport MIDI data streams into and out of the audio function To be able to manipulate the physical properties of an audio function its functionality must be divided into addressable entities Two types of such generic entities are identified and are called units and terminals The Universal Serial Bus Class Definition for Audio Devices specification defines seven types of standard units and terminals that are considered adequate to represent most audio functions These are Input Terminal Output Terminal Mixer Unit Selector Unit Feature Unit Processing Unit Exten
34. usb_bot h firmware files e Mass Storage In Mass Storage Out these two functions are called when a correct transfer IN or OUT occurs The aim of these two functions is to provide the next step after receiving sending a CBW data or CSW e CBW_Decode this function is used to decode the CBW and to dispatch the firmware to the corresponding SCSI command e DatalnTransfer this function is used to transfer the characteristic device data to the host e Set CSW this function is used to set the CSW fields with the needed parameters according to the command execution e Bot Abort this function is used to STALL the endpoints 1 or 2 or both according to the Error occurring in the BOT flow SCSI protocol implementation The aim of the SCSI Protocol is to provide a correct response to all SCSI commands needed by the operating system on the PC host This section details the method of management for all implemented SCSI command s e INQUIRY command OpCode 0x12 Send the needed inquiry page data in this demo only page O and the standard page are supported with the needed data length according to the ALLOCATION LENGTH field of the command e SCSI READ FORMAT CAPACITIES command OpCode 0x23 Send the Read Format Capacity data response ReadFormatCapacity Data from the SCSI data c file after checking the presence of the medium If no medium has been detected MEDIUM NOT PRESENT error is returned to force the host to u
35. 1 Mar 2011 10 Updated title and document from STM32F10xx to STM32 to take into account support for the STM32L152 EVAL evaluation boards for STM32L15xx devices Y Doc ID 13465 Rev 12 83 85 Revision history UM0424 84 85 Table 32 Document revision history continued Date 26 Jun 2012 Revision 11 Changes Added references to STM32L152D EVAL board Section Device firmware upgrade moved 20 Dec 2012 12 Removed support for the OTG full speed device peripheral Removed support for STM32F105 F107 Added references to the STM32373C EVAL and STM32303C EVAL boards Modified Section 5 1 General description and Section 5 3 1 LED control Modified Figure 1 Figure 2 Figure 9 Figure 12 and Figure 25 Removed the chapter USB audio streaming demo Changed name of CDC Loopback chapter to Chapter 8 VirtualComport_Loopback Added Chapter 11 Composite example Added the following tables Table 2 Reference manual name related to each STM32 device Table 3 User manual name related to each evaluation board Table 10 Key push button assignment Table 11 Eval board memory support Table 20 USART connector number for each evaluation board Table 25 Flash memory used by DFU a Doc ID 13465 Rev 12 UM0424 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics N
36. 24 3 4 1 3 4 2 22 85 Table 7 Application interface modules File Description usb_conf h USB FS_Device configuration file usb_desc h c USB FS Device descriptors usb prop h c USB FS Device application specific properties usb endp c Correct transfer interrupt handler routines for non control endpoints usb istr h c USB FS Device interrupt handler functions usb pwr h c USB FS Device power and connection management functions usb conf h The usb conf h is used to customize the USB demos and to configure the device as follows e Define the number of endpoints to be used through the define EP NUM e Enable the use of Endpoints and event callback routines by commenting the relative callback define i e comment the define EP1 IN Callback to enable and use this function when a correct transfer occurs on endpoint 1 comment the define INTR SOFINTR Callback in order to use and implement this function when an SOF interrupt occurs When a callback is to be used its relative define in usb conf h file should be commented Then it should be implemented with the same name in the user application no need to declare the callback function prototype as it is already declared in the usb istr h file You can use the file usb conf h to Configure the BTABLE and all endpoint addresses in the PMA by modifying and or adding relative address defines BTABLE ADDRESS ENDPO RXADDR ENDPO TXADDR
37. 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 4 85 Doc ID 13465 Rev 12 UMO424 Contents 11 Composite example 22 maawa a as 80 11 1 General description oe 80 11 2 ArchiteCt re ii a lts 81 11 3 USB device descriptor 81 11 4 Running the demo fs asso Dante ot UR gs ees ee eye 82 12 REVISION history 22 2 2 12 Oe bete ad eet ete bok eds 83 Doc ID 13465 Rev 12 5 85 List of tables UMO424 List of tables Table 1 Table 2 Table 3 Table 4 Table 5 Table 6 Table 8 Table 9 Table 10 Table 11 Table 12 Table 13 Table 14 Table 15 Table 16 Table 17 Table 18 Table 19 Table 20 Table 21 Table 22 Table 23 Table 24 Table 25 Table 26 Table 27 Table 28 Table 29 Table 30 Table 31 Table 32 6 85 Applicable products i eee ue A da aa KARDING 1 Reference manual name related to each STM32 device 8 User manual name related to each evaluation board 8 USB FS_Device peripheral interface modules
38. Addr uint8 t bEpNum uintl6 t wAddr bEpNum endpoint number wAddr address to be set expressed as PMA buffer address GetEPTxAddr uint16 t GetEPTxAddr uint8 t bEpNum GetEPRxAddr uint16 t GetEPRxAddr uint8 t bEpNum bEpNum endpoint number return value address value expressed as PMA buffer address b Tx Rx buffer counter fields SetEPTxCount void SetEPTxCount uint8 t bEpNum uint16 t wCount SetEPRxCount void SetEPRxCount uint8 t bEpNum uint16 t wCount bEpNum endpoint number wCount counter to be set GetEPTxCount uint16 t GetEPTxCount uint8 t bEpNum GetEPRxCount uint16 t GetEPRxCount uint8 t bEpNum bEpNum endpoint number return value counter value Double buffered endpoints functions To obtain high data transfer throughput in bulk or isochronous modes double buffered mode has to be programmed In this operating mode some fields of the endpoint registers and buffer description table cells have different meanings To ease the use of this feature several functions have been developed e SetEPDoubleBuff An endpoint programmed to work in bulk mode can be set as double buffered by setting the EP KIND bit The function SetEPDoubleBuff accomplishes this task SetEPDoubleBuff void SetEPDoubleBuff uint8 t bEpNum bEpNum endpoint number e FreeUserBuffer In double buffered mode the endpoints become mono directional and buffer description table c
39. Configuration value iConfiguration 0x00 Index of the Configuration String descriptor bmAttributes 0x80 Configuration characteristics Bus powered Maxpower 0x32 Maximum power consumption through USB bus 100 mA Table 23 Interface descriptors Field Value Description USB speaker standard interface AC descriptor Interface 0 alternate setting 0 bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x04 Descriptor type Interface descriptor binterfaceNumber 0x00 Interface number 62 85 Doc ID 13465 Rev 12 ky UMO424 USB voice speaker demo Table 23 Interface descriptors continued Field Value Description bAlternateSetting 0x00 Alternate setting number bNumEndpoints 0x00 eae endpoints O only endpoint O is used for binterfaceClass 0x01 Interface class USB DEVICE CLASS AUDIO binterfaceSubClass 0x01 Interface subclass AUDIO SUBCLASS AUDIOCONTROL binterfaceProtocol 0x00 Interface protocol AUDIO PROTOCOL UNDEFINED Interface 0x00 Index of the interface string descriptor USB speaker class specific AC interface descriptor bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x24 type AUDIO INTERFACE DESCRIPTOR bDescriptorSubtype 0x01 Descriptor Subtype AUDIO CONTROL HEADER bcdADC 0x0100 bcdADC 1 00 wTotalLength 0x0027 Total Length 39 binCollection 0x01 Number of streaming interfaces 1 balnterfaceNr 0x01 balnterfaceNr 1 USB speaker input
40. Doc ID 13465 Rev 12 13 85 STM32 USB FS Device firmware library UMO424 d Endpoint KIND field SetEP_KIND void SetEP KIND uint8 t bEpNum ClearEP_KIND void ClearEP KIND uint8 t bEpNum bEpNum endpoint number Set_Status_Out void Set Status Out uint8 t bEpNum Clear Status Out void Clear Status Out uint8 t bEpNum bEpNum endpoint number SetEPDoubleBuff void SetEPDoubleBuff uint8_t bEpNum ClearEPDoubleBuff void ClearEPDoubleBuff uint8 t bEpNum bEpNum endpoint number Correct Transfer Rx Tx fields ClearEP CTR RX void ClearEP CTR RX uint8 t bEpNum ClearEP CTR TX void ClearEP CTR TX uint8 t bEpNum bEpNum endpoint number e Data Toggle Rx Tx fields ToggleDTOG RX void ToggleDTOG RX uint8 t bEpNum ToggleDTOG TX void ToggleDTOG TX uint8 t bEpNum bEpNum endpoint number f Address field SetEPAdress void SetEPAddress uint8 t bEpNum uint8 t bAddr bEpNum endpoint number bAddr address to be set GetEPAdress uint8 t GetEPAddress uint8 t bEpNum bEpNum endpoint number 14 85 Doc ID 13465 Rev 12 a STM32 USB FS Device firmware library Buffer description table functions These functions are used in order to set or get the endpoints receive and transmit buffer addresses and sizes a Tx Rx buffer address fields SetEPTxAddr void SetEPTxAddr uint8 t bEpNum uint16 t wAddr SetEPRxAddr void SetEPRx
41. LT Class GET Interface Setting uint8 t Interface uint8 t AlternateSetting This routine is used to test the received set interface standard request The user must verify the Interface and AlternateSetting according to their own implementation and return the USB UNSUPPORT in case of error in these two fields uint8_t GetDeviceDescriptor uint16 t Length The core gets the device descriptor uint8_t GetConfigDescriptor uint16 t Length The core gets the configuration descriptor uint8_t GetStringDescriptor uint16 t Length The core gets the string descriptor uint16 t MaxPacketSize The maximum packet size of the device default control endpoint Doc ID 13465 Rev 12 23 85 STM32 USB FS Device firmware library UMO424 Note 3 4 4 24 85 The RESULT type is the following typedef enum RESULT USB_SUCCESS 0 request process sucessfully USB ERROR error USB UNSUPPORT request not supported USB NOT READY The request process has not been finished endpoint will be NAK to further requests RESULT Device endpoint implementation Description of the structure fields e Total Endpoint is the number of endpoints the USB application uses e Total Configuration is the number of configurations the USB application has USER STANDARD REQUEST implementation This structure is used to manage the user implementation after receiving all standard requests except Get descriptors
42. O AUTHORIZED ST REPRESENTATIVES ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USEIN MILITARY AIR CRAFT SPACE LIFE SAVING OR LIFE SUSTAINING APPLICATIONS NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY DEATH OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE ST PRODUCTS WHICH ARE NOT SPECIFIED AS AUTOMOTIVE GRADE MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK Resale of ST products with provisions different from the statements and or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2012 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Philippines Singapore Spain Sweden Switzerland United Kingdom United States of America www st com ky Doc ID 13465 Rev 12 85 85
43. Request the device to report if it is ready SPC 2 Verify 10 Ox2F M Verify data on the medium RBC Write 10 Ox2A M Transfer binary data from the host to the RBC medium 1 Command Support key M support is mandatory O support is optional Doc ID 13465 Rev 12 ky UMO424 Mass storage demo 6 4 Mass storage demo implementations 6 4 1 Hardware configuration interface The hardware configuration interface is a layer between the USB application in our case the Mass Storage demo and the internal external hardware of the STM32 microcontroller This internal and external hardware is managed by the STM32 standard peripheral library so from the firmware point of view the hardware configuration interface is the firmware layer between the USB application and the standard peripheral library Figure 9 shows the interaction between the different firmware components and the hardware environment Figure 9 Hardware and firmware interaction diagram USB FS Device application STM32 Standard peripheral lib USB FS Device library ag USB FS Device peripheral Or OTG FS Device peripheral Hardware STM32 evaluation board L Hardware config interface ai14302c The hardware configuration layer is represented by the two files HW config c and HW config h For the Mass Storage demo the hardware management layer manages the following hardware requirements e System and USB FS Device peripheral clock configuration Read and wri
44. V and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products are sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and use of the ST products and services described herein and ST assumes no liability whatsoever relating to the choice selection or use of the ST products and services described herein No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT UNLESS EXPRESSLY APPROVED IN WRITING BY TW
45. Zero None 10100001b DFU_GETSTATE 5 Zero Interface 1 State 00100001b DFU_ABORT 6 Zero Interface Zero None For additional information about these requests please refer to the DFU Class specification DFU mode selection The host should be able to enumerate a device with DFU capability in two ways e Asa single device with only DFU capability e As a composite device HID Mass storage or any functional class and with DFU capability During the enumeration phase the device exposes two distinct and independent descriptor sets each one at the appropriate time e Run time descriptor set shown when the device performs normal operations e DFU mode descriptor set shown when host and device agree to perform DFU operations Run time descriptor set During normal run time operation the device exposes its normal set of descriptors plus two additional descriptors e Run time DFU interface descriptor e Run time DFU functional descriptor The number of interfaces in each configuration descriptor that supports the DFU must be incremented by one to accommodate the addition of the DFU interface descriptor Doc ID 13465 Rev 12 69 85 Device firmware upgrade UM0424 10 3 2 70 85 DFU mode descriptor set After the host and the device agree to perform DFU operations the host re enumerates the device At this time the device exports the descriptor set shown below e DFU Mode Device descriptor DFU Mo
46. access layer Internal Flash if layer NOR Flash if layer SPI Flash if layer USB FS Device library ai15157b 10 6 4 Available DFU image for the STM32 The available DFU images in the STM32 USB development kit are Joystick Mouse Demo Custom HID Demo Mass Storage Demo Composite Example CDC_LoopBack Virtual COM Demo Audio Speaker Demo for the STM3210B EVAL STM3210E EVAL and STM32L152 EVAL evaluation boards 10 6 5 Creating a DFU image Two steps are needed to create a DFU image 1 Create a binary image from one of the available USB demo projects by adjusting the Flash memory base to 0x0800 3000 and by setting the vector table at the top of the Flash memory space 0x0800 3000 2 Using the DFU file manager provided with the DFU demo package generate the DFU file by setting target ID to O internal Flash and the start address to 0x0800 3000 ky Doc ID 13465 Rev 12 79 85 Composite example UMO424 11 11 1 80 85 Composite example This demo runs on the following STMicroelectronics evaluation boards and can be easily tailored to any other hardware e STM3210B EVAL STM3210E EVAL STM32L152 EVAL STM32373C EVAL STM32303C EVAL STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description A composite device is defined in the USB specification as follows A devic
47. al interface this function gets the address of the endpoint buffer and performs the packet write operation Endpoint simplified read function The read operation from an endpoint can be performed through the following function uint32 t USB SIL Read uint32 t EPNum uint8 t pBufferPointer The parameters of this function are e EPNum Number of the OUT endpoint related to the read operation e pBufferPointer Pointer to the user buffer to be filled with the data read form the OUT endpoint Depending on the peripheral interface this function performs two successive operations 1 Gets the number of data received from the host on the related OUT endpoint 2 Copies the received data from the USB dedicated memory to the pBufferPointer address Then the function returns the number of received data bytes to the user application usb type h usb def h These files provides the main types and USB definitions used in the library platform config h This file is responsible for offering a specific configuration for each eval board This file should be copied to the application folder where it can then be configured by the user Application interface The modules of the Application interface are provided as a template they must be tailored by the application developer for each application Table 7 shows the different modules used in the application interface Doc ID 13465 Rev 12 21 85 STM32 USB FS Device firmware library UMO4
48. atus wrapper CSW Table 13 shows the different fields of a CSW Table 13 CSW packet fields 7 6 5 4 3 2 1 0 0 3 dCSWSignature 4 7 dCSWTag 8 11 dCSWDataResidue 12 bCSWStatus e dCSWSignature 53425355 USBS little Endian e dCSWTag the device sets this field to the received value of dCBWTag in the concerned CBW e dCSWDataResidue the difference between the expected data the value of the dCBWDataTransferLength field of the concerned CBW and the real value of the data received or sent by the device e bCSWStatus the status of the concerned command This field can assume one of the three non reserved values shown in Table 14 Table 14 Command block status values Value Description 0x00 Command passed 0x01 Command failed 0x02 Phase error 0x03 gt 0xFF Reserved Data transfer The data transfer phase is specified by the dCBWDataTransferLength and bnCBWFlags of the correspondent CBW The host attempts to transfer the exact number of bytes to or from the device The diagram shown in Figure 8 shows the state machine of a BOT transfer For more information about the BOT protocol please refer to the Universal Serial Bus Mass Storage Class Bulk Only Transport specification Doc ID 13465 Rev 12 ky UMO424 Mass storage demo Figure 8 BOT state machine Command transport CBW Data IN to the host Data OUT from the host Stat
49. can be done simply by plugging the USB cable or by jumping to the DFU firmware code while performing an USB reset so that the device would enumerate with the DFU descriptor set Transfer phase The transfer phase begins after the device has processed the USB reset and exported the DFU Mode descriptor set Both downloads and uploads of firmware can take place during this phase This transfer phase consists of a succession of DFU requests according to the state diagram described in the following sections Requests A number of DFU class specific requests are needed to accomplish the upgrade upload operations Table 30 summarizes these requests Table 30 Summary of DFU upgrade upload requests bmRequest bRequest wValue windex wLength Data 00100001b DFU_DNLOAD 1 wBlockNum Interface Length Firmware 10100001b DFU_UPLOAD 2 wBlockNum Interface Length Firmware 10100001b DFU_GETSTATUS 3 Zero Interface 6 Status 00100001b DFU_CLRSTATUS 4 Zero Interface Zero None 10100001b DFU_GETSTATE 5 Zero Interface 1 State 00100001b DFU_ABORT 6 Zero Interface Zero None For additional information about these requests please refer to the DFU Class specification Doc ID 13465 Rev 12 ky UM0424 Device firmware upgrade 10 5 2 Note Special command protocol descriptions In order to support all features Address decoding and Memory block to erase etc of the DFU Extension implementation from STMicro
50. ce peripheral registers The available functions have two call versions e As a macro the call is _NameofFunction parameter1 e Asa subroutine the call is NameofFunction parameter1 Common register functions The functions in Table 5 can be used to set or get the various common USB FS_Device peripheral registers Table 5 Common register functions Register Function void SetCNTR uint16 t wValue CNTR uint16 t GetCNTR void void SetISTR uint16 t wValue ISTR uint16 t GetISTR void FNR uint16 t GetFNR void void SetDADDR uint16 t wValue DADDR uint16 t GetDADDR void void SetBTABLE uint16 t wValue BTABLE uint16 t GetBTABLE void Doc ID 13465 Rev 12 ky UMO424 STM32 USB FS Device firmware library Endpoint register functions All o Get perations with endpoint registers can be obtained with the SetENDPOINT and ENDPOINT functions However many functions are derived from these to offer the advantage of a direct action on a specific field 4 a Endpoint set get value SetENDPOINT void SetENDPOINT uint8 t bEpNum uint16 t wRegValue bEpNum Endpoint number wRegValue Value to write GetENDPOINT uint16 t GetENDPOINT uint8 t bEpNum bEpNum Endpoint number return value the endpoint register value b Endpoint TYPE field The EP TYPE field of the endpoint register can assume the defined values below
51. d void User ClearFeature void void User SetEndPointFeature void void User SetDeviceFeature void void User SetDeviceAddress void USER STANDARD REQUESTS If the user wants to implement specific code after receiving a standard USB Device request he has to use the corresponding functions in this structure An application developer must implement three structures having the DEVICE_PROP Device_Table and USER_STANDARD_REQUEST types in order to manage class requests and application specific controls The different fields of these structures are described in Section 3 3 4 usb_type h usb_def h a Doc ID 13465 Rev 12 UM0424 STM32 USB FS Device firmware library 3 3 3 3 3 4 3 3 5 3 4 usb sil h c The usb sil module implements an additional abstraction layer for USB FS Device peripheral It offers simple functions for accessing the Endpoints for Read and Write operations Endpoint simplified write function The write operation to an endpoint can be performed through the following function void USB SIL Write uint32 t EPNum uint8 t pBufferPointer uint32 t wBufferSize The parameters of this function are e EPNum Number of the IN endpoint related to the write operation e pBufferPointer Pointer to the user buffer to be written to the IN endpoint e wBufferSize Number of data bytes to be written to the IN endpoint Depending on the peripher
52. d DAC peripheral directly generates the audio data frame synchronization is controlled using TIM6 timer Firmware implementation The aim of the STM32 speaker demo is to store the data Audio Stream received from the host in a specific buffer called Stream Buffer and to use the PWM to play one stream 8 bit format every 45 45 us 22 kHz e Hardware configuration interface The hardware configuration interface is a layer between the USB application in our case the USB device Audio Speaker and the internal external hardware of the STM32 microcontroller This internal and external hardware is managed by the STM32 s standard peripheral library so from the firmware point of view the hardware configuration interface is the firmware layer between the USB FS_Device application and the standard peripheral library Figure 20 shows the interaction between the different firmware components and the hardware environment The hardware configuration layer is represented by the two files hw_config c and hw_config h For the USB audio speaker demo the hardware management layer manages the following hardware requirements System and USB peripheral clock configuration Timer configuration when STM3210B EVAL is used 12S configuration when STM3210E EVAL is used DAC and Timer configuration when STM32L152 EVAL is used Doc ID 13465 Rev 12 59 85 USB voice speaker demo UMO424 60 85 Figure 20 Hardware and firmware int
53. de Configuration descriptor o e DFU Mode Interface descriptor e DFU Mode Functional descriptor identical to the Run Time DFU Functional descriptor DFU mode device descriptor This descriptor is only present in the DFU mode descriptor set Table 27 DFU mode device descriptor Offset Field Size Value Description 0 bLength 1 0x12 Size of this descriptor in bytes 1 bDescriptorType 1 0x01 DEVICE descriptor type 2 veus 2 meno Rene 4 bDeviceClass 1 0x00 See interface 5 bDeviceSubClass 1 0x00 See interface 6 bDeviceProtocol 1 0x00 See interface 7 bMaxPacketSize0 1 8 16 32 64 Maximum packet size for endpoint zero 8 idVendor 1 0x0483 Vendor ID 10 idProduct OxDF11 Product ID 12 bcanovice TE rcc 14 iManufacturer Index Index of string descriptor 15 iProduct Index Index of string descriptor 16 iSerialNumber Index Index of string descriptor 17 bNumbConfigurations 0x01 One configuration only for DFU DFU mode configuration descriptor This descriptor is identical to the standard configuration descriptor described in the USB specification version 1 0 with the exception that the bInterfaceNum field must contain the value 0x01 Doc ID 13465 Rev 12 UMO424 Device firmware upgrade 4 DFU mode interface descriptor This is the descriptor for the only interface available when operating in DFU mode Therefore the value of the bInterfaceNumber field is always zero
54. e a Doc ID 13465 Rev 12 UMO424 Device firmware upgrade 10 5 4 Downloading and uploading The host slices the firmware image file into N pieces and sends them to the device by means of control write operations in the default endpoint Endpoint 0 The maximum number of bytes that the device can accept per control write transaction is specified in the wTransferSize field of the DFU Functional Descriptor There are several possible download mechanisms depending on the MCU device memory mapping and the Type of the memory that is Readable Erasable Writeable or a combination The most generic mechanism is described below where we have a readable erasable and writeable sector of memory e In addition to the data collected after the enumeration phase about the whole memory mapping the device capabilities etc the Host starts to send a GetCommands command in order to know additional device capabilities and which commands are supported by the DFU implementation e The host sends an Erase Sector Containing Address command using a DFU_DNLOAD request with wBlockNum 0 and wLength 5 At this stage the device erases the memory block where the address sent by the host is located After the erase operation the DFU firmware is able to write application data into the erased block e The host begins by sending the Set Address Pointer command using a DFU_DNLOAD request with wBlockNum 0 andwLength 5 This address pointer is saved in t
55. e that has multiple interfaces controlled independently of each other is referred to as a composite device For more details on composite devices please refer to usb_20 pdf 5 2 3 which is available on the usb org website When using such devices multiple functions are combined into a single device In this example the independent interfaces are Mass Storage MSC and HID The host can see all these available functions simultaneously and assigns a separate device driver to each Interface of the composite device as shown in Figure 23 Figure 23 USB composite device with two interface functions HOST PC Composite Device Function O gt HID Interface Number 0 Device Driver 0 Function 1 3 MSC Interface Number 1 Device Driver 1 MSv31509V1 Doc ID 13465 Rev 12 ky UMO424 Composite example 11 2 11 3 4 Architecture This example was created by combining the code in the Custom HID and USB MSC example projects Starting from the Custom HID example a new interface and Endpoint EP2 descriptor were added for mass storage and the total length in the configuration descriptor was modified The control endpoint endpoint 0 is shared by all functions Each function has one interface The block diagram in Figure 24 shows the architecture of the HID MSC composite example Figure 24 HID MSC composite architecture HOST Endpoint 0
56. e used by humans to control the operation of computer systems Typical examples of HID class devices are standard mouse devices keyboards Bluetooth adaptors etc HID Input Output reports can be exchanged both over the interrupt endpoint and over the default endpoint Get_ Set_Report requests The custom HID demo is a simple HID demo provided with a small PC applet to give an example of how to create a customized HID based on the native Windows HID driver It consists of simple data exchanges between the STM32 evaluation board and the PC Host using two interrupt pipes IN and OUT The custom HID demo implements feature request handling which allows the user to send a control commands to the device This command is sent through endpoint 0 and must be treated as a set_report request For more details on the HID device class please refer to the Device Class Definition for HID 1 11 available from the usb org website The data exchanged is related to LED commands push button state reports and ADC conversion values For more details on how to use the PC applet of the custom HID please refer to the UM0551 user manual USB HID demonstrator available from the STMicroelectronics microcontroller website www st com Descriptor topology The custom HID topology is based on two interrupt pipes used to handle the data transfer for seven different reports The following chart shows the custom HID topology Doc ID 13465 Rev 12 ky
57. edded in composite devices that are used to manipulate audio voice and sound related functionality This includes both audio data analog and digital and the functionality that is used to directly control the audio environment such as volume and tone control All audio devices are grouped from the USB point of view in the audio interface class This class is divided into several subclasses The Universal Serial Bus Class Definition for Audio Devices specification details the three following subclasses e AudioControl Interface subclass AC each audio function has a single AudioControl interface The AC interface is used to control the functional behavior of a particular audio function To achieve this functionality this interface can use the following endpoints A control endpoint endpoint 0 for manipulating unit and terminal settings and retrieving the state of the audio function using class specific requests Aninterrupt endpoint for status returns This endpoint is optional The AudioControl interface is the single entry point to access the internals of the audio function All requests that are concerned with the manipulation of certain audio controls within the audio function s units or terminals must be directed to the AudioControl Doc ID 13465 Rev 12 ky UMO424 USB voice speaker demo 9 4 interface of the audio function Likewise all descriptors related to the internals of the audio function are part of
58. electronics a few format rules are added to the DFU DNLOAD request They are defined as shown in Table 31 Table 31 Special command descriptions Command Request wBlockNum wLength Data Get Commands DFU_DNLOAD 0 1 0x00 Set Address Pointer DFU_DNLOAD 0 5 0x21 Address 4bytes Erase Sector containing DFU_DNLOAD 0 5 0x41 Address 4bytes address This new custom DFU implements only three supported basic commands Get commands ByteO 0x00 then no additional bytes The next DFU_UPLOAD request with wBlockNum 0 should give the supported commands The maximum size of the supported commands buffer is 256 bytes and the buffer must support the following commands 0x00 Get Commands 0x21 Set Address Pointer 0x41 Erase Sector containing address Set Address Pointer Byte0 0x21 then 4 bytes containing the address Pointer from which the Blocks will be downloaded or uploaded starting from the next DFU_DNLOAD or DFU_UPLOAD request with wBlockNum gt 1 Erase Sector containing address Byte0 0x41 then 4 bytes containing a valid address contained in a memory sector to be erased and as already exported by the string descriptors of the Alternate settings wBlockNum 1 for both DFU_DNLOAD and DFU_UPLOAD requests is reserved for future use by STMicroelectronics Doc ID 13465 Rev 12 75 85 Device firmware upgrade UMO424 10 5 3 Note 76 85 DFU state diagram Figu
59. ells of the unused direction are applied to handle a second buffer Addresses and counters must be handled in a different way Rx and Tx Addresses and counter cells become Buffer0 and Buffer1 cells Functions dedicated to this operating mode are provided for in the library During a bulk transfer the line fills one buffer while the other buffer is reserved to the application A user application has to process data before the arrival of bulk needing a buffer The buffer reserved to the application has to be freed in time To free the buffer in use from the application the FreeUserBuf fer function is provided FreeUserBuffer void FreeUserBuffer uint8 t bEpNum uint8 t bDir bEpNum endpoint number Doc ID 13465 Rev 12 15 85 STM32 USB FS Device firmware library UMO424 16 85 a Double buffer addresses These functions set or get buffer address value in the buffer description table for double buffered mode SetEPDblBuffAddr void SetEPDblBuffAddr uint8 t bEpNum uintl6 t wBuf0Addr uint16 t wBuflAddr SetEPDblbufOAddr void SetEPDblBuf0Addr uint8 t bEpNum uintl6 t wBuf0Addr SetEPDblbuflAddr void SetEPDblBuflAddr uint8 t bEpNum uintl6 t wBuflAddr bEpNum endpoint number wBuf0Addr wBuflAddr buffer addresses expressed as PMA buffer addresses GetEPDblBuf0Addr uint16 t GetEPDblBuf0Addr uint8 t bEpNum GetEPDblbufiAddr uint16 t GetEPDblBuflAddr uint8 t bEpNu
60. eraction diagram STM32 USB FS_Device audio speaker USB FS_Device application STM32 Standard peripheral f USB FS Device library ibrary A USPE Davics peripheral Hardware STM32F board El Hardware config interface ai14309c Endpoint configurations In the STM32 USB device speaker demo two endpoints are used to communicate with the PC host endpoint O and endpoint 1 Note that endpoint 1 is an Isochronous OUT endpoint and this kind of endpoint is managed by the STM32 USB device peripheral using the double buffer mode so the firmware has to provide two data buffers in the Packet Memory Area for this endpoint The following C code describes the method used to configure an isochronous OUT endpoint see the usb prop c file Speaker Reset function Initialize Endpoint 1 SetEPType ENDP1 EP ISOCHRONOUS SetEPDbIBuffAddr ENDP1 ENDP1_BUFOAddr ENDP1_BUF1Adadr SetEPDblBuffCount ENDP1 EP DBUF OUT 22 ClearDTOG_RX ENDP1 ClearDTOG_TX ENDP1 ToggleDTOG TX ENDP1 SetEPRxStatus ENDP1 EP RX VALID SetEPTxStatus ENDP1 EP TX DIS Class specific request This implementation supports only Mute control This feature is managed by the Mute command function usb prop c file Isochronous data transfer management As detailed before the STM32 manages the isochronous data transfer using the double buffer mode So to copy the received data from the PMA to the Stream Buffe
61. es a Sticky Notes Control Panel System and Security System 4 se esc View basic information about your computer Q Snipping Tool pager Windows edition g Paint LE Windows 7 Ultimate P Copyright 2009 Microsoft Corporation All rights reserved a Remote Desktop Connection 7 Magnifier S Solitaire System Rating m Windows Experience Index Processor Intel R Pentium R 4 CPU 320GHz 320 GHz gt Al Programs Installed memory RAM 768 MB 759 MB usable am Doc ID 13465 Rev 12 UMO424 Virtual COM port demo 7 4 Implementation 7 4 1 Hardware implementation Table 20 lists the USART connector number for each evaluation board Table 20 USART connector number for each evaluation board Eval board USART connector STM3210E EVAL USART1 STM3210B EVAL USART1 STM32303C EVAL USART1 STM32L152D EVAL USART1 STM32L152 EVAL USART2 STM32373C EVAL USART2 Note There is no need to add external hardware to run the demo 7 4 2 Firmware implementation In order to be considered as a COM port the USB device has to implement two interfaces according to the Communication Device Class CDC specification e Abstract Control Model Communication with 1 Interrupt IN endpoint in our implementation this interface is declared in the descriptor but the related endpoint endpoint 2 is not used e Abstract Control Model Data with 1 Bulk IN and 1 Bulk OUT endpoint
62. ever if there is a problem in the request the function returns the UNSUPPORT result status and the library responds with a STALL handshake 3 5 2 How to implement a data class specific request In the event of class requests requiring a data transfer phase the user implementation reports to the USB FS Device library the length of the data to transfer and the data location in the internal memory RAM if the data is received from the host and RAM or Flash memory if the data is sent to the host This type of request is managed in the function RESULT Class Data Setup uint8 t RequestNo For each class data request the user has to create a specific function with the format uint8 t My First Data Request uintl6 t Length If this function is called with the Length parameter equal to zero it sets the pInformation Ctrl Info Usb wLength field with the length of data to transfer and Doc ID 13465 Rev 12 25 85 STM32 USB FS Device firmware library UMO424 returns a NULL pointer In other cases it returns the address of the data to transfer The following C code shows a simple example uint8 t My First Data Request uintl6 t Length if Length 0 pInformation Ctrl Info Usb wLength My Data Length return NULL else return amp My Data Buffer The function RESULT Class_Data_ Setup uint8 t RequestNo manages all data requests as described in the following C code RESULT Class Data Setup
63. everts to normal operation This represents the maximum time that the device can wait depending on its timers etc The host may specify a shorter timeout in the DFU_DETACH request Maximum number of bytes that the device can accept per control write transaction wTransferSize depends on the firmware implementation on each MCU bcdDFUVersion 0x011A Version of the STMicroelectronics DFU ExtensionSpecification release Doc ID 13465 Rev 12 73 85 Device firmware upgrade UMO424 10 4 Note 10 5 10 5 1 74 85 Reconfiguration phase Once the operator has identified the device and supplied the filename the host and the device must negotiate to perform the upgrade 1 The host issues a DFU DETACH request to Control Endpoint EPO 2 The host issues a USB reset to the device This USB reset is not possible on some PC Host OS versions To bypass this issue the USB reset is performed by the MCU depending on the corresponding implementation 3 The device enumerates with the DFU Mode descriptor set as described above Some Device application may not be using USB in their run time mode such as a Motor control application or security system and USB may be used only for memory upgrade Those devices are called non USB application in the scope of this document and the above sequences are not applicable Non USB applications have to carry out the right procedure to enter the DFU mode This
64. fer Read or Write and returns a bad status to disable the transfer Management of the Read and Write processes this process is done by the two functions Read Memory and Write Memory These two functions manage the medium access based on the two functions MAL_WriteBlock and MAL_ReadBlock from the mass_mal c file After each access the current memory offset and the next Access Address are updated using the length of the previous transfer Medium access management Logical access to the addressed medium takes place in a separate layer called the medium access layer mass_mal c and mass_mal h through the logical unit number LUN This layer makes the medium access independent of the upper layer and dispatches write and read operations to the addressed medium Doc ID 13465 Rev 12 ky UMO424 Mass storage demo Caution Figure 10 Medium access layer System configuration MS application USB FS Device library Medium access layer Logical to physical translation layer NAND Flash if layer SDCard if layer ai15158b Physical access to the NAND and physical access to the micro SD are not similar In the case of the micro SD write read and erase operations can be made by page units known as logical sectors This means that access to the medium is linear and the logical address is the same as the physical one In the case of the NAND write and read operations can be made by pa
65. ge unit but erase operations are carried out by block unit This means that a write operation in a used block is performed in five steps as follows 1 Allocate a free physical block Precopy old pages Write new pages Erase the old block Assign the current logical address to the new block ak wh Figure 11 NAND write operation Read write from MAL layer Physical read Lookup table NAND Flash driver The logical to physical layer is used to keep a compatibility between the NAND and the microSD access methods by using the same input parameters for the two media In the case of the NAND the physical address is calculated internally and write and read operations are carried out in this layer ai15159 The build look up table LUT process used to translate logical addresses to physical ones and keep the block status is patented by STMicroelectronics It is not allowed to use outside the STM32 firmware and it should not be reproduced without STMicroelectronics s agreement Doc ID 13465 Rev 12 45 85 Mass storage demo UMO424 6 5 46 85 How to customize the mass storage demo The implemented firmware is a simple example used to demonstrate the STM32 USB peripheral capability in bulk transfer However it can be customized according to user requirements This customizing can be done in the three layers of the implemented mass storage protocol Customizing the BOT layer the user can impleme
66. gle of all endpoints must be cleared This requirement is served by the Mass Storage SetConfiguration function in the usb_prop c file e When the host sends a CBW command with an invalid signature or length the device must keep endpoints 1 and 2 both as STALL until it receives the Mass Storage Reset class specific request This functionality is managed by the Mass Storage ClearFeature function in the usb_prop c file BOT state machine To provide the BOT protocol a specific state machine with five states is implemented The states are described below e BOT IDLE this is the default state after a USB reset Bulk Only Mass Storage Reset or after sending a CSW In this state the device is ready to receive a new CBW from the host e BOT DATA OUT the device enters this state after receiving a CBW with data flow from the host to the device e BOT DATA IN the device enters this state after receiving a CBW with data flow from the device to the host e BOT DATA IN LAST the device enters this state when sending the last of the data asked for by the host e BOT CSW SEND the device moves to this state when sending the CSW When the device is in this state and a correct IN transfer occurs the device moves to the BOT IDLE state to be able to receive the next CBW e BOT ERROR Error state Doc ID 13465 Rev 12 ky UMO424 Mass storage demo 6 4 6 The BOT state machine is managed using the functions described below usb_bot c and
67. guous the user can add the new sectors to be decoded just after a slash as shown in the following example QFlash 0xF000 1 4Ka 0xE000 1 4Kg 0x8000 2 24Kg Doc ID 13465 Rev 12 ky UMO424 Device firmware upgrade DFU functional descriptor This descriptor is identical for both the runtime and the DFU mode descriptor sets Table 29 DFU functional descriptor Offset 0 Field bLength Size 4 Value 0x09 Description Size of this descriptor in bytes 1 bDescriptorType 4 0x21 DFU FUNCTIONAL descriptor type bmAttributes 0x00 DFU attributes Bit7 if bit1 is set the device will have an accelerated upload speed of 4096 byes per upload command bitCanAccelerate 0 No 1 Yes Bits 6 4 reserved Bit 3 device will perform a bus detach attach sequence when it receives a DFU_DETACH request 0 no 1 yes Note The host must not issue a USB Reset bitWillDetach Bit 2 device is able to communicate via USB after Manifestation phase bitManifestation tolerant 0 no must see bus reset 1 yes Bit 1 upload capable bitCanUpload 0 no 1 yes Bit 0 download capable bitCanDnload 0 n0o 1 yes wDetachTimeOut wTransferSize Number Number Time in milliseconds that the device waits after receipt of the DFU_DETACH request If this time elapses without a USB reset then the device terminates the Reconfiguration phase and r
68. gured in low power mode to reduce the power consumption and EXTI line 18 USB FS_Device Wakeup line is used for wakeup in interrupt mode When a suspend event occurs on the bus the USB FS Device library dispatches the request and calls the Enter LowPowerMode function file hw config c In this function the STM32 is put in Stop mode The STM32 remains in Stop mode until it receives a wakeup resume event on the bus In this case EXTI line 18 is activated and wakes up the STM32 After wakeup the USB FS Device library calls the Leave LowPowerMode function file hw config c to reconfigure the clock re enable the HSE and PLL To test this feature and measure the power consumption during USB FS_Device suspend connect current meter to the Vpp jumper listed in Table 9 Table 9 Eval board power consumption related jumpers Eval board name Jumper STM3210B EVAL JP9 STM3210E EVAL JP12 STM32L152 EVAL JP4 STM32L152D EVAL JP10 STM32373C EVAL JP15 STM32303C EVAL JP12 On the PC side use the USB HS Electrical Test Toolkit available for free from usb org to put the STM32 in the suspend resume state Remote wakeup implementation Remote wakeup is the ability of a USB device to bring a suspended bus back to the active condition A device that supports remote wakeup reports this capability to the PC using the bmAttributes field of the configuration descriptor bit D5 set to 1 In the Joystick demo the key pu
69. h 64 bytes in the data packet Doc ID 13465 Rev 12 55 85 USB voice speaker demo UMO424 Figure 17 Isochronous OUT transfer a o DATA o 54 bytes 3 Ej 00000001 0x87 5 2 ox 3 00 10 Bytes Transferre d Length 64 Time Ea 1024 Used 16 times T CATA Idle OUT Ent CRGS EOP s CRC1B EOP 0000 00 OO 00 O1 00 02 00 03 00 04 00 05 00 06 OO 07 00 08 JOxC785 3 00 11363 0018 00 09 00 04 00 OB O0 OC 00 OD 00 OE 00 OF OO 10 00 11 0036 00 12 00 13 00 14 00 15 00 16 00 17 00 18 OD 19 00 lA 0054 00 15 00 1C DO 1D 00 1E 00 1F Idle 0000 G0 20 00 21 00 22 00 23 00 24 00 25 00 26 00 27 00 28 0018 00 29 00 2A 00 2B O 2C 00 2D 00 ZE 00 2F OO 30 00 31 0036 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 3A 0054 00 3B 00 3C 00 3D 00 3E 00 3F d rmm 037 5 2 0 64 bytes LE 0x87 5 2 0164 bytes 9 3 56 85 Typical examples of application use of the isochronous transfer mode are audio samples compressed video streams and in general any sort of sampled data with strict requirements for the accuracy of the delivered frequency Please see the USB 2 0 specifications for more details on the USB isochronous transfer mode characteristics Audio device class overview An audio device as defined by the Universal Serial Bus Class Definition for Audio Devices specification is a device or a function emb
70. he device RAM as an Absolute Offset e The host continues to send the N pieces to the device by means of DFU_DNLOAD requests with wBlockNum starting from 2 and with the maximum number of bytes that the device can accept per control write transaction specified in the wTransferSize field of the DFU Functional Descriptor So the last data written into the memory will be located at device address Absolute Offset wBlockNum 2 x wTransferSize wLength where wBlockNum and wLength are the parameters of the last DFU_DNLOAD request If the Host wants to upload the memory data for verification or to retrieve and archive a device firmware by definition the reverse of a Download is performed 1 The host begins by sending a Set Address Pointer command using a DFU_DNLOAD request with wBlockNum 0 and wLength 5 This address pointer is saved in the device RAM as an Absolute Offset 2 The host continues to send N DFU UPLOAD requests with wBlockNun starting from 2 and with the maximum number of bytes that the device can accept per control write transaction specified in the wTransferSize field of the DFU Functional Descriptor if bitCanAccelerate O f bitCanAccelerate 1 in the DFU Functional Descriptor the value in the wTransferSize field is fixed to 0x4096 bytes So the last data retrieved from the memory will be located at device address Absolute Offset wBlockNum 2 x wTransferSize wLength Where wBlockNum and wLength are the parameter
71. ice descriptor Field Value Description bLength 0x12 Size of this descriptor in bytes bDescriptortype 0x01 Descriptor type device descriptor bcdUSB 0x0200 USB specification release number 2 0 bDeviceClass 0x00 Device Class bDeviceSubClass 0x00 Device subclass bDeviceProtocol 0x00 Device protocol bMaxPacketSize0 0x40 Max Packet Size of Endpoint 0 64 bytes idVendor 0x0483 Vendor identifier STMicroelectronics idProduct 0x5720 Product identifier bcdDevice 0x0100 Device release number 1 00 Doc ID 13465 Rev 12 ky UM0424 Mass storage demo Table 16 Device descriptor continued Field Value Description iManufacturer 4 Index of the manufacturer String descriptor 4 iProduct 42 Index of the product String descriptor 42 iSerialNumber 96 Index of the serial number String descriptor bNumConfigurations 0x01 Number of possible configurations 1 Table 17 Configuration descriptor Field Value Description bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x02 Descriptor type configuration descriptor Total length in bytes of the returned data by this wTotalLength 32 descriptor including interface endpoint descriptors bN mintertaces 0x0001 Number of interfaces supported by this configuration only one interface bConfigurationValue 0x01 Configuration value Configuration 0x00 Index of the Configuration String descriptor
72. idth modulation PWM module to generate a signal whose pulse width is proportional to the amplitude of the sample data The PWM output signal is then integrated by a low pass filter to remove high frequency components leaving only the low frequency content The output of the low pass filter provides a reasonable reproduction of the original analog signal Figure 19 shows the Audio playback diagram flow using the built in PWM In the case of the STM3210E EVAL the I2S standalone audio peripheral is used to generate the audio data Figure 19 Audio playback flow STM3210B EVAL A Low pass filter Audio amplifier Speaker STM3210E EVAL Iu Speaker I2C Audio il DAC D Audio Jack 7 STM32L152 EVAL Speaker Filter amplifier 1 DAC D Sg Audio Jack MS19242V2 58 85 Doc ID 13465 Rev 12 ky UM0424 USB voice speaker demo 9 4 2 Implementation This section describes the hardware and software solution used to implement a USB audio speaker using the STM32 microcontroller Hardware implementation In the case of the STM3210B EVAL board to implement the PWM feature the following STM32 built in timers are used e TIM2 in output compare timing mode to act as system timer e TIM4 in PWM mode In the case of the STM3210E EVAL board the IS standalone audio peripheral directly generates the audio data In the case of the STM32L152 EVAL board the embedde
73. l COM port demo UMO424 7 3 Figure 13 Communication example Laptop Hyper Term i gt HyperTerminal File Edit View Call Transfer Hek File Edit View Cal Transfer Help Dae 53 08 Y Dae o3 025 Hi Me too Hello I m here Connected 0 03 Auto detect 24008 N aisia Software driver installation To install the software driver of the Virtual COM port download and execute the Virtual Com Port Driver Setup from the STMicroelectronics website www st com At the end of the installation a new COM port appears in the Device Manager window as shown in Figure 14 Figure 14 Device manager window 50 85 Help es OlBr ie ESS 4 Windows7 86 STM Virtual COM Port COM3 Prop 1 Computer be Disk drives General Por Settings A Display adapters ld DVD CD ROM drives a eli Floppy drive controllers lt ATA ATAPI controllers STM Vitual COM Pott COM3 Device type Ports COM 8 LPT Manufacturer STMicroelectronics Location Port_ 0002 Hub_ 0004 Network adapters Gi Portable Devices a MP Ports COM amp LPT 19 Communications Port COMI Device status This device is working proper 19 ECP Printer Port LPT1 19 STM Virtual COM Port COMB Dl Processors X Sound video and game controllers 188 System devices Universal Serial Bus controllers a Getting Started voee center DTMLLUAGminUser ES cien Documents Pictur
74. m bEpNum endpoint number return value buffer addresses Double buffer counters These functions set or get buffer counter value in the buffer description table for double buffered mode SetEPDblBuffCount void SetEPDblBuffCount uint8 t bEpNum uint8 t bDir uint16 t wCount SetEPDblBuf Count void SetEPDblBuf Count uint8 t bEpNum uint8 t bDir uint16 t wCount SetEPDblBufiCount void SetEPDblBuflCount uint8 t bEpNum uint8 t b b b Dir uint16 t wCount EpNum endpoint number Dir endpoint direction wCount buffer counter GetEPDblBuf0Count uint16 t GetEPDb1BufO0Count uint8 t bEpNum GetEPDblBufiCount uint16 t GetEPDblBuflCount uint8 t bEpNum bEpNum endpoint number return value buffer counter Double buffer STATUS The simple and double buffer modes use the same functions to manage the Endpoint STATUS except for the STALL status for double buffer mode This functionality is managed by the function SetDouBleBuffEPStall void SetDouBleBuffEPStall uint8 t bEpNum uint8 t bDir bEpNum endpoint number bDir endpoint direction a Doc ID 13465 Rev 12 UMO424 STM32 USB FS Device firmware library 3 2 2 usb int h c The usb int module handles the correct transfer interrupt service routines it offers the link between the USB device protocol events and the library The STM32 USB FS Device peripheral provides two transfer routines
75. minal 0x00 Unused USB speaker standard AS interface descriptor audio streaming zero bandwidth Interface 1 alternate setting 0 bLengh Joxo9 Size of this descriptor in byts bDescriptortype 0x24 ao type AUDIO INTERFACE DESCRIPTOR binterfaceNumber 0x01 Interface Number 1 bAlternateSetting 0x00 Alternate Setting 0 bNumEndpoints 0x00 not used zero bandwidth binterfaceClass 0x01 Interface class USB DEVICE CLASS AUDIO binterfaceSubClass 0x02 yd NN a i AUDIO SHBGERSS binterfaceProtocol 0x00 Interface protocol AUDIO PROTOCOL UNDEFINED l interface OX00 Unused OO USB speaker standard AS interface descriptor audio streaming operational Interface 1 Alternate setting 1 bLength Ox09 Size of this descriptor in bytes bDescriptortype 0x24 type AUDIO INTERFACE DESCRIPTOR binterfaceNumber 0x01 Interface number 1 bAlternateSetting 0x01 Alternate Setting 1 bNumEndpoints 0x01 One Endpoint binterfaceClass 0x01 Interface class USB CLASS AUDIO binterfaceSubClass 0x02 d deo M zu EC AUDIO SUBCLASS binterfaceProtocol 0x00 Interface protocol AUDIO PROTOCOL UNDEFINED l interface Ox00 Unsed Doc ID 13465 Rev 12 a UMO424 USB voice speaker demo Table 23 Interface descriptors continued Field Value Description USB speaker audio streaming interface descriptor bLength 0x07 Size of this de
76. n Figure 5 where e Report Num report number from 1 to 4 e LED state 0 2 LED off 1 gt LEDon Doc ID 13465 Rev 12 31 85 Custom HID demo UMO424 5 3 2 5 3 3 Note 32 85 Figure 5 Data OUT format ai15154 Push button state report The states of the Key and Tamper push buttons on the STM32 evaluation boards except for the STM32L152 EVAL board where Right and Left joystick buttons are used are reported to the PC host using the endpoint 1 IN The Key push button or Right push button on the STM32L152 EVAL board corresponds to Report 5 and the Tamper push button or Left push button on the STM32L152 board to Report 6 When one of the two push buttons is pressed the device sends the related report number and the push button state to the host Figure 6 shows the used format where e Report Num report number 5 or 6 e Button state 1 gt button pressed Figure 6 Data IN Format Report Num Button state ai15155 ADC converted data transfer This part of the demo consists in transferring the result of the converted voltage connected to the potentiometer of the evaluation board to the PC host The ADC is configured in continuous mode with DMA data transfer to a RAM variable ADC_ConvertedValueX After each conversion the converted value is tested against an old one ADC_ConvertedValueX_1 and if there is a difference between the two values potentiometer value changed by a use
77. ndor specific This means that the DFU class does not define the format of the data transferred s19 hex pure binary etc Because it is impractical for a device to concurrently perform both DFU operations and its normal runtime activities those normal activities must cease for the duration of the DFU operations Doing so means that the device must change its operating mode that is a printer is not a printer while it is undergoing a firmware upgrade it is a Flash Memory programmer However a device that supports DFU is not capable of changing its mode of operation on its own volition External human or host operating system intervention is required Phases There are four distinct phases required to accomplish a firmware upgrade 1 Enumeration The device informs the host of its capabilities A DFU class interface descriptor and associated functional descriptor embedded within the device s normal run time descriptors serve this purpose and provide a target for class specific requests over the control pipe 2 DFU enumeration The host and the device agree to initiate a firmware upgrade The host issues a USB reset to the device and the device then exports a second set of descriptors in preparation for the Transfer phase This deactivates the run time device drivers associated with the device and allows the DFU driver to reprogram the device s firmware unhindered by any other communications traffic targeting the device 3 Tra
78. nsfer The host transfers the firmware image to the device The parameters specified in the functional descriptor are used to ensure correct block sizes and timing for programming the non volatile memories Status requests are employed to maintain synchronization between the host and the device 4 Manifestation Once the device reports to the host that it has completed the reprogramming operations the host issues a USB reset to the device The device re enumerates and executes the upgraded firmware To ensure that only the DFU driver is loaded it is considered necessary to change the id Product field of the device when it enumerates the DFU descriptor set This ensures that the Doc ID 13465 Rev 12 ky UMO424 Device firmware upgrade 10 2 3 10 3 10 3 1 Note DFU driver will be loaded in cases where the operating system simply matches the vendor ID and product ID to a specific driver Requests A number of DFU class specific requests are needed to accomplish the upgrade operations Table 26 summarizes the DFU class specific requests Table 26 Summary of DFU class specific requests bmRequest bRequest wValue windex wLength Data 00100001b DFU_DETACH 0 wTimeout Interface Zero None 00100001b DFU_DNLOAD 1 wBlockNum Interface Length Firmware 10100001b DFU_UPLOAD 2 wBlockNum Interface Length Firmware 10100001b DFU_GETSTATUS 3 Zero Interface 6 Status 00100001b DFU_CLRSTATUS 4 Zero Interface
79. nt their own BOT state machine or modify the implemented one just by modifying the two files usb_BOT c and usb_BOT h and by keeping the same data transfer method Customizing the SCSI layer the implemented SCSI protocol presents more than the supported command listed in Section 6 4 6 SCSI protocol implementation a list of unsupported commands When the host sends one of these commands a corresponding function is called by the CBW_Decode function like a common command However all the functions related to unsupported commands are defined by the SCSI Invalid Cmd function see usb_scsi c file The SCSI Invalid Cmd function STALLs the two endpoints 1 and 2 sets the Sense data to invalid command key and sends a CSW with a Command Failed status To support one of the invalid commands the user has to comment out the concerned line and implement their own process For example for the need to support the SCSI FormatUnit command comment the line define SCSI FormatUnit Cmd SCSI Invalid Cmd And implement a process in a function with the same name in the usb_scsi c file void SCSI Invalid Cmd void your implementation In this way the custom function is called automatically by the CBW Decode function usb_BOT c file However if you need to implement a command not listed in the previous list you have to modify the CBW_Decode and implement the protocol of the new command Mass storage descriptors Table 16 Dev
80. p packet USBwindex0 is the low byte of windex and USBwindexl is the high byte of windex USBwLengths is defined as type uint16 t uint8 t and can be accessed through 3 macros define USBwLength USBwLengths w define USBwLength0 USBwLengths bw bb0 define USBwLengthl USBwLengths bw bbl USBwLength is the copy of the wLength of a setup packet USBwLength0 and USBwLength1 are the low and high bytes of wLength respectively ControlState is the state of the core the available values are defined in CONTROL STATE Current Feature is the device feature at any time It is affected by the SET FEATURE and CLEAR FEATURE requests and retrieved by the GET STATUS request User code does not use this field Current Configuration is the configuration the device is working on at any time Itis set and retrieved by the SET CONFIGURATION and GET CONFIGURATION requests respectively Current Interface is the selected interface Current Alternatesetting is the alternative setting which has been selected for the current working configuration and interface It is set and retrieved by the SET INTERFACE and GET INTERFACE requests respectively Ctrl Info has type ENDPOINT INFO Since this structure is used everywhere in the library a global variable pinformation is defined for easy access to the Device Info table it is a pointer to the DEVICE INFO structure Actually pInformation amp Device Info ki Doc ID 13465 Rev 12
81. pdate its internal parameters e SCSI READ CAPACITY 10 command OpCode 0x25 Send the Read Capacity 10 data response ReadCapacity10 Data from the SCSI data c file after checking the presence of the medium If no medium has been detected a MEDIUM NOT PRESENT error is returned to force the host to update its internal parameters e SCSI MODE SENSE 6 command OpCode 0x14 Send the Mode Sense 6 data response Mode Sense6 datal from the SCSI data c file e SCSI MODE SENSE 10 command OpCode 0x54 Send the Mode Sense 10 data response Mode Sensel0 data from the SCSI data c file e SCSI REQUEST SENSE command OpCode 0x03 Send the Request Sense data response Note thatthe Resquest Sense Data array SCSI data c file is updated using the Set Scsi Sense Data function in order to set the Sense key and the ASC fields according to any error occurring during the transfer e SCSI TEST UNIT READY command OpCode 0x00 Check the presence of the medium If no medium has been detected a MEDIUM NOT PRESENT error is returned to force the host to update its internal parameters Doc ID 13465 Rev 12 43 85 Mass storage demo UMO424 6 4 7 6 4 8 44 85 SCSI PREVENT ALLOW MEDIUM REMOVAL command OpCode 0x1E Always return a CSW with COMMAND PASSED status SCSI START STOP UNIT command OpCode 0x1B This command is sent by the PC host when a user right clicks on the device in Windows and selec
82. pe DEVICE INFO typedef struct DEVICE INFO uint8 t USBbmRequestType uint8 t USBbRequest uintl6 t uint8 t USBwValues uint16 t uint8 t USBwIndexs uint16 t uint8 t USBwLengths uint8 t ControlState uint8 t Current Feature uint8 t Current Configuration uint8 t Current Interface uint8 t Current AlternateSetting ENDPOINT INFO Ctrl Info DEVICE INFO An union uint16 t uint8 t is defined to easily access some fields in the DEVICE INFO in either uint16 t or uint8 t format typedef union uint16 t w struct BW uint8 t bbl uint8 t bb0 bw uint16 t uint8 t 18 85 Doc ID 13465 Rev 12 ky UMO424 STM32 USB FS Device firmware library Description of the structure fields USBbmRequestType is the copy of the bmRequestType of a setup packet USBbRequest is the copy of the bRequest of a setup packet USBwValues is defined as type uint16_t_uint8_t and can be accessed through 3 macros define USBwValue USBwValues w define USBwValue0 USBwValues bw bb0 define USBwValuel USBwValues bw bbl USBwValue is the copy of the wValue of a setup packet USBwvValue0 is the low byte of wValue and USBwValuel is the high byte of wValue USBwindexs is defined as USBwValues and can be accessed by 3 macros define USBwIndex USBwIndexs w define USBwIndex0 USBwIndexs bw bb0 define USBwIndex1 USBwIndexs bw bbl USBwindex is the copy of the windex of a setu
83. ple loops back the contents of a text file over a USB port Demo overview Figure 15 shows the application s structure Figure 15 VirtualComport_Loopback application overview USB Communication MSv31507V1 Doc ID 13465 Rev 12 53 85 VirtualComport_Loopback UMO424 8 3 8 3 1 8 3 2 8 4 Note 54 85 Transferring data Once the device has been enumerated as a virtual COM port by the host data can easily be transferred in the loop back There are two functions and two buffers for transferring data into and out of the device Sending data from device to host To send the data received from the STM32 to the PC IN transfers put the data into the Send Buffer buffer and call CDC Send DATA When a packet is sent from the STM32 on the IN pipe EP1 EP1_IN_Callback processes the sent data Receiving data from host to device To receive data to the STM32 OUT transfers store the data in the Receive Buffer by calling CDC Receive DATA When a packet is received from the PC on the OUT pipe EP3 EP3_IN_Callback processes the received data Running the demo Follow the instructions below to start the demo 1 Launch the Window HyperTerminal application and select the COM port 2 Connect the USB port of the STM32 to the PC 3 Type any message on the PC s keyboard It will be displayed twice Any data shown in HyperTerminal is received from the device Figure 16 Window
84. r the new value is sent to the PC using the endpoint 1 IN The data format is the same as the one used for the push buttons but the report number 7 is followed by the MSB of the ADC conversion result Doc ID 13465 Rev 12 ky UM0424 Mass storage demo 6 6 1 6 2 Mass storage demo This demo runs on the following STMicroelectronics evaluation boards and can be easily tailored to any other hardware e STM3210B EVAL STM3210E EVAL STM32L152 EVAL STM32373C EVAL STM32303C EVAL STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description The mass storage demo gives a typical example of how to use the STM32 USB FS_Device peripheral to communicate with the PC host using bulk transfer This demo supports the BOT bulk only transfer protocol and all needed SCSI small computer system interface commands and is compatible with Windows XP SP1 SP2 SPI3 Windows 2000 SP4 Windows Vista and Windows 7 Mass storage demo overview The mass storage demo complies with USB 2 0 and USB mass storage class bulk only transfer subclass specifications After running the application the user just has to plug the USB cable into a PC Host and the device is automatically detected without any additional drive with Win 2000 XP Vista and Windows 7 A new removable drive appears in the system window and write read
85. r the swapping between the two PMA buffers ENDP1 BUFOAddr and ENDP1_BUF1Addr has to be managed Swapping access to the PMA is managed according to the buffer usage between the USB peripheral and the firmware This operation is provided by the EP1 OUT Callback function usb endp c file After Doc ID 13465 Rev 12 ky UMO424 USB voice speaker demo Note the end of the copy process a global variable called N_Data_Offset is updated by the number of bytes received and copied in the Stream Buffer Audio Playing Implementation To play back the audio samples received from the host when using the STM3210B EVAL board Timer TIM4 is programmed to generate a 125 5 kHz PWM signal and the TIM2 is programmed to generate an interrupt at a frequency equal to 22 kHz On each TIM2 interrupt one Audio Stream is used to update the pulse of the PWM A global variable Out_Data_Offset is used to point to the next Stream to play in Stream buffer When the 12S audio peripheral is used in the STM3210E EVAL board the Out_Data_Offset variable controls the streaming flow to synchronize the data from the USB with the Stream buffer used by the I S peripheral When the DAC peripheral is used in the STM32L152 EVAL board the Out Data Offset variable controls the streaming flow to synchronize the data from the USB with the Stream buffer used by the DAC peripheral Both IN Data Offset and Out Data Offset are initialized to O in each Start of frame
86. re 21 summarizes the DFU interface states and the transitions between them The events that rigger state transitions can be thought of as arriving on multiple input tapes as in the classic Turing machine concept Figure 21 Interface state transition diagram i 0 DFU_DETACH appIDLE Detach timeout i la io NG Application Program Mode MCU Reset 10 Any state USB Reset dfuERROR ERROR except DFU mode 0 or 1 selected Y Corrupbrirmware eo reset DFU_CLRSTATUS DFU_UPLOAD DFU_ABORT DFU_GETSTATUS DFU_UPLOAD HfuUPLOAD short Frame DFU_DNLOAD d D wLength gt 0 fq DEU UPLOAD bitCanDnload 1 qu Status Poll Timeout DFU_GETSTATUS ette du RAD DFU_GETSTATUS amp Manifest complete wLength 0 amp Block complete DFU_DNLOAD 8 BitManifestationTolerant 1 wLength gt 0 5 dfuMANIF DFU_DNLOAD dfuDNLO EST SYNC wLength 0 AD IDLE DFU_GETSTATUS Status Poll Timeout Manifest in progress bitManfestationTolerant 1 State a 25 9 dfuMANIF Status Poll Timeout 9 10 10 11 EST WAIT BitManif ionTol RESET itManifestationTolerant 0 C3 DFU GETSTATE DFU GETSTATUS ai14099 The state transition diagram shown in Figure 21 is almost the same as that defined in the DFU Class specification Fig A1 page 28 with the exception of the new transition from state 2 to state 6 which is additional and may or not be implemented in the device firmwar
87. rogram operations of the others Flash memory modules depending on the device capabilities it could be the main program Code Flash data Flash EEPROM or any other memory connected to the microcontroller even a serial Flash Through SPI or I2C etc Table 25 shows the Flash memory type used by the STM32 DFU demo Table 25 Flash memory used by DFU Eval board Flash memory Internal Flash STM3210E EVAL SPI NOR STM3210B EVAL SPI STM32303C EVAL Internal Flash STM32L152D EVAL Internal Flash STM32L152 EVAL Internal Flash STM32373C EVAL Internal Flash Doc ID 13465 Rev 12 67 85 Device firmware upgrade UMO424 Note 10 2 10 2 1 10 2 2 68 85 Refer to the UMO412 DfuSe USB device firmware upgrade STMicroelectronics extension for more details on the driver installation and PC user interface If the internal Flash memory where the user application is to be programmed is write or and read protected it is required to first disable the protection prior to using the DFU DFU extension protocol Introduction The DFU class uses the USB as a communication channel between the microcontroller and the programming tool generally a PC host The DFU class specification states that all the commands status and data exchanges have to be performed through Control Endpoint 0 The command set as well as the basic protocol are also defined but the higher level protocol Data format error message etc remain ve
88. s of the last DFU UPLOAD request 10 5 5 Manifestation phase After the transfer phase completes the device is ready to execute the new firmware This is achieved by performing a USB reset to re enumerate the device in normal run time operation Doc ID 13465 Rev 12 77 85 Device firmware upgrade UMO424 10 6 10 6 1 Note 10 6 2 10 6 3 78 85 STM32 DFU implementation Supported memories For the STM32 the DFU implementation supports the following memories e Internal Flash memory the first pages are reserved for the DFU read only pages and the remaining pages can be programmed by the DFU application zone For the STM3210B EVAL STM32373C EVAL and STM32303C EVAL boards the first 12 pages are read only and the remaining 116 pages are in the application zone For the STM3210E EVAL board the first 6 pages are read only and the remaining 250 pages are in the application zone For the STM32L152 EVAL board the first 48 pages are read only and the remaining 464 pages are in the application zone For the STM32L152D EVAL board the first 48 pages are read only and the remaining 1488 pages are in the application zone e External serial Flash memory M25P64 consists of 128 sectors of 64 Kbytes each e NOR Flash memory M29W128 consists of 256 blocks of 64 Kbytes each This memory is supported only by the STM3210E EVAL board To create a DFU image for the internal Flash memory select the Alterna
89. scriptor in bytes bDescriptortype 0x24 m type AUDIO INTERFACE DESCRIPTOR binterfaceNumber 0x01 Interface number 1 bAlternateSetting 0x01 Alternate Setting 1 bNumEndpoints 0x01 One Endpoint wFormatTag 0x0002 PCMB format USB speaker audio type format interface descriptor bLength 0x0B Size of this descriptor in bytes bDescriptortype 0x24 e i type AUDIO INTERFACE DESCRIPTOR bDescriptorSubtype 0x03 Descriptor subtype AUDIO STREAMING FORMAT TYPE bFormatType 0x01 Format type Type bNrChannels 0x01 Number of channels one channel bSubFrameSize 0x01 Subframe size one byte per audio subframe bBitResolution 0x08 Bit resolution 8 bits per sample bSamFreqType 0x01 One frequency supported tSamFreq 0x0055F0 22 kHz Table 24 Endpoint descriptors Field Value Description Endpoint 1 standard descriptor bLength 0x07 Size of this descriptor in bytes bDescriptortype 0x05 Descriptor type endpoint descriptor bEndpointAddress 0x01 OUT Endpoint address 1 bmAttributes 0x01 Isochronous Endpoint wMaxPacketSize 0x0016 22 bytes binterval 0x00 Unused Endpoint 1 Audio streaming descriptor bLength 0x07 Size of this descriptor in bytes bDescriptortype 0x25 Descriptor type AUDIO ENDPOINT DESCRIPTOR TYPE bDescriptor 0x01 AUDIO ENDPOINT GENERAL bmAttributes 0x80 bmAttributes 0x80 ky Doc ID 13465 Rev 12 65 85 USB voice speaker demo UM0424
90. sh button is used as the remote wakeup source The key button is connected to EXTI line The table below summarizes the key push button assignment for each eval board Table 10 Key push button assignment Eval board name EXTI line number STM3210B EVAL EXTI line 9 GPIO PB 09 STM3210E EVAL EXTI line 8 GPIO PG 08 STM32L152 EVAL STM32L152D EVAL EXTI line 0 GPIO PA 00 STM32373C EVAL EXTI line 2 GPIO PA 02 STM32303C EVAL EXTI line 6 GPIO PE 06 Doc ID 13465 Rev 12 ky UM0424 Joystick mouse demo When the key is pressed the corresponding EXTI ISR is called to initiate the USB device power management state machine using the Resume function Note that remote wakeup could be disabled by the PC host using the set feature request so the EXTI ISR tests the current feature and sends the remote wake up signal to the PC only if the feature is enabled Doc ID 13465 Rev 12 29 85 Custom HID demo UMO424 5 5 1 5 2 30 85 Custom HID demo This demo runs on the following STMicroelectronics evaluation boards and can be easily tailored to any other hardware e STM3210B EVAL STM3210E EVAL STM32L152 EVAL STM32373C EVAL STM32303C EVAL STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description The HID human interface device class primarily consists of devices that ar
91. sh memory density ranges between 256 and 512 Kbytes XL density devices STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 512 and 1024 Kbytes Medium density Low Power devices STM32L15xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes Low Power Medium density Plus devices STM32L15xx and STM32L162xx microcontrollers where the Flash memory density is 256 Kbytes Low Power High density devices STM32L15xx and STM32L162xx microcontrollers where the Flash memory density is 384 Kbytes STM32F3 Series STM32F30xx microcontrollers where the Flash memory density ranges between 128 and 256 Kbytes STM32F37xx microcontrollers where the Flash memory density ranges between 64 and 256 Kbytes Doc ID 13465 Rev 12 9 85 STM32 USB FS Device firmware library UMO424 3 3 1 10 85 STM32 USB FS Device firmware library This section describes the firmware interface called USB FS Device Library used to manage the STM32 USB 2 0 full speed device peripheral In the rest of the document it will be referred to as USB FS_Device peripheral The main purpose of this firmware library is to provide resources to ease the development of applications for each USB transfer type using the USB FS_Device peripheral in the STM32 microcontroller families USB application hierarchy Figure 1 shows the interaction between the different components of a t
92. sion Unit For more information about the audio class characteristics and requirements please refer to the Universal Serial Bus Device Class Definition for Audio Devices specification provided by the usb org website STM32 USB audio speaker demo The purpose of the USB audio speaker demo is to receive the audio stream data from a PC host using the USB and to play it back via the STM32 MCU Figure 18 STM32 USB FS Device audio speaker demo data flow represents the data flow between the PC host and the audio speaker Figure 18 STM32 USB FS Device audio speaker demo data flow Digital data flow via USB e senis e Analog data flow ai14307 Doc ID 13465 Rev 12 57 85 USB voice speaker demo UMO424 9 4 1 General characteristics e USB device characteristics Endpoint 0 used to enumerate the device and to respond to class specific requests The maximum packet size of this endpoint is 64 bytes Endpoint 1 OUT used to receive the audio stream from the PC host with a maximum packet size up to 22 bytes e Audio characteristics Audio data format Type PCM8 format Mono A Audio data resolution 8 bits Sample frequency 22 kHz e Hardware requirements In the case of he STM3210B EVAL board since the STM32 MCU does not have an on chip DAC to generate the analog data flow an alternate method is used to implement 1 channel DAC This method consists in using the build in pulse w
93. t in the MASS NoData Setup function usb prop c file After receiving this request the device clears the data toggle of the two bulk endpoints initializes the CBW signature to the default value and sets the BOT state machine to the BOT IDLE state to be ready to receive the next CBW GET MAX LUN request A Mass Storage Device may implement several logical units that share common device characteristics The host uses bCBWLUN to designate which logical unit of the device is the destination of the CBW The Get Max LUN device request is used to determine the number of logical units supported by the device Doc ID 13465 Rev 12 41 85 Mass storage demo UMO424 6 4 4 6 4 5 42 85 To issue a Get Max LUN request the host must issue a device request on the default pipe endpoint 0 of bmRequestType Class Interface Host to device bRequest field set to OXFE wValue field set to O windex field set to the interface number 0 for this implementation e wLength field set to 1 This request is implemented as a data class specific request in the MASS_Data_Setup function usb_prop c file Note that in case of the STM3210E EVAL board two LUNs are supported Standard request requirements To be compliant with the BOT specification the device must respond to the two following requirements after receiving the same standard requests e When the device switches from the unconfigured to the configured state the data tog
94. te LED configuration LED command Initialize the memory medium Get the characteristics of the memory medium the block size and the memory capacity Doc ID 13465 Rev 12 39 85 Mass storage demo UMO424 6 4 2 40 85 Endpoint configurations and data management This section provides a description of the configuration and the data flow according to the transfer mode Endpoint configurations The endpoint configurations should be done after each USB reset event so this part of code is implemented in the MASS Reset function file usp_prop c For all STM32 except Connectivity line devices To configure endpoint O it is necessary to e Configure endpoint O as the default control endpoint e Configure the endpoint O Rx and Tx count and buffer addresses in the BTABLE usb_conf h file e Configure the endpoint Rx status as VALID and the Tx status as NAK The bulk pipes endpoints 1 and 2 are configured as follows 1 Configure endpoint 1 as bulk IN 2 Configure the endpoint 1 Tx count and data buffer address in the BTABLE usb_conf h file 3 Disable the endpoint 1 Rx 4 Configure the endpoint 1 Tx status as NAK 5 Configure the endpoint 2 as bulk OUT 6 Configure the endpoint 2 Rx count and data buffer address in the BTABLE usb_conf h file 7 Disable the endpoint 2 Tx 8 Configure the endpoint 2 Rx status as VALID Doc ID 13465 Rev 12 ky UMO424 Mass storage demo 6 4 3 Data management Data
95. te Setting 00 in the DFU file Manager To create a DFU image for the external serial Flash memory select the Alternate Setting 01 in the DFU file Manager To create a DFU image for the NORFlash memory select the Alternate Setting O2 in the DFU file Manager DFU mode entry mechanism For the STM32 the DFU mode is entered after an MCU reset if e The DFU mode is forced by the user the user presses the key push button or joystick Up push button for STM32L152 EVAL board after a reset e There is no correct code available in the application area before jumping to the application code the DFU code tests if there is a correct top of stack address in the first address in the application area of the internal Flash memory for the STM32 the first application address is 0x0800 3000 This is done by reading the value of the first application address and verifying if the MSB half word is equal to 0x2000 base address of the RAM area in the STM32 DFU firmware architecture The DFU application is built around the DFU core which handles the DFU protocol and the medium access layer MAL The MAL is like an abstraction layer between the DFU core and the different medium drivers The MAL uses the base address of each medium to dispatch the write read and erase operations to the addressed medium Doc ID 13465 Rev 12 ky UMO424 Device firmware upgrade Figure 22 DFU firmware architecture System configuration DFU application Medium
96. terminal descriptor bLength OxOC Size of this descriptor in bytes 12 bDescriptortype 0x24 aaa type AUDIO INTERFACE DESCRIPTOR bDescriptorSubtype 0x02 B Subtype AUDIO CONTROL INPUT bTerminallD 0x01 Terminal ID 1 wTerminalType 0x0101 Terminal type AUDIO TERMINAL USB STREAMING bAssocTerminal 0x00 No association bNrChannels 0x01 One channel wChannelConfig 0x0000 Channel Configuration MONO iChannelNames 0x00 Unused iTerminal 0x00 Unused USB speaker audio feature unit descriptor bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x24 Descriptor type AUDIO INTERFACE DESCRIPTOR TYPE bDescriptorSubtype 0x06 DescriptorSubtype AUDIO CONTROL FEATURE UNIT bUnitlD 0x02 Unit ID 2 bSourcelD 0x01 Source ID 1 bControlSize 0x01 Control Size 1 bmaControls 0x0001 Only the control of the MUTE is supported ky Doc ID 13465 Rev 12 63 85 USB voice speaker demo UM0424 64 85 Table 23 Interface descriptors continued Field Value Description iTerminal 0x00 Unused USB speaker output terminal descriptor bLength 0x09 Size of this descriptor in bytes bDescriptortype 0x24 aay ia type AUDIO INTERFACE DESCRIPTOR bDescriptorSubtype 0x03 ms subtype AUDIO CONTROL OUTPUT bTerminallD 0x03 Terminal ID 3 wTerminalType 0x0301 Terminal Type AUDIO TERMINAL SPEAKER bAssocTerminal 0x00 No association bSourcelD 0x02 Source ID 2 Ter
97. this interface is represented in the demo by endpoint 1 IN and endpoint 3 OUT Endpoint 1 is used to send the data received from the UART to the PC through USB Endpoint 3 is used to receive the data from the PC and send it through the UART For more information on the CDC class please refer to the Universal Serial Bus Class Definitions for Communication Devices specification provided by the www usb org website Class specific requests To implement a virtual COM port the device supports the following class specific requests e SET CONTROL LINE STATE RS 232 signal used to tell the device that the Data Terminal Equipment device is now present This request always returns a USB SUCCESS status in the Virtual Com Port NoData_Setup function usb_prop c file e SET COMM FEATURE controls the settings for a particular communication feature This request always returns a USB_SUCCESS status in the Virtual Com Port NoData Setup function usb prop c file e SET LINE CODING sends the configuration of the device It includes the baud rate stop bits parity and number of character bits The received data is stored in a specific data structure called linecoding and used to update the UART parameters e GET LINE CODING This command requests the device current baud rate stop bits parity and number of character bits The device responds to this request with the data stored in the linecoding structure Doc ID 13465 Rev 12 51 85
98. ts the Eject operation In this case the firmware programs the data in the internal Flash memory using the Stor Data In Flash function SCSI READ 10 command OpCode 0x28 and SCSI WRITE 10 command OpCode 0x2A The host issues these two commands to perform a read or a write operation In these cases the device has to verify the address compatibility with the memory range and the direction bit in the bmFlag of the command If the command is validated the firmware launches the read or write operation from the microSD card SCSI VERIFY 10 command OpCode 0x2F The SCSI VERIFY 10 command requests the device to verify the data written on the medium In this case no Flash like memory support is used so when the SCSI VERIFY 10 command is received the device tests the BLKVFY bit If the BLKVFY bit is set to one a Command Passed status is returned in the CSW Memory management All the memory management functions are grouped in the two files memory c and memory h Memory management consists of two basic processes Management and validation of the address range for the SCSI READ 10 and SCSI WRITE 10 commands this process is done by the Address Management Test function The role of this function is to extract the real address and memory offset in the medium memory and test if the current transfer Read or Write is in the memory range If this is not the case the function STALLs endpoint 1 or 2 or both endpoints according to the trans
99. uint8 t RequestNo uint8 t CopyRoutine uint16 t CopyRoutine NULL if My First Condition test the filds of the first request CopyRoutine My First Data Request else if My Second Condition test the filds of the second request CopyRoutine My Second Data Request same implementation for each class data requests if CopyRoutine NULL return USB_UNSUPPORT pInformation gt Ctrl_Info CopyData CopyRoutine pInformation Ctrl Info Usb wOffset 0 CopyRoutine 0 return USB SUCCESS End of Class Data Setup 3 5 3 How to manage data transfers in non control endpoint The management of the data transfer using a pipe that is not the default one Endpoint 0 can be managed in the usb end c file The user has to uncomment the line corresponding to the endpoint with direction in the file usb conf h a 26 85 Doc ID 13465 Rev 12 UM0424 Joystick mouse demo 4 4 1 Note 4 2 Joystick mouse demo This demo runs on thefollowing STMicroelectronicsevaluation boards and can be easily tailored to any other hardware e STM3210B EVAL STM3210E EVAL STM32L152 EVAL STM32373C EVAL STM32303C EVAL STM32L152D EVAL To select the STMicroelectronics evaluation board used to run the demo uncomment the corresponding line in the platform config h file General description A USB mouse human interface device HID class is a simple example of a complete USB application The jo
100. us transport CSW ai14301 Doc ID 13465 Rev 12 37 85 Mass storage demo UMO424 6 3 2 38 85 Small computer system interface SCSI The SCSI command set is designed to provide efficient peer to peer operation of SCSI devices like for example hard desks tapes and mass storage devices In other words these are used to ensure the communication between an SCSI device and an operating system in a PC host Table 15 shows SCSI commands for removable devices Not all commands are shown For more information please refer to the SPC and RBC specifications Table 15 SCSI command set Command name OpCode kampana Description Reference support Inquiry 0x12 M Get device information SPC 2 Report current media capacity and Head Format 0x23 M formattable capacities supported by SPC 2 Capacities medium Mode Sense 6 Ox1A M Report parameters to the host SPC 2 Mode Sense 10 M Report parameters to the host SPC 2 Prevent Allow 0x1E M Prevent or allow the removal of media from SPC 2 Medium Removal a removable media device Read 10 0x28 M Transfer binary data from the medium to RBC the host GO Capacity 0x25 M Report current medium capacity RBC Request Sense 0x03 O Transfer status sense data to the host SPC 2 Enable or disable the Logical Unit for Start Stop Unit 0x1B M medium access operations and controls RBC certain power conditions Test Unit Ready 0x00 M
101. v 12 UMO424 Mass storage demo Command transfer To send a command the host uses a specific format called command block wrapper CBW The CBW is a 31 byte length packet Table 12 shows the different fields of a CBW Table 12 CBW packet fields 7 6 5 4 3 2 1 0 0 3 dCBWSignature 4 7 dCBWTag 8 11 dCBWDataTransferLength 12 bmCBWFlags 13 Reserved 0 bCBWLUN 14 Reserved 0 bCBWCBLength 15 30 CBWCB e dCBWSignature 43425355 USBC in little Endian e dCBWTag The host specifies this field for each command The device should return the same dCBWTag in the associated status e dCBWDataTransferLength total number of bytes to transfer expected by the host e bmCBWFlags This field is used to specify the direction of the data transfer if any The bits of this field are defined as follows Bit 7 Direction bit 0 Data Out transfer host to device 1 Data In transfer device to host Note The device ignores this bit if the dCBWDataTransferLength field is cleared to zero Bits 6 0 reserved cleared to zero e bCBWLUN concerned Logical Unit number bCBWCBLength this field specify the length in bytes of the command CBWCB e CBWCB the command block to be executed by the device Doc ID 13465 Rev 12 35 85 Mass storage demo UMO424 Note 36 85 Status transfer To inform the host about the status of each received command the device uses the command st
102. ypical USB application and the USB FS Device library Figure 1 USB application hierarchy User Application STM32_USB FS Device_Lib STM32xxxx_Std Periph_Driver amp CMSIS Interface can be modified by user Application usb core usb init USB FS peripheral interface Device Driver LT D o o 3 gt a D OQ E 3 E STM32_USB FS Low Layer USB FS_Device peripheral Hardware STM32 Board MSv31504V1 Doc ID 13465 Rev 12 ky UMO424 STM32 USB FS Device firmware library Note As seen in Figure 1 the USB FS Device library is divided into two layers STM32 USB FS Device Driver this layer manages the direct communication with the USB FS Device peripheral and the USB standard protocol The STM32 USB FS Device Driver is compliant with the USB 2 0 specification and is separate from the standard STM32 standard peripheral library Application Interface layer this layer provides the user with a complete interface between the library core and the final application The USB FS peripheral interface layer is loaded through defines at compile time and used as the peripheral interface layer The application interface layer and the final application can communicate with the standard peripherals library to manage the hardware needs of the application A detailed description of these layers with coding rules is provided in the next sections Figure 2
103. ystick mouse uses only one interrupt endpoint endpoint 1 in the IN direction After normal enumeration the host requests the HID report descriptor of the mouse This specific descriptor is presented with standard descriptors in the usb_desc c file To get the mouse pointer position the host requests four bytes of data with the format shown in Figure 3 using pipe 1 endpoint 1 Figure 3 Format of the four data bytes ai14098 The purpose of the mouse demo is to set the X and Y values according to the user actions with a joystick button The JoyState function gets the user actions and returns the direction of the mouse pointer The Joystick Send function formats the data to send to the host and validates the data transaction phase See the hw config c file for details on the functions STM32 low power management in suspend mode To give an example of power management during the USB suspend resume events the joystick mouse demo supports the STM32 Stop mode entry and exit The STM32 Stop mode is based on the Cortex M3 deepsleep mode combined with peripheral clock gating In Stop mode all clocks in the 1 8 V domain are stopped the PLLs HSI RC and HSE crystal oscillators are disabled Wakeup from the Stop mode is possible only using one EXTI line in interrupt or event mode Doc ID 13465 Rev 12 27 85 Joystick mouse demo UMO424 Note 4 3 28 85 In this demo during Stop mode the voltage regulator is confi

Download Pdf Manuals

image

Related Search

Related Contents

Installation and Operating Instructions  King Canada SS-5LS User's Manual  User Manual Oct. 2011 PCI  Sony OXF-R3 User's Manual  Samsung ML-2165 Mono Laser (20 ppm) Керівництво користувача  Invisorb Fragment CleanUp  P/440D - Golmar  ARCAPRO 827A.E/X∗ - ∗∗∗ - ∗∗∗ Elektropneumatischer  CyberEyes (SG-P4) DEUTSCH German user manual    

Copyright © All rights reserved.
Failed to retrieve file