Home
STM32F105/7 USB host library
Contents
1. Allocate a host channel to a device endpoint creation of a USB pipe Free a host channel Doc ID 18153 Rev 1 ky UM1021 USB host library architecture 2 3 2 3 1 Class drivers At the end of the enumeration the core calls a specific class driver function to manage all class related operations Please note that the proper class driver selection is not based on the result of device enumeration but it is pre defined when initializing the host library with function call USBH Init A class driver is implemented using a structure of type USBH Class cb TypeDef typedef struct Device cb USBH Status Init USB OTG CORE HANDLE pdev USBH DeviceProp TypeDef hdev void DeInit USB OTG CORE HANDLE pdev USBH DeviceProp TypeDef hdev USBH Status Requests USB OTG CORE HANDLE pdev USBH_DeviceProp_TypeDef hdev USBH Status Machine USB OTG CORE HANDLE pdev USBH_DeviceProp_TypeDef hdev USBH Class cb TypeDef The structure members are described below m Init this function is called at the start up of class operation for assuring all needed initializations This includes parsing interface and endpoint descriptors please note that the current USB host library supports only one interface opening and allocating host channels for non control endpoints call to a user callback see Section 3 in case the device is not
2. N UM1021 J User manual STM32F105 107xx USB Host library Introduction The STM32F105 7 USB host library is intended to provide a framework for USB host applications development The library stands on top of the STM32F105 7 USB OTG peripheral low level driver It implements the necessary software blocks that aim to facilitate the developement of USB host applications The STM32F105 7 USB host stack library supports the following two USB standard class applications m Mass Storage Class MSC for accessing USB flash pendrives m Human Interface Device HID class for keyboard and mouse devices November 2010 Doc ID 18153 Rev 1 1 31 www st com Contents UM1021 Contents 1 Folder organization of the USB host package 6 2 USB host library architecture 00 cee eee eee eee 8 2 1 Library block diagram organization 0000000 eee eeee 8 2 2 Description of the library core 1 ee 9 2 2 1 Core state machine isses suche rn eb eee bed bawes 9 2 2 2 Device enumeration 0000 eee 10 2 2 3 Control transfer state machine lille 11 2 2 4 USB I O requests module 00 000 eee eee 11 2 2 5 Host channels control module 0000 eee eee eee 12 2 3 e Tp sant ou at ann hath oh OE oar Mee Qa E ona He 13 2 3 1 USB Mass Storage Class MSC driver 020000 eee eee 13 2 3 2 USB Human Interface Device HID class driver for mouse and keyboa
3. 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 2010 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 ki Doc ID 18153 Rev 1 31 31
4. Third Party efsl EFSL FAT filesystem used for the mass storage demo Doc ID 18153 Rev 1 ky UM1021 Folder organization of the USB host package File organization of the USB host library The USB host library folder STM32_USB_HOST_Library is composed of two main subfolders m Core this folder contains the USB host library core files Those files implement the necessary functions state machines and data structures required for device detection and enumeration USB Control transfer management low level functions for issuing control bulk or interrupt USB transactions configuration of the USB host channels m Class this folder contains the necessary files for USB class management The USB host library supports two USB classes MSC Mass Storage Class HID Human Interface Device class for boot mouse and keyboard devices The following tables detail the Core and Class files Table 1 Core files File usbh core c h machines Implements the core the device enumeration and the control transfer state usbh stdreq c h USB standard requests needed during device enumeration USB chapter 9 Description usbh ioreq c h USB I O requests USB transaction requests for control bulk and interrupt pipes usbh hcs c h USB host channel control channel configuration allocation freeing usbh def h Definitions used throughout the USB host library Tabl
5. callback the user can implement any access to the FAT filesystem file open file read file write using the EFSL filesystem API Also the user can have access to an exported structure variable from the library MSC class driver USBH MSC Param This variable provides some information about the mass storage key Doc ID 18153 Rev 1 ky UM1021 Library user API and callback functions This variable is defined using a structure of type MassStorageParameter TypeDef defined as follows typedef struct __MassStorageParameter uint32_t MSCapacity MS device capacity in bytes uint32_t MSSenseKey Request Sense SCSI command returned value uinti16 t MSPageLength MS device Page length uint8 t MSBulkOutEp Bulk OUT endpoint address uint8 t MSBulkInEp Bulk IN endpoint address uint8 t MSWriteProtect Write protection status 0 non protected 1 protected MassStorageParameter TypeDef HID user callback functions For the HID class the following callbacks are defined m void USR MOUSE Init void user initialization for mouse application m void USR KEYBRD Init void user initializations for keyboard application m void USR MOUSE ProcessData HID MOUSE Data TypeDef data this callback is called when an input parameter data of type HID MOUSE Data TypeDef see Note 1 below is available m void USR KEYBRD ProcessData uint8 t data this callback is called when a new ASCII character is typed The ch
6. eee 4 l Filesystem interface MSC Class Page READ WRITE Im init MSC core state machine z l SCSI commands READ 10 WRITE 10 TEST_UNIT_READY MODE_SENSE 6 READ_CAPACITY 10 REQUEST_SENSE BOT state machine Control Class requests GET_MAX_LUN l l l l l l l l l l l l l l l l l l l l l l l l BULK IN OUT BOT_RESET USB I O requests Operation flow description The MSC core state machine starts with the required device initializations which are m Issuing GET MAX LUN class request for detecting the number of device logical units present on the device Please note that only devices with one logical unit are supported m issuing BOT RESET class requests for resetting the device BOT state machine Issuing SCSI commands MODE SENGE for detecting if the device is write protected and READ CAPACITY for detecting the size of the flash pendrive After the above device initializations the MSC core state machine calls the application user callback The user callback can do any type of file access into the used filesystem This operation is translated into a logical page read or write operation The filesystem interface provides the connection between the used filesystem and the MSC driver At the SCSI level the logical page read or write operations are
7. for keyboard and mouse devices It supports only one interface and one configuration selection default config It does not support mass storage devices with multiple logical units It comes with the EFSL FAT filesystem support a The page size is fixed to 512 bytes Flash pendrives with higher page granularity are not supported b Long filenames and Unicode are not supported Very short delay between device detach attach may result in abnormal operation Compatibility issues have been encountered with some devices not listed in Table 15 at the enumeration phase After connecting and disconnecting a non supported class device and then attaching a supported class device enumeration is done properly but the device cannot be accessed A device reset is needed Doc ID 18153 Rev 1 29 31 Revision history UM1021 6 30 31 Revision history Table 17 Document revision history Date 26 Nov 2010 Revision 1 Initial release Changes Doc ID 18153 Rev 1 UM1021 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV 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 solel
8. supported by the class m Denit this function is called for freeing allocated host channels when reinitializing the host It is called when a device is unplugged or in case of unrecovered error m Request this function implements the class request state machine It is called duringthe HOST CLASS REQUEST state its purpose is to process initial class requests m Machine implements the class core state machine It is called during the HOST CLASS core state USB Mass Storage Class MSC driver The Mass Storage Class driver is intended to support common USB flash pendrives using the BOT Bulk Only Transport protocol The following modules located in the class MSC folder are used to implement the MSC driver Table 6 Mass Storage Class modules Module Description usbh msc core c h MSC core state machine implementation usbh msc bot c h BOT Bulk Only Transport protocol implementation usbh msc scsi c h SCSI command implementation usbh msc fs interface c n Functions for interfacing with a filesystem for file access operations Doc ID 18153 Rev 1 13 31 USB host library architecture UM1021 14 31 The block diagram in Figure 5 shows the interactions between those modules Figure 5 Block diagram organization of the MSC driver User MSC application callback File access OPEN READ WRITE Filesystem EFSL User callbacks call a ea ee Sant Say ean ap a ee ee es
9. 1 ky UM1021 Library user API and callback functions Note 4 1 Device speed information is returned in the DeviceSpeed parameter Possible values are 0x1 for full speed devices and 0x2 for low speed devices Device descriptor information is returned in the pointer DeviceDesc which points to a structure of type USBH_DevDesc_TypeDef defined as follows typedef struct _DeviceDescriptor uint8_t bLength uint8_t bDescriptorType uint16 t bcdUSB USB Specification Number which device complies too uint8 t bDeviceClass uint8 t bDeviceSubClass uint8 t bDeviceProtocol uint8 t bMaxPacketSize uint16 t idVendor Vendor ID Assigned by USB Org uint16 t idProduct Product ID Assigned by Manufacturer uint16 t bcdDevice Device Release Number uint8 t iManufacturer Index of Manufacturer String Descriptor uint8 t iProduct Index of Product String Descriptor uint8 t iSerialNumber Index of Serial Number String Descriptor uint8 t bNumConfigurations Number of Possible Configurations USBH_DevDesc_TypeDef Doc ID 18153 Rev 1 23 31 Library user API and callback functions UM1021 24 31 Device configuration information config interface and endpoint descriptors are returned with pointers on structures USBH_CfgDesc_TypeDef USBH InterfaceDesc TypeDef and USBH EpDesc TypeDef defined as follows typedef struct _ConfigurationDescriptor uint8 t bLength u
10. AD 10 or WRITE 10 This module is implemented in file usbh msc bot c For details about the BOT protocol please refer to the usb org mass storage class document The BOT module has the following functions Table 8 MSC BOT module Function Description USBH MSC Init Initialize BOT state machine USBH MSC HandleBOTXfer BOT transfer state machine MSC SCSI module The SCSI Small Computer System Interface module usb msc scsi c stands on top of the BOT It implements the set of SCSI commands required to access the flash pendrives Doc ID 18153 Rev 1 15 31 USB host library architecture UM1021 Note 16 31 The implemented commands are Table 9 MSC SCSI commands Function Description USBH_MSC_Read10 Command for logical block read USBH_MSC_Write10 Command for logical block write USBH_MSC_TestUnitReady Command for checking device status USBH_MSC_ReadCapacity10 Command for requesting the device capacity Command for checking the Write protect status of the mass USBH_MSC_ModeSense6 f storage device USBH_MSC_RequestSense Command for getting error information MSC filesystem interface module The MSC filesystem interface module usbh_msc_fs_interface c allows interfacing of filesystems with the MSC driver This module should be ported to the selected filesystem The current USB host library package comes with the open source EFSL FAT filesystem suppor
11. H HID Handle rs The following table summarizes the functions implemented in the HID core module Doc ID 18153 Rev 1 17 31 USB host library architecture UM1021 18 31 Table 13 MSC core module functions Function Description Parses interface and endpoint descriptors and configures a USBH_HID_Interfacelnit host channel in order to have an interrupt IN pipe for getting HID reports USBH_HID_InterfaceDelnit Frees the allocated interrupt IN pipe Implements a state machine of the required class requests for USBH_HID_ClassRequest HID mouse and keyboard devices ex getting HID report descriptors setting IDLE time setting Protocol HID class core state machine processing of interrupt IN USBH_HID_Handle transfers USBH_Get_HID_ReportDescriptor Class request for getting HID report descriptor USBH_ParseClassDesc Function used for parsing HID report descriptor USBH Set Idle Class request for setting IDLE time Class request for sending Report OUT data not used in the USBH_Set_Report demonstration software USBH_Set_Protocol Class request for setting the HID protocol Boot or Report 1 USB_Set_Protocol is called to set the Boot protocol mode HID mouse amp keyboard specific management The detection of mouse or keyboard device will be done when parsing interface descriptor in function USBH HID Interfacelnit The specific initialization for each type of device an
12. amp USB OTG FS dev amp HID cb amp USR Callbacks 4 2 2 Mouse or keyboard device enumeration Similar to mass storage devices see section 4 1 2 Doc ID 18153 Rev 1 27 31 Demo firmware UM1021 4 2 3 4 2 4 4 3 28 31 Mouse demo After mouse device enumeration pressing button B3 displays the following screen which shows the mouse 3 buttons and the pointer green cross Figure 8 Mouse demo USB HOST HID DEMO USB HOST MODE HID DEMO Device Mouse Keyboard demo After keyboard enumeration pressing button B3 displays an LCD screen where the user can type some text Figure 9 Keyboard demo USB HOST HID DEMO USB HOST MODE HID DEMO Device Keyboard Hello testing azerty keyboard Demo footprints The following tables provide footprint data when the software is compiled using IAR EWARM v5 50 5 with high optimizations for size Table 16 Demo footprints Demo Code RO data RAM Mass Storage class demo 32 Kb 6 4 Kb HID mouse amp keyboard demo 24 Kb 5 Kb Doc ID 18153 Rev 1 UM1021 Known limitations 5 Known limitations The current version of the STM32F105 7 USB host stack has the following known limitations 1 It supports only two USB standard class applications i e a Mass Storage Class MSC for accessing USB flash pendrives b Human Interface Device HID class
13. aracter is received in input parameter data Note 1 HID MOUSE Data TypeDetf is defined as follows typedef struct HID MOUSE Data uint8_t x uint8_t y uint8_t z Not Supported uint8_t button Bitmap showing pressed buttons 1 pressed 0 non pressed HID MOUSE Data TypeDef Doc ID 18153 Rev 1 21 31 Library user API and callback functions UM1021 3 2 2 22 31 Class independent callback functions The class independent callback functions are defined in a structure of type USBH_Usr_cb_TypeDef defined as follows typedef struct _USBH_USR_PROP void void void void void void void void void void void void void Init void DeviceAttached void ResetDevice void DeviceDisconnected OverCurrentDetected void DeviceSpeedDetected uint8 t DeviceSpeed DeviceDescAvailable void DeviceAddressAssigned void ConfigurationDescAvailable USBH CfgDesc TypeDef USBH InterfaceDesc TypeDef USBH EpDesc TypeDef void XO et RO te XR OR OR OR OR ManufacturerString void ProductString void SerialNumString void EnumerationDone void USBH USR Status UserInput void void void USBH_USR_DeviceNotSupported void UnrecoveredError void USBH_Usr_cb_TypeDef The above callback functions are described below Init called during initialization by USBH nit core function In this functi
14. converted into SCSI commands READ 10 or WRITE 10 Those commands are transfered to the flash pendrive device using the Bulk Only Tranport protocol The BOT layer state machine issues the required Bulk IN and Bulk OUT transactions using the core USB I O request module Each MSC module is described below Doc ID 18153 Rev 1 ky UM1021 USB host library architecture MSC core module The MSC core module usb_msc_core c implements the MSC driver which is defined in the structure MSC_cb of type USBH Class cb TypeDef see section 2 3 USBH Class cb TypeDef MSC cb USBH MSC InterfaceInit USBH MSC InterfaceDeInit USBH MSC ClassRequest USBH MSC Handle Table 7 MSC core module Function Description Parses interface and endpoints descriptors and configures USBH_MSC_Interfacelnit host channels bulk IN and bulk OUT pipes USBH MGSC InterfaceDelnit De initialization routine freeing host channels In case of MSC this function only moves the library core state machine to the HOST CLASS state USBH MSC Handle Implements the MSC handler core state machine USBH MSC ClassRequest USBH MSO Issue BOTReset Issues a BOT reset class request USBH MSC Issue GETMaxLUN Issues a GET MAX LUN class request USBH MSC ErrorHandle MSC error handling MSC BOT module The MSC Bulk Only Transport BOT module implements the transport protocol for sending the SCSI commands such as RE
15. d the decoding of the received report IN data is done by two functions which are declared in a structure of type HID cb TypeDef which is defined as follows typedef struct HID cb void Init void void Decode uint8 t data HID cb TypeDef The implementation of the above structures in case a mouse or keyboard is respectively found in HID MOUSE cb and HID MOUSE cb is as follows HID cb TypeDef HID MOUSE cb MOUSE_Init MOUSE_Decode HID_cb_TypeDef HID_KEYBRD_cb KEYBRD_Init KEYBRD_Decode i 4 Doc ID 18153 Rev 1 UM1021 USB host library architecture Table 14 Mouse and keyboard intialization amp HID report decoding functions Function Description MOUSE Init Initialization routine for USB mouse MOUSE Decode HID report decoding for mouse decoding mouse x y positions pressed buttons KEYBRD Init Initialization routine for USB keyboard KEYBRD_Decode HID report decoding for keyboard decoding of the key pressed on the keyboard 1 Selection of AZERTY or QWERTY keyboard is done through the defines QWERTY_KEYBOARD SAZERTY KEYBOARD in file usbh hid keybrd h Doc ID 18153 Rev 1 19 31 Library user API and callback functions UM1021 3 3 1 3 2 3 2 1 20 31 Library user API and callback functions Library user API The library user API functions are limited to the following two functions m void USBH Proc
16. e 2 Class files Class File Description usbh hid core c h HID usbh hid mouse c h usbh hid keyboard c h HID class management HID mouse specific routines HID keyboard specific routines usbh msc core c h Mass Storage Class management usbh msc bot c h BOT Bulk Only Transport protocol implementation MSC usbh msc scsi c h SCSI standard command implementation usbh msc fs interface c h Interface with a filesystem for file access operations ky Doc ID 18153 Rev 1 7 31 USB host library architecture UM1021 2 2 1 8 31 USB host library architecture Library block diagram organization The USB host library has the following block diagram organization Figure 2 USB host library block diagram organization User application Library user APIs amp callback functions A A A Y File system A USB host library 4 Core v HID Msc Core Device state machine enumeration Class drivers t Control transfer state machine USB I O requests USB host channels control 4 STM32 USB OTG peripheral low level driver As shown in the above figure the USB host library is composed of two main parts the core and the class drivers The library core is composed of five main blocks core state machine device en
17. ee ee 7 SEAT 7 Device enumeration requests 0 2 2 0 cee 11 USB I O requests module 0 000s 12 Host channels control module 0 c eee eres 12 Mass Storage Class modules 0 00 0c cece tee 13 MSC core module 0 00 cee 15 MSC BOT module 000 c cette 15 MSC SCSI commands caceria nusa tinaaa ceami ea iea a a a Eaa a E 16 MSC filesystem interface functions s sasaaa aeae 16 EFSLManNAP eaea ea re a aE Raw eee we aries e E acaba 17 HID class modules 00 cece tees 17 MSC core module functions 0 0600 eee 18 Mouse and keyboard intialization amp HID report decoding functions 19 Tested flash pendrives 0 0 cc ete 27 Dermo footprints uere pp tatu RR RA RR RODA RIGEN RR Mieka aie heey eas 28 Document revision history llieleeeeeee dki Erua rE mr 30 Doc ID 18153 Rev 1 ky UM1021 List of figures List of figures Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 Figure 7 Figure 8 Figure 9 Folder organization 0 0 0 ce ee tet tenes 6 USB host library block diagram organization liliis 8 Core state machine iuis aad eg ew carae ge a x od doc Cc E RC E e CAE e Ra jc 9 Device enumeration celle rr 10 Block diagram organization of the MSC driver llle eee 14 MS device enumeration llli 25 MS device content access 1 eres 26 Mouse dem
18. ess void this function implements core state machine process It should be called periodically from the user main loop m USBH Init this function should be called for the initialization of the USB host hardware and library USBH Init has the following function prototype void USBH Init USB OTG CORE HANDLE pdev USBH Class cb TypeDef class cb USBH Usr cb TypeDef usr cb pdev pointer on the USB host core registers structure needed for future use class cb pointer to a class structure of type USBH Class cb TypeDef It can be either MSC cb for handling MSC devices or HID cb for handling HID mouse keyboard devices usr Cb pointer to a structure of type USBH Usr cb TypeDef This structure defines class independent callbacks see section 3 2 2 User callback functions User callbacks are declared in user template file usbh usr c Two types of user callbacks are defined m Callback functions related to the class operations MSC or HID m Callbacks functions independent from class operations they are mainly called during the enumeration phase These callbacks are defined in a structure of type USBH Usr cb TypeDef Class callback functions MSC user callback functions For MSC the following callback is used int USR MSC Application void After the end of the class initializations this function is called by the MSC state machine in order to give hand to the user for filesystem access operations In this
19. ile file Closes a file file read euinta2 file_read File file euint32 size Reads a file euint8 buf file_write anus file_write File file euint32 size Writes a file euint8 buf rmfile esint16 rmfile FileSystem fs euint8 filename Removes file mkdir esint8 mkdir FileSystem fs eint8 dirname Creates directory i i 81 Di DirLi dlist FileSyst Is openDir MD S open ir DirList is ileSystem Opens directory fs eint8 dirname ls getNext esint8 ls getNext DirList dlist Gets next file in directory 2 3 2 USB Human Interface Device HID class driver for mouse and q keyboard devices The HID class implementation in v1 0 of the USB host library is intended to support HID boot mouse and keyboard devices HID reports are received using the interrupt IN transfer The following modules located in class HID folder are used to implement the HID class Table 12 HID class modules file module Description usbh hid core c h This module implements the HID class core state machine usbh hid mouse c h HID mouse specific routines usbh hid keyboard c h HID keyboard specific routines The main functions of each module are described below HID class core The HID core module usb hid core c implements the HID class driver structure HID cb of type USBH Class cb TypeDef see section 2 3 USBH Class cb TypeDef HID_cb USBH HID InterfaceInit USBH HID InterfaceDeInit USBH HID ClassRequest USB
20. int8 t bDescriptorType uint16 t wTotalLength uint8 t bNumInterfaces uint8 t bConfigurationValue uint8 t iConfiguration uint8 t bmAttributes uint8 t bMaxPower USBH_CfgDesc_TypeDef typedef struct _InterfaceDescriptor uint8_t bLength uint8_t bDescriptorType uint8_t bInterfaceNumber uint8_t bAlternateSetting Value used to select alternative setting uint8_t bNumEndpoints Number of Endpoints used for this interface uint8_t bInterfaceClass Class Code Assigned by USB Org uint8_t bInterfaceSubClass Subclass Code Assigned by USB Org uint8_t bInterfaceProtocol Protocol Code uint8_t iInterface Index of String Descriptor Describing this interface USBH_InterfaceDesc_TypeDef typedef struct _EndpointDescriptor wants bLength uint8_t bDescriptorType uint8 t bEndpointAddress indicates what endpoint this descriptor is describing uint8 t bmAttributes specifies the transfer type uint16 t wMaxPacketSize Maximum Packet Size this endpoint is capable of sending or receiving uint8 t bInterval is used to specify the polling interval of certain transfers USBH EpDesc TypeDef In order to move the core state machine to HOST CLASS HEQUEST state Userlnput callback should return the value USBH USR RESP OK of type USBH USR Status typedef enum USBH_USR_NO_RESP USBH_USR_RESP_OK 1 USBH_USR_Status 0 no response f
21. is state where it polls for a USB device connection This state is also entered when a device disconnection event is detected and also when an unrecovered error occurs m HOST ISSUE CORE RESET this state is entered when a device is connected in order to issue a USB bus RESET m HOST DEV ATTACHED the core enters in this state when a device is attached When a full speed or low speed device is detected the state machine moves to the HOST ENUMERATION state m HOST ENUMERATION in this state the core proceeds with a basic enumeration of the USB device At the end of enumeration process the default device configuration configuration O is selected Doc ID 18153 Rev 1 USB host library architecture UM1021 2 2 2 10 31 m HOST_USR_INPUT this is an intermediary state which follows the enumeration and which includes a wait for user input in order to enter in USB class operation m HOST CLASS REQUEST starting from this state the class driver takes over and a class request state machine is called in order to handle all the initial class control requests ex Get Report Descriptor for HID After finishing the needed class requests the core moves to the HOST CLASS state m HOST CLASS in this state the class state machine is called for class related operation non control and control operation HOST CTRL XFER this state is entered whenever there is a need for a control transfer m HOST ERROR STATE this state i
22. library architecture UM1021 2 2 5 12 31 Table 4 shows the main functions in the I O request module These functions are implemented in file usbh_ioreq c Table 4 USB I O requests module Function Description USBH_CtlSendSetup Issue a setup transaction USBH CtlSendData Issue a control data OUT stage transaction USBH CtlReceiveData Issue a control data IN stage transaction USBH CtlReq high level function for issuing a control transfer setup data status stages USBH BulkSendData Issue a bulk OUT transaction USBH BulkReceiveData Issue a bulk IN transaction USBH InterruptSendData Issue an interrupt OUT transaction USBH InterruptReceiveData Issue an interrupt IN transaction Host channels control module The host channels control module is located in the lower layer of the core it allows the configuration of a host channel for a particular operation control bulk or interrupt transfer type also the allocation of a selected host channel to a device endpoint for creating a USB pipe The main functions for USB channel control module are defined in Table 6 These functions are implemented in file usbh hcs c Table 5 Host channels control module Function Description USBH Open Channel Open and configure a new host channel USBH Modify Channel Modify an existing host channel USBH Alloc Channel USBH Free Channel
23. llowing table selection of various flash pendrives using the STM32F105 7 USB host library and the demonstration provided with the mass storage example Doc ID 18153 Rev 1 ky UM1021 Demo firmware Table 15 Tested flash pendrives Manufacturer Name Size VID PID Kingston Data Traveler 2GB 2GB 0x0951 0x1603 Lexar JumpDrive Sport 265MB 0x05DC OxA410 Lexar JumpbDrive FireFly 265MB 0x05DC 0xA575 Lexar JumpDrive2 0 pro 256MB 0x05DC 0x0200 Memorex TravelDrive Classic 003C 512MB Ox08EC 0x0008 Memorex TravelDrive Classic 003B 2GB 0x12F7 0x1A00 Sandisk USB Flash Drive 8 GB 0x0781 0x5541 Sandisk USB Flash memory 8 GB 0x0781 0x6545 Sandisk U3 Cruzer Micro U3 1 GB 0x0781 0x5406 Sandisk Cruzer Colors 4 GB 0x0781 0x5170 Sandisk Cruzer Pro 1 GB Ox08EC 0x0507 Sandisk Cruzer Micro 512 MB 0x0781 0x5151 Kingmax USB2 0FlashDisk 2 GB 0x1687 0x6211 Netac USB Flash Disk 128 MB OxODD8 OXD202 PNY Attach 2 0 128 MB OxO8EC 0x0012 PNY Attach Pro 1GB 0x13FF 0x1A23 Sony Micro Vault Tiny 2 GB 0x054C 0x02A5 Toshiba USB Flash memory 2 GB 0x0930 0x6545 Transcend JetFlash V30 1GB Ox058F 0x6387 Corsair Flash Voyager Mini 8 GB Ox1B1C Ox0B29 Philips FMO1FDOOB 1GB 0x0471 0X082B 4 2 HID mouse and keyboard demos 4 2 1 Initializations Same as for mass storage devices see section 4 1 1 except that the HID class driver is selected in the USBH Init function Init Host Library USBH Init
24. numeration pressing button B3 displays the screen below which provides the following information m Flash pendrive capacity in Mbytes m Root folder files Figure 7 MS device content access To continue Press key B3 Please note that after browsing the mass storage device content a simple text file HostDemo txt is written into the flash pendrive assuming that it is not write protected For testing file read access the user can start an image slideshow on the LCD screen assuming that some bmp images are available in the root folder of the flash pendrive Some bmp images with LCD screen size are provided in the project folder If the device is write protected a warning message is displayed on the LCD screen Mass storage devices with multiple logical units are not supported an error message is displayed on the LCD screen If no bmp image is available in the flash pendrive root folder a warning message is displayed on the LCD screen and after 2 seconds the host re initializes restarts enumeration of the flash pendrive Flash pendrive tests Because an embedded USB host is considered limited these interoperability tests Enumeration Cold Boot with device attached Hot detach attach Browsing root content Creation of hostdemo txt file Data read from device to TFT LCD images slide show 7 Messaging to TFT LCD no silent failure oa hwoNnN are successfully applied to the fo
25. o 1 eee hrs 28 Keyboard demo cs isis eium una ka dusk ue PRG EROR E E Y po Rn RR e 28 Doc ID 18153 Rev 1 5 31 Folder organization of the USB host package UM1021 1 6 31 Folder organization of the USB host package The STM32 USB host library package has the following folder organization Figure 1 Folder organization STM32_USB_HOST_LIB_PACKAGE Librairies CMSIS STM32_USB_HOST_Library A Class HID MSC Core STM32_USB_HOST_Driver STM32F10x_StdPeriph_Driver Project USB_HOST_Examples HID_KBrd_Mouse MSC Utilities H STM32 EVAL Ej STM3210C EVAL Third Party efsl The package folders are organized as follows m Libraries CMSIS Cortex Microcontroller Software Interface Standard files STMG32 USB HOST Library USB Host library files STMG32 USB HOST Driver STM32 USB 2 0 OTG peripheral low level driver STMG2F10x StdPeriph Driver STM32 standard peripheral drivers m Project USB HOST EXAMPLES HID KBrd Mouse HID mouse and keyboard demo files USB HOST EXAMPLES MSC Mass Storage Class demo files m Utilities STMS32 EVAL STM3210C EVAL STM3210C EVAL evalboard functions configuration of GPIOs LCD clocks
26. on the user can implement any specific intialization related to his application DeviceAttached called when a USB device is attached It can be useful to informthe user of any device attachement using a display screen DeviceReset called after an USB reset is issued from the host DeviceDisconnect called when a device is disconnected OverCurrentDetected called when an overcurrent is detected on USB VBUS DeviceSpeedDetected called when the device speed is detected DeviceDescAvailable called when a device descriptor is available DeviceAddressAssigned called when the device address is assigned ConfigurationDescAvailable called when configuration interface and endpoints descriptors are available ManufacturingString called when manufacturing string is extracted ProductString called when product string is extractcted SerialNumString called when serial num string is extracted EnumerationDone called when enumeration finished Userlnput called after the end of the enumeration process for prompting the user for further action such as pressing a button to start a host class operation USBH USR DeviceNotSupported called when the detected device is not supported by the current class driver UnrecoveredError called when the core state machine is in HOST ERROR STATE state It allows the user to handle any error by displaying an error message on the LCD screen for example Doc ID 18153 Rev
27. rd devices 0 tees 17 3 Library user API and callback functions 20 3 1 Library user AP 604 42 e Roe ec eddie ved x donde ates 20 3 2 User callback functions 0 0 0 cee eee 20 3 2 1 Class callback functions s s aana 00 ccc eee eens 20 3 2 2 Class independent callback functions 000 cece eee 22 4 D mo firmware asses oro Rx RR eae eee ke ewe eee ee eee 25 4 1 Mass storage class demo 2 0 ccc sells 25 4 1 1 Software initializations 0 tenes 25 4 1 2 Mass storage device enumeration liliis 25 4 1 3 Accessing mass storage device content 00 e eee eee 26 4 1 4 Flash pendrive tests 000 eee eee eee 26 4 2 HID mouse and keyboard demos 00 e eee eee ee 27 4 2 1 InitializationS oeae e a a aE aiie eee 27 4 2 2 Mouse or keyboard device enumeration 0 naaa 27 4 2 3 Mouse demo essseeeesl nn 28 4 2 4 Keyboard demo ueesseeeeeeeee enne 28 4 3 Demo footprints 2 00 eens 28 2 31 Doc ID 18153 Rev 1 ky UM1021 Contents Known limitations Revision history Doc ID 18153 Rev 1 3 31 List of tables UM1021 List of tables Table 1 Table 2 Table 3 Table 4 Table 5 Table 6 Table 7 Table 8 Table 9 Table 10 Table 11 Table 12 Table 13 Table 14 Table 15 Table 16 Table 17 4 31 gelu yi ded dae deh aie Ma Mac eri Ra are eae be Bd w
28. rom user 4 Doc ID 18153 Rev 1 UM1021 Demo firmware 4 4 1 4 1 1 4 1 2 4 Demo firmware Mass storage class demo Software initializations The following code extract from main c file shows the initializations required before calling the USBH_Process for managing the core state machine USB Init is called with parameters defining the class driver which is the MSC class driver and also the user callbacks int main void Setup STM32 Hardware Configuration BSP_Init Init Host Library USBH_Init amp USB_OTG_FS_dev amp MSC_cb amp USR_Callbacks while 1 Host Task handler USBH Process Mass storage device enumeration When attaching a full low speed device to the STM3210C_eval board the LCD displays the following text for example when plugging the Kingston DataTraveler G2 flash pendrive Figure 6 MS device enumeration STM32F105 7 USB HOST DEMO DEVICE ATTACHED DEVICE IS FULL SPEED gt DEVICE SUPPORTS MASS STORAGE CLASS VID 0951h PID 1624h NumEndpoints 2 Manufacturer Kingston Product DataTraveler G2 Serial Number 001CCOEC309BF9C196A50D64 gt ENUMERATION COMPLETED To see the root content of the disk Press Key B3 Doc ID 18153 Rev 1 25 31 Demo firmware UM1021 4 1 3 Note 26 31 Accessing mass storage device content After the end of e
29. s entered whenever there is an unrecovered error from any library state machine in such case a user callback function is called for example for displaying an unrecovered error message Then the host library is reinitialized The core state machine process is implemented by function USBH Process This function should be called periodically from the application main loop The initalization of the USB host library is implemented by function USBH init This function should be called from the user application during initialization More details regarding this function are provided in Section 3 Device enumeration After detecting a full or low speed device the host library proceeds with a basic enumeration of the device The following diagram shows the different steps involved in the device enumeration Figure 4 Device enumeration Get first 8 bytes of device descriptor i USB reset e Get full device descriptor Set device address Y Get configuration descriptor v Get string descriptors MFC product and serial number Set device configuration Doc ID 18153 Rev 1 ky UM1021 USB host library architecture The enumeration state machine is implemented in library function USBH_HandleEnum which is called from the core state machine process USBH_HandleEnum function makes calls to the following library rou
30. t see next section for an overview about the EFSL API The implemented functions in the filesystem interface are Table 10 MSC filesystem interface functions Function Description Allows initalization of the filesystem for example reading if_initinterface capacity of flash pendrive if_readBuf Interface function for a logical page read if_writeBuf Interface function for a logical page write if_TestUnitReady Interface function for testing if unit is ready Interface function for requesting error information using SCSI if_RequestSense command Request Sense For the EFSL filesystem the page size is fixed to 512 bytes Flash pendrives with higher page granularity are not supported EFSL filesystem overview The EFSL Embedded Filesystem Library is an open source library for filesystems It is intended for embedded devices and supports the Microsoft FAT12 16 and 32 filesystems The following table summarizes the EFSL main API functions For more details about EFSL please refer to http efsl be Doc ID 18153 Rev 1 ky UM1021 USB host library architecture Table 11 EFSL main API Function Prototype Description 1 i 3 3 i efs init esint8 efs init EmbeddedFileSystem efs eint8 Initializes the filesystem opts esint8 file fopen File file FileSystem fs file fopen eint8 filename eint8 mode Opens a file file fclose esint8 file fclose F
31. tines implemented in file usbh_stdreq c Table 3 Device enumeration requests Function Description USBH_Get_CfgDesc Get configuration descriptor request USBH_Get_DevDesc Get device descriptor request USBH_Get_StringDesc Get string descriptor request USBH_GetDescriptor Generic get descriptor request USBH_SetCfg Set configuration request USBH SetAddress Set address request USBH_ClrFeature Clear feature request Note USBH SetCfg calls select the default configuration configuration 0 2 2 3 2 2 4 USBH SetAdaress calls set the device address to Ox1 A user callback will be called at the end of enumeration phase in order to enable the user to process the descriptor information such as displaying descriptor data for example For more details please refer to Section 3 Control transfer state machine The control transfer state machine is entered from core or class driver whenever a control transfer is required This state machine implements the standard stages for a control transfer i e the setup stage the optional data stage and finally the status stage The control transfer state machine is implemented in function USBH HandleControl It is called from the core state machine process USB I O requests module The USB I O requests module is located in the low layer of the core It interfaces with the USB low level driver for issuing control bulk or interrupt USB transactions Doc ID 18153 Rev 1 11 31 USB host
32. umeration control transfer state machine USB I O requests USB host channels control For all class related operations the core state machine hands over operation to a specific class driver In the current release version of the USB host libray two class drivers HID and MSC are implemented These class drivers use core layer services for communicating with the low level driver Both the core and the class drivers communicate with the user application mainly through defined callback functions The various host library blocks are described below Doc ID 18153 Rev 1 ky UM1021 USB host library architecture 2 2 Description of the library core 2 2 1 Core state machine The following figure describes the library state machine Figure 3 Core state machine Device connection Event Host Initializations Device disconnection X USB Reset Issued Event HOST ISSUE 9 a CORE RESET Device connected amp USB Reset Issued Y HoST DEV ATTACHED USB Full Low speed device attached HOST ENUMERATION Device enumerated CHOST ERROR STATE HOST_CTRL_XFER HOST USR INPUT User selects to enter in class operation HOST CLASS REQUEST End of class requests calls HOST CLASS u Control transfer Unrecovered error The core state machine shows 8 states m HOST IDLE after host initialization the core starts in th
33. y 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 AN AUTHORIZED ST REPRESENTATIVE ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USE IN 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
Download Pdf Manuals
Related Search
Related Contents
Philips RI4496 bedienungsanleitung-hybrid-insel-wechselrichter-hb GettinG started GUide - Robot Structural Analysis Professional Répertoire Qualité des produits de la Pêche Technicolor - Thomson TM9235 EN User's Manual Indesit WIXXE 167 Washer User Manual Nokia Lumia 520 Bedienungsanleitung BOUILLOIRE INOX SANS FIL Mode d`emploi Philips Headband headphones SHL5001 取扱説明書 - 三菱電機 Copyright © All rights reserved.
Failed to retrieve file