diff --git a/micropython/ports/cc3200/hal/aes.c b/micropython/ports/cc3200/hal/aes.c
index e0e129ef5f75418e1def610b5acf1edb17b5f099..8a1b211baa6abb54066f97245bb1c2384a500736 100644
--- a/micropython/ports/cc3200/hal/aes.c
+++ b/micropython/ports/cc3200/hal/aes.c
@@ -1,1360 +1,1360 @@
-//*****************************************************************************
-//
-//  aes.c
-//
-//  Driver for the AES module.
-//
-//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-//
-//
-//  Redistribution and use in source and binary forms, with or without
-//  modification, are permitted provided that the following conditions
-//  are met:
-//
-//    Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//
-//    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//
-//    Neither the name of Texas Instruments Incorporated nor the names of
-//    its contributors may be used to endorse or promote products derived
-//    from this software without specific prior written permission.
-//
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! \addtogroup AES_Advanced_Encryption_Standard_api
-//! @{
-//
-//*****************************************************************************
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "inc/hw_aes.h"
-#include "inc/hw_dthe.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "inc/hw_nvic.h"
-#include "inc/hw_types.h"
-#include "aes.h"
-#include "debug.h"
-#include "interrupt.h"
-
-#define AES_BLOCK_SIZE_IN_BYTES 16
-
-//*****************************************************************************
-//
-//! Configures the AES module.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32Config is the configuration of the AES module.
-//!
-//! This function configures the AES module based on the specified parameters.
-//! It does not change any DMA- or interrupt-related parameters.
-//!
-//! The ui32Config parameter is a bit-wise OR of a number of configuration
-//! flags. The valid flags are grouped based on their function.
-//!
-//! The direction of the operation is specified with only of following flags:
-//!
-//! - \b AES_CFG_DIR_ENCRYPT - Encryption mode
-//! - \b AES_CFG_DIR_DECRYPT - Decryption mode
-//!
-//! The key size is specified with only one of the following flags:
-//!
-//! - \b AES_CFG_KEY_SIZE_128BIT - Key size of 128 bits
-//! - \b AES_CFG_KEY_SIZE_192BIT - Key size of 192 bits
-//! - \b AES_CFG_KEY_SIZE_256BIT - Key size of 256 bits
-//!
-//! The mode of operation is specified with only one of the following flags.
-//!
-//! - \b AES_CFG_MODE_ECB - Electronic codebook mode
-//! - \b AES_CFG_MODE_CBC - Cipher-block chaining mode
-//! - \b AES_CFG_MODE_CFB - Cipher feedback mode
-//! - \b AES_CFG_MODE_CTR - Counter mode
-//! - \b AES_CFG_MODE_ICM - Integer counter mode
-//! - \b AES_CFG_MODE_XTS - Ciphertext stealing mode
-//! - \b AES_CFG_MODE_XTS_TWEAKJL - XEX-based tweaked-codebook mode with
-//! ciphertext stealing with previous/intermediate tweak value and j loaded
-//! - \b AES_CFG_MODE_XTS_K2IJL - XEX-based tweaked-codebook mode with
-//! ciphertext stealing with key2, i and j loaded
-//! - \b AES_CFG_MODE_XTS_K2ILJ0 - XEX-based tweaked-codebook mode with
-//! ciphertext stealing with key2 and i loaded, j = 0
-//! - \b AES_CFG_MODE_F8 - F8 mode
-//! - \b AES_CFG_MODE_F9 - F9 mode
-//! - \b AES_CFG_MODE_CBCMAC - Cipher block chaining message authentication
-//! code mode
-//! - \b AES_CFG_MODE_GCM - Galois/counter mode
-//! - \b AES_CFG_MODE_GCM_HLY0ZERO - Galois/counter mode with GHASH with H
-//! loaded and Y0-encrypted forced to zero
-//! - \b AES_CFG_MODE_GCM_HLY0CALC - Galois/counter mode with GHASH with H
-//! loaded and Y0-encrypted calculated internally
-//! - \b AES_CFG_MODE_GCM_HY0CALC - Galois/Counter mode with autonomous GHASH
-//! (both H and Y0-encrypted calculated internally)
-//! - \b AES_CFG_MODE_CCM - Counter with CBC-MAC mode
-//!
-//! The following defines are used to specify the counter width.  It is only
-//! required to be defined when using CTR, CCM, or GCM modes, only one of the
-//! following defines must be used to specify the counter width length:
-//!
-//! - \b AES_CFG_CTR_WIDTH_32 - Counter is 32 bits
-//! - \b AES_CFG_CTR_WIDTH_64 - Counter is 64 bits
-//! - \b AES_CFG_CTR_WIDTH_96 - Counter is 96 bits
-//! - \b AES_CFG_CTR_WIDTH_128 - Counter is 128 bits
-//!
-//! Only one of the following defines must be used to specify the length field
-//! for CCM operations (L):
-//!
-//! - \b AES_CFG_CCM_L_2 - 2 bytes
-//! - \b AES_CFG_CCM_L_4 - 4 bytes
-//! - \b AES_CFG_CCM_L_8 - 8 bytes
-//!
-//! Only one of the following defines must be used to specify the length of the
-//! authentication field for CCM operations (M) through the \e ui32Config
-//! argument in the AESConfigSet() function:
-//!
-//! - \b AES_CFG_CCM_M_4 - 4 bytes
-//! - \b AES_CFG_CCM_M_6 - 6 bytes
-//! - \b AES_CFG_CCM_M_8 - 8 bytes
-//! - \b AES_CFG_CCM_M_10 - 10 bytes
-//! - \b AES_CFG_CCM_M_12 - 12 bytes
-//! - \b AES_CFG_CCM_M_14 - 14 bytes
-//! - \b AES_CFG_CCM_M_16 - 16 bytes
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESConfigSet(uint32_t ui32Base, uint32_t ui32Config)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32Config & AES_CFG_DIR_ENCRYPT) ||
-           (ui32Config & AES_CFG_DIR_DECRYPT));
-    ASSERT((ui32Config & AES_CFG_KEY_SIZE_128BIT) ||
-           (ui32Config & AES_CFG_KEY_SIZE_192BIT) ||
-           (ui32Config & AES_CFG_KEY_SIZE_256BIT));
-    ASSERT((ui32Config & AES_CFG_MODE_ECB) ||
-           (ui32Config & AES_CFG_MODE_CBC) ||
-           (ui32Config & AES_CFG_MODE_CTR) ||
-           (ui32Config & AES_CFG_MODE_ICM) ||
-           (ui32Config & AES_CFG_MODE_CFB) ||
-           (ui32Config & AES_CFG_MODE_XTS_TWEAKJL) ||
-           (ui32Config & AES_CFG_MODE_XTS_K2IJL) ||
-           (ui32Config & AES_CFG_MODE_XTS_K2ILJ0) ||
-           (ui32Config & AES_CFG_MODE_F8) ||
-           (ui32Config & AES_CFG_MODE_F9) ||
-           (ui32Config & AES_CFG_MODE_CTR) ||
-           (ui32Config & AES_CFG_MODE_CBCMAC) ||
-           (ui32Config & AES_CFG_MODE_GCM_HLY0ZERO) ||
-           (ui32Config & AES_CFG_MODE_GCM_HLY0CALC) ||
-           (ui32Config & AES_CFG_MODE_GCM_HY0CALC) ||
-           (ui32Config & AES_CFG_MODE_CCM));
-    ASSERT(((ui32Config & AES_CFG_MODE_CTR) ||
-            (ui32Config & AES_CFG_MODE_GCM_HLY0ZERO) ||
-            (ui32Config & AES_CFG_MODE_GCM_HLY0CALC) ||
-            (ui32Config & AES_CFG_MODE_GCM_HY0CALC) ||
-            (ui32Config & AES_CFG_MODE_CCM)) &&
-           ((ui32Config & AES_CFG_CTR_WIDTH_32) ||
-            (ui32Config & AES_CFG_CTR_WIDTH_64) ||
-            (ui32Config & AES_CFG_CTR_WIDTH_96) ||
-            (ui32Config & AES_CFG_CTR_WIDTH_128)));
-    ASSERT((ui32Config & AES_CFG_MODE_CCM) &&
-           ((ui32Config & AES_CFG_CCM_L_2) ||
-            (ui32Config & AES_CFG_CCM_L_4) ||
-            (ui32Config & AES_CFG_CCM_L_8)) &&
-           ((ui32Config & AES_CFG_CCM_M_4) ||
-            (ui32Config & AES_CFG_CCM_M_6) ||
-            (ui32Config & AES_CFG_CCM_M_8) ||
-            (ui32Config & AES_CFG_CCM_M_10) ||
-            (ui32Config & AES_CFG_CCM_M_12) ||
-            (ui32Config & AES_CFG_CCM_M_14) ||
-            (ui32Config & AES_CFG_CCM_M_16)));
-
-    //
-    // Backup the save context field before updating the register.
-    //
-    if(HWREG(ui32Base + AES_O_CTRL) & AES_CTRL_SAVE_CONTEXT)
-    {
-        ui32Config |= AES_CTRL_SAVE_CONTEXT;
-    }
-
-    //
-    // Write the CTRL register with the new value
-    //
-    HWREG(ui32Base + AES_O_CTRL) = ui32Config;
-}
-
-//*****************************************************************************
-//
-//! Writes the key 1 configuration registers, which are used for encryption or
-//! decryption.
-//!
-//! \param ui32Base is the base address for the AES module.
-//! \param pui8Key is an array of bytes, containing the key to be
-//! configured.  The least significant word in the 0th index.
-//! \param ui32Keysize is the size of the key, which must be one of the
-//! following values:  \b AES_CFG_KEY_SIZE_128, \b AES_CFG_KEY_SIZE_192, or
-//! \b AES_CFG_KEY_SIZE_256.
-//!
-//! This function writes key 1 configuration registers based on the key
-//! size.  This function is used in all modes.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESKey1Set(uint32_t ui32Base, uint8_t *pui8Key, uint32_t ui32Keysize)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32Keysize == AES_CFG_KEY_SIZE_128BIT) ||
-           (ui32Keysize == AES_CFG_KEY_SIZE_192BIT) ||
-           (ui32Keysize == AES_CFG_KEY_SIZE_256BIT));
-
-    //
-    // With all key sizes, the first 4 words are written.
-    //
-    HWREG(ui32Base + AES_O_KEY1_0) = * ((uint32_t *)(pui8Key + 0));
-    HWREG(ui32Base + AES_O_KEY1_1) = * ((uint32_t *)(pui8Key + 4));
-    HWREG(ui32Base + AES_O_KEY1_2) = * ((uint32_t *)(pui8Key + 8));
-    HWREG(ui32Base + AES_O_KEY1_3) = * ((uint32_t *)(pui8Key + 12));
-
-    //
-    // The key is 192 or 256 bits.  Write the next 2 words.
-    //
-    if(ui32Keysize != AES_CFG_KEY_SIZE_128BIT)
-    {
-        HWREG(ui32Base + AES_O_KEY1_4) = * ((uint32_t *)(pui8Key + 16));
-        HWREG(ui32Base + AES_O_KEY1_5) = * ((uint32_t *)(pui8Key + 20));
-    }
-
-    //
-    // The key is 256 bits.  Write the last 2 words.
-    //
-    if(ui32Keysize == AES_CFG_KEY_SIZE_256BIT)
-    {
-        HWREG(ui32Base + AES_O_KEY1_6) = * ((uint32_t *)(pui8Key + 24));
-        HWREG(ui32Base + AES_O_KEY1_7) = * ((uint32_t *)(pui8Key + 28));
-    }
-}
-
-//*****************************************************************************
-//
-//! Writes the key 2 configuration registers, which are used for encryption or
-//! decryption.
-//!
-//! \param ui32Base is the base address for the AES module.
-//! \param pui8Key is an array of bytes, containing the key to be
-//! configured.  The least significant word in the 0th index.
-//! \param ui32Keysize is the size of the key, which must be one of the
-//! following values:  \b AES_CFG_KEY_SIZE_128, \b AES_CFG_KEY_SIZE_192, or
-//! \b AES_CFG_KEY_SIZE_256.
-//!
-//! This function writes the key 2 configuration registers based on the key
-//! size.  This function is used in the F8, F9, XTS, CCM, and CBC-MAC modes.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESKey2Set(uint32_t ui32Base, uint8_t *pui8Key, uint32_t ui32Keysize)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32Keysize == AES_CFG_KEY_SIZE_128BIT) ||
-           (ui32Keysize == AES_CFG_KEY_SIZE_192BIT) ||
-           (ui32Keysize == AES_CFG_KEY_SIZE_256BIT));
-
-    //
-    // With all key sizes, the first 4 words are written.
-    //
-    HWREG(ui32Base + AES_O_KEY2_0) = * ((uint32_t *)(pui8Key + 0));
-    HWREG(ui32Base + AES_O_KEY2_1) = * ((uint32_t *)(pui8Key + 4));
-    HWREG(ui32Base + AES_O_KEY2_2) = * ((uint32_t *)(pui8Key + 8));
-    HWREG(ui32Base + AES_O_KEY2_3) = * ((uint32_t *)(pui8Key + 12));
-
-    //
-    // The key is 192 or 256 bits.  Write the next 2 words.
-    //
-    if(ui32Keysize != AES_CFG_KEY_SIZE_128BIT)
-    {
-        HWREG(ui32Base + AES_O_KEY2_4) = * ((uint32_t *)(pui8Key + 16));
-        HWREG(ui32Base + AES_O_KEY2_5) = * ((uint32_t *)(pui8Key + 20));
-    }
-
-    //
-    // The key is 256 bits.  Write the last 2 words.
-    //
-    if(ui32Keysize == AES_CFG_KEY_SIZE_256BIT)
-    {
-        HWREG(ui32Base + AES_O_KEY2_6) = * ((uint32_t *)(pui8Key + 24));
-        HWREG(ui32Base + AES_O_KEY2_7) = * ((uint32_t *)(pui8Key + 28));
-    }
-}
-
-//*****************************************************************************
-//
-//! Writes key 3 configuration registers, which are used for encryption or
-//! decryption.
-//!
-//! \param ui32Base is the base address for the AES module.
-//! \param pui8Key is a pointer to an array bytes, containing
-//! the key to be configured. The least significant word is in the 0th index.
-//!
-//! This function writes the key 2 configuration registers with key 3 data
-//! used in CBC-MAC and F8 modes.  This key is always 128 bits.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESKey3Set(uint32_t ui32Base, uint8_t *pui8Key)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the key into the upper 4 key registers
-    //
-    HWREG(ui32Base + AES_O_KEY2_4) = * ((uint32_t *)(pui8Key + 0));
-    HWREG(ui32Base + AES_O_KEY2_5) = * ((uint32_t *)(pui8Key + 4));
-    HWREG(ui32Base + AES_O_KEY2_6) = * ((uint32_t *)(pui8Key + 8));
-    HWREG(ui32Base + AES_O_KEY2_7) = * ((uint32_t *)(pui8Key + 12));
-}
-
-//*****************************************************************************
-//
-//! Writes the Initial Vector (IV) register, needed in some of the AES Modes.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8IVdata is an array of 16 bytes (128 bits), containing the IV
-//! value to be configured. The least significant word is in the 0th index.
-//!
-//! This functions writes the initial vector registers in the AES module.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIVSet(uint32_t ui32Base, uint8_t *pui8IVdata)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the initial vector registers.
-    //
-    HWREG(ui32Base + AES_O_IV_IN_0) = *((uint32_t *)(pui8IVdata+0));
-    HWREG(ui32Base + AES_O_IV_IN_1) = *((uint32_t *)(pui8IVdata+4));
-    HWREG(ui32Base + AES_O_IV_IN_2) = *((uint32_t *)(pui8IVdata+8));
-    HWREG(ui32Base + AES_O_IV_IN_3) = *((uint32_t *)(pui8IVdata+12));
-}
-
-
-//*****************************************************************************
-//
-//! Reads the Initial Vector (IV) register, needed in some of the AES Modes.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8IVdata is pointer to an array of 16 bytes.
-//!
-//! This functions reads the initial vector registers in the AES module.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIVGet(uint32_t ui32Base, uint8_t *pui8IVdata)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the initial vector registers.
-    //
-    *((uint32_t *)(pui8IVdata+ 0)) = HWREG(ui32Base + AES_O_IV_IN_0);
-    *((uint32_t *)(pui8IVdata+ 4)) = HWREG(ui32Base + AES_O_IV_IN_1);
-    *((uint32_t *)(pui8IVdata+ 8)) = HWREG(ui32Base + AES_O_IV_IN_2);
-    *((uint32_t *)(pui8IVdata+12)) = HWREG(ui32Base + AES_O_IV_IN_3);
-}
-
-//*****************************************************************************
-//
-//! Saves the tag registers to a user-defined location.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8TagData is pointer to the location that stores the tag data.
-//!
-//! This function stores the tag data for use authenticated encryption and
-//! decryption operations.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESTagRead(uint32_t ui32Base, uint8_t *pui8TagData)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Read the tag data.
-    //
-    *((uint32_t *)(pui8TagData+0)) = HWREG((ui32Base + AES_O_TAG_OUT_0));
-    *((uint32_t *)(pui8TagData+4)) = HWREG((ui32Base + AES_O_TAG_OUT_1));
-    *((uint32_t *)(pui8TagData+8)) = HWREG((ui32Base + AES_O_TAG_OUT_2));
-    *((uint32_t *)(pui8TagData+12)) = HWREG((ui32Base + AES_O_TAG_OUT_3));
-}
-
-//*****************************************************************************
-//
-//! Used to set the write crypto data length in the AES module.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui64Length is the crypto data length in bytes.
-//!
-//! This function stores the cryptographic data length in blocks for all modes.
-//! Data lengths up to (2^61 - 1) bytes are allowed.  For GCM, any value up
-//! to (2^36 - 2) bytes are allowed because a 32-bit block counter is used.  For
-//! basic modes (ECB/CBC/CTR/ICM/CFB128), zero can be programmed into the
-//! length field, indicating that the length is infinite.
-//!
-//! When this function is called, the engine is triggered to start using
-//! this context.
-//!
-//! \note This length does not include the authentication-only data used in
-//! some modes.  Use the AESAuthLengthSet() function to specify the
-//! authentication data length.
-//!
-//! \return None
-//
-//*****************************************************************************
-void
-AESDataLengthSet(uint32_t ui32Base, uint64_t ui64Length)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the length register by shifting the 64-bit ui64Length.
-    //
-    HWREG(ui32Base + AES_O_C_LENGTH_0) = (uint32_t)(ui64Length);
-    HWREG(ui32Base + AES_O_C_LENGTH_1) = (uint32_t)(ui64Length >> 32);
-}
-
-//*****************************************************************************
-//
-//! Sets the optional additional authentication data (AAD) length.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32Length is the length in bytes.
-//!
-//! This function is only used to write the authentication data length in the
-//! combined modes (GCM or CCM) and XTS mode.  Supported AAD lengths for CCM
-//! are from 0 to (2^16 - 28) bytes.  For GCM, any value up to (2^32 - 1) can
-//! be used.  For XTS mode, this register is used to load j.  Loading of j is
-//! only required if j != 0.  j represents the sequential number of the 128-bit
-//! blocks inside the data unit.  Consequently, j must be multiplied by 16
-//! when passed to this function, thereby placing the block number in
-//! bits [31:4] of the register.
-//!
-//! When this function is called, the engine is triggered to start using
-//! this context for GCM and CCM.
-//!
-//! \return None
-//
-//*****************************************************************************
-void
-AESAuthDataLengthSet(uint32_t ui32Base, uint32_t ui32Length)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the length into the register.
-    //
-    HWREG(ui32Base + AES_O_AUTH_LENGTH) = ui32Length;
-}
-
-//*****************************************************************************
-//
-//! Reads plaintext/ciphertext from data registers without blocking.
-//! This api writes data in blocks
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8Dest is a pointer to an array of words of data.
-//! \param ui8Length the length can be from 1 to 16
-//!
-//! This function reads a block of either plaintext or ciphertext out of the
-//! AES module.  If the output data is not ready, the function returns
-//! false.  If the read completed successfully, the function returns true.
-//! A block is 16 bytes or 4 words.
-//!
-//! \return true or false.
-//
-//*****************************************************************************
-bool
-AESDataReadNonBlocking(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
-{
-	volatile uint32_t pui32Dest[4];
-	uint8_t ui8BytCnt;
-	uint8_t *pui8DestTemp;
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    if((ui8Length == 0)||(ui8Length>16))
-    {
-       	return(false);
-    }
-
-    //
-    // Check if the output is ready before reading the data.  If it not ready,
-    // return false.
-    //
-    if((AES_CTRL_OUTPUT_READY & (HWREG(ui32Base + AES_O_CTRL))) == 0)
-    {
-        return(false);
-    }
-
-    //
-    // Read a block of data from the data registers
-    //
-    pui32Dest[0] = HWREG(ui32Base + AES_O_DATA_IN_3);
-    pui32Dest[1] = HWREG(ui32Base + AES_O_DATA_IN_2);
-    pui32Dest[2] = HWREG(ui32Base + AES_O_DATA_IN_1);
-    pui32Dest[3] = HWREG(ui32Base + AES_O_DATA_IN_0);
-
-    //
-    //Copy the data to a block memory
-    //
-    pui8DestTemp = (uint8_t *)pui32Dest;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-    {
-     	*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
-    }
-    //
-    // Read successful, return true.
-    //
-    return(true);
-}
-
-
-//*****************************************************************************
-//
-//! Reads plaintext/ciphertext from data registers with blocking.
-//! This api writes data in blocks
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8Dest is a pointer to an array of words.
-//! \param ui8Length is the length of data in bytes to be read.
-//!        ui8Length can be from 1 to 16
-//!
-//! This function reads a block of either plaintext or ciphertext out of the
-//! AES module.  If the output is not ready, the function waits until it
-//! is ready. A block is 16 bytes or 4 words.
-//!
-//! \return None.
-//
-//*****************************************************************************
-
-void
-AESDataRead(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
-{
-	volatile uint32_t pui32Dest[4];
-	uint8_t ui8BytCnt;
-	uint8_t *pui8DestTemp;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    if((ui8Length == 0)||(ui8Length>16))
-   	{
-       	return;
-    }
-
-
-    //
-    // Wait for the output to be ready before reading the data.
-    //
-    while((AES_CTRL_OUTPUT_READY & (HWREG(ui32Base + AES_O_CTRL))) == 0)
-    {
-    }
-
-    //
-    // Read a block of data from the data registers
-    //
-    pui32Dest[0] = HWREG(ui32Base + AES_O_DATA_IN_3);
-    pui32Dest[1] = HWREG(ui32Base + AES_O_DATA_IN_2);
-    pui32Dest[2] = HWREG(ui32Base + AES_O_DATA_IN_1);
-    pui32Dest[3] = HWREG(ui32Base + AES_O_DATA_IN_0);
-    //
-    //Copy the data to a block memory
-    //
-    pui8DestTemp = (uint8_t *)pui32Dest;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-   	{
-    	*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
-   	}
-
-    return;
-}
-
-//*****************************************************************************
-//
-//! Writes plaintext/ciphertext to data registers without blocking.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8Src is a pointer to an array of words of data.
-//! \param ui8Length the length can be from 1 to 16
-//!
-//! This function writes a block of either plaintext or ciphertext into the
-//! AES module.  If the input is not ready, the function returns false
-//! If the write completed successfully, the function returns true.
-//!
-//! \return True or false.
-//
-//*****************************************************************************
-bool
-AESDataWriteNonBlocking(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
-{
-	volatile uint32_t pui32Src[4]={0,0,0,0};
-	uint8_t ui8BytCnt;
-	uint8_t *pui8SrcTemp;
-
-	//
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    if((ui8Length == 0)||(ui8Length>16))
-   	{
-      	return(false);
-    }
-
-    //
-    // Check if the input is ready.  If not, then return false.
-    //
-    if(!(AES_CTRL_INPUT_READY & (HWREG(ui32Base + AES_O_CTRL))))
-    {
-        return(false);
-    }
-
-
-    //
-    //Copy the data to a block memory
-    //
-    pui8SrcTemp = (uint8_t *)pui32Src;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-	{
-		*(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
-	}
-    //
-    // Write a block of data into the data registers.
-    //
-    HWREG(ui32Base + AES_O_DATA_IN_3) = pui32Src[0];
-    HWREG(ui32Base + AES_O_DATA_IN_2) = pui32Src[1];
-    HWREG(ui32Base + AES_O_DATA_IN_1) = pui32Src[2];
-    HWREG(ui32Base + AES_O_DATA_IN_0) = pui32Src[3];
-
-    //
-    // Write successful, return true.
-    //
-    return(true);
-}
-
-
-//*****************************************************************************
-//
-//! Writes plaintext/ciphertext to data registers with blocking.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8Src is a pointer to an array of bytes.
-//! \param ui8Length the length can be from 1 to 16
-//!
-//! This function writes a block of either plaintext or ciphertext into the
-//! AES module.  If the input is not ready, the function waits until it is
-//! ready before performing the write.
-//!
-//! \return None.
-//
-//*****************************************************************************
-
-void
-AESDataWrite(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
-{
-	volatile uint32_t pui32Src[4]={0,0,0,0};
-	uint8_t ui8BytCnt;
-	uint8_t *pui8SrcTemp;
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    if((ui8Length == 0)||(ui8Length>16))
-	{
-    	return;
-	}
-    //
-    // Wait for input ready.
-    //
-    while((AES_CTRL_INPUT_READY & (HWREG(ui32Base + AES_O_CTRL))) == 0)
-    {
-    }
-
-    //
-    //Copy the data to a block memory
-    //
-    pui8SrcTemp = (uint8_t *)pui32Src;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-   	{
-   		*(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
-   	}
-
-    //
-    // Write a block of data into the data registers.
-    //
-    HWREG(ui32Base + AES_O_DATA_IN_3) = pui32Src[0];
-    HWREG(ui32Base + AES_O_DATA_IN_2) = pui32Src[1];
-    HWREG(ui32Base + AES_O_DATA_IN_1) = pui32Src[2];
-    HWREG(ui32Base + AES_O_DATA_IN_0) = pui32Src[3];
-}
-
-
-//*****************************************************************************
-//
-//! Used to process(transform) blocks of data, either encrypt or decrypt it.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8Src is a pointer to the memory location where the input data
-//! is stored.
-//! \param pui8Dest is a pointer to the memory location output is written.
-//! \param ui32Length is the length of the cryptographic data in bytes.
-//!
-//! This function iterates the encryption or decryption mechanism number over
-//! the data length.  Before calling this function, ensure that the AES
-//! module is properly configured the key, data size, mode, etc.  Only ECB,
-//! CBC, CTR, ICM, CFB, XTS and F8 operating modes should be used.  The data
-//! is processed in 4-word (16-byte) blocks.
-//!
-//! \note This function only supports values of \e ui32Length less than 2^32,
-//! because the memory size is restricted to between 0 to 2^32 bytes.
-//!
-//! \return Returns true if data was processed successfully.  Returns false
-//! if data processing failed.
-//
-//*****************************************************************************
-bool
-AESDataProcess(uint32_t ui32Base, uint8_t *pui8Src, uint8_t *pui8Dest,
-               uint32_t ui32Length)
-{
-    uint32_t ui32Count, ui32BlkCount, ui32ByteCount;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the length register first, which triggers the engine to start
-    // using this context.
-    //
-    AESDataLengthSet(AES_BASE, (uint64_t) ui32Length);
-
-    //
-    // Now loop until the blocks are written.
-    //
-    ui32BlkCount = ui32Length/16;
-    for(ui32Count = 0; ui32Count < ui32BlkCount; ui32Count += 1)
-    {
-        //
-        // Write the data registers.
-        //
-        AESDataWrite(ui32Base, pui8Src + (ui32Count*16) ,16);
-
-        //
-        // Read the data registers.
-        //
-        AESDataRead(ui32Base, pui8Dest + (ui32Count*16) ,16);
-
-    }
-
-    //
-    //Now handle the residue bytes
-    //
-    ui32ByteCount = ui32Length%16;
-    if(ui32ByteCount)
-    {
-    	//
-    	// Write the data registers.
-    	//
-    	AESDataWrite(ui32Base, pui8Src + (16*ui32BlkCount) ,ui32ByteCount);
-
-    	//
-    	// Read the data registers.
-    	//
-        AESDataRead(ui32Base, pui8Dest + (16*ui32BlkCount) ,ui32ByteCount);
-    }
-
-
-
-    //
-    // Return true to indicate successful completion of the function.
-    //
-    return(true);
-}
-//*****************************************************************************
-//
-//! Used to generate message authentication code (MAC) using CBC-MAC and F9 mode.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pui8Src is a pointer to the memory location where the input data
-//! is stored.
-//! \param ui32Length  is the length of the cryptographic data in bytes.
-//! \param pui8Tag is a pointer to a 4-word array where the hash tag is
-//! written.
-//!
-//! This function processes data to produce a hash tag that can be used tor
-//! authentication.   Before calling this function, ensure that the AES
-//! module is properly configured the key, data size, mode, etc.  Only
-//! CBC-MAC and F9 modes should be used.
-//!
-//! \return Returns true if data was processed successfully.  Returns false
-//! if data processing failed.
-//
-//*****************************************************************************
-bool
-AESDataMAC(uint32_t ui32Base, uint8_t *pui8Src, uint32_t ui32Length,
-            uint8_t *pui8Tag)
-{
-    uint32_t ui32Count, ui32BlkCount, ui32ByteCount;
-	//
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Write the length register first, which triggers the engine to start
-    // using this context.
-    //
-    AESDataLengthSet(AES_BASE, (uint64_t) ui32Length);
-
-    //
-    // Write the data registers.
-    //
-
-    //
-    // Now loop until the blocks are written.
-    //
-    ui32BlkCount = ui32Length/16;
-    for(ui32Count = 0; ui32Count < ui32BlkCount; ui32Count += 1)
-    {
-	   //
-	   // Write the data registers.
-	   //
-	   AESDataWrite(ui32Base, pui8Src + ui32Count*16 ,16);
-    }
-
-    //
-    //Now handle the residue bytes
-    //
-    ui32ByteCount = ui32Length%16;
-    if(ui32ByteCount)
-    {
-	   //
-	   // Write the data registers.
-	   //
-	   AESDataWrite(ui32Base, pui8Src + (ui32Count*ui32BlkCount) ,ui32ByteCount);
-    }
-
-    //
-    // Wait for the context data regsiters to be ready.
-    //
-    while((AES_CTRL_SVCTXTRDY & (HWREG(AES_BASE + AES_O_CTRL))) == 0)
-    {
-    }
-
-    //
-    // Read the hash tag value.
-    //
-    AESTagRead(AES_BASE, pui8Tag);
-
-    //
-    // Return true to indicate successful completion of the function.
-    //
-    return(true);
-}
-
-//*****************************************************************************
-//
-//! Used for Authenticated encryption (AE) of the data. Processes and authenticates blocks of data,
-//! either encrypt the data or decrypt the data.
-//!
-//! \param ui32Base  is the base address of the AES module.
-//! \param pui8Src is a pointer to the memory location where the input data
-//! is stored. The data must be padded to the 16-byte boundary.
-//! \param pui8Dest is a pointer to the memory location output is written.
-//! The space for written data must be rounded up to the 16-byte boundary.
-//! \param ui32Length is the length of the cryptographic data in bytes.
-//! \param pui8AuthSrc is a pointer to the memory location where the
-//! additional authentication data is stored.  The data must be padded to the
-//! 16-byte boundary.
-//! \param ui32AuthLength is the length of the additional authentication
-//! data in bytes.
-//! \param pui8Tag is a pointer to a 4-word array where the hash tag is
-//! written.
-//!
-//! This function encrypts or decrypts blocks of data in addition to
-//! authentication data.  A hash tag is also produced.  Before calling this
-//! function, ensure that the AES module is properly configured the key,
-//! data size, mode, etc.  Only CCM and GCM modes should be used.
-//!
-//! \return Returns true if data was processed successfully.  Returns false
-//! if data processing failed.
-//
-//*****************************************************************************
-bool
-AESDataProcessAE(uint32_t ui32Base, uint8_t *pui8Src, uint8_t *pui8Dest,
-                   uint32_t ui32Length, uint8_t *pui8AuthSrc,
-                   uint32_t ui32AuthLength, uint8_t *pui8Tag)
-{
-    uint32_t ui32Count;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Set the data length.
-    //
-    AESDataLengthSet(AES_BASE, (uint64_t) ui32Length);
-
-    //
-    // Set the additional authentication data length.
-    //
-    AESAuthDataLengthSet(AES_BASE, ui32AuthLength);
-
-    //
-    // Now loop until the authentication data blocks are written.
-    //
-    for(ui32Count = 0; ui32Count < ui32AuthLength; ui32Count += 16)
-    {
-        //
-        // Write the data registers.
-        //
-        AESDataWrite(ui32Base, pui8AuthSrc + (ui32Count),16);
-    }
-
-    //
-    // Now loop until the data blocks are written.
-    //
-    for(ui32Count = 0; ui32Count < ui32Length; ui32Count += 16)
-    {
-        //
-        // Write the data registers.
-        //
-        AESDataWrite(ui32Base, pui8Src + (ui32Count),16);
-
-        //
-        //
-        // Read the data registers.
-        //
-        AESDataRead(ui32Base, pui8Dest + (ui32Count),16);
-    }
-
-    //
-    // Wait for the context data regsiters to be ready.
-    //
-    while((AES_CTRL_SVCTXTRDY & (HWREG(AES_BASE + AES_O_CTRL))) == 0)
-    {
-    }
-
-    //
-    // Read the hash tag value.
-    //
-    AESTagRead(AES_BASE, pui8Tag);
-
-    //
-    // Return true to indicate successful completion of the function.
-    //
-    return(true);
-}
-
-//*****************************************************************************
-//
-//! Returns the current AES module interrupt status.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param bMasked is \b false if the raw interrupt status is required and
-//! \b true if the masked interrupt status is required.
-//!
-//! \return Returns a bit mask of the interrupt sources, which is a logical OR
-//! of any of the following:
-//!
-//! - \b AES_INT_CONTEXT_IN - Context interrupt
-//! - \b AES_INT_CONTEXT_OUT - Authentication tag (and IV) interrupt.
-//! - \b AES_INT_DATA_IN - Data input interrupt
-//! - \b AES_INT_DATA_OUT - Data output interrupt
-//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
-//! interrupt
-//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//
-//*****************************************************************************
-uint32_t
-AESIntStatus(uint32_t ui32Base, bool bMasked)
-{
-    uint32_t ui32Temp;
-    uint32_t ui32IrqEnable;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Read the IRQ status register and return the value.
-    //
-    if(bMasked)
-    {
-        ui32Temp = HWREG(DTHE_BASE + DTHE_O_AES_MIS);
-        ui32IrqEnable = HWREG(ui32Base + AES_O_IRQENABLE);
-        return((HWREG(ui32Base + AES_O_IRQSTATUS) &
-                ui32IrqEnable) | ((ui32Temp & 0x0000000F) << 16));
-    }
-    else
-    {
-        ui32Temp = HWREG(DTHE_BASE + DTHE_O_AES_RIS);
-        return(HWREG(ui32Base + AES_O_IRQSTATUS) |
-               ((ui32Temp & 0x0000000F) << 16));
-    }
-}
-
-//*****************************************************************************
-//
-//! Enables AES module interrupts.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32IntFlags is a bit mask of the interrupt sources to enable.
-//!
-//! This function enables the interrupts in the AES module. The \e ui32IntFlags
-//! parameter is the logical OR of any of the following:
-//!
-//! - \b AES_INT_CONTEXT_IN - Context interrupt
-//! - \b AES_INT_CONTEXT_OUT - Authentication tag (and IV) interrupt
-//! - \b AES_INT_DATA_IN - Data input interrupt
-//! - \b AES_INT_DATA_OUT - Data output interrupt
-//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
-//! interrupt
-//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//!
-//! \note Interrupts that have been previously been enabled are not disabled
-//! when this function is called.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32IntFlags == AES_INT_CONTEXT_IN) ||
-           (ui32IntFlags == AES_INT_CONTEXT_OUT) ||
-           (ui32IntFlags == AES_INT_DATA_IN) ||
-           (ui32IntFlags == AES_INT_DATA_OUT) ||
-           (ui32IntFlags == AES_INT_DMA_CONTEXT_IN) ||
-           (ui32IntFlags == AES_INT_DMA_CONTEXT_OUT) ||
-           (ui32IntFlags == AES_INT_DMA_DATA_IN) ||
-           (ui32IntFlags == AES_INT_DMA_DATA_OUT));
-
-    //
-    // Set the flags.
-    //
-    HWREG(DTHE_BASE + DTHE_O_AES_IM) &= ~((ui32IntFlags & 0x000F0000) >> 16);
-    HWREG(ui32Base + AES_O_IRQENABLE) |= ui32IntFlags & 0x0000ffff;
-}
-
-//*****************************************************************************
-//
-//! Disables AES module interrupts.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32IntFlags is a bit mask of the interrupt sources to disable.
-//!
-//! This function disables the interrupt sources in the AES module. The
-//! \e ui32IntFlags parameter is the logical OR of any of the following:
-//!
-//! - \b AES_INT_CONTEXT_IN - Context interrupt
-//! - \b AES_INT_CONTEXT_OUT - Authentication tag (and IV) interrupt
-//! - \b AES_INT_DATA_IN - Data input interrupt
-//! - \b AES_INT_DATA_OUT - Data output interrupt
-//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
-//! interrupt
-//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//!
-//! \note The DMA done interrupts are the only interrupts that can be cleared.
-//! The remaining interrupts can be disabled instead using AESIntDisable().
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32IntFlags == AES_INT_CONTEXT_IN) ||
-           (ui32IntFlags == AES_INT_CONTEXT_OUT) ||
-           (ui32IntFlags == AES_INT_DATA_IN) ||
-           (ui32IntFlags == AES_INT_DATA_OUT) ||
-           (ui32IntFlags == AES_INT_DMA_CONTEXT_IN) ||
-           (ui32IntFlags == AES_INT_DMA_CONTEXT_OUT) ||
-           (ui32IntFlags == AES_INT_DMA_DATA_IN) ||
-           (ui32IntFlags == AES_INT_DMA_DATA_OUT));
-
-    //
-    // Clear the flags.
-    //
-    HWREG(DTHE_BASE + DTHE_O_AES_IM) |= ((ui32IntFlags & 0x000F0000) >> 16);
-    HWREG(ui32Base + AES_O_IRQENABLE) &= ~(ui32IntFlags & 0x0000ffff);
-}
-
-//*****************************************************************************
-//
-//! Clears AES module interrupts.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32IntFlags is a bit mask of the interrupt sources to disable.
-//!
-//! This function clears the interrupt sources in the AES module.  The
-//! \e ui32IntFlags parameter is the logical OR of any of the following:
-//!
-//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
-//! interrupt
-//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//!
-//! \note Only the DMA done interrupts can be cleared.  The remaining
-//! interrupts should be disabled with AESIntDisable().
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32IntFlags == AES_INT_DMA_CONTEXT_IN) ||
-           (ui32IntFlags == AES_INT_DMA_CONTEXT_OUT) ||
-           (ui32IntFlags == AES_INT_DMA_DATA_IN) ||
-           (ui32IntFlags == AES_INT_DMA_DATA_OUT));
-
-    HWREG(DTHE_BASE + DTHE_O_AES_IC) = ((ui32IntFlags >> 16) & 0x0000000F);
-}
-
-//*****************************************************************************
-//
-//! Registers an interrupt handler for the AES module.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param pfnHandler is a pointer to the function to be called when the
-//! enabled AES interrupts occur.
-//!
-//! This function registers the interrupt handler in the interrupt vector
-//! table, and enables AES interrupts on the interrupt controller; specific AES
-//! interrupt sources must be enabled using AESIntEnable().  The interrupt
-//! handler being registered must clear the source of the interrupt using
-//! AESIntClear().
-//!
-//! If the application is using a static interrupt vector table stored in
-//! flash, then it is not necessary to register the interrupt handler this way.
-//! Instead, IntEnable() is used to enable AES interrupts on the
-//! interrupt controller.
-//!
-//! \sa IntRegister() for important information about registering interrupt
-//! handlers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Register the interrupt handler.
-    //
-    IntRegister(INT_AES, pfnHandler);
-
-    //
-    // Enable the interrupt
-    //
-    IntEnable(INT_AES);
-}
-
-//*****************************************************************************
-//
-//! Unregisters an interrupt handler for the AES module.
-//!
-//! \param ui32Base is the base address of the AES module.
-//!
-//! This function unregisters the previously registered interrupt handler and
-//! disables the interrupt in the interrupt controller.
-//!
-//! \sa IntRegister() for important information about registering interrupt
-//! handlers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESIntUnregister(uint32_t ui32Base)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-
-    //
-    // Disable the interrupt.
-    //
-    IntDisable(INT_AES);
-
-    //
-    // Unregister the interrupt handler.
-    //
-    IntUnregister(INT_AES);
-}
-
-//*****************************************************************************
-//
-//! Enables uDMA requests for the AES module.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32Flags is a bit mask of the uDMA requests to be enabled.
-//!
-//! This function enables the uDMA request sources in the AES module.
-//! The \e ui32Flags parameter is the logical OR of any of the following:
-//!
-//! - \b AES_DMA_DATA_IN
-//! - \b AES_DMA_DATA_OUT
-//! - \b AES_DMA_CONTEXT_IN
-//! - \b AES_DMA_CONTEXT_OUT
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32Flags == AES_DMA_DATA_IN) ||
-           (ui32Flags == AES_DMA_DATA_OUT) ||
-           (ui32Flags == AES_DMA_CONTEXT_IN) ||
-           (ui32Flags == AES_DMA_CONTEXT_OUT));
-
-    //
-    // Set the flags in the current register value.
-    //
-    HWREG(ui32Base + AES_O_SYSCONFIG) |= ui32Flags;
-}
-
-//*****************************************************************************
-//
-//! Disables uDMA requests for the AES module.
-//!
-//! \param ui32Base is the base address of the AES module.
-//! \param ui32Flags is a bit mask of the uDMA requests to be disabled.
-//!
-//! This function disables the uDMA request sources in the AES module.
-//! The \e ui32Flags parameter is the logical OR of any of the
-//! following:
-//!
-//! - \b AES_DMA_DATA_IN
-//! - \b AES_DMA_DATA_OUT
-//! - \b AES_DMA_CONTEXT_IN
-//! - \b AES_DMA_CONTEXT_OUT
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-AESDMADisable(uint32_t ui32Base, uint32_t ui32Flags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == AES_BASE);
-    ASSERT((ui32Flags == AES_DMA_DATA_IN) ||
-           (ui32Flags == AES_DMA_DATA_OUT) ||
-           (ui32Flags == AES_DMA_CONTEXT_IN) ||
-           (ui32Flags == AES_DMA_CONTEXT_OUT));
-
-    //
-    // Clear the flags in the current register value.
-    //
-    HWREG(ui32Base + AES_O_SYSCONFIG) &= ~ui32Flags;
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
+//*****************************************************************************
+//
+//  aes.c
+//
+//  Driver for the AES module.
+//
+//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
+//  are met:
+//
+//    Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//
+//    Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//
+//    Neither the name of Texas Instruments Incorporated nor the names of
+//    its contributors may be used to endorse or promote products derived
+//    from this software without specific prior written permission.
+//
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//*****************************************************************************
+
+//*****************************************************************************
+//
+//! \addtogroup AES_Advanced_Encryption_Standard_api
+//! @{
+//
+//*****************************************************************************
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "inc/hw_aes.h"
+#include "inc/hw_dthe.h"
+#include "inc/hw_ints.h"
+#include "inc/hw_memmap.h"
+#include "inc/hw_nvic.h"
+#include "inc/hw_types.h"
+#include "aes.h"
+#include "debug.h"
+#include "interrupt.h"
+
+#define AES_BLOCK_SIZE_IN_BYTES 16
+
+//*****************************************************************************
+//
+//! Configures the AES module.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32Config is the configuration of the AES module.
+//!
+//! This function configures the AES module based on the specified parameters.
+//! It does not change any DMA- or interrupt-related parameters.
+//!
+//! The ui32Config parameter is a bit-wise OR of a number of configuration
+//! flags. The valid flags are grouped based on their function.
+//!
+//! The direction of the operation is specified with only of following flags:
+//!
+//! - \b AES_CFG_DIR_ENCRYPT - Encryption mode
+//! - \b AES_CFG_DIR_DECRYPT - Decryption mode
+//!
+//! The key size is specified with only one of the following flags:
+//!
+//! - \b AES_CFG_KEY_SIZE_128BIT - Key size of 128 bits
+//! - \b AES_CFG_KEY_SIZE_192BIT - Key size of 192 bits
+//! - \b AES_CFG_KEY_SIZE_256BIT - Key size of 256 bits
+//!
+//! The mode of operation is specified with only one of the following flags.
+//!
+//! - \b AES_CFG_MODE_ECB - Electronic codebook mode
+//! - \b AES_CFG_MODE_CBC - Cipher-block chaining mode
+//! - \b AES_CFG_MODE_CFB - Cipher feedback mode
+//! - \b AES_CFG_MODE_CTR - Counter mode
+//! - \b AES_CFG_MODE_ICM - Integer counter mode
+//! - \b AES_CFG_MODE_XTS - Ciphertext stealing mode
+//! - \b AES_CFG_MODE_XTS_TWEAKJL - XEX-based tweaked-codebook mode with
+//! ciphertext stealing with previous/intermediate tweak value and j loaded
+//! - \b AES_CFG_MODE_XTS_K2IJL - XEX-based tweaked-codebook mode with
+//! ciphertext stealing with key2, i and j loaded
+//! - \b AES_CFG_MODE_XTS_K2ILJ0 - XEX-based tweaked-codebook mode with
+//! ciphertext stealing with key2 and i loaded, j = 0
+//! - \b AES_CFG_MODE_F8 - F8 mode
+//! - \b AES_CFG_MODE_F9 - F9 mode
+//! - \b AES_CFG_MODE_CBCMAC - Cipher block chaining message authentication
+//! code mode
+//! - \b AES_CFG_MODE_GCM - Galois/counter mode
+//! - \b AES_CFG_MODE_GCM_HLY0ZERO - Galois/counter mode with GHASH with H
+//! loaded and Y0-encrypted forced to zero
+//! - \b AES_CFG_MODE_GCM_HLY0CALC - Galois/counter mode with GHASH with H
+//! loaded and Y0-encrypted calculated internally
+//! - \b AES_CFG_MODE_GCM_HY0CALC - Galois/Counter mode with autonomous GHASH
+//! (both H and Y0-encrypted calculated internally)
+//! - \b AES_CFG_MODE_CCM - Counter with CBC-MAC mode
+//!
+//! The following defines are used to specify the counter width.  It is only
+//! required to be defined when using CTR, CCM, or GCM modes, only one of the
+//! following defines must be used to specify the counter width length:
+//!
+//! - \b AES_CFG_CTR_WIDTH_32 - Counter is 32 bits
+//! - \b AES_CFG_CTR_WIDTH_64 - Counter is 64 bits
+//! - \b AES_CFG_CTR_WIDTH_96 - Counter is 96 bits
+//! - \b AES_CFG_CTR_WIDTH_128 - Counter is 128 bits
+//!
+//! Only one of the following defines must be used to specify the length field
+//! for CCM operations (L):
+//!
+//! - \b AES_CFG_CCM_L_2 - 2 bytes
+//! - \b AES_CFG_CCM_L_4 - 4 bytes
+//! - \b AES_CFG_CCM_L_8 - 8 bytes
+//!
+//! Only one of the following defines must be used to specify the length of the
+//! authentication field for CCM operations (M) through the \e ui32Config
+//! argument in the AESConfigSet() function:
+//!
+//! - \b AES_CFG_CCM_M_4 - 4 bytes
+//! - \b AES_CFG_CCM_M_6 - 6 bytes
+//! - \b AES_CFG_CCM_M_8 - 8 bytes
+//! - \b AES_CFG_CCM_M_10 - 10 bytes
+//! - \b AES_CFG_CCM_M_12 - 12 bytes
+//! - \b AES_CFG_CCM_M_14 - 14 bytes
+//! - \b AES_CFG_CCM_M_16 - 16 bytes
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESConfigSet(uint32_t ui32Base, uint32_t ui32Config)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32Config & AES_CFG_DIR_ENCRYPT) ||
+           (ui32Config & AES_CFG_DIR_DECRYPT));
+    ASSERT((ui32Config & AES_CFG_KEY_SIZE_128BIT) ||
+           (ui32Config & AES_CFG_KEY_SIZE_192BIT) ||
+           (ui32Config & AES_CFG_KEY_SIZE_256BIT));
+    ASSERT((ui32Config & AES_CFG_MODE_ECB) ||
+           (ui32Config & AES_CFG_MODE_CBC) ||
+           (ui32Config & AES_CFG_MODE_CTR) ||
+           (ui32Config & AES_CFG_MODE_ICM) ||
+           (ui32Config & AES_CFG_MODE_CFB) ||
+           (ui32Config & AES_CFG_MODE_XTS_TWEAKJL) ||
+           (ui32Config & AES_CFG_MODE_XTS_K2IJL) ||
+           (ui32Config & AES_CFG_MODE_XTS_K2ILJ0) ||
+           (ui32Config & AES_CFG_MODE_F8) ||
+           (ui32Config & AES_CFG_MODE_F9) ||
+           (ui32Config & AES_CFG_MODE_CTR) ||
+           (ui32Config & AES_CFG_MODE_CBCMAC) ||
+           (ui32Config & AES_CFG_MODE_GCM_HLY0ZERO) ||
+           (ui32Config & AES_CFG_MODE_GCM_HLY0CALC) ||
+           (ui32Config & AES_CFG_MODE_GCM_HY0CALC) ||
+           (ui32Config & AES_CFG_MODE_CCM));
+    ASSERT(((ui32Config & AES_CFG_MODE_CTR) ||
+            (ui32Config & AES_CFG_MODE_GCM_HLY0ZERO) ||
+            (ui32Config & AES_CFG_MODE_GCM_HLY0CALC) ||
+            (ui32Config & AES_CFG_MODE_GCM_HY0CALC) ||
+            (ui32Config & AES_CFG_MODE_CCM)) &&
+           ((ui32Config & AES_CFG_CTR_WIDTH_32) ||
+            (ui32Config & AES_CFG_CTR_WIDTH_64) ||
+            (ui32Config & AES_CFG_CTR_WIDTH_96) ||
+            (ui32Config & AES_CFG_CTR_WIDTH_128)));
+    ASSERT((ui32Config & AES_CFG_MODE_CCM) &&
+           ((ui32Config & AES_CFG_CCM_L_2) ||
+            (ui32Config & AES_CFG_CCM_L_4) ||
+            (ui32Config & AES_CFG_CCM_L_8)) &&
+           ((ui32Config & AES_CFG_CCM_M_4) ||
+            (ui32Config & AES_CFG_CCM_M_6) ||
+            (ui32Config & AES_CFG_CCM_M_8) ||
+            (ui32Config & AES_CFG_CCM_M_10) ||
+            (ui32Config & AES_CFG_CCM_M_12) ||
+            (ui32Config & AES_CFG_CCM_M_14) ||
+            (ui32Config & AES_CFG_CCM_M_16)));
+
+    //
+    // Backup the save context field before updating the register.
+    //
+    if(HWREG(ui32Base + AES_O_CTRL) & AES_CTRL_SAVE_CONTEXT)
+    {
+        ui32Config |= AES_CTRL_SAVE_CONTEXT;
+    }
+
+    //
+    // Write the CTRL register with the new value
+    //
+    HWREG(ui32Base + AES_O_CTRL) = ui32Config;
+}
+
+//*****************************************************************************
+//
+//! Writes the key 1 configuration registers, which are used for encryption or
+//! decryption.
+//!
+//! \param ui32Base is the base address for the AES module.
+//! \param pui8Key is an array of bytes, containing the key to be
+//! configured.  The least significant word in the 0th index.
+//! \param ui32Keysize is the size of the key, which must be one of the
+//! following values:  \b AES_CFG_KEY_SIZE_128, \b AES_CFG_KEY_SIZE_192, or
+//! \b AES_CFG_KEY_SIZE_256.
+//!
+//! This function writes key 1 configuration registers based on the key
+//! size.  This function is used in all modes.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESKey1Set(uint32_t ui32Base, uint8_t *pui8Key, uint32_t ui32Keysize)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32Keysize == AES_CFG_KEY_SIZE_128BIT) ||
+           (ui32Keysize == AES_CFG_KEY_SIZE_192BIT) ||
+           (ui32Keysize == AES_CFG_KEY_SIZE_256BIT));
+
+    //
+    // With all key sizes, the first 4 words are written.
+    //
+    HWREG(ui32Base + AES_O_KEY1_0) = * ((uint32_t *)(pui8Key + 0));
+    HWREG(ui32Base + AES_O_KEY1_1) = * ((uint32_t *)(pui8Key + 4));
+    HWREG(ui32Base + AES_O_KEY1_2) = * ((uint32_t *)(pui8Key + 8));
+    HWREG(ui32Base + AES_O_KEY1_3) = * ((uint32_t *)(pui8Key + 12));
+
+    //
+    // The key is 192 or 256 bits.  Write the next 2 words.
+    //
+    if(ui32Keysize != AES_CFG_KEY_SIZE_128BIT)
+    {
+        HWREG(ui32Base + AES_O_KEY1_4) = * ((uint32_t *)(pui8Key + 16));
+        HWREG(ui32Base + AES_O_KEY1_5) = * ((uint32_t *)(pui8Key + 20));
+    }
+
+    //
+    // The key is 256 bits.  Write the last 2 words.
+    //
+    if(ui32Keysize == AES_CFG_KEY_SIZE_256BIT)
+    {
+        HWREG(ui32Base + AES_O_KEY1_6) = * ((uint32_t *)(pui8Key + 24));
+        HWREG(ui32Base + AES_O_KEY1_7) = * ((uint32_t *)(pui8Key + 28));
+    }
+}
+
+//*****************************************************************************
+//
+//! Writes the key 2 configuration registers, which are used for encryption or
+//! decryption.
+//!
+//! \param ui32Base is the base address for the AES module.
+//! \param pui8Key is an array of bytes, containing the key to be
+//! configured.  The least significant word in the 0th index.
+//! \param ui32Keysize is the size of the key, which must be one of the
+//! following values:  \b AES_CFG_KEY_SIZE_128, \b AES_CFG_KEY_SIZE_192, or
+//! \b AES_CFG_KEY_SIZE_256.
+//!
+//! This function writes the key 2 configuration registers based on the key
+//! size.  This function is used in the F8, F9, XTS, CCM, and CBC-MAC modes.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESKey2Set(uint32_t ui32Base, uint8_t *pui8Key, uint32_t ui32Keysize)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32Keysize == AES_CFG_KEY_SIZE_128BIT) ||
+           (ui32Keysize == AES_CFG_KEY_SIZE_192BIT) ||
+           (ui32Keysize == AES_CFG_KEY_SIZE_256BIT));
+
+    //
+    // With all key sizes, the first 4 words are written.
+    //
+    HWREG(ui32Base + AES_O_KEY2_0) = * ((uint32_t *)(pui8Key + 0));
+    HWREG(ui32Base + AES_O_KEY2_1) = * ((uint32_t *)(pui8Key + 4));
+    HWREG(ui32Base + AES_O_KEY2_2) = * ((uint32_t *)(pui8Key + 8));
+    HWREG(ui32Base + AES_O_KEY2_3) = * ((uint32_t *)(pui8Key + 12));
+
+    //
+    // The key is 192 or 256 bits.  Write the next 2 words.
+    //
+    if(ui32Keysize != AES_CFG_KEY_SIZE_128BIT)
+    {
+        HWREG(ui32Base + AES_O_KEY2_4) = * ((uint32_t *)(pui8Key + 16));
+        HWREG(ui32Base + AES_O_KEY2_5) = * ((uint32_t *)(pui8Key + 20));
+    }
+
+    //
+    // The key is 256 bits.  Write the last 2 words.
+    //
+    if(ui32Keysize == AES_CFG_KEY_SIZE_256BIT)
+    {
+        HWREG(ui32Base + AES_O_KEY2_6) = * ((uint32_t *)(pui8Key + 24));
+        HWREG(ui32Base + AES_O_KEY2_7) = * ((uint32_t *)(pui8Key + 28));
+    }
+}
+
+//*****************************************************************************
+//
+//! Writes key 3 configuration registers, which are used for encryption or
+//! decryption.
+//!
+//! \param ui32Base is the base address for the AES module.
+//! \param pui8Key is a pointer to an array bytes, containing
+//! the key to be configured. The least significant word is in the 0th index.
+//!
+//! This function writes the key 2 configuration registers with key 3 data
+//! used in CBC-MAC and F8 modes.  This key is always 128 bits.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESKey3Set(uint32_t ui32Base, uint8_t *pui8Key)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the key into the upper 4 key registers
+    //
+    HWREG(ui32Base + AES_O_KEY2_4) = * ((uint32_t *)(pui8Key + 0));
+    HWREG(ui32Base + AES_O_KEY2_5) = * ((uint32_t *)(pui8Key + 4));
+    HWREG(ui32Base + AES_O_KEY2_6) = * ((uint32_t *)(pui8Key + 8));
+    HWREG(ui32Base + AES_O_KEY2_7) = * ((uint32_t *)(pui8Key + 12));
+}
+
+//*****************************************************************************
+//
+//! Writes the Initial Vector (IV) register, needed in some of the AES Modes.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8IVdata is an array of 16 bytes (128 bits), containing the IV
+//! value to be configured. The least significant word is in the 0th index.
+//!
+//! This functions writes the initial vector registers in the AES module.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIVSet(uint32_t ui32Base, uint8_t *pui8IVdata)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the initial vector registers.
+    //
+    HWREG(ui32Base + AES_O_IV_IN_0) = *((uint32_t *)(pui8IVdata+0));
+    HWREG(ui32Base + AES_O_IV_IN_1) = *((uint32_t *)(pui8IVdata+4));
+    HWREG(ui32Base + AES_O_IV_IN_2) = *((uint32_t *)(pui8IVdata+8));
+    HWREG(ui32Base + AES_O_IV_IN_3) = *((uint32_t *)(pui8IVdata+12));
+}
+
+
+//*****************************************************************************
+//
+//! Reads the Initial Vector (IV) register, needed in some of the AES Modes.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8IVdata is pointer to an array of 16 bytes.
+//!
+//! This functions reads the initial vector registers in the AES module.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIVGet(uint32_t ui32Base, uint8_t *pui8IVdata)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the initial vector registers.
+    //
+    *((uint32_t *)(pui8IVdata+ 0)) = HWREG(ui32Base + AES_O_IV_IN_0);
+    *((uint32_t *)(pui8IVdata+ 4)) = HWREG(ui32Base + AES_O_IV_IN_1);
+    *((uint32_t *)(pui8IVdata+ 8)) = HWREG(ui32Base + AES_O_IV_IN_2);
+    *((uint32_t *)(pui8IVdata+12)) = HWREG(ui32Base + AES_O_IV_IN_3);
+}
+
+//*****************************************************************************
+//
+//! Saves the tag registers to a user-defined location.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8TagData is pointer to the location that stores the tag data.
+//!
+//! This function stores the tag data for use authenticated encryption and
+//! decryption operations.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESTagRead(uint32_t ui32Base, uint8_t *pui8TagData)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Read the tag data.
+    //
+    *((uint32_t *)(pui8TagData+0)) = HWREG((ui32Base + AES_O_TAG_OUT_0));
+    *((uint32_t *)(pui8TagData+4)) = HWREG((ui32Base + AES_O_TAG_OUT_1));
+    *((uint32_t *)(pui8TagData+8)) = HWREG((ui32Base + AES_O_TAG_OUT_2));
+    *((uint32_t *)(pui8TagData+12)) = HWREG((ui32Base + AES_O_TAG_OUT_3));
+}
+
+//*****************************************************************************
+//
+//! Used to set the write crypto data length in the AES module.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui64Length is the crypto data length in bytes.
+//!
+//! This function stores the cryptographic data length in blocks for all modes.
+//! Data lengths up to (2^61 - 1) bytes are allowed.  For GCM, any value up
+//! to (2^36 - 2) bytes are allowed because a 32-bit block counter is used.  For
+//! basic modes (ECB/CBC/CTR/ICM/CFB128), zero can be programmed into the
+//! length field, indicating that the length is infinite.
+//!
+//! When this function is called, the engine is triggered to start using
+//! this context.
+//!
+//! \note This length does not include the authentication-only data used in
+//! some modes.  Use the AESAuthLengthSet() function to specify the
+//! authentication data length.
+//!
+//! \return None
+//
+//*****************************************************************************
+void
+AESDataLengthSet(uint32_t ui32Base, uint64_t ui64Length)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the length register by shifting the 64-bit ui64Length.
+    //
+    HWREG(ui32Base + AES_O_C_LENGTH_0) = (uint32_t)(ui64Length);
+    HWREG(ui32Base + AES_O_C_LENGTH_1) = (uint32_t)(ui64Length >> 32);
+}
+
+//*****************************************************************************
+//
+//! Sets the optional additional authentication data (AAD) length.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32Length is the length in bytes.
+//!
+//! This function is only used to write the authentication data length in the
+//! combined modes (GCM or CCM) and XTS mode.  Supported AAD lengths for CCM
+//! are from 0 to (2^16 - 28) bytes.  For GCM, any value up to (2^32 - 1) can
+//! be used.  For XTS mode, this register is used to load j.  Loading of j is
+//! only required if j != 0.  j represents the sequential number of the 128-bit
+//! blocks inside the data unit.  Consequently, j must be multiplied by 16
+//! when passed to this function, thereby placing the block number in
+//! bits [31:4] of the register.
+//!
+//! When this function is called, the engine is triggered to start using
+//! this context for GCM and CCM.
+//!
+//! \return None
+//
+//*****************************************************************************
+void
+AESAuthDataLengthSet(uint32_t ui32Base, uint32_t ui32Length)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the length into the register.
+    //
+    HWREG(ui32Base + AES_O_AUTH_LENGTH) = ui32Length;
+}
+
+//*****************************************************************************
+//
+//! Reads plaintext/ciphertext from data registers without blocking.
+//! This api writes data in blocks
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8Dest is a pointer to an array of words of data.
+//! \param ui8Length the length can be from 1 to 16
+//!
+//! This function reads a block of either plaintext or ciphertext out of the
+//! AES module.  If the output data is not ready, the function returns
+//! false.  If the read completed successfully, the function returns true.
+//! A block is 16 bytes or 4 words.
+//!
+//! \return true or false.
+//
+//*****************************************************************************
+bool
+AESDataReadNonBlocking(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
+{
+	volatile uint32_t pui32Dest[4];
+	uint8_t ui8BytCnt;
+	uint8_t *pui8DestTemp;
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    if((ui8Length == 0)||(ui8Length>16))
+    {
+       	return(false);
+    }
+
+    //
+    // Check if the output is ready before reading the data.  If it not ready,
+    // return false.
+    //
+    if((AES_CTRL_OUTPUT_READY & (HWREG(ui32Base + AES_O_CTRL))) == 0)
+    {
+        return(false);
+    }
+
+    //
+    // Read a block of data from the data registers
+    //
+    pui32Dest[0] = HWREG(ui32Base + AES_O_DATA_IN_3);
+    pui32Dest[1] = HWREG(ui32Base + AES_O_DATA_IN_2);
+    pui32Dest[2] = HWREG(ui32Base + AES_O_DATA_IN_1);
+    pui32Dest[3] = HWREG(ui32Base + AES_O_DATA_IN_0);
+
+    //
+    //Copy the data to a block memory
+    //
+    pui8DestTemp = (uint8_t *)pui32Dest;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+    {
+     	*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
+    }
+    //
+    // Read successful, return true.
+    //
+    return(true);
+}
+
+
+//*****************************************************************************
+//
+//! Reads plaintext/ciphertext from data registers with blocking.
+//! This api writes data in blocks
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8Dest is a pointer to an array of words.
+//! \param ui8Length is the length of data in bytes to be read.
+//!        ui8Length can be from 1 to 16
+//!
+//! This function reads a block of either plaintext or ciphertext out of the
+//! AES module.  If the output is not ready, the function waits until it
+//! is ready. A block is 16 bytes or 4 words.
+//!
+//! \return None.
+//
+//*****************************************************************************
+
+void
+AESDataRead(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
+{
+	volatile uint32_t pui32Dest[4];
+	uint8_t ui8BytCnt;
+	uint8_t *pui8DestTemp;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    if((ui8Length == 0)||(ui8Length>16))
+   	{
+       	return;
+    }
+
+
+    //
+    // Wait for the output to be ready before reading the data.
+    //
+    while((AES_CTRL_OUTPUT_READY & (HWREG(ui32Base + AES_O_CTRL))) == 0)
+    {
+    }
+
+    //
+    // Read a block of data from the data registers
+    //
+    pui32Dest[0] = HWREG(ui32Base + AES_O_DATA_IN_3);
+    pui32Dest[1] = HWREG(ui32Base + AES_O_DATA_IN_2);
+    pui32Dest[2] = HWREG(ui32Base + AES_O_DATA_IN_1);
+    pui32Dest[3] = HWREG(ui32Base + AES_O_DATA_IN_0);
+    //
+    //Copy the data to a block memory
+    //
+    pui8DestTemp = (uint8_t *)pui32Dest;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+   	{
+    	*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
+   	}
+
+    return;
+}
+
+//*****************************************************************************
+//
+//! Writes plaintext/ciphertext to data registers without blocking.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8Src is a pointer to an array of words of data.
+//! \param ui8Length the length can be from 1 to 16
+//!
+//! This function writes a block of either plaintext or ciphertext into the
+//! AES module.  If the input is not ready, the function returns false
+//! If the write completed successfully, the function returns true.
+//!
+//! \return True or false.
+//
+//*****************************************************************************
+bool
+AESDataWriteNonBlocking(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
+{
+	volatile uint32_t pui32Src[4]={0,0,0,0};
+	uint8_t ui8BytCnt;
+	uint8_t *pui8SrcTemp;
+
+	//
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    if((ui8Length == 0)||(ui8Length>16))
+   	{
+      	return(false);
+    }
+
+    //
+    // Check if the input is ready.  If not, then return false.
+    //
+    if(!(AES_CTRL_INPUT_READY & (HWREG(ui32Base + AES_O_CTRL))))
+    {
+        return(false);
+    }
+
+
+    //
+    //Copy the data to a block memory
+    //
+    pui8SrcTemp = (uint8_t *)pui32Src;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+	{
+		*(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
+	}
+    //
+    // Write a block of data into the data registers.
+    //
+    HWREG(ui32Base + AES_O_DATA_IN_3) = pui32Src[0];
+    HWREG(ui32Base + AES_O_DATA_IN_2) = pui32Src[1];
+    HWREG(ui32Base + AES_O_DATA_IN_1) = pui32Src[2];
+    HWREG(ui32Base + AES_O_DATA_IN_0) = pui32Src[3];
+
+    //
+    // Write successful, return true.
+    //
+    return(true);
+}
+
+
+//*****************************************************************************
+//
+//! Writes plaintext/ciphertext to data registers with blocking.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8Src is a pointer to an array of bytes.
+//! \param ui8Length the length can be from 1 to 16
+//!
+//! This function writes a block of either plaintext or ciphertext into the
+//! AES module.  If the input is not ready, the function waits until it is
+//! ready before performing the write.
+//!
+//! \return None.
+//
+//*****************************************************************************
+
+void
+AESDataWrite(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
+{
+	volatile uint32_t pui32Src[4]={0,0,0,0};
+	uint8_t ui8BytCnt;
+	uint8_t *pui8SrcTemp;
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    if((ui8Length == 0)||(ui8Length>16))
+	{
+    	return;
+	}
+    //
+    // Wait for input ready.
+    //
+    while((AES_CTRL_INPUT_READY & (HWREG(ui32Base + AES_O_CTRL))) == 0)
+    {
+    }
+
+    //
+    //Copy the data to a block memory
+    //
+    pui8SrcTemp = (uint8_t *)pui32Src;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+   	{
+   		*(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
+   	}
+
+    //
+    // Write a block of data into the data registers.
+    //
+    HWREG(ui32Base + AES_O_DATA_IN_3) = pui32Src[0];
+    HWREG(ui32Base + AES_O_DATA_IN_2) = pui32Src[1];
+    HWREG(ui32Base + AES_O_DATA_IN_1) = pui32Src[2];
+    HWREG(ui32Base + AES_O_DATA_IN_0) = pui32Src[3];
+}
+
+
+//*****************************************************************************
+//
+//! Used to process(transform) blocks of data, either encrypt or decrypt it.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8Src is a pointer to the memory location where the input data
+//! is stored.
+//! \param pui8Dest is a pointer to the memory location output is written.
+//! \param ui32Length is the length of the cryptographic data in bytes.
+//!
+//! This function iterates the encryption or decryption mechanism number over
+//! the data length.  Before calling this function, ensure that the AES
+//! module is properly configured the key, data size, mode, etc.  Only ECB,
+//! CBC, CTR, ICM, CFB, XTS and F8 operating modes should be used.  The data
+//! is processed in 4-word (16-byte) blocks.
+//!
+//! \note This function only supports values of \e ui32Length less than 2^32,
+//! because the memory size is restricted to between 0 to 2^32 bytes.
+//!
+//! \return Returns true if data was processed successfully.  Returns false
+//! if data processing failed.
+//
+//*****************************************************************************
+bool
+AESDataProcess(uint32_t ui32Base, uint8_t *pui8Src, uint8_t *pui8Dest,
+               uint32_t ui32Length)
+{
+    uint32_t ui32Count, ui32BlkCount, ui32ByteCount;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the length register first, which triggers the engine to start
+    // using this context.
+    //
+    AESDataLengthSet(AES_BASE, (uint64_t) ui32Length);
+
+    //
+    // Now loop until the blocks are written.
+    //
+    ui32BlkCount = ui32Length/16;
+    for(ui32Count = 0; ui32Count < ui32BlkCount; ui32Count += 1)
+    {
+        //
+        // Write the data registers.
+        //
+        AESDataWrite(ui32Base, pui8Src + (ui32Count*16) ,16);
+
+        //
+        // Read the data registers.
+        //
+        AESDataRead(ui32Base, pui8Dest + (ui32Count*16) ,16);
+
+    }
+
+    //
+    //Now handle the residue bytes
+    //
+    ui32ByteCount = ui32Length%16;
+    if(ui32ByteCount)
+    {
+    	//
+    	// Write the data registers.
+    	//
+    	AESDataWrite(ui32Base, pui8Src + (16*ui32BlkCount) ,ui32ByteCount);
+
+    	//
+    	// Read the data registers.
+    	//
+        AESDataRead(ui32Base, pui8Dest + (16*ui32BlkCount) ,ui32ByteCount);
+    }
+
+
+
+    //
+    // Return true to indicate successful completion of the function.
+    //
+    return(true);
+}
+//*****************************************************************************
+//
+//! Used to generate message authentication code (MAC) using CBC-MAC and F9 mode.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pui8Src is a pointer to the memory location where the input data
+//! is stored.
+//! \param ui32Length  is the length of the cryptographic data in bytes.
+//! \param pui8Tag is a pointer to a 4-word array where the hash tag is
+//! written.
+//!
+//! This function processes data to produce a hash tag that can be used tor
+//! authentication.   Before calling this function, ensure that the AES
+//! module is properly configured the key, data size, mode, etc.  Only
+//! CBC-MAC and F9 modes should be used.
+//!
+//! \return Returns true if data was processed successfully.  Returns false
+//! if data processing failed.
+//
+//*****************************************************************************
+bool
+AESDataMAC(uint32_t ui32Base, uint8_t *pui8Src, uint32_t ui32Length,
+            uint8_t *pui8Tag)
+{
+    uint32_t ui32Count, ui32BlkCount, ui32ByteCount;
+	//
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Write the length register first, which triggers the engine to start
+    // using this context.
+    //
+    AESDataLengthSet(AES_BASE, (uint64_t) ui32Length);
+
+    //
+    // Write the data registers.
+    //
+
+    //
+    // Now loop until the blocks are written.
+    //
+    ui32BlkCount = ui32Length/16;
+    for(ui32Count = 0; ui32Count < ui32BlkCount; ui32Count += 1)
+    {
+	   //
+	   // Write the data registers.
+	   //
+	   AESDataWrite(ui32Base, pui8Src + ui32Count*16 ,16);
+    }
+
+    //
+    //Now handle the residue bytes
+    //
+    ui32ByteCount = ui32Length%16;
+    if(ui32ByteCount)
+    {
+	   //
+	   // Write the data registers.
+	   //
+	   AESDataWrite(ui32Base, pui8Src + (ui32Count*ui32BlkCount) ,ui32ByteCount);
+    }
+
+    //
+    // Wait for the context data regsiters to be ready.
+    //
+    while((AES_CTRL_SVCTXTRDY & (HWREG(AES_BASE + AES_O_CTRL))) == 0)
+    {
+    }
+
+    //
+    // Read the hash tag value.
+    //
+    AESTagRead(AES_BASE, pui8Tag);
+
+    //
+    // Return true to indicate successful completion of the function.
+    //
+    return(true);
+}
+
+//*****************************************************************************
+//
+//! Used for Authenticated encryption (AE) of the data. Processes and authenticates blocks of data,
+//! either encrypt the data or decrypt the data.
+//!
+//! \param ui32Base  is the base address of the AES module.
+//! \param pui8Src is a pointer to the memory location where the input data
+//! is stored. The data must be padded to the 16-byte boundary.
+//! \param pui8Dest is a pointer to the memory location output is written.
+//! The space for written data must be rounded up to the 16-byte boundary.
+//! \param ui32Length is the length of the cryptographic data in bytes.
+//! \param pui8AuthSrc is a pointer to the memory location where the
+//! additional authentication data is stored.  The data must be padded to the
+//! 16-byte boundary.
+//! \param ui32AuthLength is the length of the additional authentication
+//! data in bytes.
+//! \param pui8Tag is a pointer to a 4-word array where the hash tag is
+//! written.
+//!
+//! This function encrypts or decrypts blocks of data in addition to
+//! authentication data.  A hash tag is also produced.  Before calling this
+//! function, ensure that the AES module is properly configured the key,
+//! data size, mode, etc.  Only CCM and GCM modes should be used.
+//!
+//! \return Returns true if data was processed successfully.  Returns false
+//! if data processing failed.
+//
+//*****************************************************************************
+bool
+AESDataProcessAE(uint32_t ui32Base, uint8_t *pui8Src, uint8_t *pui8Dest,
+                   uint32_t ui32Length, uint8_t *pui8AuthSrc,
+                   uint32_t ui32AuthLength, uint8_t *pui8Tag)
+{
+    uint32_t ui32Count;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Set the data length.
+    //
+    AESDataLengthSet(AES_BASE, (uint64_t) ui32Length);
+
+    //
+    // Set the additional authentication data length.
+    //
+    AESAuthDataLengthSet(AES_BASE, ui32AuthLength);
+
+    //
+    // Now loop until the authentication data blocks are written.
+    //
+    for(ui32Count = 0; ui32Count < ui32AuthLength; ui32Count += 16)
+    {
+        //
+        // Write the data registers.
+        //
+        AESDataWrite(ui32Base, pui8AuthSrc + (ui32Count),16);
+    }
+
+    //
+    // Now loop until the data blocks are written.
+    //
+    for(ui32Count = 0; ui32Count < ui32Length; ui32Count += 16)
+    {
+        //
+        // Write the data registers.
+        //
+        AESDataWrite(ui32Base, pui8Src + (ui32Count),16);
+
+        //
+        //
+        // Read the data registers.
+        //
+        AESDataRead(ui32Base, pui8Dest + (ui32Count),16);
+    }
+
+    //
+    // Wait for the context data regsiters to be ready.
+    //
+    while((AES_CTRL_SVCTXTRDY & (HWREG(AES_BASE + AES_O_CTRL))) == 0)
+    {
+    }
+
+    //
+    // Read the hash tag value.
+    //
+    AESTagRead(AES_BASE, pui8Tag);
+
+    //
+    // Return true to indicate successful completion of the function.
+    //
+    return(true);
+}
+
+//*****************************************************************************
+//
+//! Returns the current AES module interrupt status.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param bMasked is \b false if the raw interrupt status is required and
+//! \b true if the masked interrupt status is required.
+//!
+//! \return Returns a bit mask of the interrupt sources, which is a logical OR
+//! of any of the following:
+//!
+//! - \b AES_INT_CONTEXT_IN - Context interrupt
+//! - \b AES_INT_CONTEXT_OUT - Authentication tag (and IV) interrupt.
+//! - \b AES_INT_DATA_IN - Data input interrupt
+//! - \b AES_INT_DATA_OUT - Data output interrupt
+//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
+//! interrupt
+//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//
+//*****************************************************************************
+uint32_t
+AESIntStatus(uint32_t ui32Base, bool bMasked)
+{
+    uint32_t ui32Temp;
+    uint32_t ui32IrqEnable;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Read the IRQ status register and return the value.
+    //
+    if(bMasked)
+    {
+        ui32Temp = HWREG(DTHE_BASE + DTHE_O_AES_MIS);
+        ui32IrqEnable = HWREG(ui32Base + AES_O_IRQENABLE);
+        return((HWREG(ui32Base + AES_O_IRQSTATUS) &
+                ui32IrqEnable) | ((ui32Temp & 0x0000000F) << 16));
+    }
+    else
+    {
+        ui32Temp = HWREG(DTHE_BASE + DTHE_O_AES_RIS);
+        return(HWREG(ui32Base + AES_O_IRQSTATUS) |
+               ((ui32Temp & 0x0000000F) << 16));
+    }
+}
+
+//*****************************************************************************
+//
+//! Enables AES module interrupts.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32IntFlags is a bit mask of the interrupt sources to enable.
+//!
+//! This function enables the interrupts in the AES module. The \e ui32IntFlags
+//! parameter is the logical OR of any of the following:
+//!
+//! - \b AES_INT_CONTEXT_IN - Context interrupt
+//! - \b AES_INT_CONTEXT_OUT - Authentication tag (and IV) interrupt
+//! - \b AES_INT_DATA_IN - Data input interrupt
+//! - \b AES_INT_DATA_OUT - Data output interrupt
+//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
+//! interrupt
+//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//!
+//! \note Interrupts that have been previously been enabled are not disabled
+//! when this function is called.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32IntFlags == AES_INT_CONTEXT_IN) ||
+           (ui32IntFlags == AES_INT_CONTEXT_OUT) ||
+           (ui32IntFlags == AES_INT_DATA_IN) ||
+           (ui32IntFlags == AES_INT_DATA_OUT) ||
+           (ui32IntFlags == AES_INT_DMA_CONTEXT_IN) ||
+           (ui32IntFlags == AES_INT_DMA_CONTEXT_OUT) ||
+           (ui32IntFlags == AES_INT_DMA_DATA_IN) ||
+           (ui32IntFlags == AES_INT_DMA_DATA_OUT));
+
+    //
+    // Set the flags.
+    //
+    HWREG(DTHE_BASE + DTHE_O_AES_IM) &= ~((ui32IntFlags & 0x000F0000) >> 16);
+    HWREG(ui32Base + AES_O_IRQENABLE) |= ui32IntFlags & 0x0000ffff;
+}
+
+//*****************************************************************************
+//
+//! Disables AES module interrupts.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32IntFlags is a bit mask of the interrupt sources to disable.
+//!
+//! This function disables the interrupt sources in the AES module. The
+//! \e ui32IntFlags parameter is the logical OR of any of the following:
+//!
+//! - \b AES_INT_CONTEXT_IN - Context interrupt
+//! - \b AES_INT_CONTEXT_OUT - Authentication tag (and IV) interrupt
+//! - \b AES_INT_DATA_IN - Data input interrupt
+//! - \b AES_INT_DATA_OUT - Data output interrupt
+//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
+//! interrupt
+//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//!
+//! \note The DMA done interrupts are the only interrupts that can be cleared.
+//! The remaining interrupts can be disabled instead using AESIntDisable().
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32IntFlags == AES_INT_CONTEXT_IN) ||
+           (ui32IntFlags == AES_INT_CONTEXT_OUT) ||
+           (ui32IntFlags == AES_INT_DATA_IN) ||
+           (ui32IntFlags == AES_INT_DATA_OUT) ||
+           (ui32IntFlags == AES_INT_DMA_CONTEXT_IN) ||
+           (ui32IntFlags == AES_INT_DMA_CONTEXT_OUT) ||
+           (ui32IntFlags == AES_INT_DMA_DATA_IN) ||
+           (ui32IntFlags == AES_INT_DMA_DATA_OUT));
+
+    //
+    // Clear the flags.
+    //
+    HWREG(DTHE_BASE + DTHE_O_AES_IM) |= ((ui32IntFlags & 0x000F0000) >> 16);
+    HWREG(ui32Base + AES_O_IRQENABLE) &= ~(ui32IntFlags & 0x0000ffff);
+}
+
+//*****************************************************************************
+//
+//! Clears AES module interrupts.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32IntFlags is a bit mask of the interrupt sources to disable.
+//!
+//! This function clears the interrupt sources in the AES module.  The
+//! \e ui32IntFlags parameter is the logical OR of any of the following:
+//!
+//! - \b AES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b AES_INT_DMA_CONTEXT_OUT - Authentication tag (and IV) DMA done
+//! interrupt
+//! - \b AES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b AES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//!
+//! \note Only the DMA done interrupts can be cleared.  The remaining
+//! interrupts should be disabled with AESIntDisable().
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32IntFlags == AES_INT_DMA_CONTEXT_IN) ||
+           (ui32IntFlags == AES_INT_DMA_CONTEXT_OUT) ||
+           (ui32IntFlags == AES_INT_DMA_DATA_IN) ||
+           (ui32IntFlags == AES_INT_DMA_DATA_OUT));
+
+    HWREG(DTHE_BASE + DTHE_O_AES_IC) = ((ui32IntFlags >> 16) & 0x0000000F);
+}
+
+//*****************************************************************************
+//
+//! Registers an interrupt handler for the AES module.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param pfnHandler is a pointer to the function to be called when the
+//! enabled AES interrupts occur.
+//!
+//! This function registers the interrupt handler in the interrupt vector
+//! table, and enables AES interrupts on the interrupt controller; specific AES
+//! interrupt sources must be enabled using AESIntEnable().  The interrupt
+//! handler being registered must clear the source of the interrupt using
+//! AESIntClear().
+//!
+//! If the application is using a static interrupt vector table stored in
+//! flash, then it is not necessary to register the interrupt handler this way.
+//! Instead, IntEnable() is used to enable AES interrupts on the
+//! interrupt controller.
+//!
+//! \sa IntRegister() for important information about registering interrupt
+//! handlers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Register the interrupt handler.
+    //
+    IntRegister(INT_AES, pfnHandler);
+
+    //
+    // Enable the interrupt
+    //
+    IntEnable(INT_AES);
+}
+
+//*****************************************************************************
+//
+//! Unregisters an interrupt handler for the AES module.
+//!
+//! \param ui32Base is the base address of the AES module.
+//!
+//! This function unregisters the previously registered interrupt handler and
+//! disables the interrupt in the interrupt controller.
+//!
+//! \sa IntRegister() for important information about registering interrupt
+//! handlers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESIntUnregister(uint32_t ui32Base)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+
+    //
+    // Disable the interrupt.
+    //
+    IntDisable(INT_AES);
+
+    //
+    // Unregister the interrupt handler.
+    //
+    IntUnregister(INT_AES);
+}
+
+//*****************************************************************************
+//
+//! Enables uDMA requests for the AES module.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32Flags is a bit mask of the uDMA requests to be enabled.
+//!
+//! This function enables the uDMA request sources in the AES module.
+//! The \e ui32Flags parameter is the logical OR of any of the following:
+//!
+//! - \b AES_DMA_DATA_IN
+//! - \b AES_DMA_DATA_OUT
+//! - \b AES_DMA_CONTEXT_IN
+//! - \b AES_DMA_CONTEXT_OUT
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32Flags == AES_DMA_DATA_IN) ||
+           (ui32Flags == AES_DMA_DATA_OUT) ||
+           (ui32Flags == AES_DMA_CONTEXT_IN) ||
+           (ui32Flags == AES_DMA_CONTEXT_OUT));
+
+    //
+    // Set the flags in the current register value.
+    //
+    HWREG(ui32Base + AES_O_SYSCONFIG) |= ui32Flags;
+}
+
+//*****************************************************************************
+//
+//! Disables uDMA requests for the AES module.
+//!
+//! \param ui32Base is the base address of the AES module.
+//! \param ui32Flags is a bit mask of the uDMA requests to be disabled.
+//!
+//! This function disables the uDMA request sources in the AES module.
+//! The \e ui32Flags parameter is the logical OR of any of the
+//! following:
+//!
+//! - \b AES_DMA_DATA_IN
+//! - \b AES_DMA_DATA_OUT
+//! - \b AES_DMA_CONTEXT_IN
+//! - \b AES_DMA_CONTEXT_OUT
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+AESDMADisable(uint32_t ui32Base, uint32_t ui32Flags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == AES_BASE);
+    ASSERT((ui32Flags == AES_DMA_DATA_IN) ||
+           (ui32Flags == AES_DMA_DATA_OUT) ||
+           (ui32Flags == AES_DMA_CONTEXT_IN) ||
+           (ui32Flags == AES_DMA_CONTEXT_OUT));
+
+    //
+    // Clear the flags in the current register value.
+    //
+    HWREG(ui32Base + AES_O_SYSCONFIG) &= ~ui32Flags;
+}
+
+//*****************************************************************************
+//
+// Close the Doxygen group.
+//! @}
+//
+//*****************************************************************************
diff --git a/micropython/ports/cc3200/hal/aes.h b/micropython/ports/cc3200/hal/aes.h
index 766d3587e4fc30a1ebbbaae68cee3e0b66881ea6..59f1599d1b452de0c0dc5e652928187ed176fff2 100644
--- a/micropython/ports/cc3200/hal/aes.h
+++ b/micropython/ports/cc3200/hal/aes.h
@@ -1,218 +1,218 @@
-//*****************************************************************************
-//
-//  aes.h
-//
-//  Defines and Macros for the AES module.
-//
-//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-//
-//
-//  Redistribution and use in source and binary forms, with or without
-//  modification, are permitted provided that the following conditions
-//  are met:
-//
-//    Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//
-//    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//
-//    Neither the name of Texas Instruments Incorporated nor the names of
-//    its contributors may be used to endorse or promote products derived
-//    from this software without specific prior written permission.
-//
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-//*****************************************************************************
-
-#ifndef __DRIVERLIB_AES_H__
-#define __DRIVERLIB_AES_H__
-
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-//*****************************************************************************
-//
-// The following defines are used to specify the operation direction in the
-// ui32Config argument in the AESConfig function.  Only one is permitted.
-//
-//*****************************************************************************
-#define AES_CFG_DIR_ENCRYPT     0x00000004
-#define AES_CFG_DIR_DECRYPT     0x00000000
-
-//*****************************************************************************
-//
-// The following defines are used to specify the key size in the ui32Config
-// argument in the AESConfig function.  Only one is permitted.
-//
-//*****************************************************************************
-#define AES_CFG_KEY_SIZE_128BIT 0x00000008
-#define AES_CFG_KEY_SIZE_192BIT 0x00000010
-#define AES_CFG_KEY_SIZE_256BIT 0x00000018
-
-//*****************************************************************************
-//
-// The following defines are used to specify the mode of operation in the
-// ui32Config argument in the AESConfig function.  Only one is permitted.
-//
-//*****************************************************************************
-#define AES_CFG_MODE_M          0x2007fe60
-#define AES_CFG_MODE_ECB        0x00000000
-#define AES_CFG_MODE_CBC        0x00000020
-#define AES_CFG_MODE_CTR        0x00000040
-#define AES_CFG_MODE_ICM        0x00000200
-#define AES_CFG_MODE_CFB        0x00000400
-#define AES_CFG_MODE_XTS_TWEAKJL \
-                                0x00000800
-#define AES_CFG_MODE_XTS_K2IJL \
-                                0x00001000
-#define AES_CFG_MODE_XTS_K2ILJ0 \
-                                0x00001800
-#define AES_CFG_MODE_F8         0x00002000
-#define AES_CFG_MODE_F9         0x20004000
-#define AES_CFG_MODE_CBCMAC     0x20008000
-#define AES_CFG_MODE_GCM_HLY0ZERO \
-                                0x20010040
-#define AES_CFG_MODE_GCM_HLY0CALC \
-                                0x20020040
-#define AES_CFG_MODE_GCM_HY0CALC \
-                                0x20030040
-#define AES_CFG_MODE_CCM        0x20040040
-
-//*****************************************************************************
-//
-// The following defines are used to specify the counter width in the
-// ui32Config argument in the AESConfig function.  It is only required to
-// be defined when using CTR, CCM, or GCM modes. Only one length is permitted.
-//
-//*****************************************************************************
-#define AES_CFG_CTR_WIDTH_32    0x00000000
-#define AES_CFG_CTR_WIDTH_64    0x00000080
-#define AES_CFG_CTR_WIDTH_96    0x00000100
-#define AES_CFG_CTR_WIDTH_128   0x00000180
-
-//*****************************************************************************
-//
-// The following defines are used to define the width of the length field for
-// CCM operation through the ui32Config argument in the AESConfig function.
-// This value is also known as L.  Only one is permitted.
-//
-//*****************************************************************************
-#define AES_CFG_CCM_L_2         0x00080000
-#define AES_CFG_CCM_L_4         0x00180000
-#define AES_CFG_CCM_L_8         0x00380000
-
-//*****************************************************************************
-//
-// The following defines are used to define the length of the authentication
-// field for CCM operations through the ui32Config argument in the AESConfig
-// function.  This value is also known as M.  Only one is permitted.
-//
-//*****************************************************************************
-#define AES_CFG_CCM_M_4         0x00400000
-#define AES_CFG_CCM_M_6         0x00800000
-#define AES_CFG_CCM_M_8         0x00c00000
-#define AES_CFG_CCM_M_10        0x01000000
-#define AES_CFG_CCM_M_12        0x01400000
-#define AES_CFG_CCM_M_14        0x01800000
-#define AES_CFG_CCM_M_16        0x01c00000
-
-//*****************************************************************************
-//
-// Interrupt flags for use with the AESIntEnable, AESIntDisable, and
-// AESIntStatus functions.
-//
-//*****************************************************************************
-#define AES_INT_CONTEXT_IN      0x00000001
-#define AES_INT_CONTEXT_OUT     0x00000008
-#define AES_INT_DATA_IN         0x00000002
-#define AES_INT_DATA_OUT        0x00000004
-#define AES_INT_DMA_CONTEXT_IN  0x00010000
-#define AES_INT_DMA_CONTEXT_OUT 0x00020000
-#define AES_INT_DMA_DATA_IN     0x00040000
-#define AES_INT_DMA_DATA_OUT    0x00080000
-
-//*****************************************************************************
-//
-// Defines used when enabling and disabling DMA requests in the
-// AESEnableDMA and AESDisableDMA functions.
-//
-//*****************************************************************************
-#define AES_DMA_DATA_IN         0x00000040
-#define AES_DMA_DATA_OUT        0x00000020
-#define AES_DMA_CONTEXT_IN      0x00000080
-#define AES_DMA_CONTEXT_OUT     0x00000100
-
-//*****************************************************************************
-//
-// Function prototypes.
-//
-//*****************************************************************************
-extern void AESConfigSet(uint32_t ui32Base, uint32_t ui32Config);
-extern void AESKey1Set(uint32_t ui32Base, uint8_t *pui8Key,
-                       uint32_t ui32Keysize);
-extern void AESKey2Set(uint32_t ui32Base, uint8_t *pui8Key,
-                       uint32_t ui32Keysize);
-extern void AESKey3Set(uint32_t ui32Base, uint8_t *pui8Key);
-extern void AESIVSet(uint32_t ui32Base, uint8_t *pui8IVdata);
-extern void AESIVGet(uint32_t ui32Base, uint8_t *pui8IVdata);
-extern void AESTagRead(uint32_t ui32Base, uint8_t *pui8TagData);
-extern void AESDataLengthSet(uint32_t ui32Base, uint64_t ui64Length);
-extern void AESAuthDataLengthSet(uint32_t ui32Base, uint32_t ui32Length);
-extern bool AESDataReadNonBlocking(uint32_t ui32Base, uint8_t *pui8Dest,
-                                   uint8_t ui8Length);
-extern void AESDataRead(uint32_t ui32Base, uint8_t *pui8Dest,
-                        uint8_t ui8Length);
-extern bool AESDataWriteNonBlocking(uint32_t ui32Base, uint8_t *pui8Src,
-                                    uint8_t ui8Length);
-extern void AESDataWrite(uint32_t ui32Base, uint8_t *pui8Src,
-                         uint8_t ui8Length);
-extern bool AESDataProcess(uint32_t ui32Base, uint8_t *pui8Src,
-                           uint8_t *pui8Dest,
-               uint32_t ui32Length);
-extern bool AESDataMAC(uint32_t ui32Base, uint8_t *pui8Src,
-                       uint32_t ui32Length,
-            uint8_t *pui8Tag);
-extern bool AESDataProcessAE(uint32_t ui32Base, uint8_t *pui8Src,
-                             uint8_t *pui8Dest, uint32_t ui32Length,
-                             uint8_t *pui8AuthSrc, uint32_t ui32AuthLength,
-                             uint8_t *pui8Tag);
-extern uint32_t AESIntStatus(uint32_t ui32Base, bool bMasked);
-extern void AESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
-extern void AESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
-extern void AESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
-extern void AESIntRegister(uint32_t ui32Base, void(*pfnHandler)(void));
-extern void AESIntUnregister(uint32_t ui32Base);
-extern void AESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags);
-extern void AESDMADisable(uint32_t ui32Base, uint32_t ui32Flags);
-
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
-#ifdef __cplusplus
-}
-#endif
-
-#endif //  __DRIVERLIB_AES_H__
+//*****************************************************************************
+//
+//  aes.h
+//
+//  Defines and Macros for the AES module.
+//
+//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
+//  are met:
+//
+//    Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//
+//    Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//
+//    Neither the name of Texas Instruments Incorporated nor the names of
+//    its contributors may be used to endorse or promote products derived
+//    from this software without specific prior written permission.
+//
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//*****************************************************************************
+
+#ifndef __DRIVERLIB_AES_H__
+#define __DRIVERLIB_AES_H__
+
+//*****************************************************************************
+//
+// If building with a C++ compiler, make all of the definitions in this header
+// have a C binding.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+//*****************************************************************************
+//
+// The following defines are used to specify the operation direction in the
+// ui32Config argument in the AESConfig function.  Only one is permitted.
+//
+//*****************************************************************************
+#define AES_CFG_DIR_ENCRYPT     0x00000004
+#define AES_CFG_DIR_DECRYPT     0x00000000
+
+//*****************************************************************************
+//
+// The following defines are used to specify the key size in the ui32Config
+// argument in the AESConfig function.  Only one is permitted.
+//
+//*****************************************************************************
+#define AES_CFG_KEY_SIZE_128BIT 0x00000008
+#define AES_CFG_KEY_SIZE_192BIT 0x00000010
+#define AES_CFG_KEY_SIZE_256BIT 0x00000018
+
+//*****************************************************************************
+//
+// The following defines are used to specify the mode of operation in the
+// ui32Config argument in the AESConfig function.  Only one is permitted.
+//
+//*****************************************************************************
+#define AES_CFG_MODE_M          0x2007fe60
+#define AES_CFG_MODE_ECB        0x00000000
+#define AES_CFG_MODE_CBC        0x00000020
+#define AES_CFG_MODE_CTR        0x00000040
+#define AES_CFG_MODE_ICM        0x00000200
+#define AES_CFG_MODE_CFB        0x00000400
+#define AES_CFG_MODE_XTS_TWEAKJL \
+                                0x00000800
+#define AES_CFG_MODE_XTS_K2IJL \
+                                0x00001000
+#define AES_CFG_MODE_XTS_K2ILJ0 \
+                                0x00001800
+#define AES_CFG_MODE_F8         0x00002000
+#define AES_CFG_MODE_F9         0x20004000
+#define AES_CFG_MODE_CBCMAC     0x20008000
+#define AES_CFG_MODE_GCM_HLY0ZERO \
+                                0x20010040
+#define AES_CFG_MODE_GCM_HLY0CALC \
+                                0x20020040
+#define AES_CFG_MODE_GCM_HY0CALC \
+                                0x20030040
+#define AES_CFG_MODE_CCM        0x20040040
+
+//*****************************************************************************
+//
+// The following defines are used to specify the counter width in the
+// ui32Config argument in the AESConfig function.  It is only required to
+// be defined when using CTR, CCM, or GCM modes. Only one length is permitted.
+//
+//*****************************************************************************
+#define AES_CFG_CTR_WIDTH_32    0x00000000
+#define AES_CFG_CTR_WIDTH_64    0x00000080
+#define AES_CFG_CTR_WIDTH_96    0x00000100
+#define AES_CFG_CTR_WIDTH_128   0x00000180
+
+//*****************************************************************************
+//
+// The following defines are used to define the width of the length field for
+// CCM operation through the ui32Config argument in the AESConfig function.
+// This value is also known as L.  Only one is permitted.
+//
+//*****************************************************************************
+#define AES_CFG_CCM_L_2         0x00080000
+#define AES_CFG_CCM_L_4         0x00180000
+#define AES_CFG_CCM_L_8         0x00380000
+
+//*****************************************************************************
+//
+// The following defines are used to define the length of the authentication
+// field for CCM operations through the ui32Config argument in the AESConfig
+// function.  This value is also known as M.  Only one is permitted.
+//
+//*****************************************************************************
+#define AES_CFG_CCM_M_4         0x00400000
+#define AES_CFG_CCM_M_6         0x00800000
+#define AES_CFG_CCM_M_8         0x00c00000
+#define AES_CFG_CCM_M_10        0x01000000
+#define AES_CFG_CCM_M_12        0x01400000
+#define AES_CFG_CCM_M_14        0x01800000
+#define AES_CFG_CCM_M_16        0x01c00000
+
+//*****************************************************************************
+//
+// Interrupt flags for use with the AESIntEnable, AESIntDisable, and
+// AESIntStatus functions.
+//
+//*****************************************************************************
+#define AES_INT_CONTEXT_IN      0x00000001
+#define AES_INT_CONTEXT_OUT     0x00000008
+#define AES_INT_DATA_IN         0x00000002
+#define AES_INT_DATA_OUT        0x00000004
+#define AES_INT_DMA_CONTEXT_IN  0x00010000
+#define AES_INT_DMA_CONTEXT_OUT 0x00020000
+#define AES_INT_DMA_DATA_IN     0x00040000
+#define AES_INT_DMA_DATA_OUT    0x00080000
+
+//*****************************************************************************
+//
+// Defines used when enabling and disabling DMA requests in the
+// AESEnableDMA and AESDisableDMA functions.
+//
+//*****************************************************************************
+#define AES_DMA_DATA_IN         0x00000040
+#define AES_DMA_DATA_OUT        0x00000020
+#define AES_DMA_CONTEXT_IN      0x00000080
+#define AES_DMA_CONTEXT_OUT     0x00000100
+
+//*****************************************************************************
+//
+// Function prototypes.
+//
+//*****************************************************************************
+extern void AESConfigSet(uint32_t ui32Base, uint32_t ui32Config);
+extern void AESKey1Set(uint32_t ui32Base, uint8_t *pui8Key,
+                       uint32_t ui32Keysize);
+extern void AESKey2Set(uint32_t ui32Base, uint8_t *pui8Key,
+                       uint32_t ui32Keysize);
+extern void AESKey3Set(uint32_t ui32Base, uint8_t *pui8Key);
+extern void AESIVSet(uint32_t ui32Base, uint8_t *pui8IVdata);
+extern void AESIVGet(uint32_t ui32Base, uint8_t *pui8IVdata);
+extern void AESTagRead(uint32_t ui32Base, uint8_t *pui8TagData);
+extern void AESDataLengthSet(uint32_t ui32Base, uint64_t ui64Length);
+extern void AESAuthDataLengthSet(uint32_t ui32Base, uint32_t ui32Length);
+extern bool AESDataReadNonBlocking(uint32_t ui32Base, uint8_t *pui8Dest,
+                                   uint8_t ui8Length);
+extern void AESDataRead(uint32_t ui32Base, uint8_t *pui8Dest,
+                        uint8_t ui8Length);
+extern bool AESDataWriteNonBlocking(uint32_t ui32Base, uint8_t *pui8Src,
+                                    uint8_t ui8Length);
+extern void AESDataWrite(uint32_t ui32Base, uint8_t *pui8Src,
+                         uint8_t ui8Length);
+extern bool AESDataProcess(uint32_t ui32Base, uint8_t *pui8Src,
+                           uint8_t *pui8Dest,
+               uint32_t ui32Length);
+extern bool AESDataMAC(uint32_t ui32Base, uint8_t *pui8Src,
+                       uint32_t ui32Length,
+            uint8_t *pui8Tag);
+extern bool AESDataProcessAE(uint32_t ui32Base, uint8_t *pui8Src,
+                             uint8_t *pui8Dest, uint32_t ui32Length,
+                             uint8_t *pui8AuthSrc, uint32_t ui32AuthLength,
+                             uint8_t *pui8Tag);
+extern uint32_t AESIntStatus(uint32_t ui32Base, bool bMasked);
+extern void AESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
+extern void AESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
+extern void AESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
+extern void AESIntRegister(uint32_t ui32Base, void(*pfnHandler)(void));
+extern void AESIntUnregister(uint32_t ui32Base);
+extern void AESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags);
+extern void AESDMADisable(uint32_t ui32Base, uint32_t ui32Flags);
+
+//*****************************************************************************
+//
+// Mark the end of the C bindings section for C++ compilers.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+}
+#endif
+
+#endif //  __DRIVERLIB_AES_H__
diff --git a/micropython/ports/cc3200/hal/des.c b/micropython/ports/cc3200/hal/des.c
index 1620e6bafc83115881aea139906c83a2fa35ca81..fbb3b585e9f8e8f8bcded9115241a0371ea8582b 100644
--- a/micropython/ports/cc3200/hal/des.c
+++ b/micropython/ports/cc3200/hal/des.c
@@ -1,887 +1,887 @@
-//*****************************************************************************
-//
-//  des.c
-//
-//  Driver for the DES data transformation.
-//
-//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-//
-//
-//  Redistribution and use in source and binary forms, with or without
-//  modification, are permitted provided that the following conditions
-//  are met:
-//
-//    Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//
-//    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//
-//    Neither the name of Texas Instruments Incorporated nor the names of
-//    its contributors may be used to endorse or promote products derived
-//    from this software without specific prior written permission.
-//
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! \addtogroup DES_Data_Encryption_Standard_api
-//! @{
-//
-//*****************************************************************************
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "inc/hw_des.h"
-#include "inc/hw_dthe.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "inc/hw_types.h"
-#include "debug.h"
-#include "des.h"
-#include "interrupt.h"
-
-
-//*****************************************************************************
-//
-//! Configures the DES module for operation.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32Config is the configuration of the DES module.
-//!
-//! This function configures the DES module for operation.
-//!
-//! The \e ui32Config parameter is a bit-wise OR of a number of configuration
-//! flags. The valid flags are grouped below based on their function.
-//!
-//! The direction of the operation is specified with one of the following two
-//! flags.  Only one is permitted.
-//!
-//! - \b DES_CFG_DIR_ENCRYPT - Encryption
-//! - \b DES_CFG_DIR_DECRYPT - Decryption
-//!
-//! The operational mode of the DES engine is specified with one of the
-//! following flags. Only one is permitted.
-//!
-//! - \b DES_CFG_MODE_ECB - Electronic Codebook Mode
-//! - \b DES_CFG_MODE_CBC - Cipher-Block Chaining Mode
-//! - \b DES_CFG_MODE_CFB - Cipher Feedback Mode
-//!
-//! The selection of single DES or triple DES is specified with one of the
-//! following two flags. Only one is permitted.
-//!
-//! - \b DES_CFG_SINGLE - Single DES
-//! - \b DES_CFG_TRIPLE - Triple DES
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESConfigSet(uint32_t ui32Base, uint32_t ui32Config)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Backup the save context field.
-    //
-    ui32Config |= (HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_CONTEXT);
-
-    //
-    // Write the control register.
-    //
-    HWREG(ui32Base + DES_O_CTRL) = ui32Config;
-}
-
-//*****************************************************************************
-//
-//! Sets the key used for DES operations.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8Key is a pointer to an array that holds the key
-//!
-//! This function sets the key used for DES operations.
-//!
-//! \e pui8Key should be 64 bits long (2 words) if single DES is being used or
-//! 192 bits (6 words) if triple DES is being used.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESKeySet(uint32_t ui32Base, uint8_t *pui8Key)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Write the first part of the key.
-    //
-    HWREG(ui32Base + DES_O_KEY1_L) =  * ((uint32_t *)(pui8Key + 0));
-    HWREG(ui32Base + DES_O_KEY1_H) = * ((uint32_t *)(pui8Key + 4));
-
-    //
-    // If we are performing triple DES, then write the key registers for
-    // the second and third rounds.
-    //
-    if(HWREG(ui32Base + DES_O_CTRL) & DES_CFG_TRIPLE)
-    {
-        HWREG(ui32Base + DES_O_KEY2_L) = * ((uint32_t *)(pui8Key + 8));
-        HWREG(ui32Base + DES_O_KEY2_H) = * ((uint32_t *)(pui8Key + 12));
-        HWREG(ui32Base + DES_O_KEY3_L) = * ((uint32_t *)(pui8Key + 16));
-        HWREG(ui32Base + DES_O_KEY3_H) = * ((uint32_t *)(pui8Key + 20));
-    }
-}
-
-//*****************************************************************************
-//
-//! Sets the initialization vector in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8IVdata is a pointer to an array of 64 bits (2 words) of data to
-//! be written into the initialization vectors registers.
-//!
-//! This function sets the initialization vector in the DES module.  It returns
-//! true if the registers were successfully written.  If the context registers
-//! cannot be written at the time the function was called, then false is
-//! returned.
-//!
-//! \return True or false.
-//
-//*****************************************************************************
-bool
-DESIVSet(uint32_t ui32Base, uint8_t *pui8IVdata)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Check to see if context registers can be overwritten.  If not, return
-    // false.
-    //
-    if((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_CONTEXT) == 0)
-    {
-        return(false);
-    }
-
-    //
-    // Write the initialization vector registers.
-    //
-    HWREG(ui32Base + DES_O_IV_L) =  *((uint32_t *) (pui8IVdata + 0));
-    HWREG(ui32Base + DES_O_IV_H) = *((uint32_t *) (pui8IVdata + 4));
-
-    //
-    // Return true to indicate the write was successful.
-    //
-    return(true);
-}
-
-//*****************************************************************************
-//
-//! Sets the crytographic data length in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32Length is the length of the data in bytes.
-//!
-//! This function writes the cryptographic data length into the DES module.
-//! When this register is written, the engine is triggersed to start using
-//! this context.
-//!
-//! \note Data lengths up to (2^32 - 1) bytes are allowed.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESDataLengthSet(uint32_t ui32Base, uint32_t ui32Length)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Write the length register.
-    //
-    HWREG(ui32Base + DES_O_LENGTH) = ui32Length;
-}
-
-//*****************************************************************************
-//
-//! Reads plaintext/ciphertext from data registers without blocking
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8Dest is a pointer to an array of 2 words.
-//! \param ui8Length the length can be from 1 to 8
-//!
-//! This function returns true if the data was ready when the function was
-//! called. If the data was not ready, false is returned.
-//!
-//! \return True or false.
-//
-//*****************************************************************************
-bool
-DESDataReadNonBlocking(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
-{
-	volatile uint32_t pui32Dest[2];
-	uint8_t ui8BytCnt;
-	uint8_t *pui8DestTemp;
-
-	//
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    if((ui8Length == 0)||(ui8Length>8))
-    {
-       	return(false);
-    }
-
-    //
-    // Check to see if the data is ready to be read.
-    //
-    if((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
-    {
-        return(false);
-    }
-
-    //
-    // Read two words of data from the data registers.
-    //
-    pui32Dest[0] = HWREG(DES_BASE + DES_O_DATA_L);
-    pui32Dest[1] = HWREG(DES_BASE + DES_O_DATA_H);
-
-    //
-    //Copy the data to a block memory
-    //
-    pui8DestTemp = (uint8_t *)pui32Dest;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-    {
- 		*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
-    }
-
-    //
-    // Return true to indicate a successful write.
-    //
-    return(true);
-}
-
-//*****************************************************************************
-//
-//! Reads plaintext/ciphertext from data registers with blocking.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8Dest is a pointer to an array of bytes.
-//! \param ui8Length the length can be from 1 to 8
-//!
-//! This function waits until the DES module is finished and encrypted or
-//! decrypted data is ready.  The output data is then stored in the pui8Dest
-//! array.
-//!
-//! \return None
-//
-//*****************************************************************************
-void
-DESDataRead(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
-{
-	volatile uint32_t pui32Dest[2];
-	uint8_t ui8BytCnt;
-	uint8_t *pui8DestTemp;
-
-	//
-	// Check the arguments.
-	//
-	ASSERT(ui32Base == DES_BASE);
-	if((ui8Length == 0)||(ui8Length>8))
-	{
-		return;
-	}
-    //
-    // Wait for data output to be ready.
-    //
-    while((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_OUTPUT_READY) == 0)
-    {
-    }
-
-    //
-    // Read two words of data from the data registers.
-    //
-    pui32Dest[0] = HWREG(DES_BASE + DES_O_DATA_L);
-    pui32Dest[1] = HWREG(DES_BASE + DES_O_DATA_H);
-
-    //
-    //Copy the data to a block memory
-    //
-    pui8DestTemp = (uint8_t *)pui32Dest;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-    {
-    	*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
-    }
-}
-
-//*****************************************************************************
-//
-//! Writes plaintext/ciphertext to data registers without blocking
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8Src is a pointer to an array of 2 words.
-//! \param ui8Length the length can be from 1 to 8
-//!
-//! This function returns false if the DES module is not ready to accept
-//! data.  It returns true if the data was written successfully.
-//!
-//! \return true or false.
-//
-//*****************************************************************************
-bool
-DESDataWriteNonBlocking(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
-{
-
-    volatile uint32_t pui32Src[2]={0,0};
-    uint8_t ui8BytCnt;
-    uint8_t *pui8SrcTemp;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    if((ui8Length == 0)||(ui8Length>8))
-    {
-            return(false);
-    }
-
-    //
-    // Check if the DES module is ready to encrypt or decrypt data.  If it
-    // is not, return false.
-    //
-    if(!(DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))))
-    {
-        return(false);
-    }
-
-    //
-    // Copy the data to a block memory
-    //
-    pui8SrcTemp = (uint8_t *)pui32Src;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-    {
-            *(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
-    }
-
-    //
-    // Write the data.
-    //
-    HWREG(DES_BASE + DES_O_DATA_L) = pui32Src[0];
-    HWREG(DES_BASE + DES_O_DATA_H) = pui32Src[1];
-
-    //
-    // Return true to indicate a successful write.
-    //
-    return(true);
-}
-
-//*****************************************************************************
-//
-//! Writes plaintext/ciphertext to data registers without blocking
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8Src is a pointer to an array of bytes.
-//! \param ui8Length the length can be from 1 to 8
-//!
-//! This function waits until the DES module is ready before writing the
-//! data contained in the pui8Src array.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESDataWrite(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
-{
-    volatile uint32_t pui32Src[2]={0,0};
-    uint8_t ui8BytCnt;
-    uint8_t *pui8SrcTemp;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    if((ui8Length == 0)||(ui8Length>8))
-    {
-            return;
-    }
-
-    //
-    // Wait for the input ready bit to go high.
-    //
-    while(((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_INPUT_READY)) == 0)
-    {
-    }
-
-    //
-    //Copy the data to a block memory
-    //
-    pui8SrcTemp = (uint8_t *)pui32Src;
-    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
-    {
-            *(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
-    }
-
-    //
-    // Write the data.
-    //
-    HWREG(DES_BASE + DES_O_DATA_L) = pui32Src[0];
-    HWREG(DES_BASE + DES_O_DATA_H) = pui32Src[1];
-}
-
-//*****************************************************************************
-//
-//! Processes blocks of data through the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pui8Src is a pointer to an array of words that contains the
-//! source data for processing.
-//! \param pui8Dest is a pointer to an array of words consisting of the
-//! processed data.
-//! \param ui32Length is the length of the cryptographic data in bytes.
-//! It must be a multiple of eight.
-//!
-//! This function takes the data contained in the pui8Src array and processes
-//! it using the DES engine.  The resulting data is stored in the
-//! pui8Dest array.  The function blocks until all of the data has been
-//! processed. If processing is successful, the function returns true.
-//!
-//! \note This functions assumes that the DES module has been configured,
-//! and initialization values and keys have been written.
-//!
-//! \return true or false.
-//
-//*****************************************************************************
-bool
-DESDataProcess(uint32_t ui32Base, uint8_t *pui8Src, uint8_t *pui8Dest,
-               uint32_t ui32Length)
-{
-    uint32_t ui32Count, ui32BlkCount, ui32ByteCount;
-
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    ASSERT((ui32Length % 8) == 0);
-
-    //
-    // Write the length register first. This triggers the engine to start
-    // using this context.
-    //
-    HWREG(ui32Base + DES_O_LENGTH) = ui32Length;
-
-
-    //
-    // Now loop until the blocks are written.
-    //
-    ui32BlkCount = ui32Length/8;
-    for(ui32Count = 0; ui32Count <ui32BlkCount; ui32Count ++)
-    {
-      //
-      // Check if the input ready is fine
-      //
-      while((DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
-      {
-      }
-
-      //
-      // Write the data registers.
-      //
-      DESDataWriteNonBlocking(ui32Base, pui8Src + ui32Count*8 ,8);
-
-      //
-      // Wait for the output ready
-      //
-      while((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
-      {
-      }
-
-      //
-      // Read the data registers.
-      //
-      DESDataReadNonBlocking(ui32Base, pui8Dest + ui32Count*8 ,8);
-    }
-
-    //
-    //Now handle the residue bytes
-    //
-    ui32ByteCount = ui32Length%8;
-    if(ui32ByteCount)
-    {
-      //
-      // Check if the input ready is fine
-      //
-      while((DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
-      {
-      }
-      //
-      // Write the data registers.
-      //
-      DESDataWriteNonBlocking(ui32Base, pui8Src + (8*ui32BlkCount) ,
-                              ui32ByteCount);
-      //
-      // Wait for the output ready
-      //
-      while((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
-      {
-      }
-
-      //
-      // Read the data registers.
-      //
-      DESDataReadNonBlocking(ui32Base, pui8Dest + (8*ui32BlkCount) ,
-                             ui32ByteCount);
-    }
-
-
-
-    //
-    // Return true to indicate the process was successful.
-    //
-    return(true);
-}
-
-//*****************************************************************************
-//
-//! Returns the current interrupt status of the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param bMasked is \b false if the raw interrupt status is required and
-//! \b true if the masked interrupt status is required.
-//!
-//! This function gets the current interrupt status of the DES module.
-//! The value returned is a logical OR of the following values:
-//!
-//! - \b DES_INT_CONTEXT_IN - Context interrupt
-//! - \b DES_INT_DATA_IN - Data input interrupt
-//! - \b DES_INT_DATA_OUT_INT - Data output interrupt
-//! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//!
-//! \return A bit mask of the current interrupt status.
-//
-//*****************************************************************************
-uint32_t
-DESIntStatus(uint32_t ui32Base, bool bMasked)
-{
-   uint32_t ui32IntStatus;
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Read the status register and return the value.
-    //
-    if(bMasked)
-    {
-        ui32IntStatus = HWREG(ui32Base + DES_O_IRQSTATUS);
-        ui32IntStatus &= HWREG(ui32Base + DES_O_IRQENABLE);
-        ui32IntStatus |= ((HWREG(DTHE_BASE + DTHE_O_DES_MIS) & 0x7) << 16);
-
-        return(ui32IntStatus);
-    }
-    else
-    {
-        ui32IntStatus = HWREG(ui32Base + DES_O_IRQSTATUS);
-        ui32IntStatus |= ((HWREG(DTHE_BASE + DTHE_O_DES_MIS) & 0xD) << 16);
-        return(ui32IntStatus);
-    }
-}
-
-//*****************************************************************************
-//
-//! Enables interrupts in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32IntFlags is a bit mask of the interrupts to be enabled.
-//!
-//! \e ui32IntFlags should be a logical OR of one or more of the following
-//! values:
-//!
-//! - \b DES_INT_CONTEXT_IN - Context interrupt
-//! - \b DES_INT_DATA_IN - Data input interrupt
-//! - \b DES_INT_DATA_OUT - Data output interrupt
-//! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    ASSERT((ui32IntFlags & DES_INT_CONTEXT_IN) ||
-           (ui32IntFlags & DES_INT_DATA_IN) ||
-           (ui32IntFlags & DES_INT_DATA_OUT) ||
-           (ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
-           (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
-           (ui32IntFlags & DES_INT_DMA_DATA_OUT));
-
-    //
-    // Enable the interrupts from the flags.
-    //
-    HWREG(DTHE_BASE + DTHE_O_DES_IM)  &= ~((ui32IntFlags & 0x00070000) >> 16);
-    HWREG(ui32Base + DES_O_IRQENABLE) |= ui32IntFlags & 0x0000ffff;
-}
-
-//*****************************************************************************
-//
-//! Disables interrupts in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32IntFlags is a bit mask of the interrupts to be disabled.
-//!
-//! This function disables interrupt sources in the DES module.
-//! \e ui32IntFlags should be a logical OR of one or more of the following
-//! values:
-//!
-//! - \b DES_INT_CONTEXT_IN - Context interrupt
-//! - \b DES_INT_DATA_IN - Data input interrupt
-//! - \b DES_INT_DATA_OUT - Data output interrupt
-//! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
-//! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
-//! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    ASSERT((ui32IntFlags & DES_INT_CONTEXT_IN) ||
-           (ui32IntFlags & DES_INT_DATA_IN) ||
-           (ui32IntFlags & DES_INT_DATA_OUT) ||
-           (ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
-           (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
-           (ui32IntFlags & DES_INT_DMA_DATA_OUT));
-
-    //
-    // Clear the interrupts from the flags.
-    //
-    HWREG(DTHE_BASE + DTHE_O_AES_IM)  |= ((ui32IntFlags & 0x00070000) >> 16);
-    HWREG(ui32Base + DES_O_IRQENABLE) &= ~(ui32IntFlags & 0x0000ffff);
-}
-
-//*****************************************************************************
-//
-//! Clears interrupts in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32IntFlags is a bit mask of the interrupts to be disabled.
-//!
-//! This function disables interrupt sources in the DES module.
-//! \e ui32IntFlags should be a logical OR of one or more of the following
-//! values:
-//!
-//! - \b DES_INT_DMA_CONTEXT_IN - Context interrupt
-//! - \b DES_INT_DMA_DATA_IN - Data input interrupt
-//! - \b DES_INT_DMA_DATA_OUT - Data output interrupt
-//!
-//! \note The DMA done interrupts are the only interrupts that can be cleared.
-//! The remaining interrupts can be disabled instead using DESIntDisable().
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    ASSERT((ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
-           (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
-           (ui32IntFlags & DES_INT_DMA_DATA_OUT));
-
-    HWREG(DTHE_BASE + DTHE_O_DES_IC) = ((ui32IntFlags & 0x00070000) >> 16);
-}
-
-//*****************************************************************************
-//
-//! Registers an interrupt handler for the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param pfnHandler is a pointer to the function to be called when the
-//! enabled DES interrupts occur.
-//!
-//! This function registers the interrupt handler in the interrupt vector
-//! table, and enables DES interrupts on the interrupt controller; specific DES
-//! interrupt sources must be enabled using DESIntEnable().  The interrupt
-//! handler being registered must clear the source of the interrupt using
-//! DESIntClear().
-//!
-//! If the application is using a static interrupt vector table stored in
-//! flash, then it is not necessary to register the interrupt handler this way.
-//! Instead, IntEnable() should be used to enable DES interrupts on the
-//! interrupt controller.
-//!
-//! \sa IntRegister() for important information about registering interrupt
-//! handlers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Register the interrupt handler.
-    //
-    IntRegister(INT_DES, pfnHandler);
-
-    //
-    // Enable the interrupt.
-    //
-    IntEnable(INT_DES);
-}
-
-//*****************************************************************************
-//
-//! Unregisters an interrupt handler for the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//!
-//! This function unregisters the previously registered interrupt handler and
-//! disables the interrupt in the interrupt controller.
-//!
-//! \sa IntRegister() for important information about registering interrupt
-//! handlers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESIntUnregister(uint32_t ui32Base)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-
-    //
-    // Disable the interrupt.
-    //
-    IntDisable(INT_DES);
-
-    //
-    // Unregister the interrupt handler.
-    //
-    IntUnregister(INT_DES);
-}
-
-//*****************************************************************************
-//
-//! Enables DMA request sources in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32Flags is a bit mask of the DMA requests to be enabled.
-//!
-//! This function enables DMA request sources in the DES module.  The
-//! \e ui32Flags parameter should be the logical OR of any of the following:
-//!
-//! - \b DES_DMA_CONTEXT_IN - Context In
-//! - \b DES_DMA_DATA_OUT - Data Out
-//! - \b DES_DMA_DATA_IN - Data In
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    ASSERT((ui32Flags & DES_DMA_CONTEXT_IN) ||
-           (ui32Flags & DES_DMA_DATA_OUT) ||
-           (ui32Flags & DES_DMA_DATA_IN));
-
-    //
-    // Set the data in and data out DMA request enable bits.
-    //
-    HWREG(ui32Base + DES_O_SYSCONFIG) |= ui32Flags;
-}
-
-//*****************************************************************************
-//
-//! Disables DMA request sources in the DES module.
-//!
-//! \param ui32Base is the base address of the DES module.
-//! \param ui32Flags is a bit mask of the DMA requests to be disabled.
-//!
-//! This function disables DMA request sources in the DES module.  The
-//! \e ui32Flags parameter should be the logical OR of any of the following:
-//!
-//! - \b DES_DMA_CONTEXT_IN - Context In
-//! - \b DES_DMA_DATA_OUT - Data Out
-//! - \b DES_DMA_DATA_IN - Data In
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-DESDMADisable(uint32_t ui32Base, uint32_t ui32Flags)
-{
-    //
-    // Check the arguments.
-    //
-    ASSERT(ui32Base == DES_BASE);
-    ASSERT((ui32Flags & DES_DMA_CONTEXT_IN) ||
-           (ui32Flags & DES_DMA_DATA_OUT) ||
-           (ui32Flags & DES_DMA_DATA_IN));
-
-    //
-    // Disable the DMA sources.
-    //
-    HWREG(ui32Base + DES_O_SYSCONFIG) &= ~ui32Flags;
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
+//*****************************************************************************
+//
+//  des.c
+//
+//  Driver for the DES data transformation.
+//
+//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
+//  are met:
+//
+//    Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//
+//    Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//
+//    Neither the name of Texas Instruments Incorporated nor the names of
+//    its contributors may be used to endorse or promote products derived
+//    from this software without specific prior written permission.
+//
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//*****************************************************************************
+
+//*****************************************************************************
+//
+//! \addtogroup DES_Data_Encryption_Standard_api
+//! @{
+//
+//*****************************************************************************
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "inc/hw_des.h"
+#include "inc/hw_dthe.h"
+#include "inc/hw_ints.h"
+#include "inc/hw_memmap.h"
+#include "inc/hw_types.h"
+#include "debug.h"
+#include "des.h"
+#include "interrupt.h"
+
+
+//*****************************************************************************
+//
+//! Configures the DES module for operation.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32Config is the configuration of the DES module.
+//!
+//! This function configures the DES module for operation.
+//!
+//! The \e ui32Config parameter is a bit-wise OR of a number of configuration
+//! flags. The valid flags are grouped below based on their function.
+//!
+//! The direction of the operation is specified with one of the following two
+//! flags.  Only one is permitted.
+//!
+//! - \b DES_CFG_DIR_ENCRYPT - Encryption
+//! - \b DES_CFG_DIR_DECRYPT - Decryption
+//!
+//! The operational mode of the DES engine is specified with one of the
+//! following flags. Only one is permitted.
+//!
+//! - \b DES_CFG_MODE_ECB - Electronic Codebook Mode
+//! - \b DES_CFG_MODE_CBC - Cipher-Block Chaining Mode
+//! - \b DES_CFG_MODE_CFB - Cipher Feedback Mode
+//!
+//! The selection of single DES or triple DES is specified with one of the
+//! following two flags. Only one is permitted.
+//!
+//! - \b DES_CFG_SINGLE - Single DES
+//! - \b DES_CFG_TRIPLE - Triple DES
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESConfigSet(uint32_t ui32Base, uint32_t ui32Config)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Backup the save context field.
+    //
+    ui32Config |= (HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_CONTEXT);
+
+    //
+    // Write the control register.
+    //
+    HWREG(ui32Base + DES_O_CTRL) = ui32Config;
+}
+
+//*****************************************************************************
+//
+//! Sets the key used for DES operations.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8Key is a pointer to an array that holds the key
+//!
+//! This function sets the key used for DES operations.
+//!
+//! \e pui8Key should be 64 bits long (2 words) if single DES is being used or
+//! 192 bits (6 words) if triple DES is being used.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESKeySet(uint32_t ui32Base, uint8_t *pui8Key)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Write the first part of the key.
+    //
+    HWREG(ui32Base + DES_O_KEY1_L) =  * ((uint32_t *)(pui8Key + 0));
+    HWREG(ui32Base + DES_O_KEY1_H) = * ((uint32_t *)(pui8Key + 4));
+
+    //
+    // If we are performing triple DES, then write the key registers for
+    // the second and third rounds.
+    //
+    if(HWREG(ui32Base + DES_O_CTRL) & DES_CFG_TRIPLE)
+    {
+        HWREG(ui32Base + DES_O_KEY2_L) = * ((uint32_t *)(pui8Key + 8));
+        HWREG(ui32Base + DES_O_KEY2_H) = * ((uint32_t *)(pui8Key + 12));
+        HWREG(ui32Base + DES_O_KEY3_L) = * ((uint32_t *)(pui8Key + 16));
+        HWREG(ui32Base + DES_O_KEY3_H) = * ((uint32_t *)(pui8Key + 20));
+    }
+}
+
+//*****************************************************************************
+//
+//! Sets the initialization vector in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8IVdata is a pointer to an array of 64 bits (2 words) of data to
+//! be written into the initialization vectors registers.
+//!
+//! This function sets the initialization vector in the DES module.  It returns
+//! true if the registers were successfully written.  If the context registers
+//! cannot be written at the time the function was called, then false is
+//! returned.
+//!
+//! \return True or false.
+//
+//*****************************************************************************
+bool
+DESIVSet(uint32_t ui32Base, uint8_t *pui8IVdata)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Check to see if context registers can be overwritten.  If not, return
+    // false.
+    //
+    if((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_CONTEXT) == 0)
+    {
+        return(false);
+    }
+
+    //
+    // Write the initialization vector registers.
+    //
+    HWREG(ui32Base + DES_O_IV_L) =  *((uint32_t *) (pui8IVdata + 0));
+    HWREG(ui32Base + DES_O_IV_H) = *((uint32_t *) (pui8IVdata + 4));
+
+    //
+    // Return true to indicate the write was successful.
+    //
+    return(true);
+}
+
+//*****************************************************************************
+//
+//! Sets the crytographic data length in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32Length is the length of the data in bytes.
+//!
+//! This function writes the cryptographic data length into the DES module.
+//! When this register is written, the engine is triggersed to start using
+//! this context.
+//!
+//! \note Data lengths up to (2^32 - 1) bytes are allowed.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESDataLengthSet(uint32_t ui32Base, uint32_t ui32Length)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Write the length register.
+    //
+    HWREG(ui32Base + DES_O_LENGTH) = ui32Length;
+}
+
+//*****************************************************************************
+//
+//! Reads plaintext/ciphertext from data registers without blocking
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8Dest is a pointer to an array of 2 words.
+//! \param ui8Length the length can be from 1 to 8
+//!
+//! This function returns true if the data was ready when the function was
+//! called. If the data was not ready, false is returned.
+//!
+//! \return True or false.
+//
+//*****************************************************************************
+bool
+DESDataReadNonBlocking(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
+{
+	volatile uint32_t pui32Dest[2];
+	uint8_t ui8BytCnt;
+	uint8_t *pui8DestTemp;
+
+	//
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    if((ui8Length == 0)||(ui8Length>8))
+    {
+       	return(false);
+    }
+
+    //
+    // Check to see if the data is ready to be read.
+    //
+    if((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
+    {
+        return(false);
+    }
+
+    //
+    // Read two words of data from the data registers.
+    //
+    pui32Dest[0] = HWREG(DES_BASE + DES_O_DATA_L);
+    pui32Dest[1] = HWREG(DES_BASE + DES_O_DATA_H);
+
+    //
+    //Copy the data to a block memory
+    //
+    pui8DestTemp = (uint8_t *)pui32Dest;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+    {
+ 		*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
+    }
+
+    //
+    // Return true to indicate a successful write.
+    //
+    return(true);
+}
+
+//*****************************************************************************
+//
+//! Reads plaintext/ciphertext from data registers with blocking.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8Dest is a pointer to an array of bytes.
+//! \param ui8Length the length can be from 1 to 8
+//!
+//! This function waits until the DES module is finished and encrypted or
+//! decrypted data is ready.  The output data is then stored in the pui8Dest
+//! array.
+//!
+//! \return None
+//
+//*****************************************************************************
+void
+DESDataRead(uint32_t ui32Base, uint8_t *pui8Dest, uint8_t ui8Length)
+{
+	volatile uint32_t pui32Dest[2];
+	uint8_t ui8BytCnt;
+	uint8_t *pui8DestTemp;
+
+	//
+	// Check the arguments.
+	//
+	ASSERT(ui32Base == DES_BASE);
+	if((ui8Length == 0)||(ui8Length>8))
+	{
+		return;
+	}
+    //
+    // Wait for data output to be ready.
+    //
+    while((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_OUTPUT_READY) == 0)
+    {
+    }
+
+    //
+    // Read two words of data from the data registers.
+    //
+    pui32Dest[0] = HWREG(DES_BASE + DES_O_DATA_L);
+    pui32Dest[1] = HWREG(DES_BASE + DES_O_DATA_H);
+
+    //
+    //Copy the data to a block memory
+    //
+    pui8DestTemp = (uint8_t *)pui32Dest;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+    {
+    	*(pui8Dest+ui8BytCnt) = *(pui8DestTemp+ui8BytCnt);
+    }
+}
+
+//*****************************************************************************
+//
+//! Writes plaintext/ciphertext to data registers without blocking
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8Src is a pointer to an array of 2 words.
+//! \param ui8Length the length can be from 1 to 8
+//!
+//! This function returns false if the DES module is not ready to accept
+//! data.  It returns true if the data was written successfully.
+//!
+//! \return true or false.
+//
+//*****************************************************************************
+bool
+DESDataWriteNonBlocking(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
+{
+
+    volatile uint32_t pui32Src[2]={0,0};
+    uint8_t ui8BytCnt;
+    uint8_t *pui8SrcTemp;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    if((ui8Length == 0)||(ui8Length>8))
+    {
+            return(false);
+    }
+
+    //
+    // Check if the DES module is ready to encrypt or decrypt data.  If it
+    // is not, return false.
+    //
+    if(!(DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))))
+    {
+        return(false);
+    }
+
+    //
+    // Copy the data to a block memory
+    //
+    pui8SrcTemp = (uint8_t *)pui32Src;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+    {
+            *(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
+    }
+
+    //
+    // Write the data.
+    //
+    HWREG(DES_BASE + DES_O_DATA_L) = pui32Src[0];
+    HWREG(DES_BASE + DES_O_DATA_H) = pui32Src[1];
+
+    //
+    // Return true to indicate a successful write.
+    //
+    return(true);
+}
+
+//*****************************************************************************
+//
+//! Writes plaintext/ciphertext to data registers without blocking
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8Src is a pointer to an array of bytes.
+//! \param ui8Length the length can be from 1 to 8
+//!
+//! This function waits until the DES module is ready before writing the
+//! data contained in the pui8Src array.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESDataWrite(uint32_t ui32Base, uint8_t *pui8Src, uint8_t ui8Length)
+{
+    volatile uint32_t pui32Src[2]={0,0};
+    uint8_t ui8BytCnt;
+    uint8_t *pui8SrcTemp;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    if((ui8Length == 0)||(ui8Length>8))
+    {
+            return;
+    }
+
+    //
+    // Wait for the input ready bit to go high.
+    //
+    while(((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_INPUT_READY)) == 0)
+    {
+    }
+
+    //
+    //Copy the data to a block memory
+    //
+    pui8SrcTemp = (uint8_t *)pui32Src;
+    for(ui8BytCnt = 0; ui8BytCnt < ui8Length ; ui8BytCnt++)
+    {
+            *(pui8SrcTemp+ui8BytCnt) = *(pui8Src+ui8BytCnt);
+    }
+
+    //
+    // Write the data.
+    //
+    HWREG(DES_BASE + DES_O_DATA_L) = pui32Src[0];
+    HWREG(DES_BASE + DES_O_DATA_H) = pui32Src[1];
+}
+
+//*****************************************************************************
+//
+//! Processes blocks of data through the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pui8Src is a pointer to an array of words that contains the
+//! source data for processing.
+//! \param pui8Dest is a pointer to an array of words consisting of the
+//! processed data.
+//! \param ui32Length is the length of the cryptographic data in bytes.
+//! It must be a multiple of eight.
+//!
+//! This function takes the data contained in the pui8Src array and processes
+//! it using the DES engine.  The resulting data is stored in the
+//! pui8Dest array.  The function blocks until all of the data has been
+//! processed. If processing is successful, the function returns true.
+//!
+//! \note This functions assumes that the DES module has been configured,
+//! and initialization values and keys have been written.
+//!
+//! \return true or false.
+//
+//*****************************************************************************
+bool
+DESDataProcess(uint32_t ui32Base, uint8_t *pui8Src, uint8_t *pui8Dest,
+               uint32_t ui32Length)
+{
+    uint32_t ui32Count, ui32BlkCount, ui32ByteCount;
+
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    ASSERT((ui32Length % 8) == 0);
+
+    //
+    // Write the length register first. This triggers the engine to start
+    // using this context.
+    //
+    HWREG(ui32Base + DES_O_LENGTH) = ui32Length;
+
+
+    //
+    // Now loop until the blocks are written.
+    //
+    ui32BlkCount = ui32Length/8;
+    for(ui32Count = 0; ui32Count <ui32BlkCount; ui32Count ++)
+    {
+      //
+      // Check if the input ready is fine
+      //
+      while((DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
+      {
+      }
+
+      //
+      // Write the data registers.
+      //
+      DESDataWriteNonBlocking(ui32Base, pui8Src + ui32Count*8 ,8);
+
+      //
+      // Wait for the output ready
+      //
+      while((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
+      {
+      }
+
+      //
+      // Read the data registers.
+      //
+      DESDataReadNonBlocking(ui32Base, pui8Dest + ui32Count*8 ,8);
+    }
+
+    //
+    //Now handle the residue bytes
+    //
+    ui32ByteCount = ui32Length%8;
+    if(ui32ByteCount)
+    {
+      //
+      // Check if the input ready is fine
+      //
+      while((DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
+      {
+      }
+      //
+      // Write the data registers.
+      //
+      DESDataWriteNonBlocking(ui32Base, pui8Src + (8*ui32BlkCount) ,
+                              ui32ByteCount);
+      //
+      // Wait for the output ready
+      //
+      while((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
+      {
+      }
+
+      //
+      // Read the data registers.
+      //
+      DESDataReadNonBlocking(ui32Base, pui8Dest + (8*ui32BlkCount) ,
+                             ui32ByteCount);
+    }
+
+
+
+    //
+    // Return true to indicate the process was successful.
+    //
+    return(true);
+}
+
+//*****************************************************************************
+//
+//! Returns the current interrupt status of the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param bMasked is \b false if the raw interrupt status is required and
+//! \b true if the masked interrupt status is required.
+//!
+//! This function gets the current interrupt status of the DES module.
+//! The value returned is a logical OR of the following values:
+//!
+//! - \b DES_INT_CONTEXT_IN - Context interrupt
+//! - \b DES_INT_DATA_IN - Data input interrupt
+//! - \b DES_INT_DATA_OUT_INT - Data output interrupt
+//! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//!
+//! \return A bit mask of the current interrupt status.
+//
+//*****************************************************************************
+uint32_t
+DESIntStatus(uint32_t ui32Base, bool bMasked)
+{
+   uint32_t ui32IntStatus;
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Read the status register and return the value.
+    //
+    if(bMasked)
+    {
+        ui32IntStatus = HWREG(ui32Base + DES_O_IRQSTATUS);
+        ui32IntStatus &= HWREG(ui32Base + DES_O_IRQENABLE);
+        ui32IntStatus |= ((HWREG(DTHE_BASE + DTHE_O_DES_MIS) & 0x7) << 16);
+
+        return(ui32IntStatus);
+    }
+    else
+    {
+        ui32IntStatus = HWREG(ui32Base + DES_O_IRQSTATUS);
+        ui32IntStatus |= ((HWREG(DTHE_BASE + DTHE_O_DES_MIS) & 0xD) << 16);
+        return(ui32IntStatus);
+    }
+}
+
+//*****************************************************************************
+//
+//! Enables interrupts in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32IntFlags is a bit mask of the interrupts to be enabled.
+//!
+//! \e ui32IntFlags should be a logical OR of one or more of the following
+//! values:
+//!
+//! - \b DES_INT_CONTEXT_IN - Context interrupt
+//! - \b DES_INT_DATA_IN - Data input interrupt
+//! - \b DES_INT_DATA_OUT - Data output interrupt
+//! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    ASSERT((ui32IntFlags & DES_INT_CONTEXT_IN) ||
+           (ui32IntFlags & DES_INT_DATA_IN) ||
+           (ui32IntFlags & DES_INT_DATA_OUT) ||
+           (ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
+           (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
+           (ui32IntFlags & DES_INT_DMA_DATA_OUT));
+
+    //
+    // Enable the interrupts from the flags.
+    //
+    HWREG(DTHE_BASE + DTHE_O_DES_IM)  &= ~((ui32IntFlags & 0x00070000) >> 16);
+    HWREG(ui32Base + DES_O_IRQENABLE) |= ui32IntFlags & 0x0000ffff;
+}
+
+//*****************************************************************************
+//
+//! Disables interrupts in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32IntFlags is a bit mask of the interrupts to be disabled.
+//!
+//! This function disables interrupt sources in the DES module.
+//! \e ui32IntFlags should be a logical OR of one or more of the following
+//! values:
+//!
+//! - \b DES_INT_CONTEXT_IN - Context interrupt
+//! - \b DES_INT_DATA_IN - Data input interrupt
+//! - \b DES_INT_DATA_OUT - Data output interrupt
+//! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
+//! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
+//! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    ASSERT((ui32IntFlags & DES_INT_CONTEXT_IN) ||
+           (ui32IntFlags & DES_INT_DATA_IN) ||
+           (ui32IntFlags & DES_INT_DATA_OUT) ||
+           (ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
+           (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
+           (ui32IntFlags & DES_INT_DMA_DATA_OUT));
+
+    //
+    // Clear the interrupts from the flags.
+    //
+    HWREG(DTHE_BASE + DTHE_O_AES_IM)  |= ((ui32IntFlags & 0x00070000) >> 16);
+    HWREG(ui32Base + DES_O_IRQENABLE) &= ~(ui32IntFlags & 0x0000ffff);
+}
+
+//*****************************************************************************
+//
+//! Clears interrupts in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32IntFlags is a bit mask of the interrupts to be disabled.
+//!
+//! This function disables interrupt sources in the DES module.
+//! \e ui32IntFlags should be a logical OR of one or more of the following
+//! values:
+//!
+//! - \b DES_INT_DMA_CONTEXT_IN - Context interrupt
+//! - \b DES_INT_DMA_DATA_IN - Data input interrupt
+//! - \b DES_INT_DMA_DATA_OUT - Data output interrupt
+//!
+//! \note The DMA done interrupts are the only interrupts that can be cleared.
+//! The remaining interrupts can be disabled instead using DESIntDisable().
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    ASSERT((ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
+           (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
+           (ui32IntFlags & DES_INT_DMA_DATA_OUT));
+
+    HWREG(DTHE_BASE + DTHE_O_DES_IC) = ((ui32IntFlags & 0x00070000) >> 16);
+}
+
+//*****************************************************************************
+//
+//! Registers an interrupt handler for the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param pfnHandler is a pointer to the function to be called when the
+//! enabled DES interrupts occur.
+//!
+//! This function registers the interrupt handler in the interrupt vector
+//! table, and enables DES interrupts on the interrupt controller; specific DES
+//! interrupt sources must be enabled using DESIntEnable().  The interrupt
+//! handler being registered must clear the source of the interrupt using
+//! DESIntClear().
+//!
+//! If the application is using a static interrupt vector table stored in
+//! flash, then it is not necessary to register the interrupt handler this way.
+//! Instead, IntEnable() should be used to enable DES interrupts on the
+//! interrupt controller.
+//!
+//! \sa IntRegister() for important information about registering interrupt
+//! handlers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Register the interrupt handler.
+    //
+    IntRegister(INT_DES, pfnHandler);
+
+    //
+    // Enable the interrupt.
+    //
+    IntEnable(INT_DES);
+}
+
+//*****************************************************************************
+//
+//! Unregisters an interrupt handler for the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//!
+//! This function unregisters the previously registered interrupt handler and
+//! disables the interrupt in the interrupt controller.
+//!
+//! \sa IntRegister() for important information about registering interrupt
+//! handlers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESIntUnregister(uint32_t ui32Base)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+
+    //
+    // Disable the interrupt.
+    //
+    IntDisable(INT_DES);
+
+    //
+    // Unregister the interrupt handler.
+    //
+    IntUnregister(INT_DES);
+}
+
+//*****************************************************************************
+//
+//! Enables DMA request sources in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32Flags is a bit mask of the DMA requests to be enabled.
+//!
+//! This function enables DMA request sources in the DES module.  The
+//! \e ui32Flags parameter should be the logical OR of any of the following:
+//!
+//! - \b DES_DMA_CONTEXT_IN - Context In
+//! - \b DES_DMA_DATA_OUT - Data Out
+//! - \b DES_DMA_DATA_IN - Data In
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    ASSERT((ui32Flags & DES_DMA_CONTEXT_IN) ||
+           (ui32Flags & DES_DMA_DATA_OUT) ||
+           (ui32Flags & DES_DMA_DATA_IN));
+
+    //
+    // Set the data in and data out DMA request enable bits.
+    //
+    HWREG(ui32Base + DES_O_SYSCONFIG) |= ui32Flags;
+}
+
+//*****************************************************************************
+//
+//! Disables DMA request sources in the DES module.
+//!
+//! \param ui32Base is the base address of the DES module.
+//! \param ui32Flags is a bit mask of the DMA requests to be disabled.
+//!
+//! This function disables DMA request sources in the DES module.  The
+//! \e ui32Flags parameter should be the logical OR of any of the following:
+//!
+//! - \b DES_DMA_CONTEXT_IN - Context In
+//! - \b DES_DMA_DATA_OUT - Data Out
+//! - \b DES_DMA_DATA_IN - Data In
+//!
+//! \return None.
+//
+//*****************************************************************************
+void
+DESDMADisable(uint32_t ui32Base, uint32_t ui32Flags)
+{
+    //
+    // Check the arguments.
+    //
+    ASSERT(ui32Base == DES_BASE);
+    ASSERT((ui32Flags & DES_DMA_CONTEXT_IN) ||
+           (ui32Flags & DES_DMA_DATA_OUT) ||
+           (ui32Flags & DES_DMA_DATA_IN));
+
+    //
+    // Disable the DMA sources.
+    //
+    HWREG(ui32Base + DES_O_SYSCONFIG) &= ~ui32Flags;
+}
+
+//*****************************************************************************
+//
+// Close the Doxygen group.
+//! @}
+//
+//*****************************************************************************
diff --git a/micropython/ports/cc3200/hal/i2s.c b/micropython/ports/cc3200/hal/i2s.c
index dbbb936d776c5d9c78c1f3d5a73b0f1fa0049228..350bac4b54789b8ee473bbf0ae684be6819b24f7 100644
--- a/micropython/ports/cc3200/hal/i2s.c
+++ b/micropython/ports/cc3200/hal/i2s.c
@@ -1,1012 +1,1012 @@
-//*****************************************************************************
-//
-//  i2s.c
-//
-//  Driver for the I2S interface.
-//
-//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-//
-//
-//  Redistribution and use in source and binary forms, with or without
-//  modification, are permitted provided that the following conditions
-//  are met:
-//
-//    Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//
-//    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//
-//    Neither the name of Texas Instruments Incorporated nor the names of
-//    its contributors may be used to endorse or promote products derived
-//    from this software without specific prior written permission.
-//
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! \addtogroup I2S_api
-//! @{
-//
-//*****************************************************************************
-#include "inc/hw_types.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "inc/hw_mcasp.h"
-#include "inc/hw_apps_config.h"
-#include "interrupt.h"
-#include "i2s.h"
-
-//*****************************************************************************
-// Macros
-//*****************************************************************************
-#define MCASP_GBL_RCLK		0x00000001
-#define MCASP_GBL_RHCLK		0x00000002
-#define MCASP_GBL_RSER		0x00000004
-#define MCASP_GBL_RSM		0x00000008
-#define MCASP_GBL_RFSYNC	0x00000010
-#define MCASP_GBL_XCLK		0x00000100
-#define MCASP_GBL_XHCLK		0x00000200
-#define MCASP_GBL_XSER		0x00000400
-#define MCASP_GBL_XSM		0x00000800
-#define MCASP_GBL_XFSYNC	0x00001000
-
-
-//*****************************************************************************
-//
-//! \internal
-//! Releases the specifed submodule out of reset.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulFlag is one of the valid sub module.
-//!
-//! This function Releases the specifed submodule out of reset.
-//!
-//! \return None.
-//
-//*****************************************************************************
-static void I2SGBLEnable(unsigned long ulBase, unsigned long ulFlag)
-{
-  unsigned long ulReg;
-
-  //
-  // Read global control register
-  //
-  ulReg = HWREG(ulBase + MCASP_O_GBLCTL);
-
-  //
-  // Remove the sub modules reset as specified by ulFlag parameter
-  //
-  ulReg |= ulFlag;
-
-  //
-  // Write the configuration
-  //
-  HWREG(ulBase + MCASP_O_GBLCTL) = ulReg;
-
-  //
-  // Wait for write completeion
-  //
-  while(HWREG(ulBase + MCASP_O_GBLCTL) != ulReg)
-  {
-
-  }
-
-}
-
-//*****************************************************************************
-//
-//! Enables transmit and/or receive.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulMode is one of the valid modes.
-//!
-//! This function enables the I2S module in specified mode. The parameter
-//! \e ulMode should be one of the following
-//!
-//! -\b I2S_MODE_TX_ONLY
-//! -\b I2S_MODE_TX_RX_SYNC
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SEnable(unsigned long ulBase, unsigned long ulMode)
-{
-  //
-  // FSYNC and Bit clock are output only in master mode
-  //
-  if( HWREG(ulBase + MCASP_O_ACLKXCTL) & 0x20)
-  {
-    //
-    // Set FSYNC anc BitClk as output
-    //
-    HWREG(ulBase + MCASP_O_PDIR) |= 0x14000000;
-  }
-
-
-  if(ulMode & 0x2)
-  {
-    //
-    // Remove Rx HCLK reset
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_RHCLK);
-
-    //
-    // Remove Rx XCLK reset
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_RCLK);
-
-    //
-    // Enable Rx SERDES(s)
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_RSER);
-
-    //
-    // Enable Rx state machine
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_RSM);
-
-    //
-    // Enable FSync generator
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_RFSYNC);
-  }
-
-
-  //
-  // Remove Tx  HCLK reset
-  //
-  I2SGBLEnable(ulBase, MCASP_GBL_XHCLK);
-
-  //
-  // Remove Tx XCLK reset
-  //
-  I2SGBLEnable(ulBase, MCASP_GBL_XCLK);
-
-
-  if(ulMode & 0x1)
-  {
-    //
-    // Enable Tx SERDES(s)
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_XSER);
-
-    //
-    // Enable Tx state machine
-    //
-    I2SGBLEnable(ulBase, MCASP_GBL_XSM);
-  }
-
-   //
-   // Enable FSync generator
-   //
-   I2SGBLEnable(ulBase, MCASP_GBL_XFSYNC);
-}
-
-//*****************************************************************************
-//
-//! Disables transmit and/or receive.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function disables transmit and/or receive from I2S module.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SDisable(unsigned long ulBase)
-{
-  //
-  // Reset all sub modules
-  //
-  HWREG(ulBase + MCASP_O_GBLCTL) = 0;
-
-  //
-  // Wait for write to complete
-  //
-  while( HWREG(ulBase + MCASP_O_GBLCTL) != 0)
-  {
-
-  }
-}
-
-//*****************************************************************************
-//
-//! Waits to send data over the specified data line
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulDataLine is one of the valid data lines.
-//! \param ulData is the data to be transmitted.
-//!
-//! This function sends the \e ucData to the transmit register for the
-//! specified data line. If there is no space available, this
-//! function waits until there is space available before returning.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SDataPut(unsigned long ulBase, unsigned long ulDataLine,
-                unsigned long ulData)
-{
-  //
-  // Compute register the offeset
-  //
-  ulDataLine = (ulDataLine-1) << 2;
-
-  //
-  // Wait for free space in fifo
-  //
-  while(!( HWREG(ulBase + MCASP_O_TXSTAT) & MCASP_TXSTAT_XDATA))
-  {
-
-  }
-
-  //
-  // Write Data into the FIFO
-  //
-  HWREG(ulBase + MCASP_O_TXBUF0 + ulDataLine) = ulData;
-}
-
-//*****************************************************************************
-//
-//! Sends data over the specified data line
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulDataLine is one of the valid data lines.
-//! \param ulData is the data to be transmitted.
-//!
-//! This function writes the \e ucData to the transmit register for
-//! the specified data line. This function does not block, so if there is no
-//! space available, then \b -1 is returned, and the application must retry the
-//! function later.
-//!
-//! \return Returns 0 on success, -1 otherwise.
-//
-//*****************************************************************************
-long I2SDataPutNonBlocking(unsigned long ulBase,  unsigned long ulDataLine,
-                           unsigned long ulData)
-{
-
-  //
-  // Compute register the offeset
-  //
-  ulDataLine = (ulDataLine-1) << 2;
-
-  //
-  // Send Data if fifo has free space
-  //
-  if( HWREG(ulBase + MCASP_O_TXSTAT) & MCASP_TXSTAT_XDATA)
-  {
-    //
-    // Write data into the FIFO
-    //
-    HWREG(ulBase + MCASP_O_TXBUF0 + ulDataLine) = ulData;
-    return 0;
-  }
-
-  //
-  // FIFO is full
-  //
-  return(-1);
-}
-
-//*****************************************************************************
-//
-//! Waits for data from the specified data line.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulDataLine is one of the valid data lines.
-//! \param pulData is pointer to receive data variable.
-//!
-//! This function gets data from the receive register for the specified
-//! data line. If there are no data available, this function waits until a
-//! receive before returning.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SDataGet(unsigned long ulBase, unsigned long ulDataLine,
-                unsigned long *pulData)
-{
-
-  //
-  // Compute register the offeset
-  //
-  ulDataLine = (ulDataLine-1) << 2;
-
-  //
-  // Wait for atleat on word in FIFO
-  //
-  while(!(HWREG(ulBase + MCASP_O_RXSTAT) & MCASP_RXSTAT_RDATA))
-  {
-
-  }
-
-  //
-  // Read the Data
-  //
-  *pulData = HWREG(ulBase + MCASP_O_RXBUF0 + ulDataLine);
-}
-
-
-//*****************************************************************************
-//
-//! Receives data from the specified data line.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulDataLine is one of the valid data lines.
-//! \param pulData is pointer to receive data variable.
-//!
-//! This function gets data from the receive register for the specified
-//! data line.
-//!
-//!
-//! \return Returns 0 on success, -1 otherwise.
-//
-//*****************************************************************************
-long I2SDataGetNonBlocking(unsigned long ulBase, unsigned long ulDataLine,
-                unsigned long *pulData)
-{
-
-  //
-  // Compute register the offeset
-  //
-  ulDataLine = (ulDataLine-1) << 2;
-
-  //
-  // Check if data is available in FIFO
-  //
-  if(HWREG(ulBase + MCASP_O_RXSTAT) & MCASP_RXSTAT_RDATA)
-  {
-    //
-    // Read the Data
-    //
-    *pulData = HWREG(ulBase + MCASP_O_RXBUF0 + ulDataLine);
-    return 0;
-  }
-
-  //
-  // FIFO is empty
-  //
-  return -1;
-}
-
-
-//*****************************************************************************
-//
-//! Sets the configuration of the I2S module.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulI2SClk is the rate of the clock supplied to the I2S module.
-//! \param ulBitClk is the desired bit rate.
-//! \param ulConfig is the data format.
-//!
-//! This function configures the I2S for operation in the specified data
-//! format.  The bit rate is provided in the \e ulBitClk parameter and the data
-//! format in the \e ulConfig parameter.
-//!
-//! The \e ulConfig parameter is the logical OR of three values: the slot size
-//! the data read/write port select, Master or Slave mode
-//!
-//! Follwoing selects the Master-Slave mode
-//! -\b I2S_MODE_MASTER
-//! -\b I2S_MODE_SLAVE
-//!
-//! Following selects the slot size:
-//! -\b I2S_SLOT_SIZE_24
-//! -\b I2S_SLOT_SIZE_16
-//!
-//! Following selects the data read/write port:
-//! -\b I2S_PORT_DMA
-//! -\b I2S_PORT_CPU
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SConfigSetExpClk(unsigned long ulBase, unsigned long ulI2SClk,
-                               unsigned long ulBitClk, unsigned long ulConfig)
-{
-  unsigned long ulHClkDiv;
-  unsigned long ulClkDiv;
-  unsigned long ulSlotSize;
-  unsigned long ulBitMask;
-
-  //
-  // Calculate clock dividers
-  //
-  ulHClkDiv = ((ulI2SClk/ulBitClk)-1);
-  ulClkDiv  = 0;
-
-  //
-  // Check if HCLK divider is overflowing
-  //
-  if(ulHClkDiv > 0xFFF)
-  {
-    ulHClkDiv = 0xFFF;
-
-    //
-    // Calculate clock divider
-    //
-    ulClkDiv = ((ulI2SClk/(ulBitClk * (ulHClkDiv + 1))) & 0x1F);
-  }
-
-  //
-  //
-  //
-  ulClkDiv = ((ulConfig & I2S_MODE_SLAVE )?0x80:0xA0|ulClkDiv);
-
-  HWREG(ulBase + MCASP_O_ACLKXCTL) = ulClkDiv;
-
-  HWREG(ulBase + MCASP_O_AHCLKXCTL) = (0x8000|ulHClkDiv);
-
-  //
-  // Write the Tx format register
-  //
-  HWREG(ulBase + MCASP_O_TXFMT) = (0x18000 | (ulConfig & 0x7FFF));
-
-  //
-  // Write the Rx format register
-  //
-  HWREG(ulBase + MCASP_O_RXFMT) = (0x18000 | ((ulConfig >> 16) &0x7FFF));
-
-  //
-  // Check if in master mode
-  //
-  if( ulConfig & I2S_MODE_SLAVE)
-  {
-    //
-    // Configure Tx FSync generator in I2S mode
-    //
-    HWREG(ulBase + MCASP_O_TXFMCTL) = 0x111;
-
-    //
-    // Configure Rx FSync generator in I2S mode
-    //
-    HWREG(ulBase + MCASP_O_RXFMCTL) = 0x111;
-  }
-  else
-  {
-    //
-    // Configure Tx FSync generator in I2S mode
-    //
-    HWREG(ulBase + MCASP_O_TXFMCTL) = 0x113;
-
-    //
-    // Configure Rx FSync generator in I2S mode
-    //
-    HWREG(ulBase + MCASP_O_RXFMCTL) = 0x113;
-  }
-
-  //
-  // Compute Slot Size
-  //
-  ulSlotSize = ((((ulConfig & 0xFF) >> 4) + 1) * 2);
-
-  //
-  // Creat the bit mask
-  //
-  ulBitMask = (0xFFFFFFFF >> (32 - ulSlotSize));
-
-  //
-  // Set Tx bit valid mask
-  //
-  HWREG(ulBase + MCASP_O_TXMASK) = ulBitMask;
-
-  //
-  // Set Rx bit valid mask
-  //
-  HWREG(ulBase + MCASP_O_RXMASK) = ulBitMask;
-
-  //
-  // Set Tx slot valid mask
-  //
-  HWREG(ulBase + MCASP_O_TXTDM) = 0x3;
-
-  //
-  // Set Rx slot valid mask
-  //
-  HWREG(ulBase + MCASP_O_RXTDM) = 0x3;
-}
-
-//*****************************************************************************
-//
-//! Configure and enable transmit FIFO.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulTxLevel is the transmit FIFO DMA request level.
-//! \param ulWordsPerTransfer is the nuber of words transferred from the FIFO.
-//!
-//! This function configures and enable I2S transmit FIFO.
-//!
-//! The parameter \e ulTxLevel sets the level at which transmit DMA requests
-//! are generated. This should be non-zero integer multiple of number of
-//! serializers enabled as transmitters
-//!
-//! The parameter \e ulWordsPerTransfer sets the number of words that are
-//! transferred from the transmit FIFO to the data line(s). This value must
-//! equal the number of serializers used as transmitters.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2STxFIFOEnable(unsigned long ulBase, unsigned long ulTxLevel,
-                     unsigned long ulWordsPerTransfer)
-{
-  //
-  // Set transmit FIFO configuration and
-  // enable it
-  //
-  HWREG(ulBase + MCASP_0_WFIFOCTL) = ((1 <<16) | ((ulTxLevel & 0xFF) << 8)
-					| (ulWordsPerTransfer & 0x1F));
-
-}
-
-//*****************************************************************************
-//
-//! Disables transmit FIFO.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function disables the I2S transmit FIFO.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2STxFIFODisable(unsigned long ulBase)
-{
-  //
-  // Disable transmit FIFO.
-  //
-  HWREG(ulBase + MCASP_0_WFIFOCTL) = 0;
-}
-
-//*****************************************************************************
-//
-//! Configure and enable receive FIFO.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulRxLevel is the receive FIFO DMA request level.
-//! \param ulWordsPerTransfer is the nuber of words transferred from the FIFO.
-//!
-//! This function configures and enable I2S receive FIFO.
-//!
-//! The parameter \e ulRxLevel sets the level at which receive DMA requests
-//! are generated. This should be non-zero integer multiple of number of
-//! serializers enabled as receivers.
-//!
-//! The parameter \e ulWordsPerTransfer sets the number of words that are
-//! transferred to the receive FIFO from the data line(s). This value must
-//! equal the number of serializers used as receivers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SRxFIFOEnable(unsigned long ulBase, unsigned long ulRxLevel,
-                     unsigned long ulWordsPerTransfer)
-{
-  //
-  // Set FIFO configuration
-  //
-  HWREG(ulBase + MCASP_0_RFIFOCTL) = ( (1 <<16) | ((ulRxLevel & 0xFF) << 8)
-					| (ulWordsPerTransfer & 0x1F));
-
-}
-
-//*****************************************************************************
-//
-//! Disables receive FIFO.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function disables the I2S receive FIFO.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SRxFIFODisable(unsigned long ulBase)
-{
-  //
-  // Disable receive FIFO.
-  //
-  HWREG(ulBase + MCASP_0_RFIFOCTL) = 0;
-}
-
-//*****************************************************************************
-//
-//! Get the transmit FIFO status.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function gets the number of 32-bit words currently in the transmit
-//! FIFO.
-//!
-//! \return Returns transmit FIFO status.
-//
-//*****************************************************************************
-unsigned long I2STxFIFOStatusGet(unsigned long ulBase)
-{
-  //
-  // Return transmit FIFO level
-  //
-  return HWREG(ulBase + MCASP_0_WFIFOSTS);
-}
-
-//*****************************************************************************
-//
-//! Get the receive FIFO status.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function gets the number of 32-bit words currently in the receive
-//! FIFO.
-//!
-//! \return Returns receive FIFO status.
-//
-//*****************************************************************************
-unsigned long I2SRxFIFOStatusGet(unsigned long ulBase)
-{
-  //
-  // Return receive FIFO level
-  //
-  return HWREG(ulBase + MCASP_0_RFIFOSTS);
-}
-
-//*****************************************************************************
-//
-//! Configure the serializer in specified mode.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulDataLine is the data line (serilizer) to be configured.
-//! \param ulSerMode is the required serializer mode.
-//! \param ulInActState sets the inactive state of the data line.
-//!
-//! This function configure and enable the serializer associated with the given
-//! data line in specified mode.
-//!
-//! The paramenter \e ulDataLine selects to data line to be configured and
-//! can be one of the following:
-//! -\b I2S_DATA_LINE_0
-//! -\b I2S_DATA_LINE_1
-//!
-//! The parameter \e ulSerMode can be one of the following:
-//! -\b I2S_SER_MODE_TX
-//! -\b I2S_SER_MODE_RX
-//! -\b I2S_SER_MODE_DISABLE
-//!
-//! The parameter \e ulInActState can be one of the following
-//! -\b I2S_INACT_TRI_STATE
-//! -\b I2S_INACT_LOW_LEVEL
-//! -\b I2S_INACT_LOW_HIGH
-//!
-//! \return Returns receive FIFO status.
-//
-//*****************************************************************************
-void I2SSerializerConfig(unsigned long ulBase, unsigned long ulDataLine,
-                         unsigned long ulSerMode, unsigned long ulInActState)
-{
-  if( ulSerMode == I2S_SER_MODE_TX)
-  {
-    //
-    // Set the data line in output mode
-    //
-    HWREG(ulBase + MCASP_O_PDIR) |= ulDataLine;
-  }
-  else
-  {
-    //
-    // Set the data line in input mode
-    //
-    HWREG(ulBase + MCASP_O_PDIR) &= ~ulDataLine;
-  }
-
-  //
-  // Set the serializer configuration.
-  //
-  HWREG(ulBase + MCASP_O_XRSRCTL0 + ((ulDataLine-1) << 2))
-                                            = (ulSerMode | ulInActState);
-}
-
-//*****************************************************************************
-//
-//! Enables individual I2S interrupt sources.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
-//!
-//! This function enables the indicated I2S interrupt sources.  Only the
-//! sources that are enabled can be reflected to the processor interrupt;
-//! disabled sources have no effect on the processor.
-//!
-//! The \e ulIntFlags parameter is the logical OR of any of the following:
-//!
-//! -\b I2S_INT_XUNDRN
-//! -\b I2S_INT_XSYNCERR
-//! -\b I2S_INT_XLAST
-//! -\b I2S_INT_XDATA
-//! -\b I2S_INT_XSTAFRM
-//! -\b I2S_INT_XDMA
-//! -\b I2S_INT_ROVRN
-//! -\b I2S_INT_RSYNCERR
-//! -\b I2S_INT_RLAST
-//! -\b I2S_INT_RDATA
-//! -\b I2S_INT_RSTAFRM
-//! -\b I2S_INT_RDMA
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
-{
-
-  //
-  // Enable DMA done interrupts
-  //
-  HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_CLR )
-     |= ((ulIntFlags &0xC0000000) >> 20);
-
-  //
-  // Enable specific Tx Interrupts
-  //
-  HWREG(ulBase + MCASP_O_EVTCTLX) |= (ulIntFlags & 0xFF);
-
-  //
-  // Enable specific Rx Interrupts
-  //
-  HWREG(ulBase + MCASP_O_EVTCTLR) |= ((ulIntFlags >> 16) & 0xFF);
-}
-
-//*****************************************************************************
-//
-//! Disables individual I2S interrupt sources.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
-//!
-//! This function disables the indicated I2S interrupt sources.  Only the
-//! sources that are enabled can be reflected to the processor interrupt;
-//! disabled sources have no effect on the processor.
-//!
-//! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
-//! parameter to I2SIntEnable().
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
-{
-  //
-  // Disable DMA done interrupts
-  //
-  HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_SET)
-     |= ((ulIntFlags &0xC0000000) >> 20);
-
-  //
-  // Disable specific Tx Interrupts
-  //
-  HWREG(ulBase + MCASP_O_EVTCTLX) &= ~(ulIntFlags & 0xFF);
-
-  //
-  // Disable specific Rx Interrupts
-  //
-  HWREG(ulBase + MCASP_O_EVTCTLR) &= ~((ulIntFlags >> 16) & 0xFF);
-}
-
-
-//*****************************************************************************
-//
-//! Gets the current interrupt status.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function returns the raw interrupt status for I2S enumerated
-//! as a bit field of values:
-//! -\b I2S_STS_XERR
-//! -\b I2S_STS_XDMAERR
-//! -\b I2S_STS_XSTAFRM
-//! -\b I2S_STS_XDATA
-//! -\b I2S_STS_XLAST
-//! -\b I2S_STS_XSYNCERR
-//! -\b I2S_STS_XUNDRN
-//! -\b I2S_STS_XDMA
-//! -\b I2S_STS_RERR
-//! -\b I2S_STS_RDMAERR
-//! -\b I2S_STS_RSTAFRM
-//! -\b I2S_STS_RDATA
-//! -\b I2S_STS_RLAST
-//! -\b I2S_STS_RSYNCERR
-//! -\b I2S_STS_ROVERN
-//! -\b I2S_STS_RDMA
-//!
-//! \return Returns the current interrupt status, enumerated as a bit field of
-//! values described above.
-//
-//*****************************************************************************
-unsigned long I2SIntStatus(unsigned long ulBase)
-{
-  unsigned long ulStatus;
-
-  //
-  // Get DMA interrupt status
-  //
-  ulStatus =
-    HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_STS_RAW) << 20;
-
-  ulStatus &= 0xC0000000;
-
-  //
-  // Read Tx Interrupt status
-  //
-  ulStatus |= HWREG(ulBase + MCASP_O_TXSTAT);
-
-  //
-  // Read Rx Interrupt status
-  //
-  ulStatus |= HWREG(ulBase + MCASP_O_RXSTAT) << 16;
-
-  //
-  // Return the status
-  //
-  return ulStatus;
-}
-
-//*****************************************************************************
-//
-//! Clears I2S interrupt sources.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulStatFlags is a bit mask of the interrupt sources to be cleared.
-//!
-//! The specified I2S interrupt sources are cleared, so that they no longer
-//! assert.  This function must be called in the interrupt handler to keep the
-//! interrupt from being recognized again immediately upon exit.
-//!
-//! The \e ulIntFlags parameter is the logical OR of any of the value
-//! describe in I2SIntStatus().
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SIntClear(unsigned long ulBase, unsigned long ulStatFlags)
-{
-  //
-  // Clear DMA done interrupts
-  //
-  HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_ACK)
-     |= ((ulStatFlags &0xC0000000) >> 20);
-
-  //
-  // Clear Tx Interrupt
-  //
-  HWREG(ulBase + MCASP_O_TXSTAT) = ulStatFlags & 0x1FF ;
-
-  //
-  // Clear Rx Interrupt
-  //
-  HWREG(ulBase + MCASP_O_RXSTAT) = (ulStatFlags >> 16) & 0x1FF;
-}
-
-//*****************************************************************************
-//
-//! Registers an interrupt handler for a I2S interrupt.
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param pfnHandler is a pointer to the function to be called when the
-//! I2S interrupt occurs.
-//!
-//! This function does the actual registering of the interrupt handler.  This
-//! function enables the global interrupt in the interrupt controller; specific
-//! I2S interrupts must be enabled via I2SIntEnable().  It is the interrupt
-//! handler's responsibility to clear the interrupt source.
-//!
-//! \sa IntRegister() for important information about registering interrupt
-//! handlers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
-{
-  //
-  // Register the interrupt handler
-  //
-  IntRegister(INT_I2S,pfnHandler);
-
-  //
-  // Enable the interrupt
-  //
-  IntEnable(INT_I2S);
-}
-
-//*****************************************************************************
-//
-//! Unregisters an interrupt handler for a I2S interrupt.
-//!
-//! \param ulBase is the base address of the I2S module.
-//!
-//! This function does the actual unregistering of the interrupt handler.  It
-//! clears the handler to be called when a I2S interrupt occurs.  This
-//! function also masks off the interrupt in the interrupt controller so that
-//! the interrupt handler no longer is called.
-//!
-//! \sa IntRegister() for important information about registering interrupt
-//! handlers.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SIntUnregister(unsigned long ulBase)
-{
-  //
-  // Disable interrupt
-  //
-  IntDisable(INT_I2S);
-
-  //
-  // Unregister the handler
-  //
-  IntUnregister(INT_I2S);
-
-}
-
-//*****************************************************************************
-//
-//! Set the active slots for Trasmitter
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulActSlot is the bit-mask of activ slots
-//!
-//! This function sets the active slots for the transmitter. By default both
-//! the slots are active. The parameter \e ulActSlot is logical OR follwoing
-//! values:
-//! -\b I2S_ACT_SLOT_EVEN
-//! -\b I2S_ACT_SLOT_ODD
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2STxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot)
-{
-   HWREG(ulBase + MCASP_O_TXTDM) = ulActSlot;
-}
-
-//*****************************************************************************
-//
-//! Set the active slots for Receiver
-//!
-//! \param ulBase is the base address of the I2S module.
-//! \param ulActSlot is the bit-mask of activ slots
-//!
-//! This function sets the active slots for the receiver. By default both
-//! the slots are active. The parameter \e ulActSlot is logical OR follwoing
-//! values:
-//! -\b I2S_ACT_SLOT_EVEN
-//! -\b I2S_ACT_SLOT_ODD
-//!
-//! \return None.
-//
-//*****************************************************************************
-void I2SRxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot)
-{
-   HWREG(ulBase + MCASP_O_RXTDM) = ulActSlot;
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
+//*****************************************************************************
+//
+//  i2s.c
+//
+//  Driver for the I2S interface.
+//
+//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
+//  are met:
+//
+//    Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//
+//    Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//
+//    Neither the name of Texas Instruments Incorporated nor the names of
+//    its contributors may be used to endorse or promote products derived
+//    from this software without specific prior written permission.
+//
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//*****************************************************************************
+
+//*****************************************************************************
+//
+//! \addtogroup I2S_api
+//! @{
+//
+//*****************************************************************************
+#include "inc/hw_types.h"
+#include "inc/hw_ints.h"
+#include "inc/hw_memmap.h"
+#include "inc/hw_mcasp.h"
+#include "inc/hw_apps_config.h"
+#include "interrupt.h"
+#include "i2s.h"
+
+//*****************************************************************************
+// Macros
+//*****************************************************************************
+#define MCASP_GBL_RCLK		0x00000001
+#define MCASP_GBL_RHCLK		0x00000002
+#define MCASP_GBL_RSER		0x00000004
+#define MCASP_GBL_RSM		0x00000008
+#define MCASP_GBL_RFSYNC	0x00000010
+#define MCASP_GBL_XCLK		0x00000100
+#define MCASP_GBL_XHCLK		0x00000200
+#define MCASP_GBL_XSER		0x00000400
+#define MCASP_GBL_XSM		0x00000800
+#define MCASP_GBL_XFSYNC	0x00001000
+
+
+//*****************************************************************************
+//
+//! \internal
+//! Releases the specifed submodule out of reset.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulFlag is one of the valid sub module.
+//!
+//! This function Releases the specifed submodule out of reset.
+//!
+//! \return None.
+//
+//*****************************************************************************
+static void I2SGBLEnable(unsigned long ulBase, unsigned long ulFlag)
+{
+  unsigned long ulReg;
+
+  //
+  // Read global control register
+  //
+  ulReg = HWREG(ulBase + MCASP_O_GBLCTL);
+
+  //
+  // Remove the sub modules reset as specified by ulFlag parameter
+  //
+  ulReg |= ulFlag;
+
+  //
+  // Write the configuration
+  //
+  HWREG(ulBase + MCASP_O_GBLCTL) = ulReg;
+
+  //
+  // Wait for write completeion
+  //
+  while(HWREG(ulBase + MCASP_O_GBLCTL) != ulReg)
+  {
+
+  }
+
+}
+
+//*****************************************************************************
+//
+//! Enables transmit and/or receive.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulMode is one of the valid modes.
+//!
+//! This function enables the I2S module in specified mode. The parameter
+//! \e ulMode should be one of the following
+//!
+//! -\b I2S_MODE_TX_ONLY
+//! -\b I2S_MODE_TX_RX_SYNC
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SEnable(unsigned long ulBase, unsigned long ulMode)
+{
+  //
+  // FSYNC and Bit clock are output only in master mode
+  //
+  if( HWREG(ulBase + MCASP_O_ACLKXCTL) & 0x20)
+  {
+    //
+    // Set FSYNC anc BitClk as output
+    //
+    HWREG(ulBase + MCASP_O_PDIR) |= 0x14000000;
+  }
+
+
+  if(ulMode & 0x2)
+  {
+    //
+    // Remove Rx HCLK reset
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_RHCLK);
+
+    //
+    // Remove Rx XCLK reset
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_RCLK);
+
+    //
+    // Enable Rx SERDES(s)
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_RSER);
+
+    //
+    // Enable Rx state machine
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_RSM);
+
+    //
+    // Enable FSync generator
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_RFSYNC);
+  }
+
+
+  //
+  // Remove Tx  HCLK reset
+  //
+  I2SGBLEnable(ulBase, MCASP_GBL_XHCLK);
+
+  //
+  // Remove Tx XCLK reset
+  //
+  I2SGBLEnable(ulBase, MCASP_GBL_XCLK);
+
+
+  if(ulMode & 0x1)
+  {
+    //
+    // Enable Tx SERDES(s)
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_XSER);
+
+    //
+    // Enable Tx state machine
+    //
+    I2SGBLEnable(ulBase, MCASP_GBL_XSM);
+  }
+
+   //
+   // Enable FSync generator
+   //
+   I2SGBLEnable(ulBase, MCASP_GBL_XFSYNC);
+}
+
+//*****************************************************************************
+//
+//! Disables transmit and/or receive.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function disables transmit and/or receive from I2S module.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SDisable(unsigned long ulBase)
+{
+  //
+  // Reset all sub modules
+  //
+  HWREG(ulBase + MCASP_O_GBLCTL) = 0;
+
+  //
+  // Wait for write to complete
+  //
+  while( HWREG(ulBase + MCASP_O_GBLCTL) != 0)
+  {
+
+  }
+}
+
+//*****************************************************************************
+//
+//! Waits to send data over the specified data line
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulDataLine is one of the valid data lines.
+//! \param ulData is the data to be transmitted.
+//!
+//! This function sends the \e ucData to the transmit register for the
+//! specified data line. If there is no space available, this
+//! function waits until there is space available before returning.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SDataPut(unsigned long ulBase, unsigned long ulDataLine,
+                unsigned long ulData)
+{
+  //
+  // Compute register the offeset
+  //
+  ulDataLine = (ulDataLine-1) << 2;
+
+  //
+  // Wait for free space in fifo
+  //
+  while(!( HWREG(ulBase + MCASP_O_TXSTAT) & MCASP_TXSTAT_XDATA))
+  {
+
+  }
+
+  //
+  // Write Data into the FIFO
+  //
+  HWREG(ulBase + MCASP_O_TXBUF0 + ulDataLine) = ulData;
+}
+
+//*****************************************************************************
+//
+//! Sends data over the specified data line
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulDataLine is one of the valid data lines.
+//! \param ulData is the data to be transmitted.
+//!
+//! This function writes the \e ucData to the transmit register for
+//! the specified data line. This function does not block, so if there is no
+//! space available, then \b -1 is returned, and the application must retry the
+//! function later.
+//!
+//! \return Returns 0 on success, -1 otherwise.
+//
+//*****************************************************************************
+long I2SDataPutNonBlocking(unsigned long ulBase,  unsigned long ulDataLine,
+                           unsigned long ulData)
+{
+
+  //
+  // Compute register the offeset
+  //
+  ulDataLine = (ulDataLine-1) << 2;
+
+  //
+  // Send Data if fifo has free space
+  //
+  if( HWREG(ulBase + MCASP_O_TXSTAT) & MCASP_TXSTAT_XDATA)
+  {
+    //
+    // Write data into the FIFO
+    //
+    HWREG(ulBase + MCASP_O_TXBUF0 + ulDataLine) = ulData;
+    return 0;
+  }
+
+  //
+  // FIFO is full
+  //
+  return(-1);
+}
+
+//*****************************************************************************
+//
+//! Waits for data from the specified data line.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulDataLine is one of the valid data lines.
+//! \param pulData is pointer to receive data variable.
+//!
+//! This function gets data from the receive register for the specified
+//! data line. If there are no data available, this function waits until a
+//! receive before returning.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SDataGet(unsigned long ulBase, unsigned long ulDataLine,
+                unsigned long *pulData)
+{
+
+  //
+  // Compute register the offeset
+  //
+  ulDataLine = (ulDataLine-1) << 2;
+
+  //
+  // Wait for atleat on word in FIFO
+  //
+  while(!(HWREG(ulBase + MCASP_O_RXSTAT) & MCASP_RXSTAT_RDATA))
+  {
+
+  }
+
+  //
+  // Read the Data
+  //
+  *pulData = HWREG(ulBase + MCASP_O_RXBUF0 + ulDataLine);
+}
+
+
+//*****************************************************************************
+//
+//! Receives data from the specified data line.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulDataLine is one of the valid data lines.
+//! \param pulData is pointer to receive data variable.
+//!
+//! This function gets data from the receive register for the specified
+//! data line.
+//!
+//!
+//! \return Returns 0 on success, -1 otherwise.
+//
+//*****************************************************************************
+long I2SDataGetNonBlocking(unsigned long ulBase, unsigned long ulDataLine,
+                unsigned long *pulData)
+{
+
+  //
+  // Compute register the offeset
+  //
+  ulDataLine = (ulDataLine-1) << 2;
+
+  //
+  // Check if data is available in FIFO
+  //
+  if(HWREG(ulBase + MCASP_O_RXSTAT) & MCASP_RXSTAT_RDATA)
+  {
+    //
+    // Read the Data
+    //
+    *pulData = HWREG(ulBase + MCASP_O_RXBUF0 + ulDataLine);
+    return 0;
+  }
+
+  //
+  // FIFO is empty
+  //
+  return -1;
+}
+
+
+//*****************************************************************************
+//
+//! Sets the configuration of the I2S module.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulI2SClk is the rate of the clock supplied to the I2S module.
+//! \param ulBitClk is the desired bit rate.
+//! \param ulConfig is the data format.
+//!
+//! This function configures the I2S for operation in the specified data
+//! format.  The bit rate is provided in the \e ulBitClk parameter and the data
+//! format in the \e ulConfig parameter.
+//!
+//! The \e ulConfig parameter is the logical OR of three values: the slot size
+//! the data read/write port select, Master or Slave mode
+//!
+//! Follwoing selects the Master-Slave mode
+//! -\b I2S_MODE_MASTER
+//! -\b I2S_MODE_SLAVE
+//!
+//! Following selects the slot size:
+//! -\b I2S_SLOT_SIZE_24
+//! -\b I2S_SLOT_SIZE_16
+//!
+//! Following selects the data read/write port:
+//! -\b I2S_PORT_DMA
+//! -\b I2S_PORT_CPU
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SConfigSetExpClk(unsigned long ulBase, unsigned long ulI2SClk,
+                               unsigned long ulBitClk, unsigned long ulConfig)
+{
+  unsigned long ulHClkDiv;
+  unsigned long ulClkDiv;
+  unsigned long ulSlotSize;
+  unsigned long ulBitMask;
+
+  //
+  // Calculate clock dividers
+  //
+  ulHClkDiv = ((ulI2SClk/ulBitClk)-1);
+  ulClkDiv  = 0;
+
+  //
+  // Check if HCLK divider is overflowing
+  //
+  if(ulHClkDiv > 0xFFF)
+  {
+    ulHClkDiv = 0xFFF;
+
+    //
+    // Calculate clock divider
+    //
+    ulClkDiv = ((ulI2SClk/(ulBitClk * (ulHClkDiv + 1))) & 0x1F);
+  }
+
+  //
+  //
+  //
+  ulClkDiv = ((ulConfig & I2S_MODE_SLAVE )?0x80:0xA0|ulClkDiv);
+
+  HWREG(ulBase + MCASP_O_ACLKXCTL) = ulClkDiv;
+
+  HWREG(ulBase + MCASP_O_AHCLKXCTL) = (0x8000|ulHClkDiv);
+
+  //
+  // Write the Tx format register
+  //
+  HWREG(ulBase + MCASP_O_TXFMT) = (0x18000 | (ulConfig & 0x7FFF));
+
+  //
+  // Write the Rx format register
+  //
+  HWREG(ulBase + MCASP_O_RXFMT) = (0x18000 | ((ulConfig >> 16) &0x7FFF));
+
+  //
+  // Check if in master mode
+  //
+  if( ulConfig & I2S_MODE_SLAVE)
+  {
+    //
+    // Configure Tx FSync generator in I2S mode
+    //
+    HWREG(ulBase + MCASP_O_TXFMCTL) = 0x111;
+
+    //
+    // Configure Rx FSync generator in I2S mode
+    //
+    HWREG(ulBase + MCASP_O_RXFMCTL) = 0x111;
+  }
+  else
+  {
+    //
+    // Configure Tx FSync generator in I2S mode
+    //
+    HWREG(ulBase + MCASP_O_TXFMCTL) = 0x113;
+
+    //
+    // Configure Rx FSync generator in I2S mode
+    //
+    HWREG(ulBase + MCASP_O_RXFMCTL) = 0x113;
+  }
+
+  //
+  // Compute Slot Size
+  //
+  ulSlotSize = ((((ulConfig & 0xFF) >> 4) + 1) * 2);
+
+  //
+  // Creat the bit mask
+  //
+  ulBitMask = (0xFFFFFFFF >> (32 - ulSlotSize));
+
+  //
+  // Set Tx bit valid mask
+  //
+  HWREG(ulBase + MCASP_O_TXMASK) = ulBitMask;
+
+  //
+  // Set Rx bit valid mask
+  //
+  HWREG(ulBase + MCASP_O_RXMASK) = ulBitMask;
+
+  //
+  // Set Tx slot valid mask
+  //
+  HWREG(ulBase + MCASP_O_TXTDM) = 0x3;
+
+  //
+  // Set Rx slot valid mask
+  //
+  HWREG(ulBase + MCASP_O_RXTDM) = 0x3;
+}
+
+//*****************************************************************************
+//
+//! Configure and enable transmit FIFO.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulTxLevel is the transmit FIFO DMA request level.
+//! \param ulWordsPerTransfer is the nuber of words transferred from the FIFO.
+//!
+//! This function configures and enable I2S transmit FIFO.
+//!
+//! The parameter \e ulTxLevel sets the level at which transmit DMA requests
+//! are generated. This should be non-zero integer multiple of number of
+//! serializers enabled as transmitters
+//!
+//! The parameter \e ulWordsPerTransfer sets the number of words that are
+//! transferred from the transmit FIFO to the data line(s). This value must
+//! equal the number of serializers used as transmitters.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2STxFIFOEnable(unsigned long ulBase, unsigned long ulTxLevel,
+                     unsigned long ulWordsPerTransfer)
+{
+  //
+  // Set transmit FIFO configuration and
+  // enable it
+  //
+  HWREG(ulBase + MCASP_0_WFIFOCTL) = ((1 <<16) | ((ulTxLevel & 0xFF) << 8)
+					| (ulWordsPerTransfer & 0x1F));
+
+}
+
+//*****************************************************************************
+//
+//! Disables transmit FIFO.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function disables the I2S transmit FIFO.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2STxFIFODisable(unsigned long ulBase)
+{
+  //
+  // Disable transmit FIFO.
+  //
+  HWREG(ulBase + MCASP_0_WFIFOCTL) = 0;
+}
+
+//*****************************************************************************
+//
+//! Configure and enable receive FIFO.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulRxLevel is the receive FIFO DMA request level.
+//! \param ulWordsPerTransfer is the nuber of words transferred from the FIFO.
+//!
+//! This function configures and enable I2S receive FIFO.
+//!
+//! The parameter \e ulRxLevel sets the level at which receive DMA requests
+//! are generated. This should be non-zero integer multiple of number of
+//! serializers enabled as receivers.
+//!
+//! The parameter \e ulWordsPerTransfer sets the number of words that are
+//! transferred to the receive FIFO from the data line(s). This value must
+//! equal the number of serializers used as receivers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SRxFIFOEnable(unsigned long ulBase, unsigned long ulRxLevel,
+                     unsigned long ulWordsPerTransfer)
+{
+  //
+  // Set FIFO configuration
+  //
+  HWREG(ulBase + MCASP_0_RFIFOCTL) = ( (1 <<16) | ((ulRxLevel & 0xFF) << 8)
+					| (ulWordsPerTransfer & 0x1F));
+
+}
+
+//*****************************************************************************
+//
+//! Disables receive FIFO.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function disables the I2S receive FIFO.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SRxFIFODisable(unsigned long ulBase)
+{
+  //
+  // Disable receive FIFO.
+  //
+  HWREG(ulBase + MCASP_0_RFIFOCTL) = 0;
+}
+
+//*****************************************************************************
+//
+//! Get the transmit FIFO status.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function gets the number of 32-bit words currently in the transmit
+//! FIFO.
+//!
+//! \return Returns transmit FIFO status.
+//
+//*****************************************************************************
+unsigned long I2STxFIFOStatusGet(unsigned long ulBase)
+{
+  //
+  // Return transmit FIFO level
+  //
+  return HWREG(ulBase + MCASP_0_WFIFOSTS);
+}
+
+//*****************************************************************************
+//
+//! Get the receive FIFO status.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function gets the number of 32-bit words currently in the receive
+//! FIFO.
+//!
+//! \return Returns receive FIFO status.
+//
+//*****************************************************************************
+unsigned long I2SRxFIFOStatusGet(unsigned long ulBase)
+{
+  //
+  // Return receive FIFO level
+  //
+  return HWREG(ulBase + MCASP_0_RFIFOSTS);
+}
+
+//*****************************************************************************
+//
+//! Configure the serializer in specified mode.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulDataLine is the data line (serilizer) to be configured.
+//! \param ulSerMode is the required serializer mode.
+//! \param ulInActState sets the inactive state of the data line.
+//!
+//! This function configure and enable the serializer associated with the given
+//! data line in specified mode.
+//!
+//! The paramenter \e ulDataLine selects to data line to be configured and
+//! can be one of the following:
+//! -\b I2S_DATA_LINE_0
+//! -\b I2S_DATA_LINE_1
+//!
+//! The parameter \e ulSerMode can be one of the following:
+//! -\b I2S_SER_MODE_TX
+//! -\b I2S_SER_MODE_RX
+//! -\b I2S_SER_MODE_DISABLE
+//!
+//! The parameter \e ulInActState can be one of the following
+//! -\b I2S_INACT_TRI_STATE
+//! -\b I2S_INACT_LOW_LEVEL
+//! -\b I2S_INACT_LOW_HIGH
+//!
+//! \return Returns receive FIFO status.
+//
+//*****************************************************************************
+void I2SSerializerConfig(unsigned long ulBase, unsigned long ulDataLine,
+                         unsigned long ulSerMode, unsigned long ulInActState)
+{
+  if( ulSerMode == I2S_SER_MODE_TX)
+  {
+    //
+    // Set the data line in output mode
+    //
+    HWREG(ulBase + MCASP_O_PDIR) |= ulDataLine;
+  }
+  else
+  {
+    //
+    // Set the data line in input mode
+    //
+    HWREG(ulBase + MCASP_O_PDIR) &= ~ulDataLine;
+  }
+
+  //
+  // Set the serializer configuration.
+  //
+  HWREG(ulBase + MCASP_O_XRSRCTL0 + ((ulDataLine-1) << 2))
+                                            = (ulSerMode | ulInActState);
+}
+
+//*****************************************************************************
+//
+//! Enables individual I2S interrupt sources.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
+//!
+//! This function enables the indicated I2S interrupt sources.  Only the
+//! sources that are enabled can be reflected to the processor interrupt;
+//! disabled sources have no effect on the processor.
+//!
+//! The \e ulIntFlags parameter is the logical OR of any of the following:
+//!
+//! -\b I2S_INT_XUNDRN
+//! -\b I2S_INT_XSYNCERR
+//! -\b I2S_INT_XLAST
+//! -\b I2S_INT_XDATA
+//! -\b I2S_INT_XSTAFRM
+//! -\b I2S_INT_XDMA
+//! -\b I2S_INT_ROVRN
+//! -\b I2S_INT_RSYNCERR
+//! -\b I2S_INT_RLAST
+//! -\b I2S_INT_RDATA
+//! -\b I2S_INT_RSTAFRM
+//! -\b I2S_INT_RDMA
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
+{
+
+  //
+  // Enable DMA done interrupts
+  //
+  HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_CLR )
+     |= ((ulIntFlags &0xC0000000) >> 20);
+
+  //
+  // Enable specific Tx Interrupts
+  //
+  HWREG(ulBase + MCASP_O_EVTCTLX) |= (ulIntFlags & 0xFF);
+
+  //
+  // Enable specific Rx Interrupts
+  //
+  HWREG(ulBase + MCASP_O_EVTCTLR) |= ((ulIntFlags >> 16) & 0xFF);
+}
+
+//*****************************************************************************
+//
+//! Disables individual I2S interrupt sources.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
+//!
+//! This function disables the indicated I2S interrupt sources.  Only the
+//! sources that are enabled can be reflected to the processor interrupt;
+//! disabled sources have no effect on the processor.
+//!
+//! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
+//! parameter to I2SIntEnable().
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
+{
+  //
+  // Disable DMA done interrupts
+  //
+  HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_SET)
+     |= ((ulIntFlags &0xC0000000) >> 20);
+
+  //
+  // Disable specific Tx Interrupts
+  //
+  HWREG(ulBase + MCASP_O_EVTCTLX) &= ~(ulIntFlags & 0xFF);
+
+  //
+  // Disable specific Rx Interrupts
+  //
+  HWREG(ulBase + MCASP_O_EVTCTLR) &= ~((ulIntFlags >> 16) & 0xFF);
+}
+
+
+//*****************************************************************************
+//
+//! Gets the current interrupt status.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function returns the raw interrupt status for I2S enumerated
+//! as a bit field of values:
+//! -\b I2S_STS_XERR
+//! -\b I2S_STS_XDMAERR
+//! -\b I2S_STS_XSTAFRM
+//! -\b I2S_STS_XDATA
+//! -\b I2S_STS_XLAST
+//! -\b I2S_STS_XSYNCERR
+//! -\b I2S_STS_XUNDRN
+//! -\b I2S_STS_XDMA
+//! -\b I2S_STS_RERR
+//! -\b I2S_STS_RDMAERR
+//! -\b I2S_STS_RSTAFRM
+//! -\b I2S_STS_RDATA
+//! -\b I2S_STS_RLAST
+//! -\b I2S_STS_RSYNCERR
+//! -\b I2S_STS_ROVERN
+//! -\b I2S_STS_RDMA
+//!
+//! \return Returns the current interrupt status, enumerated as a bit field of
+//! values described above.
+//
+//*****************************************************************************
+unsigned long I2SIntStatus(unsigned long ulBase)
+{
+  unsigned long ulStatus;
+
+  //
+  // Get DMA interrupt status
+  //
+  ulStatus =
+    HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_STS_RAW) << 20;
+
+  ulStatus &= 0xC0000000;
+
+  //
+  // Read Tx Interrupt status
+  //
+  ulStatus |= HWREG(ulBase + MCASP_O_TXSTAT);
+
+  //
+  // Read Rx Interrupt status
+  //
+  ulStatus |= HWREG(ulBase + MCASP_O_RXSTAT) << 16;
+
+  //
+  // Return the status
+  //
+  return ulStatus;
+}
+
+//*****************************************************************************
+//
+//! Clears I2S interrupt sources.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulStatFlags is a bit mask of the interrupt sources to be cleared.
+//!
+//! The specified I2S interrupt sources are cleared, so that they no longer
+//! assert.  This function must be called in the interrupt handler to keep the
+//! interrupt from being recognized again immediately upon exit.
+//!
+//! The \e ulIntFlags parameter is the logical OR of any of the value
+//! describe in I2SIntStatus().
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SIntClear(unsigned long ulBase, unsigned long ulStatFlags)
+{
+  //
+  // Clear DMA done interrupts
+  //
+  HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_ACK)
+     |= ((ulStatFlags &0xC0000000) >> 20);
+
+  //
+  // Clear Tx Interrupt
+  //
+  HWREG(ulBase + MCASP_O_TXSTAT) = ulStatFlags & 0x1FF ;
+
+  //
+  // Clear Rx Interrupt
+  //
+  HWREG(ulBase + MCASP_O_RXSTAT) = (ulStatFlags >> 16) & 0x1FF;
+}
+
+//*****************************************************************************
+//
+//! Registers an interrupt handler for a I2S interrupt.
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param pfnHandler is a pointer to the function to be called when the
+//! I2S interrupt occurs.
+//!
+//! This function does the actual registering of the interrupt handler.  This
+//! function enables the global interrupt in the interrupt controller; specific
+//! I2S interrupts must be enabled via I2SIntEnable().  It is the interrupt
+//! handler's responsibility to clear the interrupt source.
+//!
+//! \sa IntRegister() for important information about registering interrupt
+//! handlers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
+{
+  //
+  // Register the interrupt handler
+  //
+  IntRegister(INT_I2S,pfnHandler);
+
+  //
+  // Enable the interrupt
+  //
+  IntEnable(INT_I2S);
+}
+
+//*****************************************************************************
+//
+//! Unregisters an interrupt handler for a I2S interrupt.
+//!
+//! \param ulBase is the base address of the I2S module.
+//!
+//! This function does the actual unregistering of the interrupt handler.  It
+//! clears the handler to be called when a I2S interrupt occurs.  This
+//! function also masks off the interrupt in the interrupt controller so that
+//! the interrupt handler no longer is called.
+//!
+//! \sa IntRegister() for important information about registering interrupt
+//! handlers.
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SIntUnregister(unsigned long ulBase)
+{
+  //
+  // Disable interrupt
+  //
+  IntDisable(INT_I2S);
+
+  //
+  // Unregister the handler
+  //
+  IntUnregister(INT_I2S);
+
+}
+
+//*****************************************************************************
+//
+//! Set the active slots for Trasmitter
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulActSlot is the bit-mask of activ slots
+//!
+//! This function sets the active slots for the transmitter. By default both
+//! the slots are active. The parameter \e ulActSlot is logical OR follwoing
+//! values:
+//! -\b I2S_ACT_SLOT_EVEN
+//! -\b I2S_ACT_SLOT_ODD
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2STxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot)
+{
+   HWREG(ulBase + MCASP_O_TXTDM) = ulActSlot;
+}
+
+//*****************************************************************************
+//
+//! Set the active slots for Receiver
+//!
+//! \param ulBase is the base address of the I2S module.
+//! \param ulActSlot is the bit-mask of activ slots
+//!
+//! This function sets the active slots for the receiver. By default both
+//! the slots are active. The parameter \e ulActSlot is logical OR follwoing
+//! values:
+//! -\b I2S_ACT_SLOT_EVEN
+//! -\b I2S_ACT_SLOT_ODD
+//!
+//! \return None.
+//
+//*****************************************************************************
+void I2SRxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot)
+{
+   HWREG(ulBase + MCASP_O_RXTDM) = ulActSlot;
+}
+
+//*****************************************************************************
+//
+// Close the Doxygen group.
+//! @}
+//
+//*****************************************************************************
diff --git a/micropython/ports/cc3200/hal/i2s.h b/micropython/ports/cc3200/hal/i2s.h
index 38620aef5a773cd2daacc6ede807e3cf806e6014..640696610094da36fd27c89b0a7bac0d612601b2 100644
--- a/micropython/ports/cc3200/hal/i2s.h
+++ b/micropython/ports/cc3200/hal/i2s.h
@@ -1,218 +1,218 @@
-//*****************************************************************************
-//
-//  i2s.h
-//
-//  Defines and Macros for the I2S.
-//
-//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-//
-//
-//  Redistribution and use in source and binary forms, with or without
-//  modification, are permitted provided that the following conditions
-//  are met:
-//
-//    Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//
-//    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//
-//    Neither the name of Texas Instruments Incorporated nor the names of
-//    its contributors may be used to endorse or promote products derived
-//    from this software without specific prior written permission.
-//
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-//*****************************************************************************
-
-#ifndef __I2S_H__
-#define __I2S_H__
-
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-//*****************************************************************************
-//
-// I2S DMA ports.
-//
-//*****************************************************************************
-#define I2S_TX_DMA_PORT      0x4401E200
-#define I2S_RX_DMA_PORT      0x4401E280
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SConfigSetExpClk() as the ulConfig parameter.
-//
-//*****************************************************************************
-#define I2S_SLOT_SIZE_8       0x00300032
-#define I2S_SLOT_SIZE_16      0x00700074
-#define I2S_SLOT_SIZE_24      0x00B000B6
-
-
-#define I2S_PORT_CPU          0x00080008
-#define I2S_PORT_DMA          0x00000000
-
-#define I2S_MODE_MASTER       0x00000000
-#define I2S_MODE_SLAVE        0x00008000
-
-//*****************************************************************************
-//
-// Values that can be passed as ulDataLine parameter.
-//
-//*****************************************************************************
-#define I2S_DATA_LINE_0       0x00000001
-#define I2S_DATA_LINE_1       0x00000002
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SSerializerConfig() as the ulSerMode
-// parameter.
-//
-//*****************************************************************************
-#define I2S_SER_MODE_TX       0x00000001
-#define I2S_SER_MODE_RX       0x00000002
-#define I2S_SER_MODE_DISABLE  0x00000000
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SSerializerConfig() as the ulInActState
-// parameter.
-//
-//*****************************************************************************
-#define I2S_INACT_TRI_STATE   0x00000000
-#define I2S_INACT_LOW_LEVEL   0x00000008
-#define I2S_INACT_HIGH_LEVEL  0x0000000C
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SIntEnable() and I2SIntDisable() as the
-// ulIntFlags parameter.
-//
-//*****************************************************************************
-#define I2S_INT_XUNDRN	      0x00000001
-#define I2S_INT_XSYNCERR      0x00000002
-#define I2S_INT_XLAST         0x00000010
-#define I2S_INT_XDATA         0x00000020
-#define I2S_INT_XSTAFRM       0x00000080
-#define I2S_INT_XDMA	      0x80000000
-#define I2S_INT_ROVRN         0x00010000
-#define I2S_INT_RSYNCERR      0x00020000
-#define I2S_INT_RLAST         0x00100000
-#define I2S_INT_RDATA         0x00200000
-#define I2S_INT_RSTAFRM       0x00800000
-#define I2S_INT_RDMA          0x40000000
-
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SRxActiveSlotSet() and I2STxActiveSlotSet
-//
-//*****************************************************************************
-#define I2S_ACT_SLOT_EVEN     0x00000001
-#define I2S_ACT_SLOT_ODD      0x00000002
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SIntClear() as the
-// ulIntFlags parameter and returned from I2SIntStatus().
-//
-//*****************************************************************************
-#define I2S_STS_XERR          0x00000100
-#define I2S_STS_XDMAERR	      0x00000080
-#define I2S_STS_XSTAFRM	      0x00000040
-#define I2S_STS_XDATA	      0x00000020
-#define I2S_STS_XLAST	      0x00000010
-#define I2S_STS_XSYNCERR      0x00000002
-#define I2S_STS_XUNDRN	      0x00000001
-#define I2S_STS_XDMA	      0x80000000
-#define I2S_STS_RERR          0x01000000
-#define I2S_STS_RDMAERR       0x00800000
-#define I2S_STS_RSTAFRM       0x00400000
-#define I2S_STS_RDATA         0x00200000
-#define I2S_STS_RLAST         0x00100000
-#define I2S_STS_RSYNCERR      0x00020000
-#define I2S_STS_ROVERN	      0x00010000
-#define I2S_STS_RDMA          0x40000000
-
-//*****************************************************************************
-//
-// Values that can be passed to I2SEnable() as the ulMode parameter.
-//
-//*****************************************************************************
-#define I2S_MODE_TX_ONLY      0x00000001
-#define I2S_MODE_TX_RX_SYNC   0x00000003
-
-
-//*****************************************************************************
-//
-// API Function prototypes
-//
-//*****************************************************************************
-extern void I2SEnable(unsigned long ulBase, unsigned long ulMode);
-extern void I2SDisable(unsigned long ulBase);
-
-extern void I2SDataPut(unsigned long ulBase, unsigned long ulDataLine,
-                unsigned long ulData);
-extern long I2SDataPutNonBlocking(unsigned long ulBase,
-                               unsigned long ulDataLine, unsigned long ulData);
-
-extern void I2SDataGet(unsigned long ulBase, unsigned long ulDataLine,
-                unsigned long *pulData);
-extern long I2SDataGetNonBlocking(unsigned long ulBase,
-                unsigned long ulDataLine, unsigned long *pulData);
-
-extern void I2SConfigSetExpClk(unsigned long ulBase, unsigned long ulI2SClk,
-                               unsigned long ulBitClk, unsigned long ulConfig);
-
-extern void I2STxFIFOEnable(unsigned long ulBase, unsigned long ulTxLevel,
-                     unsigned long ulWordsPerTransfer);
-extern void I2STxFIFODisable(unsigned long ulBase);
-extern void I2SRxFIFOEnable(unsigned long ulBase, unsigned long ulRxLevel,
-                     unsigned long ulWordsPerTransfer);
-extern void I2SRxFIFODisable(unsigned long ulBase);
-extern unsigned long I2STxFIFOStatusGet(unsigned long ulBase);
-extern unsigned long I2SRxFIFOStatusGet(unsigned long ulBase);
-
-extern void I2SSerializerConfig(unsigned long ulBase, unsigned long ulDataLine,
-                         unsigned long ulSerMode, unsigned long ulInActState);
-
-extern void I2SIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
-extern void I2SIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
-extern unsigned long I2SIntStatus(unsigned long ulBase);
-extern void I2SIntClear(unsigned long ulBase, unsigned long ulIntFlags);
-extern void I2SIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
-extern void I2SIntUnregister(unsigned long ulBase);
-extern void I2STxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot);
-extern void I2SRxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot);
-
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__I2S_H__
-
+//*****************************************************************************
+//
+//  i2s.h
+//
+//  Defines and Macros for the I2S.
+//
+//  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
+//  are met:
+//
+//    Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//
+//    Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//
+//    Neither the name of Texas Instruments Incorporated nor the names of
+//    its contributors may be used to endorse or promote products derived
+//    from this software without specific prior written permission.
+//
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//*****************************************************************************
+
+#ifndef __I2S_H__
+#define __I2S_H__
+
+//*****************************************************************************
+//
+// If building with a C++ compiler, make all of the definitions in this header
+// have a C binding.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+//*****************************************************************************
+//
+// I2S DMA ports.
+//
+//*****************************************************************************
+#define I2S_TX_DMA_PORT      0x4401E200
+#define I2S_RX_DMA_PORT      0x4401E280
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SConfigSetExpClk() as the ulConfig parameter.
+//
+//*****************************************************************************
+#define I2S_SLOT_SIZE_8       0x00300032
+#define I2S_SLOT_SIZE_16      0x00700074
+#define I2S_SLOT_SIZE_24      0x00B000B6
+
+
+#define I2S_PORT_CPU          0x00080008
+#define I2S_PORT_DMA          0x00000000
+
+#define I2S_MODE_MASTER       0x00000000
+#define I2S_MODE_SLAVE        0x00008000
+
+//*****************************************************************************
+//
+// Values that can be passed as ulDataLine parameter.
+//
+//*****************************************************************************
+#define I2S_DATA_LINE_0       0x00000001
+#define I2S_DATA_LINE_1       0x00000002
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SSerializerConfig() as the ulSerMode
+// parameter.
+//
+//*****************************************************************************
+#define I2S_SER_MODE_TX       0x00000001
+#define I2S_SER_MODE_RX       0x00000002
+#define I2S_SER_MODE_DISABLE  0x00000000
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SSerializerConfig() as the ulInActState
+// parameter.
+//
+//*****************************************************************************
+#define I2S_INACT_TRI_STATE   0x00000000
+#define I2S_INACT_LOW_LEVEL   0x00000008
+#define I2S_INACT_HIGH_LEVEL  0x0000000C
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SIntEnable() and I2SIntDisable() as the
+// ulIntFlags parameter.
+//
+//*****************************************************************************
+#define I2S_INT_XUNDRN	      0x00000001
+#define I2S_INT_XSYNCERR      0x00000002
+#define I2S_INT_XLAST         0x00000010
+#define I2S_INT_XDATA         0x00000020
+#define I2S_INT_XSTAFRM       0x00000080
+#define I2S_INT_XDMA	      0x80000000
+#define I2S_INT_ROVRN         0x00010000
+#define I2S_INT_RSYNCERR      0x00020000
+#define I2S_INT_RLAST         0x00100000
+#define I2S_INT_RDATA         0x00200000
+#define I2S_INT_RSTAFRM       0x00800000
+#define I2S_INT_RDMA          0x40000000
+
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SRxActiveSlotSet() and I2STxActiveSlotSet
+//
+//*****************************************************************************
+#define I2S_ACT_SLOT_EVEN     0x00000001
+#define I2S_ACT_SLOT_ODD      0x00000002
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SIntClear() as the
+// ulIntFlags parameter and returned from I2SIntStatus().
+//
+//*****************************************************************************
+#define I2S_STS_XERR          0x00000100
+#define I2S_STS_XDMAERR	      0x00000080
+#define I2S_STS_XSTAFRM	      0x00000040
+#define I2S_STS_XDATA	      0x00000020
+#define I2S_STS_XLAST	      0x00000010
+#define I2S_STS_XSYNCERR      0x00000002
+#define I2S_STS_XUNDRN	      0x00000001
+#define I2S_STS_XDMA	      0x80000000
+#define I2S_STS_RERR          0x01000000
+#define I2S_STS_RDMAERR       0x00800000
+#define I2S_STS_RSTAFRM       0x00400000
+#define I2S_STS_RDATA         0x00200000
+#define I2S_STS_RLAST         0x00100000
+#define I2S_STS_RSYNCERR      0x00020000
+#define I2S_STS_ROVERN	      0x00010000
+#define I2S_STS_RDMA          0x40000000
+
+//*****************************************************************************
+//
+// Values that can be passed to I2SEnable() as the ulMode parameter.
+//
+//*****************************************************************************
+#define I2S_MODE_TX_ONLY      0x00000001
+#define I2S_MODE_TX_RX_SYNC   0x00000003
+
+
+//*****************************************************************************
+//
+// API Function prototypes
+//
+//*****************************************************************************
+extern void I2SEnable(unsigned long ulBase, unsigned long ulMode);
+extern void I2SDisable(unsigned long ulBase);
+
+extern void I2SDataPut(unsigned long ulBase, unsigned long ulDataLine,
+                unsigned long ulData);
+extern long I2SDataPutNonBlocking(unsigned long ulBase,
+                               unsigned long ulDataLine, unsigned long ulData);
+
+extern void I2SDataGet(unsigned long ulBase, unsigned long ulDataLine,
+                unsigned long *pulData);
+extern long I2SDataGetNonBlocking(unsigned long ulBase,
+                unsigned long ulDataLine, unsigned long *pulData);
+
+extern void I2SConfigSetExpClk(unsigned long ulBase, unsigned long ulI2SClk,
+                               unsigned long ulBitClk, unsigned long ulConfig);
+
+extern void I2STxFIFOEnable(unsigned long ulBase, unsigned long ulTxLevel,
+                     unsigned long ulWordsPerTransfer);
+extern void I2STxFIFODisable(unsigned long ulBase);
+extern void I2SRxFIFOEnable(unsigned long ulBase, unsigned long ulRxLevel,
+                     unsigned long ulWordsPerTransfer);
+extern void I2SRxFIFODisable(unsigned long ulBase);
+extern unsigned long I2STxFIFOStatusGet(unsigned long ulBase);
+extern unsigned long I2SRxFIFOStatusGet(unsigned long ulBase);
+
+extern void I2SSerializerConfig(unsigned long ulBase, unsigned long ulDataLine,
+                         unsigned long ulSerMode, unsigned long ulInActState);
+
+extern void I2SIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
+extern void I2SIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
+extern unsigned long I2SIntStatus(unsigned long ulBase);
+extern void I2SIntClear(unsigned long ulBase, unsigned long ulIntFlags);
+extern void I2SIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
+extern void I2SIntUnregister(unsigned long ulBase);
+extern void I2STxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot);
+extern void I2SRxActiveSlotSet(unsigned long ulBase, unsigned long ulActSlot);
+
+//*****************************************************************************
+//
+// Mark the end of the C bindings section for C++ compilers.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__I2S_H__
+
diff --git a/micropython/ports/stm32/pybcdc.inf_template b/micropython/ports/stm32/pybcdc.inf_template
index 85279ada3414af110ae7d78449830eb0dfc0dc88..bd91f27810ca6cf4ea7b91cedc7fe1056fc8564a 100644
--- a/micropython/ports/stm32/pybcdc.inf_template
+++ b/micropython/ports/stm32/pybcdc.inf_template
@@ -1,92 +1,92 @@
-; Windows USB CDC ACM Setup File
-; Based on INF files which were:
-;     Copyright (c) 2000 Microsoft Corporation
-;     Copyright (C) 2007 Microchip Technology Inc.
-; Likely to be covered by the MLPL as found at:
-;    <http://msdn.microsoft.com/en-us/cc300389.aspx#MLPL>.
-
-[Version]
-Signature="$Windows NT$"
-Class=Ports
-ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
-Provider=%MFGNAME%
-LayoutFile=layout.inf
-DriverVer=03/11/2010,5.1.2600.3
-
-[Manufacturer]
-%MFGNAME%=DeviceList, NTamd64
-
-[DestinationDirs]
-DefaultDestDir=12
-
-;---------------------------------------------------------------------
-; Windows 2000/XP/Server2003/Vista/Server2008/7 - 32bit Sections
-
-[DriverInstall.nt]
-include=mdmcpq.inf
-CopyFiles=DriverCopyFiles.nt
-AddReg=DriverInstall.nt.AddReg
-
-[DriverCopyFiles.nt]
-usbser.sys,,,0x20
-
-[DriverInstall.nt.AddReg]
-HKR,,DevLoader,,*ntkern
-HKR,,NTMPDriver,,usbser.sys
-HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
-
-[DriverInstall.nt.Services]
-AddService=usbser, 0x00000002, DriverService.nt
-
-[DriverService.nt]
-DisplayName=%SERVICE%
-ServiceType=1
-StartType=3
-ErrorControl=1
-ServiceBinary=%12%\usbser.sys
-
-;---------------------------------------------------------------------
-;  Windows XP/Server2003/Vista/Server2008/7 - 64bit Sections
-
-[DriverInstall.NTamd64]
-include=mdmcpq.inf
-CopyFiles=DriverCopyFiles.NTamd64
-AddReg=DriverInstall.NTamd64.AddReg
-
-[DriverCopyFiles.NTamd64]
-usbser.sys,,,0x20
-
-[DriverInstall.NTamd64.AddReg]
-HKR,,DevLoader,,*ntkern
-HKR,,NTMPDriver,,usbser.sys
-HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
-
-[DriverInstall.NTamd64.Services]
-AddService=usbser, 0x00000002, DriverService.NTamd64
-
-[DriverService.NTamd64]
-DisplayName=%SERVICE%
-ServiceType=1
-StartType=3
-ErrorControl=1
-ServiceBinary=%12%\usbser.sys
-
-;---------------------------------------------------------------------
-;  Vendor and Product ID Definitions
-
-[SourceDisksFiles]
-[SourceDisksNames]
-[DeviceList]
-%DESCRIPTION%=DriverInstall, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC}
-
-[DeviceList.NTamd64]
-%DESCRIPTION%=DriverInstall, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC}
-
-;---------------------------------------------------------------------
-;  String Definitions
-
-[Strings]
-MFGFILENAME="pybcdc"
-MFGNAME="MicroPython"
-DESCRIPTION="Pyboard USB Comm Port"
-SERVICE="USB Serial Driver"
+; Windows USB CDC ACM Setup File
+; Based on INF files which were:
+;     Copyright (c) 2000 Microsoft Corporation
+;     Copyright (C) 2007 Microchip Technology Inc.
+; Likely to be covered by the MLPL as found at:
+;    <http://msdn.microsoft.com/en-us/cc300389.aspx#MLPL>.
+
+[Version]
+Signature="$Windows NT$"
+Class=Ports
+ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
+Provider=%MFGNAME%
+LayoutFile=layout.inf
+DriverVer=03/11/2010,5.1.2600.3
+
+[Manufacturer]
+%MFGNAME%=DeviceList, NTamd64
+
+[DestinationDirs]
+DefaultDestDir=12
+
+;---------------------------------------------------------------------
+; Windows 2000/XP/Server2003/Vista/Server2008/7 - 32bit Sections
+
+[DriverInstall.nt]
+include=mdmcpq.inf
+CopyFiles=DriverCopyFiles.nt
+AddReg=DriverInstall.nt.AddReg
+
+[DriverCopyFiles.nt]
+usbser.sys,,,0x20
+
+[DriverInstall.nt.AddReg]
+HKR,,DevLoader,,*ntkern
+HKR,,NTMPDriver,,usbser.sys
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
+
+[DriverInstall.nt.Services]
+AddService=usbser, 0x00000002, DriverService.nt
+
+[DriverService.nt]
+DisplayName=%SERVICE%
+ServiceType=1
+StartType=3
+ErrorControl=1
+ServiceBinary=%12%\usbser.sys
+
+;---------------------------------------------------------------------
+;  Windows XP/Server2003/Vista/Server2008/7 - 64bit Sections
+
+[DriverInstall.NTamd64]
+include=mdmcpq.inf
+CopyFiles=DriverCopyFiles.NTamd64
+AddReg=DriverInstall.NTamd64.AddReg
+
+[DriverCopyFiles.NTamd64]
+usbser.sys,,,0x20
+
+[DriverInstall.NTamd64.AddReg]
+HKR,,DevLoader,,*ntkern
+HKR,,NTMPDriver,,usbser.sys
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
+
+[DriverInstall.NTamd64.Services]
+AddService=usbser, 0x00000002, DriverService.NTamd64
+
+[DriverService.NTamd64]
+DisplayName=%SERVICE%
+ServiceType=1
+StartType=3
+ErrorControl=1
+ServiceBinary=%12%\usbser.sys
+
+;---------------------------------------------------------------------
+;  Vendor and Product ID Definitions
+
+[SourceDisksFiles]
+[SourceDisksNames]
+[DeviceList]
+%DESCRIPTION%=DriverInstall, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC}
+
+[DeviceList.NTamd64]
+%DESCRIPTION%=DriverInstall, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_MSC}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_00, USB\VID_${USB_VID}&PID_${USB_PID_CDC_HID}&MI_01, USB\VID_${USB_VID}&PID_${USB_PID_CDC}
+
+;---------------------------------------------------------------------
+;  String Definitions
+
+[Strings]
+MFGFILENAME="pybcdc"
+MFGNAME="MicroPython"
+DESCRIPTION="Pyboard USB Comm Port"
+SERVICE="USB Serial Driver"
diff --git a/micropython/ports/stm32/usbhost/Class/AUDIO/Inc/usbh_audio.h b/micropython/ports/stm32/usbhost/Class/AUDIO/Inc/usbh_audio.h
index 8cee530d06e5dd2f608873ee92a9e3f3ece9dacc..8d765734e64343bbf1896a9a643deb3bbbf0d4a8 100644
--- a/micropython/ports/stm32/usbhost/Class/AUDIO/Inc/usbh_audio.h
+++ b/micropython/ports/stm32/usbhost/Class/AUDIO/Inc/usbh_audio.h
@@ -1,581 +1,581 @@
-/**
-  ******************************************************************************
-  * @file    usbh_audio.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_audio.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_AUDIO_H
-#define __USBH_AUDIO_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
- 
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_AUDIO_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_AUDIO_CORE
-  * @brief This file is the Header file for usbh_audio.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_AUDIO_CORE_Exported_Types
-  * @{
-  */ 
-
-/* States for AUDIO State Machine */
-typedef enum
-{
-  AUDIO_INIT = 0, 
-  AUDIO_IDLE,   
-  AUDIO_CS_REQUESTS,
-  AUDIO_SET_DEFAULT_FEATURE_UNIT,
-  AUDIO_SET_INTERFACE,
-  AUDIO_SET_STREAMING_INTERFACE,
-  AUDIO_SET_CUR1,
-  AUDIO_GET_MIN,
-  AUDIO_GET_MAX,
-  AUDIO_GET_RES,
-  AUDIO_GET_CUR1,
-  AUDIO_SET_CUR2,
-  AUDIO_GET_CUR2,
-  AUDIO_SET_CUR3,
-  AUDIO_SET_INTERFACE0,
-  AUDIO_SET_INTERFACE1,
-  AUDIO_SET_INTERFACE2,
-  AUDIO_ISOC_OUT,        
-  AUDIO_ISOC_IN,  
-  AUDIO_ISOC_POLL,
-  AUDIO_ERROR,  
-}
-AUDIO_StateTypeDef;
-
-typedef enum
-{
-  AUDIO_REQ_INIT = 1,
-  AUDIO_REQ_IDLE, 
-  AUDIO_REQ_SET_DEFAULT_IN_INTERFACE,
-  AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE,  
-  AUDIO_REQ_SET_IN_INTERFACE,
-  AUDIO_REQ_SET_OUT_INTERFACE,
-  AUDIO_REQ_CS_REQUESTS,
-}
-AUDIO_ReqStateTypeDef;
-
-typedef enum
-{
-  AUDIO_REQ_SET_VOLUME = 1,
-  AUDIO_REQ_SET_MUTE,  
-  AUDIO_REQ_GET_CURR_VOLUME,
-  AUDIO_REQ_GET_MIN_VOLUME,
-  AUDIO_REQ_GET_MAX_VOLUME, 
-  AUDIO_REQ_GET_VOLUME, 
-  AUDIO_REQ_GET_RESOLUTION,
-  AUDIO_REQ_CS_IDLE,
-}
-AUDIO_CSReqStateTypeDef;
-
-typedef enum
-{
- AUDIO_PLAYBACK_INIT = 1,
- AUDIO_PLAYBACK_SET_EP,
- AUDIO_PLAYBACK_SET_EP_FREQ,
- AUDIO_PLAYBACK_PLAY,  
- AUDIO_PLAYBACK_IDLE,
-}
-AUDIO_PlayStateTypeDef;
-
-typedef enum
-{
- VOLUME_UP = 1,
- VOLUME_DOWN = 2,   
-}
-AUDIO_VolumeCtrlTypeDef;
-
-typedef enum
-{
- AUDIO_CONTROL_INIT = 1,
- AUDIO_CONTROL_CHANGE,
- AUDIO_CONTROL_IDLE,
- AUDIO_CONTROL_VOLUME_UP,
- AUDIO_CONTROL_VOLUME_DOWN,   
-}
-AUDIO_ControlStateTypeDef;
-
-
-typedef enum
-{
- AUDIO_DATA_START_OUT = 1,  
- AUDIO_DATA_OUT,
-}
-AUDIO_ProcessingTypeDef;
-
-/* Structure for AUDIO process */
-typedef struct
-{
-  uint8_t   Channels;
-  uint8_t   Bits;
-  uint32_t  SampleRate;
-} 
-AUDIO_FormatTypeDef;
-
-typedef struct
-{
-  uint8_t              Ep;
-  uint16_t             EpSize;
-  uint8_t              AltSettings;
-  uint8_t              interface;
-  uint8_t              valid; 
-  uint16_t             Poll;     
-}
-AUDIO_STREAMING_IN_HandleTypeDef;
-
-typedef struct
-{
-  uint8_t              Ep;
-  uint16_t             EpSize;
-  uint8_t              AltSettings;
-  uint8_t              interface;
-  uint8_t              valid;  
-  uint16_t             Poll;       
-}
-AUDIO_STREAMING_OUT_HandleTypeDef;
-
-
-typedef struct
-{
-  uint8_t              mute;
-  uint32_t             volumeMin;
-  uint32_t             volumeMax;
-  uint32_t             volume;
-  uint32_t             resolution;  
-} 
-AUDIO_ControlAttributeTypeDef;
-
-typedef struct
-{
-
-  uint8_t              Ep;
-  uint16_t             EpSize; 
-  uint8_t              interface; 
-  uint8_t              AltSettings;
-  uint8_t              supported;    
-
-  uint8_t              Pipe;  
-  uint8_t              Poll; 
-  uint32_t             timer ; 
-  
-  uint8_t              asociated_as; 
-  uint8_t              asociated_mixer; 
-  uint8_t              asociated_selector; 
-  uint8_t              asociated_feature; 
-  uint8_t              asociated_terminal;
-  uint8_t              asociated_channels;
-  
-  uint32_t             frequency; 
-  uint8_t              *buf;
-  uint8_t              *cbuf; 
-  uint32_t             partial_ptr; 
-
-  uint32_t             global_ptr;  
-  uint16_t             frame_length;  
-  uint32_t             total_length; 
-  
-  AUDIO_ControlAttributeTypeDef attribute;  
-}
-AUDIO_InterfaceStreamPropTypeDef;
-
-typedef struct
-{
-
-  uint8_t              Ep;
-  uint16_t             EpSize; 
-  uint8_t              interface; 
-  uint8_t              supported; 
-  
-  uint8_t              Pipe;  
-  uint8_t              Poll; 
-  uint32_t             timer ; 
-}
-AUDIO_InterfaceControlPropTypeDef;
-
-
-#define AUDIO_MAX_AUDIO_STD_INTERFACE      0x05
-#define AUDIO_MAX_FREQ_SUPPORTED           0x05
-#define AUDIO_MAX_STREAMING_INTERFACE      0x05
-#define AUDIO_MAX_NUM_IN_TERMINAL          0x04
-#define AUDIO_MAX_NUM_OUT_TERMINAL         0x04
-#define AUDIO_MAX_NUM_FEATURE_UNIT         0x04
-#define AUDIO_MAX_NUM_MIXER_UNIT           0x04
-#define AUDIO_MAX_NUM_SELECTOR_UNIT        0x04
-
-#define HEADPHONE_SUPPORTED                0x01
-#define MICROPHONE_SUPPORTED               0x02
-#define HEADSET_SUPPORTED                  0x03
-
-
-/*Class-Specific AS(Audio Streaming) Interface Descriptor*/
-typedef struct
-{
-  uint8_t bLength; 
-  uint8_t bDescriptorType;
-  uint8_t bDescriptorSubtype;
-  uint8_t bTerminalLink;
-  uint8_t bDelay;
-  uint8_t wFormatTag[2];
-}
-AUDIO_ASGeneralDescTypeDef;
-
-/*Class-Specific AS(Audio Streaming) Format Type Descriptor*/
-typedef struct
-{
-  uint8_t bLength;    /*At to be deside*/
-  uint8_t bDescriptorType;
-  uint8_t bDescriptorSubtype;
-  uint8_t bFormatType;
-  uint8_t bNrChannels;
-  uint8_t bSubframeSize;
-  uint8_t bBitResolution;
-  uint8_t bSamFreqType;
-  uint8_t tSamFreq[][3];
-}
-AUDIO_ASFormatTypeDescTypeDef;
-
-/*Class-Specific AS(Audio Streaming) Interface Descriptor*/
-typedef struct
-{
-  AUDIO_ASGeneralDescTypeDef      *GeneralDesc;
-  AUDIO_ASFormatTypeDescTypeDef   *FormatTypeDesc;
-}
-AUDIO_ASDescTypeDef;
-
-/* 4.3.2  Class-Specific AC Interface Descriptor */
-
-typedef struct
-{
-  uint8_t  bLength;                 
-  uint8_t  bDescriptorType;         
-  uint8_t  bDescriptorSubtype;      
-  uint8_t  bcdADC[2];                  
-  uint8_t  wTotalLength[2];            
-  uint8_t  bInCollection;           
-  uint8_t  baInterfaceNr[];         
-} 
-AUDIO_HeaderDescTypeDef;
-
-/* 4.3.2.1 Input Terminal Descriptor */
-typedef struct 
-{
-  uint8_t  bLength;                 
-  uint8_t  bDescriptorType;         
-  uint8_t  bDescriptorSubtype;      
-  uint8_t  bTerminalID;             
-  uint8_t  wTerminalType[2];          
-  uint8_t  bAssocTerminal;          
-  uint8_t  bNrChannels;             
-  uint8_t  wChannelConfig[2];
-  uint8_t  iChannelNames;
-  uint8_t  iTerminal;
-}
-AUDIO_ITDescTypeDef;
-
-/* 4.3.2.2 Output Terminal Descriptor */
-typedef struct 
-{
-  uint8_t  bLength;                 
-  uint8_t  bDescriptorType;         
-  uint8_t  bDescriptorSubtype;      
-  uint8_t  bTerminalID;             
-  uint8_t  wTerminalType[2];          
-  uint8_t  bAssocTerminal;          
-  uint8_t  bSourceID;               
-  uint8_t  iTerminal;
-}
-AUDIO_OTDescTypeDef;
-
-/* 4.3.2.3 Feature Descriptor */
-typedef struct
-{                                                             
-  uint8_t  bLength;                                        
-  uint8_t  bDescriptorType;                                
-  uint8_t  bDescriptorSubtype;                             
-  uint8_t  bUnitID;                                        
-  uint8_t  bSourceID;                                      
-  uint8_t  bControlSize;                                   
-  uint8_t bmaControls[][2];                                                                 
-}
-AUDIO_FeatureDescTypeDef;
-
-
-/* 4.3.2.3 Feature Descriptor */
-typedef struct
-{                                                             
-  uint8_t  bLength;                                        
-  uint8_t  bDescriptorType;                                
-  uint8_t  bDescriptorSubtype;                             
-  uint8_t  bUnitID; 
-  uint8_t  bNrInPins; 
-  uint8_t  bSourceID0; 
-  uint8_t  bSourceID1;  
-  uint8_t  bNrChannels;    
-  uint8_t  bmChannelsConfig[2];                                   
-  uint8_t iChannelsNames;    
-  uint8_t bmaControls;   
-  uint8_t iMixer;   
-}
-AUDIO_MixerDescTypeDef;
-
-
-
-/* 4.3.2.3 Feature Descriptor */
-typedef struct
-{                                                             
-  uint8_t  bLength;                                        
-  uint8_t  bDescriptorType;                                
-  uint8_t  bDescriptorSubtype;                             
-  uint8_t  bUnitID;                                        
-  uint8_t  bNrInPins; 
-  uint8_t  bSourceID0;  
-  uint8_t  iSelector;                                                                   
-}
-AUDIO_SelectorDescTypeDef;
-
-/*Class-Specific AC(Audio Control) Interface Descriptor*/
-typedef struct
-{
-  AUDIO_HeaderDescTypeDef   *HeaderDesc;
-  AUDIO_ITDescTypeDef       *InputTerminalDesc [AUDIO_MAX_NUM_IN_TERMINAL];
-  AUDIO_OTDescTypeDef       *OutputTerminalDesc[AUDIO_MAX_NUM_OUT_TERMINAL];
-  AUDIO_FeatureDescTypeDef  *FeatureUnitDesc   [AUDIO_MAX_NUM_FEATURE_UNIT];
-  AUDIO_MixerDescTypeDef    *MixerUnitDesc     [AUDIO_MAX_NUM_MIXER_UNIT];
-  AUDIO_SelectorDescTypeDef *SelectorUnitDesc  [AUDIO_MAX_NUM_SELECTOR_UNIT];
-}
-AUDIO_ACDescTypeDef;
-
-/*Class-Specific AC : Global descriptor*/
-
-typedef struct
-{
-  AUDIO_ACDescTypeDef   cs_desc; /* Only one control descriptor*/
-  AUDIO_ASDescTypeDef   as_desc[AUDIO_MAX_STREAMING_INTERFACE];
-
-  uint16_t ASNum; 
-  uint16_t InputTerminalNum;   
-  uint16_t OutputTerminalNum;  
-  uint16_t FeatureUnitNum;    
-  uint16_t SelectorUnitNum;    
-  uint16_t MixerUnitNum;    
-}
-AUDIO_ClassSpecificDescTypedef;
-
-
-typedef struct _AUDIO_Process
-{
-  AUDIO_ReqStateTypeDef              req_state;
-  AUDIO_CSReqStateTypeDef            cs_req_state;  
-  AUDIO_PlayStateTypeDef             play_state;  
-  AUDIO_ControlStateTypeDef          control_state; 
-  AUDIO_ProcessingTypeDef            processing_state;
-  
-  AUDIO_STREAMING_IN_HandleTypeDef   stream_in[AUDIO_MAX_AUDIO_STD_INTERFACE];
-  AUDIO_STREAMING_OUT_HandleTypeDef  stream_out[AUDIO_MAX_AUDIO_STD_INTERFACE];
-  AUDIO_ClassSpecificDescTypedef     class_desc;
-  
-  AUDIO_InterfaceStreamPropTypeDef   headphone;
-  AUDIO_InterfaceStreamPropTypeDef   microphone; 
-  AUDIO_InterfaceControlPropTypeDef  control;
-  uint16_t                            mem [8];  
-  uint8_t                            temp_feature;   
-  uint8_t                            temp_channels;      
-}
-AUDIO_HandleTypeDef;
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_AUDIO_CORE_Exported_Defines
-  * @{
-  */ 
-
-
-/*Audio Interface Subclass Codes*/
-#define AC_CLASS                        0x01
-
-/* A.2 Audio Interface Subclass Codes */
-#define USB_SUBCLASS_AUDIOCONTROL	0x01
-#define USB_SUBCLASS_AUDIOSTREAMING	0x02
-#define USB_SUBCLASS_MIDISTREAMING	0x03 
-
-#define USB_DESC_TYPE_CS_INTERFACE      0x24
-#define USB_DESC_TYPE_CS_ENDPOINT       0x25
-
-/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
-#define UAC_HEADER			0x01
-#define UAC_INPUT_TERMINAL		0x02
-#define UAC_OUTPUT_TERMINAL		0x03
-#define UAC_MIXER_UNIT			0x04
-#define UAC_SELECTOR_UNIT		0x05
-#define UAC_FEATURE_UNIT		0x06
-#define UAC_PROCESSING_UNIT		0x07
-#define UAC_EXTENSION_UNIT		0x08
-
-/*Audio Class-Specific Endpoint Descriptor Subtypes*/
-#define  EP_CONTROL_UNDEFINED             0x00
-#define  SAMPLING_FREQ_CONTROL            0x01
-#define  PITCH_CONTROL                    0x02
-
-/*Feature unit control selector*/
-#define FU_CONTROL_UNDEFINED                        0x00
-#define MUTE_CONTROL                                0x01
-#define VOLUME_CONTROL                              0x02
-#define BASS_CONTROL                                0x03
-#define MID_CONTROL                                 0x04
-#define TREBLE_CONTROL                              0x05
-#define GRAPHIC_EQUALIZER_CONTROL                   0x06
-#define AUTOMATIC_GAIN_CONTROL                      0x07
-#define DELAY_CONTROL                               0x08
-#define BASS_BOOST_CONTROL                          0x09
-#define LOUDNESS_CONTROL                            0x0A
-
-/*Terminal control selector*/
-#define TE_CONTROL_UNDEFINED                        0x00
-#define COPY_PROTECT_CONTROL                        0x01
-
-
-/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
-#define UAC_AS_GENERAL			0x01
-#define UAC_FORMAT_TYPE			0x02
-#define UAC_FORMAT_SPECIFIC		0x03
-
-/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
-#define UAC_EP_GENERAL			0x01
-
-/* A.9 Audio Class-Specific Request Codes */
-#define UAC_SET_			0x00
-#define UAC_GET_			0x80
-
-#define UAC__CUR			0x1
-#define UAC__MIN			0x2
-#define UAC__MAX			0x3
-#define UAC__RES			0x4
-#define UAC__MEM			0x5
-
-#define UAC_SET_CUR			(UAC_SET_ | UAC__CUR)
-#define UAC_GET_CUR			(UAC_GET_ | UAC__CUR)
-#define UAC_SET_MIN			(UAC_SET_ | UAC__MIN)
-#define UAC_GET_MIN			(UAC_GET_ | UAC__MIN)
-#define UAC_SET_MAX			(UAC_SET_ | UAC__MAX)
-#define UAC_GET_MAX			(UAC_GET_ | UAC__MAX)
-#define UAC_SET_RES			(UAC_SET_ | UAC__RES)
-#define UAC_GET_RES			(UAC_GET_ | UAC__RES)
-#define UAC_SET_MEM			(UAC_SET_ | UAC__MEM)
-#define UAC_GET_MEM			(UAC_GET_ | UAC__MEM)
-
-#define UAC_GET_STAT			0xff
-
-/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
-#define UAC_MS_HEADER			0x01
-#define UAC_MIDI_IN_JACK		0x02
-#define UAC_MIDI_OUT_JACK		0x03
-
-/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
-#define UAC_MS_GENERAL			0x01
-
-/* Terminals - 2.1 USB Terminal Types */
-#define UAC_TERMINAL_UNDEFINED		0x100
-#define UAC_TERMINAL_STREAMING		0x101
-#define UAC_TERMINAL_VENDOR_SPEC	0x1FF
-    
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_AUDIO_CORE_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_AUDIO_CORE_Exported_Variables
-  * @{
-  */ 
-extern USBH_ClassTypeDef  AUDIO_Class;
-#define USBH_AUDIO_CLASS    &AUDIO_Class
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_AUDIO_CORE_Exported_FunctionsPrototype
-  * @{
-  */ 
-USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, 
-                                            uint16_t sample_rate,
-                                            uint8_t  channel_num,
-                                            uint8_t data_width);
-  
-USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length);
-USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl);
-USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf);
-int32_t            USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost);
-
-void        USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost);
-/**
-  * @}
-  */ 
-
-
-#endif /* __USBH_AUDIO_H */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_audio.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_audio.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_AUDIO_H
+#define __USBH_AUDIO_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+ 
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_AUDIO_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_AUDIO_CORE
+  * @brief This file is the Header file for usbh_audio.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_AUDIO_CORE_Exported_Types
+  * @{
+  */ 
+
+/* States for AUDIO State Machine */
+typedef enum
+{
+  AUDIO_INIT = 0, 
+  AUDIO_IDLE,   
+  AUDIO_CS_REQUESTS,
+  AUDIO_SET_DEFAULT_FEATURE_UNIT,
+  AUDIO_SET_INTERFACE,
+  AUDIO_SET_STREAMING_INTERFACE,
+  AUDIO_SET_CUR1,
+  AUDIO_GET_MIN,
+  AUDIO_GET_MAX,
+  AUDIO_GET_RES,
+  AUDIO_GET_CUR1,
+  AUDIO_SET_CUR2,
+  AUDIO_GET_CUR2,
+  AUDIO_SET_CUR3,
+  AUDIO_SET_INTERFACE0,
+  AUDIO_SET_INTERFACE1,
+  AUDIO_SET_INTERFACE2,
+  AUDIO_ISOC_OUT,        
+  AUDIO_ISOC_IN,  
+  AUDIO_ISOC_POLL,
+  AUDIO_ERROR,  
+}
+AUDIO_StateTypeDef;
+
+typedef enum
+{
+  AUDIO_REQ_INIT = 1,
+  AUDIO_REQ_IDLE, 
+  AUDIO_REQ_SET_DEFAULT_IN_INTERFACE,
+  AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE,  
+  AUDIO_REQ_SET_IN_INTERFACE,
+  AUDIO_REQ_SET_OUT_INTERFACE,
+  AUDIO_REQ_CS_REQUESTS,
+}
+AUDIO_ReqStateTypeDef;
+
+typedef enum
+{
+  AUDIO_REQ_SET_VOLUME = 1,
+  AUDIO_REQ_SET_MUTE,  
+  AUDIO_REQ_GET_CURR_VOLUME,
+  AUDIO_REQ_GET_MIN_VOLUME,
+  AUDIO_REQ_GET_MAX_VOLUME, 
+  AUDIO_REQ_GET_VOLUME, 
+  AUDIO_REQ_GET_RESOLUTION,
+  AUDIO_REQ_CS_IDLE,
+}
+AUDIO_CSReqStateTypeDef;
+
+typedef enum
+{
+ AUDIO_PLAYBACK_INIT = 1,
+ AUDIO_PLAYBACK_SET_EP,
+ AUDIO_PLAYBACK_SET_EP_FREQ,
+ AUDIO_PLAYBACK_PLAY,  
+ AUDIO_PLAYBACK_IDLE,
+}
+AUDIO_PlayStateTypeDef;
+
+typedef enum
+{
+ VOLUME_UP = 1,
+ VOLUME_DOWN = 2,   
+}
+AUDIO_VolumeCtrlTypeDef;
+
+typedef enum
+{
+ AUDIO_CONTROL_INIT = 1,
+ AUDIO_CONTROL_CHANGE,
+ AUDIO_CONTROL_IDLE,
+ AUDIO_CONTROL_VOLUME_UP,
+ AUDIO_CONTROL_VOLUME_DOWN,   
+}
+AUDIO_ControlStateTypeDef;
+
+
+typedef enum
+{
+ AUDIO_DATA_START_OUT = 1,  
+ AUDIO_DATA_OUT,
+}
+AUDIO_ProcessingTypeDef;
+
+/* Structure for AUDIO process */
+typedef struct
+{
+  uint8_t   Channels;
+  uint8_t   Bits;
+  uint32_t  SampleRate;
+} 
+AUDIO_FormatTypeDef;
+
+typedef struct
+{
+  uint8_t              Ep;
+  uint16_t             EpSize;
+  uint8_t              AltSettings;
+  uint8_t              interface;
+  uint8_t              valid; 
+  uint16_t             Poll;     
+}
+AUDIO_STREAMING_IN_HandleTypeDef;
+
+typedef struct
+{
+  uint8_t              Ep;
+  uint16_t             EpSize;
+  uint8_t              AltSettings;
+  uint8_t              interface;
+  uint8_t              valid;  
+  uint16_t             Poll;       
+}
+AUDIO_STREAMING_OUT_HandleTypeDef;
+
+
+typedef struct
+{
+  uint8_t              mute;
+  uint32_t             volumeMin;
+  uint32_t             volumeMax;
+  uint32_t             volume;
+  uint32_t             resolution;  
+} 
+AUDIO_ControlAttributeTypeDef;
+
+typedef struct
+{
+
+  uint8_t              Ep;
+  uint16_t             EpSize; 
+  uint8_t              interface; 
+  uint8_t              AltSettings;
+  uint8_t              supported;    
+
+  uint8_t              Pipe;  
+  uint8_t              Poll; 
+  uint32_t             timer ; 
+  
+  uint8_t              asociated_as; 
+  uint8_t              asociated_mixer; 
+  uint8_t              asociated_selector; 
+  uint8_t              asociated_feature; 
+  uint8_t              asociated_terminal;
+  uint8_t              asociated_channels;
+  
+  uint32_t             frequency; 
+  uint8_t              *buf;
+  uint8_t              *cbuf; 
+  uint32_t             partial_ptr; 
+
+  uint32_t             global_ptr;  
+  uint16_t             frame_length;  
+  uint32_t             total_length; 
+  
+  AUDIO_ControlAttributeTypeDef attribute;  
+}
+AUDIO_InterfaceStreamPropTypeDef;
+
+typedef struct
+{
+
+  uint8_t              Ep;
+  uint16_t             EpSize; 
+  uint8_t              interface; 
+  uint8_t              supported; 
+  
+  uint8_t              Pipe;  
+  uint8_t              Poll; 
+  uint32_t             timer ; 
+}
+AUDIO_InterfaceControlPropTypeDef;
+
+
+#define AUDIO_MAX_AUDIO_STD_INTERFACE      0x05
+#define AUDIO_MAX_FREQ_SUPPORTED           0x05
+#define AUDIO_MAX_STREAMING_INTERFACE      0x05
+#define AUDIO_MAX_NUM_IN_TERMINAL          0x04
+#define AUDIO_MAX_NUM_OUT_TERMINAL         0x04
+#define AUDIO_MAX_NUM_FEATURE_UNIT         0x04
+#define AUDIO_MAX_NUM_MIXER_UNIT           0x04
+#define AUDIO_MAX_NUM_SELECTOR_UNIT        0x04
+
+#define HEADPHONE_SUPPORTED                0x01
+#define MICROPHONE_SUPPORTED               0x02
+#define HEADSET_SUPPORTED                  0x03
+
+
+/*Class-Specific AS(Audio Streaming) Interface Descriptor*/
+typedef struct
+{
+  uint8_t bLength; 
+  uint8_t bDescriptorType;
+  uint8_t bDescriptorSubtype;
+  uint8_t bTerminalLink;
+  uint8_t bDelay;
+  uint8_t wFormatTag[2];
+}
+AUDIO_ASGeneralDescTypeDef;
+
+/*Class-Specific AS(Audio Streaming) Format Type Descriptor*/
+typedef struct
+{
+  uint8_t bLength;    /*At to be deside*/
+  uint8_t bDescriptorType;
+  uint8_t bDescriptorSubtype;
+  uint8_t bFormatType;
+  uint8_t bNrChannels;
+  uint8_t bSubframeSize;
+  uint8_t bBitResolution;
+  uint8_t bSamFreqType;
+  uint8_t tSamFreq[][3];
+}
+AUDIO_ASFormatTypeDescTypeDef;
+
+/*Class-Specific AS(Audio Streaming) Interface Descriptor*/
+typedef struct
+{
+  AUDIO_ASGeneralDescTypeDef      *GeneralDesc;
+  AUDIO_ASFormatTypeDescTypeDef   *FormatTypeDesc;
+}
+AUDIO_ASDescTypeDef;
+
+/* 4.3.2  Class-Specific AC Interface Descriptor */
+
+typedef struct
+{
+  uint8_t  bLength;                 
+  uint8_t  bDescriptorType;         
+  uint8_t  bDescriptorSubtype;      
+  uint8_t  bcdADC[2];                  
+  uint8_t  wTotalLength[2];            
+  uint8_t  bInCollection;           
+  uint8_t  baInterfaceNr[];         
+} 
+AUDIO_HeaderDescTypeDef;
+
+/* 4.3.2.1 Input Terminal Descriptor */
+typedef struct 
+{
+  uint8_t  bLength;                 
+  uint8_t  bDescriptorType;         
+  uint8_t  bDescriptorSubtype;      
+  uint8_t  bTerminalID;             
+  uint8_t  wTerminalType[2];          
+  uint8_t  bAssocTerminal;          
+  uint8_t  bNrChannels;             
+  uint8_t  wChannelConfig[2];
+  uint8_t  iChannelNames;
+  uint8_t  iTerminal;
+}
+AUDIO_ITDescTypeDef;
+
+/* 4.3.2.2 Output Terminal Descriptor */
+typedef struct 
+{
+  uint8_t  bLength;                 
+  uint8_t  bDescriptorType;         
+  uint8_t  bDescriptorSubtype;      
+  uint8_t  bTerminalID;             
+  uint8_t  wTerminalType[2];          
+  uint8_t  bAssocTerminal;          
+  uint8_t  bSourceID;               
+  uint8_t  iTerminal;
+}
+AUDIO_OTDescTypeDef;
+
+/* 4.3.2.3 Feature Descriptor */
+typedef struct
+{                                                             
+  uint8_t  bLength;                                        
+  uint8_t  bDescriptorType;                                
+  uint8_t  bDescriptorSubtype;                             
+  uint8_t  bUnitID;                                        
+  uint8_t  bSourceID;                                      
+  uint8_t  bControlSize;                                   
+  uint8_t bmaControls[][2];                                                                 
+}
+AUDIO_FeatureDescTypeDef;
+
+
+/* 4.3.2.3 Feature Descriptor */
+typedef struct
+{                                                             
+  uint8_t  bLength;                                        
+  uint8_t  bDescriptorType;                                
+  uint8_t  bDescriptorSubtype;                             
+  uint8_t  bUnitID; 
+  uint8_t  bNrInPins; 
+  uint8_t  bSourceID0; 
+  uint8_t  bSourceID1;  
+  uint8_t  bNrChannels;    
+  uint8_t  bmChannelsConfig[2];                                   
+  uint8_t iChannelsNames;    
+  uint8_t bmaControls;   
+  uint8_t iMixer;   
+}
+AUDIO_MixerDescTypeDef;
+
+
+
+/* 4.3.2.3 Feature Descriptor */
+typedef struct
+{                                                             
+  uint8_t  bLength;                                        
+  uint8_t  bDescriptorType;                                
+  uint8_t  bDescriptorSubtype;                             
+  uint8_t  bUnitID;                                        
+  uint8_t  bNrInPins; 
+  uint8_t  bSourceID0;  
+  uint8_t  iSelector;                                                                   
+}
+AUDIO_SelectorDescTypeDef;
+
+/*Class-Specific AC(Audio Control) Interface Descriptor*/
+typedef struct
+{
+  AUDIO_HeaderDescTypeDef   *HeaderDesc;
+  AUDIO_ITDescTypeDef       *InputTerminalDesc [AUDIO_MAX_NUM_IN_TERMINAL];
+  AUDIO_OTDescTypeDef       *OutputTerminalDesc[AUDIO_MAX_NUM_OUT_TERMINAL];
+  AUDIO_FeatureDescTypeDef  *FeatureUnitDesc   [AUDIO_MAX_NUM_FEATURE_UNIT];
+  AUDIO_MixerDescTypeDef    *MixerUnitDesc     [AUDIO_MAX_NUM_MIXER_UNIT];
+  AUDIO_SelectorDescTypeDef *SelectorUnitDesc  [AUDIO_MAX_NUM_SELECTOR_UNIT];
+}
+AUDIO_ACDescTypeDef;
+
+/*Class-Specific AC : Global descriptor*/
+
+typedef struct
+{
+  AUDIO_ACDescTypeDef   cs_desc; /* Only one control descriptor*/
+  AUDIO_ASDescTypeDef   as_desc[AUDIO_MAX_STREAMING_INTERFACE];
+
+  uint16_t ASNum; 
+  uint16_t InputTerminalNum;   
+  uint16_t OutputTerminalNum;  
+  uint16_t FeatureUnitNum;    
+  uint16_t SelectorUnitNum;    
+  uint16_t MixerUnitNum;    
+}
+AUDIO_ClassSpecificDescTypedef;
+
+
+typedef struct _AUDIO_Process
+{
+  AUDIO_ReqStateTypeDef              req_state;
+  AUDIO_CSReqStateTypeDef            cs_req_state;  
+  AUDIO_PlayStateTypeDef             play_state;  
+  AUDIO_ControlStateTypeDef          control_state; 
+  AUDIO_ProcessingTypeDef            processing_state;
+  
+  AUDIO_STREAMING_IN_HandleTypeDef   stream_in[AUDIO_MAX_AUDIO_STD_INTERFACE];
+  AUDIO_STREAMING_OUT_HandleTypeDef  stream_out[AUDIO_MAX_AUDIO_STD_INTERFACE];
+  AUDIO_ClassSpecificDescTypedef     class_desc;
+  
+  AUDIO_InterfaceStreamPropTypeDef   headphone;
+  AUDIO_InterfaceStreamPropTypeDef   microphone; 
+  AUDIO_InterfaceControlPropTypeDef  control;
+  uint16_t                            mem [8];  
+  uint8_t                            temp_feature;   
+  uint8_t                            temp_channels;      
+}
+AUDIO_HandleTypeDef;
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_AUDIO_CORE_Exported_Defines
+  * @{
+  */ 
+
+
+/*Audio Interface Subclass Codes*/
+#define AC_CLASS                        0x01
+
+/* A.2 Audio Interface Subclass Codes */
+#define USB_SUBCLASS_AUDIOCONTROL	0x01
+#define USB_SUBCLASS_AUDIOSTREAMING	0x02
+#define USB_SUBCLASS_MIDISTREAMING	0x03 
+
+#define USB_DESC_TYPE_CS_INTERFACE      0x24
+#define USB_DESC_TYPE_CS_ENDPOINT       0x25
+
+/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
+#define UAC_HEADER			0x01
+#define UAC_INPUT_TERMINAL		0x02
+#define UAC_OUTPUT_TERMINAL		0x03
+#define UAC_MIXER_UNIT			0x04
+#define UAC_SELECTOR_UNIT		0x05
+#define UAC_FEATURE_UNIT		0x06
+#define UAC_PROCESSING_UNIT		0x07
+#define UAC_EXTENSION_UNIT		0x08
+
+/*Audio Class-Specific Endpoint Descriptor Subtypes*/
+#define  EP_CONTROL_UNDEFINED             0x00
+#define  SAMPLING_FREQ_CONTROL            0x01
+#define  PITCH_CONTROL                    0x02
+
+/*Feature unit control selector*/
+#define FU_CONTROL_UNDEFINED                        0x00
+#define MUTE_CONTROL                                0x01
+#define VOLUME_CONTROL                              0x02
+#define BASS_CONTROL                                0x03
+#define MID_CONTROL                                 0x04
+#define TREBLE_CONTROL                              0x05
+#define GRAPHIC_EQUALIZER_CONTROL                   0x06
+#define AUTOMATIC_GAIN_CONTROL                      0x07
+#define DELAY_CONTROL                               0x08
+#define BASS_BOOST_CONTROL                          0x09
+#define LOUDNESS_CONTROL                            0x0A
+
+/*Terminal control selector*/
+#define TE_CONTROL_UNDEFINED                        0x00
+#define COPY_PROTECT_CONTROL                        0x01
+
+
+/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
+#define UAC_AS_GENERAL			0x01
+#define UAC_FORMAT_TYPE			0x02
+#define UAC_FORMAT_SPECIFIC		0x03
+
+/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
+#define UAC_EP_GENERAL			0x01
+
+/* A.9 Audio Class-Specific Request Codes */
+#define UAC_SET_			0x00
+#define UAC_GET_			0x80
+
+#define UAC__CUR			0x1
+#define UAC__MIN			0x2
+#define UAC__MAX			0x3
+#define UAC__RES			0x4
+#define UAC__MEM			0x5
+
+#define UAC_SET_CUR			(UAC_SET_ | UAC__CUR)
+#define UAC_GET_CUR			(UAC_GET_ | UAC__CUR)
+#define UAC_SET_MIN			(UAC_SET_ | UAC__MIN)
+#define UAC_GET_MIN			(UAC_GET_ | UAC__MIN)
+#define UAC_SET_MAX			(UAC_SET_ | UAC__MAX)
+#define UAC_GET_MAX			(UAC_GET_ | UAC__MAX)
+#define UAC_SET_RES			(UAC_SET_ | UAC__RES)
+#define UAC_GET_RES			(UAC_GET_ | UAC__RES)
+#define UAC_SET_MEM			(UAC_SET_ | UAC__MEM)
+#define UAC_GET_MEM			(UAC_GET_ | UAC__MEM)
+
+#define UAC_GET_STAT			0xff
+
+/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
+#define UAC_MS_HEADER			0x01
+#define UAC_MIDI_IN_JACK		0x02
+#define UAC_MIDI_OUT_JACK		0x03
+
+/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
+#define UAC_MS_GENERAL			0x01
+
+/* Terminals - 2.1 USB Terminal Types */
+#define UAC_TERMINAL_UNDEFINED		0x100
+#define UAC_TERMINAL_STREAMING		0x101
+#define UAC_TERMINAL_VENDOR_SPEC	0x1FF
+    
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_AUDIO_CORE_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_AUDIO_CORE_Exported_Variables
+  * @{
+  */ 
+extern USBH_ClassTypeDef  AUDIO_Class;
+#define USBH_AUDIO_CLASS    &AUDIO_Class
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_AUDIO_CORE_Exported_FunctionsPrototype
+  * @{
+  */ 
+USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, 
+                                            uint16_t sample_rate,
+                                            uint8_t  channel_num,
+                                            uint8_t data_width);
+  
+USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length);
+USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl);
+USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf);
+int32_t            USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost);
+
+void        USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost);
+/**
+  * @}
+  */ 
+
+
+#endif /* __USBH_AUDIO_H */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/AUDIO/Src/usbh_audio.c b/micropython/ports/stm32/usbhost/Class/AUDIO/Src/usbh_audio.c
index b9677b6c2b4d53661b25897578e7f67d06d43d39..748e63abe805b0614928d700a91ae47c77a587ea 100644
--- a/micropython/ports/stm32/usbhost/Class/AUDIO/Src/usbh_audio.c
+++ b/micropython/ports/stm32/usbhost/Class/AUDIO/Src/usbh_audio.c
@@ -1,1994 +1,1994 @@
-/**
-  ******************************************************************************
-  * @file    usbh_audio.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the AC Layer Handlers for USB Host AC class. 
-  *
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_audio.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_AUDIO_CLASS
-  * @{
-  */
-
-/** @defgroup USBH_AUDIO_CORE 
-  * @brief    This file includes HID Layer Handlers for USB Host HID class.
-  * @{
-  */ 
-
-/** @defgroup USBH_AUDIO_CORE_Private_TypesDefinitions
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_AUDIO_CORE_Private_Defines
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_AUDIO_CORE_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_AUDIO_CORE_Private_Variables
-  * @{
-  */
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_AUDIO_CORE_Private_FunctionPrototypes
-  * @{
-  */ 
-
-static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit  (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit  (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_Process(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_SOFProcess(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, 
-                                               uint8_t feature, 
-                                               uint8_t channel);
-
-static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *phost);
-int32_t USBH_AUDIO_FindLinkedUnitIN(USBH_HandleTypeDef *phost, uint8_t UnitID);
-int32_t USBH_AUDIO_FindLinkedUnitOUT(USBH_HandleTypeDef *phost, uint8_t UnitID);
-
-
-
-static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, 
-                                      uint8_t ac_subclass, 
-                                      uint8_t *pdesc);
-
-
-static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost);
-
-
-static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length);
-
-static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length);
-
-static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length);
-
-static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length);
-
-static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length);
-
-static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost,
-                                               uint8_t  Ep,
-                                               uint8_t *buff);
-
-static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume);
-
-static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib);
-static int32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID);
-
-USBH_ClassTypeDef  AUDIO_Class = 
-{
-  "AUDIO",
-  AC_CLASS,  
-  USBH_AUDIO_InterfaceInit,
-  USBH_AUDIO_InterfaceDeInit,
-  USBH_AUDIO_ClassRequest,
-  USBH_AUDIO_Process,
-  USBH_AUDIO_SOFProcess,
-  NULL,
-};
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_AUDIO_CORE_Private_Functions
-  * @{
-  */ 
-
-/**
-  * @brief  USBH_AUDIO_InterfaceInit 
-  *         The function init the Audio class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  USBH_StatusTypeDef out_status, in_status ;    
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  uint8_t  interface, index;
-  uint16_t ep_size_out = 0;
-  uint16_t ep_size_in = 0;  
-  
-  interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0x00);
-  
-  if(interface == 0xFF) /* Not Valid Interface */
-  {
-    USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
-    status = USBH_FAIL;      
-  }
-  else
-  {
-    
-    
-    phost->pActiveClass->pData = (AUDIO_HandleTypeDef *)USBH_malloc (sizeof(AUDIO_HandleTypeDef));
-    AUDIO_Handle =  phost->pActiveClass->pData; 
-    USBH_memset(AUDIO_Handle, 0, sizeof(AUDIO_HandleTypeDef));
-    
-    
-    /* 1st Step:  Find Audio Interfaces */
-    out_status = USBH_AUDIO_FindAudioStreamingIN (phost);
-    
-    in_status = USBH_AUDIO_FindAudioStreamingOUT(phost);
-    
-    if((out_status == USBH_FAIL) && (in_status == USBH_FAIL))
-    {
-      USBH_DbgLog ("%s class configuration not supported.", phost->pActiveClass->Name);
-    }
-    else
-    {
-      /* 2nd Step:  Select Audio Streaming Interfaces with largest endpoint size : default behavior*/ 
-      for (index = 0; index < AUDIO_MAX_AUDIO_STD_INTERFACE; index ++)
-      {
-        if( AUDIO_Handle->stream_out[index].valid == 1)
-        {
-          if(ep_size_out < AUDIO_Handle->stream_out[index].EpSize)
-          {
-            ep_size_out = AUDIO_Handle->stream_out[index].EpSize;
-            AUDIO_Handle->headphone.interface = AUDIO_Handle->stream_out[index].interface;
-            AUDIO_Handle->headphone.AltSettings = AUDIO_Handle->stream_out[index].AltSettings;           
-            AUDIO_Handle->headphone.Ep = AUDIO_Handle->stream_out[index].Ep;
-            AUDIO_Handle->headphone.EpSize = AUDIO_Handle->stream_out[index].EpSize; 
-            AUDIO_Handle->headphone.Poll = AUDIO_Handle->stream_out[index].Poll;
-            AUDIO_Handle->headphone.supported = 1;  
-          }
-        }
-        
-        if( AUDIO_Handle->stream_in[index].valid == 1)
-        {
-          if(ep_size_in < AUDIO_Handle->stream_in[index].EpSize)
-          {
-            ep_size_in = AUDIO_Handle->stream_in[index].EpSize;
-            AUDIO_Handle->microphone.interface = AUDIO_Handle->stream_in[index].interface;
-            AUDIO_Handle->microphone.AltSettings = AUDIO_Handle->stream_in[index].AltSettings;                
-            AUDIO_Handle->microphone.Ep = AUDIO_Handle->stream_in[index].Ep;
-            AUDIO_Handle->microphone.EpSize = AUDIO_Handle->stream_in[index].EpSize;
-            AUDIO_Handle->microphone.Poll = AUDIO_Handle->stream_out[index].Poll;         
-            AUDIO_Handle->microphone.supported = 1;       
-          }
-        }
-      }
-      
-      if(USBH_AUDIO_FindHIDControl(phost) == USBH_OK)
-      {
-        AUDIO_Handle->control.supported = 1;
-      }
-      
-      /* 3rd Step:  Find and Parse Audio interfaces */ 
-      USBH_AUDIO_ParseCSDescriptors (phost);
-     
-      
-      /* 4th Step:  Open the Audio streaming pipes*/ 
-      if(AUDIO_Handle->headphone.supported == 1)
-      {
-        USBH_AUDIO_BuildHeadphonePath (phost);
-         
-        AUDIO_Handle->headphone.Pipe  = USBH_AllocPipe(phost, AUDIO_Handle->headphone.Ep);
-        
-        /* Open pipe for IN endpoint */
-        USBH_OpenPipe  (phost,
-                        AUDIO_Handle->headphone.Pipe,
-                        AUDIO_Handle->headphone.Ep,
-                        phost->device.address,
-                        phost->device.speed,
-                        USB_EP_TYPE_ISOC,
-                        AUDIO_Handle->headphone.EpSize); 
-        
-        USBH_LL_SetToggle (phost,  AUDIO_Handle->headphone.Pipe, 0);          
-        
-      }
-      
-      if(AUDIO_Handle->microphone.supported == 1)
-      {
-        USBH_AUDIO_BuildMicrophonePath (phost);        
-        AUDIO_Handle->microphone.Pipe  = USBH_AllocPipe(phost, AUDIO_Handle->microphone.Ep);
-        
-        /* Open pipe for IN endpoint */
-        USBH_OpenPipe  (phost,
-                        AUDIO_Handle->microphone.Pipe,
-                        AUDIO_Handle->microphone.Ep,
-                        phost->device.address,
-                        phost->device.speed,
-                        USB_EP_TYPE_ISOC,
-                        AUDIO_Handle->microphone.EpSize); 
-        
-        USBH_LL_SetToggle (phost,  AUDIO_Handle->microphone.Pipe, 0);  
-      }
-      
-      if(AUDIO_Handle->control.supported == 1)
-      {     
-        AUDIO_Handle->control.Pipe  = USBH_AllocPipe(phost, AUDIO_Handle->control.Ep);
-        
-        /* Open pipe for IN endpoint */
-        USBH_OpenPipe  (phost,
-                        AUDIO_Handle->control.Pipe,
-                        AUDIO_Handle->control.Ep,
-                        phost->device.address,
-                        phost->device.speed,
-                        USB_EP_TYPE_INTR,
-                        AUDIO_Handle->control.EpSize); 
-        
-        USBH_LL_SetToggle (phost,  AUDIO_Handle->control.Pipe, 0);          
-   
-      }
-      
-      AUDIO_Handle->req_state     = AUDIO_REQ_INIT;
-      AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
-      
-      status = USBH_OK;
-    }
-  }
-  return status;
-}
-
-
-
-/**
-  * @brief  USBH_AUDIO_InterfaceDeInit 
-  *         The function DeInit the Pipes used for the Audio class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost)
-{
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData; 
-  
-  if(AUDIO_Handle->microphone.Pipe != 0x00)
-  {   
-    USBH_ClosePipe  (phost, AUDIO_Handle->microphone.Pipe);
-    USBH_FreePipe  (phost, AUDIO_Handle->microphone.Pipe);
-    AUDIO_Handle->microphone.Pipe = 0;     /* Reset the pipe as Free */  
-  }
-  
-  if( AUDIO_Handle->headphone.Pipe != 0x00)
-  {   
-    USBH_ClosePipe(phost,  AUDIO_Handle->headphone.Pipe);
-    USBH_FreePipe  (phost,  AUDIO_Handle->headphone.Pipe);
-    AUDIO_Handle->headphone.Pipe = 0;     /* Reset the pipe as Free */  
-  }
-  
-  if( AUDIO_Handle->control.Pipe != 0x00)
-  {   
-    USBH_ClosePipe(phost,  AUDIO_Handle->control.Pipe);
-    USBH_FreePipe  (phost,  AUDIO_Handle->control.Pipe);
-    AUDIO_Handle->control.Pipe = 0;     /* Reset the pipe as Free */  
-  }
-  
-  if(phost->pActiveClass->pData)
-  {
-    USBH_free (phost->pActiveClass->pData);
-    phost->pActiveClass->pData = 0;
-  }  
-  return USBH_OK ;
-}
-
-/**
-  * @brief  USBH_AUDIO_ClassRequest 
-  *         The function is responsible for handling Standard requests
-  *         for Audio class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost)
-{   
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
-  USBH_StatusTypeDef status = USBH_BUSY;
-  USBH_StatusTypeDef req_status = USBH_BUSY;
-  
-  /* Switch AUDIO REQ state machine */
-  switch (AUDIO_Handle->req_state)
-  {
-  case AUDIO_REQ_INIT:
-  case AUDIO_REQ_SET_DEFAULT_IN_INTERFACE:
-    if(AUDIO_Handle->microphone.supported == 1)
-    {
-      req_status = USBH_SetInterface(phost, 
-                                     AUDIO_Handle->microphone.interface, 
-                                     0);
-      
-      if(req_status == USBH_OK)
-      {
-        AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE;
-      }
-      
-    }
-    else
-    {
-      AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE:
-    if(AUDIO_Handle->headphone.supported == 1)
-    {
-      req_status = USBH_SetInterface(phost, 
-                                     AUDIO_Handle->headphone.interface, 
-                                     0);
-      
-      if(req_status == USBH_OK)
-      {
-        AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS;
-        AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
-        
-        AUDIO_Handle->temp_feature  = AUDIO_Handle->headphone.asociated_feature;
-        AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels;
-      }
-    }
-    else
-    {
-        AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS;
-        AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif         
-    }
-    break;
-    
-  case AUDIO_REQ_CS_REQUESTS:
-    if(USBH_AUDIO_HandleCSRequest (phost) == USBH_OK)
-    {
-      AUDIO_Handle->req_state = AUDIO_REQ_SET_IN_INTERFACE;
-    }
-    break;
-   
-  case AUDIO_REQ_SET_IN_INTERFACE:
-    if(AUDIO_Handle->microphone.supported == 1)
-    {
-      req_status = USBH_SetInterface(phost, 
-                                     AUDIO_Handle->microphone.interface, 
-                                     AUDIO_Handle->microphone.AltSettings);
-      
-      if(req_status == USBH_OK)
-      {
-        AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE;
-      }
-    }
-    else
-    {
-      AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-  case AUDIO_REQ_SET_OUT_INTERFACE:
-   if(AUDIO_Handle->headphone.supported == 1)
-    {
-      req_status = USBH_SetInterface(phost, 
-                                     AUDIO_Handle->headphone.interface, 
-                                     AUDIO_Handle->headphone.AltSettings);
-      
-      if(req_status == USBH_OK)
-      {
-        AUDIO_Handle->req_state = AUDIO_REQ_IDLE;
-      }
-      
-    }
-   else
-   {
-     AUDIO_Handle->req_state = AUDIO_REQ_IDLE;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif      
-   }
-   break;
-  case AUDIO_REQ_IDLE:
-    AUDIO_Handle->play_state = AUDIO_PLAYBACK_INIT;
-    phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
-    status  = USBH_OK;    
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif
-  default:
-    break;
-  }
-  return status; 
-}
-
-/**
-  * @brief  USBH_AUDIO_CSRequest 
-  *         The function is responsible for handling AC Specific requests for a specific feature and channel
-  *         for Audio class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel)
-{   
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
-  USBH_StatusTypeDef status = USBH_BUSY;
-  USBH_StatusTypeDef req_status = USBH_BUSY;
-  
-  /* Switch AUDIO REQ state machine */
-  switch (AUDIO_Handle->cs_req_state)
-  {
-  case AUDIO_REQ_GET_VOLUME:
-    req_status = USBH_AC_GetCur(phost,                 
-                                UAC_FEATURE_UNIT,     /* subtype  */
-                                feature,              /* feature  */
-                                VOLUME_CONTROL,       /* Selector */
-                                channel,              /* channel  */
-                                0x02);                /* length   */
-    if(req_status != USBH_BUSY)
-    {
-      AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MIN_VOLUME;
-      AUDIO_Handle->headphone.attribute.volume = LE16(&(AUDIO_Handle->mem[0]));
-    }
-    break;
-    
-  case AUDIO_REQ_GET_MIN_VOLUME:
-    req_status = USBH_AC_GetMin(phost,                 
-                                UAC_FEATURE_UNIT,     /* subtype  */
-                                feature,              /* feature  */
-                                VOLUME_CONTROL,       /* Selector */
-                                channel,              /* channel  */
-                                0x02);                /* length   */
-    if(req_status != USBH_BUSY)
-    {
-      AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MAX_VOLUME;
-      AUDIO_Handle->headphone.attribute.volumeMin = LE16(&AUDIO_Handle->mem[0]);
-    }
-    break;
-
-  case AUDIO_REQ_GET_MAX_VOLUME:
-    req_status = USBH_AC_GetMax(phost,                 
-                                UAC_FEATURE_UNIT,     /* subtype  */
-                                feature,              /* feature  */
-                                VOLUME_CONTROL,       /* Selector */
-                                channel,              /* channel  */
-                                0x02);                /* length   */
-    if(req_status != USBH_BUSY)
-    {
-      AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_RESOLUTION;
-      AUDIO_Handle->headphone.attribute.volumeMax = LE16(&AUDIO_Handle->mem[0]);   
-      
-      if (AUDIO_Handle->headphone.attribute.volumeMax < AUDIO_Handle->headphone.attribute.volumeMin)
-      {
-        AUDIO_Handle->headphone.attribute.volumeMax = 0xFF00; 
-      }
-    }
-    break;
-    
-  case AUDIO_REQ_GET_RESOLUTION:
-    req_status = USBH_AC_GetRes(phost,                 
-                                UAC_FEATURE_UNIT,     /* subtype  */
-                                feature,              /* feature  */
-                                VOLUME_CONTROL,       /* Selector */
-                                channel,              /* channel  */
-                                0x02);                /* length   */
-    if(req_status != USBH_BUSY)
-    {
-      AUDIO_Handle->cs_req_state = AUDIO_REQ_CS_IDLE;
-      AUDIO_Handle->headphone.attribute.resolution = LE16(&AUDIO_Handle->mem[0]);    
-    }
-    break;
-    
- 
-  case AUDIO_REQ_CS_IDLE:
-    status = USBH_OK;
-  default:
-    break;
-  }
-  return status; 
-}
-
-/**
-  * @brief  USBH_AUDIO_HandleCSRequest 
-  *         The function is responsible for handling AC Specific requests for a all features 
-  *         and associated channels for Audio class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost)
-{ 
-
-  USBH_StatusTypeDef status = USBH_BUSY;
-  USBH_StatusTypeDef cs_status = USBH_BUSY;
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
-        
-  cs_status = USBH_AUDIO_CSRequest(phost, 
-                                   AUDIO_Handle->temp_feature, 
-                                   AUDIO_Handle->temp_channels);
-  
-  if(cs_status != USBH_BUSY)
-  {
-    
-    if(AUDIO_Handle->temp_channels ==  1)
-    {
-        AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature;
-        AUDIO_Handle->temp_channels = 0;
-        status = USBH_OK; 
-    }
-    else
-    {
-      AUDIO_Handle->temp_channels--;
-    }
-    AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif     
-  }
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_AUDIO_Process 
-  *         The function is for managing state machine for Audio data transfers 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_Process (USBH_HandleTypeDef *phost)
-{   
-  USBH_StatusTypeDef status = USBH_BUSY;
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
-  
-  if(AUDIO_Handle->headphone.supported == 1)
-  {
-    USBH_AUDIO_OutputStream (phost);
-  }
-  
-  if(AUDIO_Handle->microphone.supported == 1)
-  {
-    USBH_AUDIO_InputStream (phost);
-  }
- 
-  return status;
-}
-
-/**
-  * @brief  USBH_AUDIO_SOFProcess 
-  *         The function is for managing the SOF callback
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_SOFProcess (USBH_HandleTypeDef *phost)
-{  
-  return USBH_OK;
-}
-/**
-  * @brief  Find IN Audio Streaming interfaces
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *phost)
-{
-  uint8_t interface, alt_settings;
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-
-  AUDIO_Handle =  phost->pActiveClass->pData; 
-
-  /* Look For AUDIOSTREAMING IN interface */
-  alt_settings = 0;
-  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
-  {
-    if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&&
-       (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING))
-    {
-      if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)&&
-         (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0))
-      {
-        AUDIO_Handle->stream_in[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
-        AUDIO_Handle->stream_in[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
-        AUDIO_Handle->stream_in[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber;        
-        AUDIO_Handle->stream_in[alt_settings].AltSettings = phost->device.CfgDesc.Itf_Desc[interface].bAlternateSetting;
-        AUDIO_Handle->stream_in[alt_settings].Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval;   
-        AUDIO_Handle->stream_in[alt_settings].valid = 1; 
-        alt_settings++;
-      }
-    }
-  } 
-  
-  if(alt_settings > 0)
-  {  
-     status = USBH_OK;
-  }
-  
-  return status;
-}
-
-/**
-  * @brief  Find OUT Audio Streaming interfaces
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *phost)
-{
-  uint8_t interface, alt_settings;
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-
-  AUDIO_Handle =  phost->pActiveClass->pData; 
-
-  /* Look For AUDIOSTREAMING IN interface */
-  alt_settings = 0;
-  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
-  {
-    if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&&
-       (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING))
-    {
-      if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) == 0x00)&&
-         (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0))        
-      {
-        AUDIO_Handle->stream_out[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
-        AUDIO_Handle->stream_out[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
-        AUDIO_Handle->stream_out[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber;
-        AUDIO_Handle->stream_out[alt_settings].AltSettings = phost->device.CfgDesc.Itf_Desc[interface].bAlternateSetting;
-        AUDIO_Handle->stream_out[alt_settings].Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval;           
-        AUDIO_Handle->stream_out[alt_settings].valid = 1; 
-        alt_settings++;
-      }
-    }
-  }
-  
-  if(alt_settings > 0)
-  {
-     status = USBH_OK;
-  }
-  
-  return status;  
-}
-
-/**
-  * @brief  Find HID Control interfaces
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost)
-{
-  uint8_t interface;
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-
-  AUDIO_Handle =  phost->pActiveClass->pData;   
-
-  /* Look For AUDIOCONTROL  interface */
-  interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0xFF);
-  if(interface != 0xFF)
-  {
-    for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
-    {
-      if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == 0x03)&& /*HID*/
-        (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0))
-      {
-        if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) == 0x80)
-        {
-          AUDIO_Handle->control.Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
-          AUDIO_Handle->control.EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
-          AUDIO_Handle->control.interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber;          
-          AUDIO_Handle->control.Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval;
-          AUDIO_Handle->control.supported = 1;
-          status = USBH_OK;
-          break;
-        }
-      }
-    } 
-  }
-  return status;
-}
-
-/**
-  * @brief  Parse AC and interfaces Descriptors
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phost)
-{
-  USBH_DescHeader_t            *pdesc ;
-  uint16_t                      ptr;
-  int8_t                        itf_index = 0;
-  int8_t                        itf_number = 0; 
-  int8_t                        alt_setting;   
-  AUDIO_HandleTypeDef           *AUDIO_Handle;
-  
-  AUDIO_Handle =  phost->pActiveClass->pData;  
-  pdesc   = (USBH_DescHeader_t *)(phost->device.CfgDesc_Raw);
-  ptr = USB_LEN_CFG_DESC;
-  
-  AUDIO_Handle->class_desc.FeatureUnitNum = 0;
-  AUDIO_Handle->class_desc.InputTerminalNum = 0;
-  AUDIO_Handle->class_desc.OutputTerminalNum = 0;  
-  AUDIO_Handle->class_desc.ASNum = 0;
-  
-  while(ptr < phost->device.CfgDesc.wTotalLength)
-  {
-    pdesc = USBH_GetNextDesc((void *)pdesc, &ptr);
-    
-    switch (pdesc->bDescriptorType)
-    {
-      
-    case USB_DESC_TYPE_INTERFACE:
-      itf_number = *((uint8_t *)pdesc + 2);
-      alt_setting = *((uint8_t *)pdesc + 3);
-      itf_index = USBH_FindInterfaceIndex (phost, itf_number, alt_setting);     
-      break;
-      
-    case USB_DESC_TYPE_CS_INTERFACE:
-      if(itf_number <= phost->device.CfgDesc.bNumInterfaces)
-      {
-        
-        ParseCSDescriptors(&AUDIO_Handle->class_desc,
-                           phost->device.CfgDesc.Itf_Desc[itf_index].bInterfaceSubClass, 
-                           (uint8_t *)pdesc);
-      }
-      break;
-      
-    default:
-      break; 
-    }
-  }
-  return USBH_OK;
-}
-
-/**
-  * @brief  Parse AC interfaces
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, 
-                                      uint8_t ac_subclass, 
-                                      uint8_t *pdesc)
-{
-  if(ac_subclass == USB_SUBCLASS_AUDIOCONTROL)
-  {
-    switch(pdesc[2])
-    {
-    case UAC_HEADER: 
-      class_desc->cs_desc.HeaderDesc = (AUDIO_HeaderDescTypeDef *)pdesc;    
-      break;
-      
-    case UAC_INPUT_TERMINAL:
-      class_desc->cs_desc.InputTerminalDesc[class_desc->InputTerminalNum++] = (AUDIO_ITDescTypeDef*) pdesc;    
-      break;
-      
-    case UAC_OUTPUT_TERMINAL:
-      class_desc->cs_desc.OutputTerminalDesc[class_desc->OutputTerminalNum++] = (AUDIO_OTDescTypeDef*) pdesc;   
-      break;
-
-    case UAC_FEATURE_UNIT:
-      class_desc->cs_desc.FeatureUnitDesc[class_desc->FeatureUnitNum++] = (AUDIO_FeatureDescTypeDef*) pdesc; 
-      break;
-      
-    case UAC_SELECTOR_UNIT:
-      class_desc->cs_desc.SelectorUnitDesc[class_desc->SelectorUnitNum++] = (AUDIO_SelectorDescTypeDef*) pdesc; 
-      break;
-
-    case UAC_MIXER_UNIT:
-      class_desc->cs_desc.MixerUnitDesc[class_desc->MixerUnitNum++] = (AUDIO_MixerDescTypeDef*) pdesc; 
-      break;      
-
-    default: 
-      break;
-    }
-  }
-  else if(ac_subclass == USB_SUBCLASS_AUDIOSTREAMING)
-  {
-    switch(pdesc[2])
-    {
-    case UAC_AS_GENERAL:
-      class_desc->as_desc[class_desc->ASNum].GeneralDesc = (AUDIO_ASGeneralDescTypeDef*) pdesc; 
-      break;
-    case UAC_FORMAT_TYPE:      
-      class_desc->as_desc[class_desc->ASNum++].FormatTypeDesc = (AUDIO_ASFormatTypeDescTypeDef*) pdesc; 
-      break;
-    default:
-      break;
-    }
-  }
- 
-  return USBH_OK;
-}
-
-
-/**
-  * @brief  Link a Unit to next associated one
-  * @param  phost: Host handle
-  * @param  UnitID: Unit identifer
-  * @retval UnitID, Index and Type of the assicated Unit 
-  */
-static int32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID)
-{
-  uint8_t Index;  
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  
-  AUDIO_Handle =  phost->pActiveClass->pData;    
-  
-  /* Find Feature Unit */
-  for(Index = 0; Index < AUDIO_Handle->class_desc.FeatureUnitNum; Index ++)
-  {
-    if(AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bSourceID == UnitID)
-    {
-      UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bUnitID;
-      
-      return ((UnitID << 16) | (UAC_FEATURE_UNIT << 8) | Index);
-    }
-  }
-  
-  /* Find Mixer Unit */
-  for(Index = 0; Index < AUDIO_Handle->class_desc.MixerUnitNum; Index ++)
-  {
-    if((AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID0 == UnitID)||
-       (AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID1 == UnitID))
-    {
-      UnitID = AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bUnitID;
-      
-      return ((UnitID << 16) | (UAC_MIXER_UNIT << 8) | Index);
-    }
-  }
-  
-  
-  /* Find Selector Unit */
-  for(Index = 0; Index < AUDIO_Handle->class_desc.SelectorUnitNum; Index ++)
-  {
-    if(AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bSourceID0 == UnitID)
-    {
-      UnitID = AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bUnitID;
-      
-      return ((UnitID << 16) | (UAC_SELECTOR_UNIT << 8) | Index); 
-    }
-  }  
-  
-  
-  /* Find OT Unit */  
-  for(Index = 0; Index < AUDIO_Handle->class_desc.OutputTerminalNum; Index ++)
-  {
-    if(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bSourceID == UnitID)
-    {
-      UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bTerminalID;
-      
-      return ((UnitID << 16) | (UAC_OUTPUT_TERMINAL << 8) | Index);
-    }
-  } 
-  
-  /* No associated Unit found */
-  return -1;
-}
-
-/**
-  * @brief  Build full path for Microphone device
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *phost)
-{
-  uint8_t UnitID = 0, Type, Index;
-  uint32_t value;
-  uint8_t terminalIndex;  
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  
-  AUDIO_Handle =  phost->pActiveClass->pData;    
-  
-  /*Find microphone IT*/
-  for(terminalIndex = 0; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++)
-  {
-    if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x201)
-    {    
-      UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID;
-      AUDIO_Handle->microphone.asociated_channels =  AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels;
-      break;
-    }
-  }
-  
-  do
-  {
-    value =  USBH_AUDIO_FindLinkedUnit(phost, UnitID);
-    Index = value & 0xFF;
-    Type   = (value >> 8) & 0xFF;
-    UnitID   = (value >> 16) & 0xFF;
-    
-    switch (Type)
-    {
-    case UAC_FEATURE_UNIT:
-      AUDIO_Handle->microphone.asociated_feature = Index;
-      break;
-      
-    case UAC_MIXER_UNIT:
-      AUDIO_Handle->microphone.asociated_mixer = Index;
-      break;
-      
-    case UAC_SELECTOR_UNIT:
-      AUDIO_Handle->microphone.asociated_selector = Index;
-      break;
-      
-    case UAC_OUTPUT_TERMINAL:
-      AUDIO_Handle->microphone.asociated_terminal = Index;
-      break;    
-    }
-  }
-  while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0));
-  
-  
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  Build full path for Headphone device
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phost)
-{
-  uint8_t UnitID = 0, Type, Index;
-  uint32_t value;
-  uint8_t terminalIndex;  
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  
-  AUDIO_Handle =  phost->pActiveClass->pData;    
-  
-  /*Find association betwen audio streaming and microphone*/
-  for(terminalIndex = 0; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++)
-  {
-    if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x101)
-    {    
-      UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID;
-      AUDIO_Handle->headphone.asociated_channels =  AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels;
-      break;
-    }
-  }
-  
-  for(Index = 0; Index < AUDIO_Handle->class_desc.ASNum; Index++)
-  {
-    if(AUDIO_Handle->class_desc.as_desc[Index].GeneralDesc->bTerminalLink == UnitID)
-    {    
-      AUDIO_Handle->headphone.asociated_as = Index;
-      break;
-    }
-  } 
-        
-  do
-  {
-    value =  USBH_AUDIO_FindLinkedUnit(phost, UnitID);
-    Index = value & 0xFF;
-    Type   = (value >> 8) & 0xFF;
-    UnitID   = (value >> 16) & 0xFF;
-    
-    switch (Type)
-    {
-    case UAC_FEATURE_UNIT:
-      AUDIO_Handle->headphone.asociated_feature = Index;
-      break;
-      
-    case UAC_MIXER_UNIT:
-      AUDIO_Handle->headphone.asociated_mixer = Index;
-      break;
-      
-    case UAC_SELECTOR_UNIT:
-      AUDIO_Handle->headphone.asociated_selector = Index;
-      break;
-      
-    case UAC_OUTPUT_TERMINAL:
-      AUDIO_Handle->headphone.asociated_terminal = Index;
-      if(LE16(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->wTerminalType) != 0x103)
-      {
-        return  USBH_OK;
-      }
-      break;    
-    }
-  }
-  while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0));
-
-  return USBH_FAIL;
-}
-
-
-/**
-  * @brief  Handle Set Cur request
-  * @param  phost: Host handle
-  * @param  subtype: subtype index
-  * @param  feature: feature index
-  * @param  controlSelector: control code
-  * @param  channel: channel index
-  * @param  length: Command length
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length)
-{
-  uint16_t wValue,wIndex,wLength;
-  uint8_t UnitID,InterfaceNum;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  AUDIO_Handle =  phost->pActiveClass->pData;
-  
-  switch(subtype)
-  {
-  case UAC_INPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
-    AUDIO_Handle->mem[0] = 0x00;
-    
-    wLength = 1;
-    break;
-  case UAC_FEATURE_UNIT:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    /*holds the CS(control selector ) and CN (channel number)*/
-    wValue =  (controlSelector << 8) | channel;
-    wLength = length;
-    break;
-  }
-  
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \
-    USB_REQ_TYPE_CLASS;
-  
-  phost->Control.setup.b.bRequest = UAC_SET_CUR;
-  phost->Control.setup.b.wValue.w = wValue;
-  phost->Control.setup.b.wIndex.w = wIndex;
-  phost->Control.setup.b.wLength.w = wLength; 
-  
-  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
-  
-}
-
-/**
-  * @brief  Handle Get Cur request
-  * @param  phost: Host handle
-  * @param  subtype: subtype index
-  * @param  feature: feature index
-  * @param  controlSelector: control code
-  * @param  channel: channel index
-  * @param  length: Command length
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length)
-{
-  uint16_t wValue = 0, wIndex = 0,wLength = 0;
-  uint8_t UnitID = 0, InterfaceNum = 0;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  AUDIO_Handle =  phost->pActiveClass->pData;
-  
-  switch(subtype)
-  {
-  case UAC_INPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
-    AUDIO_Handle->mem[0] = 0x00;
-    
-    wLength = 1;
-    break;
-  case UAC_FEATURE_UNIT:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    /*holds the CS(control selector ) and CN (channel number)*/
-    wValue =  (controlSelector << 8) | channel;
-    wLength = length;
-    break;
-    
-  case UAC_OUTPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
-    wLength = 1; 
-    break;
-  }
-  
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
-    USB_REQ_TYPE_CLASS;
-  
-  phost->Control.setup.b.bRequest = UAC_GET_CUR;
-  phost->Control.setup.b.wValue.w = wValue;
-  phost->Control.setup.b.wIndex.w = wIndex;
-  phost->Control.setup.b.wLength.w = wLength; 
-  
-  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
-  
-}
-
-
-/**
-  * @brief  Handle Get Max request
-  * @param  phost: Host handle
-  * @param  subtype: subtype index
-  * @param  feature: feature index
-  * @param  controlSelector: control code
-  * @param  channel: channel index
-  * @param  length: Command length
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length)
-{
-  uint16_t wValue = 0, wIndex = 0, wLength = 0;
-  uint8_t UnitID = 0, InterfaceNum = 0;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  AUDIO_Handle =  phost->pActiveClass->pData;
-  
-  switch(subtype)
-  {
-  case UAC_INPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
-    AUDIO_Handle->mem[0] = 0x00;
-    
-    wLength = 1;
-    break;
-  case UAC_FEATURE_UNIT:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    /*holds the CS(control selector ) and CN (channel number)*/
-    wValue =  (controlSelector << 8) | channel;
-    wLength = length;
-    break;
-    
-  case UAC_OUTPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
-    wLength = 1; 
-    break;
-  }
-  
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
-    USB_REQ_TYPE_CLASS;
-  
-  phost->Control.setup.b.bRequest = UAC_GET_MAX;
-  phost->Control.setup.b.wValue.w = wValue;
-  phost->Control.setup.b.wIndex.w = wIndex;
-  phost->Control.setup.b.wLength.w = wLength; 
-  
-  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
-  
-}
-
-
-
-/**
-  * @brief  Handle Get Res request
-  * @param  phost: Host handle
-  * @param  subtype: subtype index
-  * @param  feature: feature index
-  * @param  controlSelector: control code
-  * @param  channel: channel index
-  * @param  length: Command length
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length)
-{
-  uint16_t wValue = 0, wIndex = 0, wLength = 0;
-  uint8_t UnitID = 0, InterfaceNum = 0;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  AUDIO_Handle =  phost->pActiveClass->pData;
-  
-  switch(subtype)
-  {
-  case UAC_INPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
-    AUDIO_Handle->mem[0] = 0x00;
-    
-    wLength = 1;
-    break;
-  case UAC_FEATURE_UNIT:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    /*holds the CS(control selector ) and CN (channel number)*/
-    wValue =  (controlSelector << 8) | channel;
-    wLength = length;
-    break;
-    
-  case UAC_OUTPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
-    wLength = 1; 
-    break;
-  }
-  
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
-    USB_REQ_TYPE_CLASS;
-  
-  phost->Control.setup.b.bRequest = UAC_GET_RES;
-  phost->Control.setup.b.wValue.w = wValue;
-  phost->Control.setup.b.wIndex.w = wIndex;
-  phost->Control.setup.b.wLength.w = wLength; 
-  
-  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
-  
-}
-
-/**
-  * @brief  Handle Get Min request
-  * @param  phost: Host handle
-  * @param  subtype: subtype index
-  * @param  feature: feature index
-  * @param  controlSelector: control code
-  * @param  channel: channel index
-  * @param  length: Command length
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, 
-                                         uint8_t subtype, 
-                                         uint8_t feature,
-                                         uint8_t controlSelector,
-                                         uint8_t channel,
-                                         uint16_t length)
-{
-  uint16_t wValue = 0, wIndex = 0, wLength = 0;
-  uint8_t UnitID = 0, InterfaceNum = 0;
-  AUDIO_HandleTypeDef *AUDIO_Handle;
-  AUDIO_Handle =  phost->pActiveClass->pData;
-  
-  switch(subtype)
-  {
-  case UAC_INPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
-    AUDIO_Handle->mem[0] = 0x00;
-    
-    wLength = 1;
-    break;
-  case UAC_FEATURE_UNIT:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    /*holds the CS(control selector ) and CN (channel number)*/
-    wValue =  (controlSelector << 8) | channel;
-    wLength = length;
-    break;
-    
-  case UAC_OUTPUT_TERMINAL:
-    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
-    InterfaceNum = 0; /*Always zero Control Interface */
-    wIndex = ( UnitID << 8 ) | InterfaceNum ;
-    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
-    wLength = 1; 
-    break;
-  }
-  
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
-    USB_REQ_TYPE_CLASS;
-  
-  phost->Control.setup.b.bRequest = UAC_GET_MIN;
-  phost->Control.setup.b.wValue.w = wValue;
-  phost->Control.setup.b.wIndex.w = wIndex;
-  phost->Control.setup.b.wLength.w = wLength; 
-  
-  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
-  
-}
-
-/**
-  * @brief  Handle Set Endpoint Controls Request
-  * @param  phost: Host handle
-  * @param  Ep: Endpoint address
-  * @param  buf: pointer to data
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost,
-                                               uint8_t  Ep,
-                                               uint8_t *buff) 
-{
-  uint16_t wValue, wIndex, wLength;
-  
-
-  wValue = SAMPLING_FREQ_CONTROL << 8;
-  wIndex = Ep; 
-  wLength = 3; /*length of the frequency parameter*/   
-  
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_ENDPOINT | \
-    USB_REQ_TYPE_CLASS;
-  
-  phost->Control.setup.b.bRequest = UAC_SET_CUR;
-  phost->Control.setup.b.wValue.w = wValue;
-  phost->Control.setup.b.wIndex.w = wIndex;
-  phost->Control.setup.b.wLength.w = wLength; 
-  
-  return(USBH_CtlReq(phost, (uint8_t *)buff, wLength ));
-    
-}
-
-/**
-  * @brief  Handle Input stream process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ; 
-  
-  return status;  
-}
-
-/**
-  * @brief  Handle HID Control process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ;
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData; 
-  uint16_t attribute  = 0; 
- 
-  
-  switch(AUDIO_Handle->control_state)
-  {
-  case AUDIO_CONTROL_INIT:
-    if((phost->Timer & 1) == 0)
-    {
-      AUDIO_Handle->control.timer = phost->Timer;
-      USBH_InterruptReceiveData(phost, 
-                                (uint8_t *)(AUDIO_Handle->mem),
-                                AUDIO_Handle->control.EpSize,
-                                AUDIO_Handle->control.Pipe);
-      
-      AUDIO_Handle->temp_feature  = AUDIO_Handle->headphone.asociated_feature;
-      AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels;
-      
-      AUDIO_Handle->control_state = AUDIO_CONTROL_CHANGE ;
-    }
-    break;
-  case AUDIO_CONTROL_CHANGE:
-    if(USBH_LL_GetURBState(phost , AUDIO_Handle->control.Pipe) == USBH_URB_DONE)
-    {
-      attribute = LE16(&AUDIO_Handle->mem[0]); 
-      if(USBH_AUDIO_SetControlAttribute (phost, attribute) == USBH_BUSY)
-      {
-        break;
-      }
-    }
-    
-    if(( phost->Timer - AUDIO_Handle->control.timer) >= AUDIO_Handle->control.Poll)
-    {
-      AUDIO_Handle->control.timer = phost->Timer;
-      
-      USBH_InterruptReceiveData(phost, 
-                                (uint8_t *)(AUDIO_Handle->mem),
-                                AUDIO_Handle->control.EpSize,
-                                AUDIO_Handle->control.Pipe);      
-      
-    }
-    break;
-    
-  case AUDIO_CONTROL_VOLUME_UP:
-       if( USBH_AUDIO_SetControlAttribute (phost, 1) == USBH_OK)
-       {
-         AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
-        status = USBH_OK; 
-       }
-       break;
-       
-  case AUDIO_CONTROL_VOLUME_DOWN:
-       if( USBH_AUDIO_SetControlAttribute (phost, 2) == USBH_OK)
-       {
-         AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;         
-         status = USBH_OK; 
-       }     
-       break;
-       
-  case AUDIO_CONTROL_IDLE:
-  default:  
-    break; 
-  }
-    
-  return status;  
-}
-
-/**
-  * @brief  Handle Output stream process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ;
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;   
-  uint8_t *buff;
-  
-  
-  switch(AUDIO_Handle->play_state)
-  {
-  case AUDIO_PLAYBACK_INIT:
-    
-    if( AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0)
-    {
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP_FREQ;        
-    }
-    else
-    {
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP;
-    }
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif  
-    break;
-    
-  case AUDIO_PLAYBACK_SET_EP_FREQ:
-
-    buff = (uint8_t*)AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0];    
-
-    status = USBH_AUDIO_SetEndpointControls(phost, AUDIO_Handle->headphone.Ep, buff);
-    if(status == USBH_OK) 
-    {
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;    
-    }
-    break;
-    
-  case AUDIO_PLAYBACK_SET_EP:
-    buff = (uint8_t *)&AUDIO_Handle->headphone.frequency;    
-    status = USBH_AUDIO_SetEndpointControls(phost,AUDIO_Handle->headphone.Ep, buff);
-    if(status == USBH_OK)
-    {
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;
-      USBH_AUDIO_FrequencySet(phost);
-    }
-    break;
-  case AUDIO_PLAYBACK_IDLE:
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif      
-    status = USBH_OK;
-    break;
-    
-  case AUDIO_PLAYBACK_PLAY:
-    USBH_AUDIO_Transmit(phost);
-    status = USBH_OK;
-    break;
-    
-  default:
-    break;
-  }  
-  
-  return status;
-}
-
-/**
-  * @brief  Handle Transmission process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ;
-  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;   
-  
-  switch(AUDIO_Handle->processing_state)
-  {
-  case AUDIO_DATA_START_OUT:
-    /* Sync with start of Even Frame */
-    if((phost->Timer & 1) == 0)
-    {
-      AUDIO_Handle->headphone.timer = phost->Timer;
-      AUDIO_Handle->processing_state = AUDIO_DATA_OUT;
-      USBH_IsocSendData(phost, 
-                       AUDIO_Handle->headphone.buf,
-                       AUDIO_Handle->headphone.frame_length,
-                       AUDIO_Handle->headphone.Pipe);
-      
-      AUDIO_Handle->headphone.partial_ptr = AUDIO_Handle->headphone.frame_length; 
-      AUDIO_Handle->headphone.global_ptr = AUDIO_Handle->headphone.frame_length; 
-      AUDIO_Handle->headphone.cbuf = AUDIO_Handle->headphone.buf;
-
-    }
-    break;
-    
-  case AUDIO_DATA_OUT:
-    if((USBH_LL_GetURBState(phost , AUDIO_Handle->headphone.Pipe) == USBH_URB_DONE)&&
-       (( phost->Timer - AUDIO_Handle->headphone.timer) >= AUDIO_Handle->headphone.Poll))
-    {
-      AUDIO_Handle->headphone.timer = phost->Timer;
-      
-      if(AUDIO_Handle->control.supported == 1)
-      {
-        USBH_AUDIO_Control (phost);
-      }
-      
-      if(AUDIO_Handle->headphone.global_ptr <= AUDIO_Handle->headphone.total_length)
-      {
-        USBH_IsocSendData(phost, 
-                          AUDIO_Handle->headphone.cbuf,
-                          AUDIO_Handle->headphone.frame_length,
-                          AUDIO_Handle->headphone.Pipe);
-        
-        AUDIO_Handle->headphone.cbuf += AUDIO_Handle->headphone.frame_length;
-        AUDIO_Handle->headphone.partial_ptr += AUDIO_Handle->headphone.frame_length;
-        AUDIO_Handle->headphone.global_ptr += AUDIO_Handle->headphone.frame_length;
-      }
-      else
-      {
-       AUDIO_Handle->headphone.partial_ptr = 0xFFFFFFFF;
-       AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;
-      }
-    }
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_AUDIO_SetFrequency 
-  *         Set Audio sampling parameters
-  * @param  phost: Host handle
-  * @param  SampleRate: Sample Rate
-  * @param  NbrChannels: Number of Channels
-  * @param  BitPerSample: Bit Per Sample
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, 
-                                            uint16_t SampleRate,
-                                            uint8_t  NbrChannels,
-                                            uint8_t  BitPerSample)
-{
-  USBH_StatusTypeDef Status = USBH_BUSY;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-  uint8_t              index; 
-  uint8_t              change_freq = FALSE;
-  uint32_t             freq_min, freq_max;
-  uint8_t              num_supported_freq;
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    AUDIO_Handle =  phost->pActiveClass->pData;
-    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE)
-    {
-      
-      if(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0)
-      { 
-        freq_min = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]); 
-        freq_max = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[1]);         
-        
-        if(( SampleRate >= freq_min)&& (SampleRate <= freq_max))
-        {
-          change_freq = TRUE;
-        }
-      }
-      else
-      {    
-        
-        num_supported_freq = (AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bLength - 8)/3;
-        
-        
-        for(index = 0; index < num_supported_freq; index++)
-        {
-          if(SampleRate == LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[index]))
-          {
-            change_freq = TRUE;            
-            break;
-          }
-        }  
-      }      
-      
-      if(change_freq == TRUE)
-      {
-        AUDIO_Handle->headphone.frequency = SampleRate;
-        AUDIO_Handle->headphone.frame_length    = (SampleRate * BitPerSample * NbrChannels) / 8000;
-        AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP;
-        Status = USBH_OK;  
-        
-      }
-    }
-  }
-   return Status;  
-}
-
-/**
-  * @brief  USBH_AUDIO_Play 
-  *         Start playback process
-  * @param  phost: Host handle
-  * @param  buf: pointer to raw audio data
-  * @param  length: total length of the audio data
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length)
-{
-  USBH_StatusTypeDef Status = USBH_FAIL;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    AUDIO_Handle =  phost->pActiveClass->pData;
-    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE)
-    {
-      AUDIO_Handle->headphone.buf = buf;
-      AUDIO_Handle->headphone.total_length = length;
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY;
-      AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
-      AUDIO_Handle->processing_state = AUDIO_DATA_START_OUT;
-      Status = USBH_OK;
-    }
-  }
-  return Status;  
-}
-
-/**
-  * @brief  USBH_AUDIO_Pause 
-  *         Stop the playback process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef Status = USBH_FAIL;
-  Status = USBH_AUDIO_Suspend(phost);
-  return Status;  
-}
-
-/**
-  * @brief  USBH_AUDIO_Suspend 
-  *         Suspend the playback process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef Status = USBH_FAIL;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    AUDIO_Handle =  phost->pActiveClass->pData;
-    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
-    {
-      AUDIO_Handle->control_state = AUDIO_CONTROL_IDLE;
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;
-      Status = USBH_OK;      
-    }
-  }
-  return Status;  
-}
-/**
-  * @brief  USBH_AUDIO_Resume 
-  *         Resume the playback process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef Status = USBH_FAIL;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    AUDIO_Handle =  phost->pActiveClass->pData;
-    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE)
-    {
-      AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
-      AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY;
-    }
-  }
-  return Status;  
-}
-/**
-  * @brief  USBH_AUDIO_GetOutOffset 
-  *         return the current buffer pointer for OUT proces
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-int32_t USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost)
-{
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    AUDIO_Handle =  phost->pActiveClass->pData;
-    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
-    {
-      return AUDIO_Handle->headphone.partial_ptr;
-    }
-  }
-  return -1;  
-}
-
-/**
-  * @brief  USBH_AUDIO_ChangeOutBuffer 
-  *         Change audio data buffer address
-  * @param  phost: Host handle
-  * @param  buf: buffer address
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf)
-{
-  USBH_StatusTypeDef Status = USBH_FAIL;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    AUDIO_Handle =  phost->pActiveClass->pData;
-    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
-    {
-      if(AUDIO_Handle->headphone.buf <= buf)
-      {
-        AUDIO_Handle->headphone.cbuf = buf;
-        if ( AUDIO_Handle->headphone.buf == buf)
-        {
-          AUDIO_Handle->headphone.partial_ptr = 0;
-        }
-        Status = USBH_OK;  
-      }    
-    }
-  }
-  return Status;  
-}
-
-/**
-  * @brief  USBH_AUDIO_SetControlAttribute 
-  *         Set Control Attribute
-  * @param  phost: Host handle
-  * @param  attrib: control attribute
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-
-  
-  AUDIO_Handle = phost->pActiveClass->pData;
-  
-  switch (attrib)
-  {
-  case 0x01:
-    AUDIO_Handle->headphone.attribute.volume += AUDIO_Handle->headphone.attribute.resolution;
-    break;
-    
-  case 0x02:
-    AUDIO_Handle->headphone.attribute.volume -= AUDIO_Handle->headphone.attribute.resolution; 
-    break;
-    
-  }
-  
-  if(AUDIO_Handle->headphone.attribute.volume > AUDIO_Handle->headphone.attribute.volumeMax)
-  {
-    AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMax;
-  }
-  
-  if(AUDIO_Handle->headphone.attribute.volume < AUDIO_Handle->headphone.attribute.volumeMin)
-  {
-    AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMin;
-  }
-  
-  if(AUDIO_SetVolume (phost, 
-                                 AUDIO_Handle->temp_feature, 
-                                 AUDIO_Handle->temp_channels, 
-                                 AUDIO_Handle->headphone.attribute.volume) != USBH_BUSY)
-  {
-    
-    if(AUDIO_Handle->temp_channels ==  1)
-    {
-      AUDIO_Handle->temp_feature  = AUDIO_Handle->headphone.asociated_feature;
-      AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels;
-      status = USBH_OK;
-    }
-    else
-    {
-      AUDIO_Handle->temp_channels--;
-    }
-    AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
-  }
-  
- 
-  return status;
-}
-
-
-/**
-  * @brief  USBH_AUDIO_SetVolume 
-  *         Set Volume
-  * @param  phost: Host handle
-  * @param  volume: VOLUME_UP/ VOLUME_DOWN
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl)
-{
-  AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData;
-  
-  if((volume_ctl == VOLUME_UP) || (volume_ctl == VOLUME_DOWN))
-  {
-    if(phost->gState == HOST_CLASS)
-    {
-      AUDIO_Handle =  phost->pActiveClass->pData;
-      if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
-      {
-        AUDIO_Handle->control_state = (volume_ctl == VOLUME_UP)? AUDIO_CONTROL_VOLUME_UP : AUDIO_CONTROL_VOLUME_DOWN;
-        return USBH_OK;  
-      }
-    }
-  }
-  return USBH_FAIL;
-}
-/**
-  * @brief  AUDIO_SetVolume 
-  *         Set Volume
-  * @param  phost: Host handle
-  * @param  feature: feature Unit index
-  * @param  channel: channel index
-  * @param  volume: new volume
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ;
-  AUDIO_HandleTypeDef *AUDIO_Handle; 
-
-  
-  AUDIO_Handle = phost->pActiveClass->pData;
-
-  AUDIO_Handle->mem[0] = volume;
-  
-  status = USBH_AC_SetCur(phost, 
-                          UAC_FEATURE_UNIT, 
-                          feature,
-                          VOLUME_CONTROL,
-                          channel,
-                          2);
-    
-  return status; 
-}
-
-/**
-  * @brief  The function informs user that Settings have been changed
-  *  @param  pdev: Selected device
-  * @retval None
-  */
-__weak void USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost)
-{
-  
-}
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_audio.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the AC Layer Handlers for USB Host AC class. 
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_audio.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_AUDIO_CLASS
+  * @{
+  */
+
+/** @defgroup USBH_AUDIO_CORE 
+  * @brief    This file includes HID Layer Handlers for USB Host HID class.
+  * @{
+  */ 
+
+/** @defgroup USBH_AUDIO_CORE_Private_TypesDefinitions
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_AUDIO_CORE_Private_Defines
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_AUDIO_CORE_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_AUDIO_CORE_Private_Variables
+  * @{
+  */
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_AUDIO_CORE_Private_FunctionPrototypes
+  * @{
+  */ 
+
+static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit  (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit  (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_Process(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_SOFProcess(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, 
+                                               uint8_t feature, 
+                                               uint8_t channel);
+
+static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *phost);
+int32_t USBH_AUDIO_FindLinkedUnitIN(USBH_HandleTypeDef *phost, uint8_t UnitID);
+int32_t USBH_AUDIO_FindLinkedUnitOUT(USBH_HandleTypeDef *phost, uint8_t UnitID);
+
+
+
+static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, 
+                                      uint8_t ac_subclass, 
+                                      uint8_t *pdesc);
+
+
+static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost);
+
+
+static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length);
+
+static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length);
+
+static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length);
+
+static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length);
+
+static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length);
+
+static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost,
+                                               uint8_t  Ep,
+                                               uint8_t *buff);
+
+static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume);
+
+static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib);
+static int32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID);
+
+USBH_ClassTypeDef  AUDIO_Class = 
+{
+  "AUDIO",
+  AC_CLASS,  
+  USBH_AUDIO_InterfaceInit,
+  USBH_AUDIO_InterfaceDeInit,
+  USBH_AUDIO_ClassRequest,
+  USBH_AUDIO_Process,
+  USBH_AUDIO_SOFProcess,
+  NULL,
+};
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_AUDIO_CORE_Private_Functions
+  * @{
+  */ 
+
+/**
+  * @brief  USBH_AUDIO_InterfaceInit 
+  *         The function init the Audio class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  USBH_StatusTypeDef out_status, in_status ;    
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  uint8_t  interface, index;
+  uint16_t ep_size_out = 0;
+  uint16_t ep_size_in = 0;  
+  
+  interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0x00);
+  
+  if(interface == 0xFF) /* Not Valid Interface */
+  {
+    USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
+    status = USBH_FAIL;      
+  }
+  else
+  {
+    
+    
+    phost->pActiveClass->pData = (AUDIO_HandleTypeDef *)USBH_malloc (sizeof(AUDIO_HandleTypeDef));
+    AUDIO_Handle =  phost->pActiveClass->pData; 
+    USBH_memset(AUDIO_Handle, 0, sizeof(AUDIO_HandleTypeDef));
+    
+    
+    /* 1st Step:  Find Audio Interfaces */
+    out_status = USBH_AUDIO_FindAudioStreamingIN (phost);
+    
+    in_status = USBH_AUDIO_FindAudioStreamingOUT(phost);
+    
+    if((out_status == USBH_FAIL) && (in_status == USBH_FAIL))
+    {
+      USBH_DbgLog ("%s class configuration not supported.", phost->pActiveClass->Name);
+    }
+    else
+    {
+      /* 2nd Step:  Select Audio Streaming Interfaces with largest endpoint size : default behavior*/ 
+      for (index = 0; index < AUDIO_MAX_AUDIO_STD_INTERFACE; index ++)
+      {
+        if( AUDIO_Handle->stream_out[index].valid == 1)
+        {
+          if(ep_size_out < AUDIO_Handle->stream_out[index].EpSize)
+          {
+            ep_size_out = AUDIO_Handle->stream_out[index].EpSize;
+            AUDIO_Handle->headphone.interface = AUDIO_Handle->stream_out[index].interface;
+            AUDIO_Handle->headphone.AltSettings = AUDIO_Handle->stream_out[index].AltSettings;           
+            AUDIO_Handle->headphone.Ep = AUDIO_Handle->stream_out[index].Ep;
+            AUDIO_Handle->headphone.EpSize = AUDIO_Handle->stream_out[index].EpSize; 
+            AUDIO_Handle->headphone.Poll = AUDIO_Handle->stream_out[index].Poll;
+            AUDIO_Handle->headphone.supported = 1;  
+          }
+        }
+        
+        if( AUDIO_Handle->stream_in[index].valid == 1)
+        {
+          if(ep_size_in < AUDIO_Handle->stream_in[index].EpSize)
+          {
+            ep_size_in = AUDIO_Handle->stream_in[index].EpSize;
+            AUDIO_Handle->microphone.interface = AUDIO_Handle->stream_in[index].interface;
+            AUDIO_Handle->microphone.AltSettings = AUDIO_Handle->stream_in[index].AltSettings;                
+            AUDIO_Handle->microphone.Ep = AUDIO_Handle->stream_in[index].Ep;
+            AUDIO_Handle->microphone.EpSize = AUDIO_Handle->stream_in[index].EpSize;
+            AUDIO_Handle->microphone.Poll = AUDIO_Handle->stream_out[index].Poll;         
+            AUDIO_Handle->microphone.supported = 1;       
+          }
+        }
+      }
+      
+      if(USBH_AUDIO_FindHIDControl(phost) == USBH_OK)
+      {
+        AUDIO_Handle->control.supported = 1;
+      }
+      
+      /* 3rd Step:  Find and Parse Audio interfaces */ 
+      USBH_AUDIO_ParseCSDescriptors (phost);
+     
+      
+      /* 4th Step:  Open the Audio streaming pipes*/ 
+      if(AUDIO_Handle->headphone.supported == 1)
+      {
+        USBH_AUDIO_BuildHeadphonePath (phost);
+         
+        AUDIO_Handle->headphone.Pipe  = USBH_AllocPipe(phost, AUDIO_Handle->headphone.Ep);
+        
+        /* Open pipe for IN endpoint */
+        USBH_OpenPipe  (phost,
+                        AUDIO_Handle->headphone.Pipe,
+                        AUDIO_Handle->headphone.Ep,
+                        phost->device.address,
+                        phost->device.speed,
+                        USB_EP_TYPE_ISOC,
+                        AUDIO_Handle->headphone.EpSize); 
+        
+        USBH_LL_SetToggle (phost,  AUDIO_Handle->headphone.Pipe, 0);          
+        
+      }
+      
+      if(AUDIO_Handle->microphone.supported == 1)
+      {
+        USBH_AUDIO_BuildMicrophonePath (phost);        
+        AUDIO_Handle->microphone.Pipe  = USBH_AllocPipe(phost, AUDIO_Handle->microphone.Ep);
+        
+        /* Open pipe for IN endpoint */
+        USBH_OpenPipe  (phost,
+                        AUDIO_Handle->microphone.Pipe,
+                        AUDIO_Handle->microphone.Ep,
+                        phost->device.address,
+                        phost->device.speed,
+                        USB_EP_TYPE_ISOC,
+                        AUDIO_Handle->microphone.EpSize); 
+        
+        USBH_LL_SetToggle (phost,  AUDIO_Handle->microphone.Pipe, 0);  
+      }
+      
+      if(AUDIO_Handle->control.supported == 1)
+      {     
+        AUDIO_Handle->control.Pipe  = USBH_AllocPipe(phost, AUDIO_Handle->control.Ep);
+        
+        /* Open pipe for IN endpoint */
+        USBH_OpenPipe  (phost,
+                        AUDIO_Handle->control.Pipe,
+                        AUDIO_Handle->control.Ep,
+                        phost->device.address,
+                        phost->device.speed,
+                        USB_EP_TYPE_INTR,
+                        AUDIO_Handle->control.EpSize); 
+        
+        USBH_LL_SetToggle (phost,  AUDIO_Handle->control.Pipe, 0);          
+   
+      }
+      
+      AUDIO_Handle->req_state     = AUDIO_REQ_INIT;
+      AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
+      
+      status = USBH_OK;
+    }
+  }
+  return status;
+}
+
+
+
+/**
+  * @brief  USBH_AUDIO_InterfaceDeInit 
+  *         The function DeInit the Pipes used for the Audio class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost)
+{
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData; 
+  
+  if(AUDIO_Handle->microphone.Pipe != 0x00)
+  {   
+    USBH_ClosePipe  (phost, AUDIO_Handle->microphone.Pipe);
+    USBH_FreePipe  (phost, AUDIO_Handle->microphone.Pipe);
+    AUDIO_Handle->microphone.Pipe = 0;     /* Reset the pipe as Free */  
+  }
+  
+  if( AUDIO_Handle->headphone.Pipe != 0x00)
+  {   
+    USBH_ClosePipe(phost,  AUDIO_Handle->headphone.Pipe);
+    USBH_FreePipe  (phost,  AUDIO_Handle->headphone.Pipe);
+    AUDIO_Handle->headphone.Pipe = 0;     /* Reset the pipe as Free */  
+  }
+  
+  if( AUDIO_Handle->control.Pipe != 0x00)
+  {   
+    USBH_ClosePipe(phost,  AUDIO_Handle->control.Pipe);
+    USBH_FreePipe  (phost,  AUDIO_Handle->control.Pipe);
+    AUDIO_Handle->control.Pipe = 0;     /* Reset the pipe as Free */  
+  }
+  
+  if(phost->pActiveClass->pData)
+  {
+    USBH_free (phost->pActiveClass->pData);
+    phost->pActiveClass->pData = 0;
+  }  
+  return USBH_OK ;
+}
+
+/**
+  * @brief  USBH_AUDIO_ClassRequest 
+  *         The function is responsible for handling Standard requests
+  *         for Audio class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost)
+{   
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
+  USBH_StatusTypeDef status = USBH_BUSY;
+  USBH_StatusTypeDef req_status = USBH_BUSY;
+  
+  /* Switch AUDIO REQ state machine */
+  switch (AUDIO_Handle->req_state)
+  {
+  case AUDIO_REQ_INIT:
+  case AUDIO_REQ_SET_DEFAULT_IN_INTERFACE:
+    if(AUDIO_Handle->microphone.supported == 1)
+    {
+      req_status = USBH_SetInterface(phost, 
+                                     AUDIO_Handle->microphone.interface, 
+                                     0);
+      
+      if(req_status == USBH_OK)
+      {
+        AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE;
+      }
+      
+    }
+    else
+    {
+      AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE:
+    if(AUDIO_Handle->headphone.supported == 1)
+    {
+      req_status = USBH_SetInterface(phost, 
+                                     AUDIO_Handle->headphone.interface, 
+                                     0);
+      
+      if(req_status == USBH_OK)
+      {
+        AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS;
+        AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
+        
+        AUDIO_Handle->temp_feature  = AUDIO_Handle->headphone.asociated_feature;
+        AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels;
+      }
+    }
+    else
+    {
+        AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS;
+        AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif         
+    }
+    break;
+    
+  case AUDIO_REQ_CS_REQUESTS:
+    if(USBH_AUDIO_HandleCSRequest (phost) == USBH_OK)
+    {
+      AUDIO_Handle->req_state = AUDIO_REQ_SET_IN_INTERFACE;
+    }
+    break;
+   
+  case AUDIO_REQ_SET_IN_INTERFACE:
+    if(AUDIO_Handle->microphone.supported == 1)
+    {
+      req_status = USBH_SetInterface(phost, 
+                                     AUDIO_Handle->microphone.interface, 
+                                     AUDIO_Handle->microphone.AltSettings);
+      
+      if(req_status == USBH_OK)
+      {
+        AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE;
+      }
+    }
+    else
+    {
+      AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+  case AUDIO_REQ_SET_OUT_INTERFACE:
+   if(AUDIO_Handle->headphone.supported == 1)
+    {
+      req_status = USBH_SetInterface(phost, 
+                                     AUDIO_Handle->headphone.interface, 
+                                     AUDIO_Handle->headphone.AltSettings);
+      
+      if(req_status == USBH_OK)
+      {
+        AUDIO_Handle->req_state = AUDIO_REQ_IDLE;
+      }
+      
+    }
+   else
+   {
+     AUDIO_Handle->req_state = AUDIO_REQ_IDLE;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif      
+   }
+   break;
+  case AUDIO_REQ_IDLE:
+    AUDIO_Handle->play_state = AUDIO_PLAYBACK_INIT;
+    phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
+    status  = USBH_OK;    
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif
+  default:
+    break;
+  }
+  return status; 
+}
+
+/**
+  * @brief  USBH_AUDIO_CSRequest 
+  *         The function is responsible for handling AC Specific requests for a specific feature and channel
+  *         for Audio class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel)
+{   
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
+  USBH_StatusTypeDef status = USBH_BUSY;
+  USBH_StatusTypeDef req_status = USBH_BUSY;
+  
+  /* Switch AUDIO REQ state machine */
+  switch (AUDIO_Handle->cs_req_state)
+  {
+  case AUDIO_REQ_GET_VOLUME:
+    req_status = USBH_AC_GetCur(phost,                 
+                                UAC_FEATURE_UNIT,     /* subtype  */
+                                feature,              /* feature  */
+                                VOLUME_CONTROL,       /* Selector */
+                                channel,              /* channel  */
+                                0x02);                /* length   */
+    if(req_status != USBH_BUSY)
+    {
+      AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MIN_VOLUME;
+      AUDIO_Handle->headphone.attribute.volume = LE16(&(AUDIO_Handle->mem[0]));
+    }
+    break;
+    
+  case AUDIO_REQ_GET_MIN_VOLUME:
+    req_status = USBH_AC_GetMin(phost,                 
+                                UAC_FEATURE_UNIT,     /* subtype  */
+                                feature,              /* feature  */
+                                VOLUME_CONTROL,       /* Selector */
+                                channel,              /* channel  */
+                                0x02);                /* length   */
+    if(req_status != USBH_BUSY)
+    {
+      AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MAX_VOLUME;
+      AUDIO_Handle->headphone.attribute.volumeMin = LE16(&AUDIO_Handle->mem[0]);
+    }
+    break;
+
+  case AUDIO_REQ_GET_MAX_VOLUME:
+    req_status = USBH_AC_GetMax(phost,                 
+                                UAC_FEATURE_UNIT,     /* subtype  */
+                                feature,              /* feature  */
+                                VOLUME_CONTROL,       /* Selector */
+                                channel,              /* channel  */
+                                0x02);                /* length   */
+    if(req_status != USBH_BUSY)
+    {
+      AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_RESOLUTION;
+      AUDIO_Handle->headphone.attribute.volumeMax = LE16(&AUDIO_Handle->mem[0]);   
+      
+      if (AUDIO_Handle->headphone.attribute.volumeMax < AUDIO_Handle->headphone.attribute.volumeMin)
+      {
+        AUDIO_Handle->headphone.attribute.volumeMax = 0xFF00; 
+      }
+    }
+    break;
+    
+  case AUDIO_REQ_GET_RESOLUTION:
+    req_status = USBH_AC_GetRes(phost,                 
+                                UAC_FEATURE_UNIT,     /* subtype  */
+                                feature,              /* feature  */
+                                VOLUME_CONTROL,       /* Selector */
+                                channel,              /* channel  */
+                                0x02);                /* length   */
+    if(req_status != USBH_BUSY)
+    {
+      AUDIO_Handle->cs_req_state = AUDIO_REQ_CS_IDLE;
+      AUDIO_Handle->headphone.attribute.resolution = LE16(&AUDIO_Handle->mem[0]);    
+    }
+    break;
+    
+ 
+  case AUDIO_REQ_CS_IDLE:
+    status = USBH_OK;
+  default:
+    break;
+  }
+  return status; 
+}
+
+/**
+  * @brief  USBH_AUDIO_HandleCSRequest 
+  *         The function is responsible for handling AC Specific requests for a all features 
+  *         and associated channels for Audio class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost)
+{ 
+
+  USBH_StatusTypeDef status = USBH_BUSY;
+  USBH_StatusTypeDef cs_status = USBH_BUSY;
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
+        
+  cs_status = USBH_AUDIO_CSRequest(phost, 
+                                   AUDIO_Handle->temp_feature, 
+                                   AUDIO_Handle->temp_channels);
+  
+  if(cs_status != USBH_BUSY)
+  {
+    
+    if(AUDIO_Handle->temp_channels ==  1)
+    {
+        AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature;
+        AUDIO_Handle->temp_channels = 0;
+        status = USBH_OK; 
+    }
+    else
+    {
+      AUDIO_Handle->temp_channels--;
+    }
+    AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif     
+  }
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_AUDIO_Process 
+  *         The function is for managing state machine for Audio data transfers 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_Process (USBH_HandleTypeDef *phost)
+{   
+  USBH_StatusTypeDef status = USBH_BUSY;
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;  
+  
+  if(AUDIO_Handle->headphone.supported == 1)
+  {
+    USBH_AUDIO_OutputStream (phost);
+  }
+  
+  if(AUDIO_Handle->microphone.supported == 1)
+  {
+    USBH_AUDIO_InputStream (phost);
+  }
+ 
+  return status;
+}
+
+/**
+  * @brief  USBH_AUDIO_SOFProcess 
+  *         The function is for managing the SOF callback
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_SOFProcess (USBH_HandleTypeDef *phost)
+{  
+  return USBH_OK;
+}
+/**
+  * @brief  Find IN Audio Streaming interfaces
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *phost)
+{
+  uint8_t interface, alt_settings;
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+
+  AUDIO_Handle =  phost->pActiveClass->pData; 
+
+  /* Look For AUDIOSTREAMING IN interface */
+  alt_settings = 0;
+  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
+  {
+    if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&&
+       (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING))
+    {
+      if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)&&
+         (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0))
+      {
+        AUDIO_Handle->stream_in[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
+        AUDIO_Handle->stream_in[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
+        AUDIO_Handle->stream_in[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber;        
+        AUDIO_Handle->stream_in[alt_settings].AltSettings = phost->device.CfgDesc.Itf_Desc[interface].bAlternateSetting;
+        AUDIO_Handle->stream_in[alt_settings].Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval;   
+        AUDIO_Handle->stream_in[alt_settings].valid = 1; 
+        alt_settings++;
+      }
+    }
+  } 
+  
+  if(alt_settings > 0)
+  {  
+     status = USBH_OK;
+  }
+  
+  return status;
+}
+
+/**
+  * @brief  Find OUT Audio Streaming interfaces
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *phost)
+{
+  uint8_t interface, alt_settings;
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+
+  AUDIO_Handle =  phost->pActiveClass->pData; 
+
+  /* Look For AUDIOSTREAMING IN interface */
+  alt_settings = 0;
+  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
+  {
+    if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&&
+       (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING))
+    {
+      if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) == 0x00)&&
+         (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0))        
+      {
+        AUDIO_Handle->stream_out[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
+        AUDIO_Handle->stream_out[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
+        AUDIO_Handle->stream_out[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber;
+        AUDIO_Handle->stream_out[alt_settings].AltSettings = phost->device.CfgDesc.Itf_Desc[interface].bAlternateSetting;
+        AUDIO_Handle->stream_out[alt_settings].Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval;           
+        AUDIO_Handle->stream_out[alt_settings].valid = 1; 
+        alt_settings++;
+      }
+    }
+  }
+  
+  if(alt_settings > 0)
+  {
+     status = USBH_OK;
+  }
+  
+  return status;  
+}
+
+/**
+  * @brief  Find HID Control interfaces
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost)
+{
+  uint8_t interface;
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+
+  AUDIO_Handle =  phost->pActiveClass->pData;   
+
+  /* Look For AUDIOCONTROL  interface */
+  interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0xFF);
+  if(interface != 0xFF)
+  {
+    for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
+    {
+      if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == 0x03)&& /*HID*/
+        (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0))
+      {
+        if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) == 0x80)
+        {
+          AUDIO_Handle->control.Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
+          AUDIO_Handle->control.EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
+          AUDIO_Handle->control.interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber;          
+          AUDIO_Handle->control.Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval;
+          AUDIO_Handle->control.supported = 1;
+          status = USBH_OK;
+          break;
+        }
+      }
+    } 
+  }
+  return status;
+}
+
+/**
+  * @brief  Parse AC and interfaces Descriptors
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phost)
+{
+  USBH_DescHeader_t            *pdesc ;
+  uint16_t                      ptr;
+  int8_t                        itf_index = 0;
+  int8_t                        itf_number = 0; 
+  int8_t                        alt_setting;   
+  AUDIO_HandleTypeDef           *AUDIO_Handle;
+  
+  AUDIO_Handle =  phost->pActiveClass->pData;  
+  pdesc   = (USBH_DescHeader_t *)(phost->device.CfgDesc_Raw);
+  ptr = USB_LEN_CFG_DESC;
+  
+  AUDIO_Handle->class_desc.FeatureUnitNum = 0;
+  AUDIO_Handle->class_desc.InputTerminalNum = 0;
+  AUDIO_Handle->class_desc.OutputTerminalNum = 0;  
+  AUDIO_Handle->class_desc.ASNum = 0;
+  
+  while(ptr < phost->device.CfgDesc.wTotalLength)
+  {
+    pdesc = USBH_GetNextDesc((void *)pdesc, &ptr);
+    
+    switch (pdesc->bDescriptorType)
+    {
+      
+    case USB_DESC_TYPE_INTERFACE:
+      itf_number = *((uint8_t *)pdesc + 2);
+      alt_setting = *((uint8_t *)pdesc + 3);
+      itf_index = USBH_FindInterfaceIndex (phost, itf_number, alt_setting);     
+      break;
+      
+    case USB_DESC_TYPE_CS_INTERFACE:
+      if(itf_number <= phost->device.CfgDesc.bNumInterfaces)
+      {
+        
+        ParseCSDescriptors(&AUDIO_Handle->class_desc,
+                           phost->device.CfgDesc.Itf_Desc[itf_index].bInterfaceSubClass, 
+                           (uint8_t *)pdesc);
+      }
+      break;
+      
+    default:
+      break; 
+    }
+  }
+  return USBH_OK;
+}
+
+/**
+  * @brief  Parse AC interfaces
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, 
+                                      uint8_t ac_subclass, 
+                                      uint8_t *pdesc)
+{
+  if(ac_subclass == USB_SUBCLASS_AUDIOCONTROL)
+  {
+    switch(pdesc[2])
+    {
+    case UAC_HEADER: 
+      class_desc->cs_desc.HeaderDesc = (AUDIO_HeaderDescTypeDef *)pdesc;    
+      break;
+      
+    case UAC_INPUT_TERMINAL:
+      class_desc->cs_desc.InputTerminalDesc[class_desc->InputTerminalNum++] = (AUDIO_ITDescTypeDef*) pdesc;    
+      break;
+      
+    case UAC_OUTPUT_TERMINAL:
+      class_desc->cs_desc.OutputTerminalDesc[class_desc->OutputTerminalNum++] = (AUDIO_OTDescTypeDef*) pdesc;   
+      break;
+
+    case UAC_FEATURE_UNIT:
+      class_desc->cs_desc.FeatureUnitDesc[class_desc->FeatureUnitNum++] = (AUDIO_FeatureDescTypeDef*) pdesc; 
+      break;
+      
+    case UAC_SELECTOR_UNIT:
+      class_desc->cs_desc.SelectorUnitDesc[class_desc->SelectorUnitNum++] = (AUDIO_SelectorDescTypeDef*) pdesc; 
+      break;
+
+    case UAC_MIXER_UNIT:
+      class_desc->cs_desc.MixerUnitDesc[class_desc->MixerUnitNum++] = (AUDIO_MixerDescTypeDef*) pdesc; 
+      break;      
+
+    default: 
+      break;
+    }
+  }
+  else if(ac_subclass == USB_SUBCLASS_AUDIOSTREAMING)
+  {
+    switch(pdesc[2])
+    {
+    case UAC_AS_GENERAL:
+      class_desc->as_desc[class_desc->ASNum].GeneralDesc = (AUDIO_ASGeneralDescTypeDef*) pdesc; 
+      break;
+    case UAC_FORMAT_TYPE:      
+      class_desc->as_desc[class_desc->ASNum++].FormatTypeDesc = (AUDIO_ASFormatTypeDescTypeDef*) pdesc; 
+      break;
+    default:
+      break;
+    }
+  }
+ 
+  return USBH_OK;
+}
+
+
+/**
+  * @brief  Link a Unit to next associated one
+  * @param  phost: Host handle
+  * @param  UnitID: Unit identifer
+  * @retval UnitID, Index and Type of the assicated Unit 
+  */
+static int32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID)
+{
+  uint8_t Index;  
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  
+  AUDIO_Handle =  phost->pActiveClass->pData;    
+  
+  /* Find Feature Unit */
+  for(Index = 0; Index < AUDIO_Handle->class_desc.FeatureUnitNum; Index ++)
+  {
+    if(AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bSourceID == UnitID)
+    {
+      UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bUnitID;
+      
+      return ((UnitID << 16) | (UAC_FEATURE_UNIT << 8) | Index);
+    }
+  }
+  
+  /* Find Mixer Unit */
+  for(Index = 0; Index < AUDIO_Handle->class_desc.MixerUnitNum; Index ++)
+  {
+    if((AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID0 == UnitID)||
+       (AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID1 == UnitID))
+    {
+      UnitID = AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bUnitID;
+      
+      return ((UnitID << 16) | (UAC_MIXER_UNIT << 8) | Index);
+    }
+  }
+  
+  
+  /* Find Selector Unit */
+  for(Index = 0; Index < AUDIO_Handle->class_desc.SelectorUnitNum; Index ++)
+  {
+    if(AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bSourceID0 == UnitID)
+    {
+      UnitID = AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bUnitID;
+      
+      return ((UnitID << 16) | (UAC_SELECTOR_UNIT << 8) | Index); 
+    }
+  }  
+  
+  
+  /* Find OT Unit */  
+  for(Index = 0; Index < AUDIO_Handle->class_desc.OutputTerminalNum; Index ++)
+  {
+    if(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bSourceID == UnitID)
+    {
+      UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bTerminalID;
+      
+      return ((UnitID << 16) | (UAC_OUTPUT_TERMINAL << 8) | Index);
+    }
+  } 
+  
+  /* No associated Unit found */
+  return -1;
+}
+
+/**
+  * @brief  Build full path for Microphone device
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *phost)
+{
+  uint8_t UnitID = 0, Type, Index;
+  uint32_t value;
+  uint8_t terminalIndex;  
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  
+  AUDIO_Handle =  phost->pActiveClass->pData;    
+  
+  /*Find microphone IT*/
+  for(terminalIndex = 0; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++)
+  {
+    if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x201)
+    {    
+      UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID;
+      AUDIO_Handle->microphone.asociated_channels =  AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels;
+      break;
+    }
+  }
+  
+  do
+  {
+    value =  USBH_AUDIO_FindLinkedUnit(phost, UnitID);
+    Index = value & 0xFF;
+    Type   = (value >> 8) & 0xFF;
+    UnitID   = (value >> 16) & 0xFF;
+    
+    switch (Type)
+    {
+    case UAC_FEATURE_UNIT:
+      AUDIO_Handle->microphone.asociated_feature = Index;
+      break;
+      
+    case UAC_MIXER_UNIT:
+      AUDIO_Handle->microphone.asociated_mixer = Index;
+      break;
+      
+    case UAC_SELECTOR_UNIT:
+      AUDIO_Handle->microphone.asociated_selector = Index;
+      break;
+      
+    case UAC_OUTPUT_TERMINAL:
+      AUDIO_Handle->microphone.asociated_terminal = Index;
+      break;    
+    }
+  }
+  while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0));
+  
+  
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  Build full path for Headphone device
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phost)
+{
+  uint8_t UnitID = 0, Type, Index;
+  uint32_t value;
+  uint8_t terminalIndex;  
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  
+  AUDIO_Handle =  phost->pActiveClass->pData;    
+  
+  /*Find association betwen audio streaming and microphone*/
+  for(terminalIndex = 0; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++)
+  {
+    if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x101)
+    {    
+      UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID;
+      AUDIO_Handle->headphone.asociated_channels =  AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels;
+      break;
+    }
+  }
+  
+  for(Index = 0; Index < AUDIO_Handle->class_desc.ASNum; Index++)
+  {
+    if(AUDIO_Handle->class_desc.as_desc[Index].GeneralDesc->bTerminalLink == UnitID)
+    {    
+      AUDIO_Handle->headphone.asociated_as = Index;
+      break;
+    }
+  } 
+        
+  do
+  {
+    value =  USBH_AUDIO_FindLinkedUnit(phost, UnitID);
+    Index = value & 0xFF;
+    Type   = (value >> 8) & 0xFF;
+    UnitID   = (value >> 16) & 0xFF;
+    
+    switch (Type)
+    {
+    case UAC_FEATURE_UNIT:
+      AUDIO_Handle->headphone.asociated_feature = Index;
+      break;
+      
+    case UAC_MIXER_UNIT:
+      AUDIO_Handle->headphone.asociated_mixer = Index;
+      break;
+      
+    case UAC_SELECTOR_UNIT:
+      AUDIO_Handle->headphone.asociated_selector = Index;
+      break;
+      
+    case UAC_OUTPUT_TERMINAL:
+      AUDIO_Handle->headphone.asociated_terminal = Index;
+      if(LE16(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->wTerminalType) != 0x103)
+      {
+        return  USBH_OK;
+      }
+      break;    
+    }
+  }
+  while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0));
+
+  return USBH_FAIL;
+}
+
+
+/**
+  * @brief  Handle Set Cur request
+  * @param  phost: Host handle
+  * @param  subtype: subtype index
+  * @param  feature: feature index
+  * @param  controlSelector: control code
+  * @param  channel: channel index
+  * @param  length: Command length
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length)
+{
+  uint16_t wValue,wIndex,wLength;
+  uint8_t UnitID,InterfaceNum;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  AUDIO_Handle =  phost->pActiveClass->pData;
+  
+  switch(subtype)
+  {
+  case UAC_INPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
+    AUDIO_Handle->mem[0] = 0x00;
+    
+    wLength = 1;
+    break;
+  case UAC_FEATURE_UNIT:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    /*holds the CS(control selector ) and CN (channel number)*/
+    wValue =  (controlSelector << 8) | channel;
+    wLength = length;
+    break;
+  }
+  
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \
+    USB_REQ_TYPE_CLASS;
+  
+  phost->Control.setup.b.bRequest = UAC_SET_CUR;
+  phost->Control.setup.b.wValue.w = wValue;
+  phost->Control.setup.b.wIndex.w = wIndex;
+  phost->Control.setup.b.wLength.w = wLength; 
+  
+  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
+  
+}
+
+/**
+  * @brief  Handle Get Cur request
+  * @param  phost: Host handle
+  * @param  subtype: subtype index
+  * @param  feature: feature index
+  * @param  controlSelector: control code
+  * @param  channel: channel index
+  * @param  length: Command length
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length)
+{
+  uint16_t wValue = 0, wIndex = 0,wLength = 0;
+  uint8_t UnitID = 0, InterfaceNum = 0;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  AUDIO_Handle =  phost->pActiveClass->pData;
+  
+  switch(subtype)
+  {
+  case UAC_INPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
+    AUDIO_Handle->mem[0] = 0x00;
+    
+    wLength = 1;
+    break;
+  case UAC_FEATURE_UNIT:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    /*holds the CS(control selector ) and CN (channel number)*/
+    wValue =  (controlSelector << 8) | channel;
+    wLength = length;
+    break;
+    
+  case UAC_OUTPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
+    wLength = 1; 
+    break;
+  }
+  
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
+    USB_REQ_TYPE_CLASS;
+  
+  phost->Control.setup.b.bRequest = UAC_GET_CUR;
+  phost->Control.setup.b.wValue.w = wValue;
+  phost->Control.setup.b.wIndex.w = wIndex;
+  phost->Control.setup.b.wLength.w = wLength; 
+  
+  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
+  
+}
+
+
+/**
+  * @brief  Handle Get Max request
+  * @param  phost: Host handle
+  * @param  subtype: subtype index
+  * @param  feature: feature index
+  * @param  controlSelector: control code
+  * @param  channel: channel index
+  * @param  length: Command length
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length)
+{
+  uint16_t wValue = 0, wIndex = 0, wLength = 0;
+  uint8_t UnitID = 0, InterfaceNum = 0;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  AUDIO_Handle =  phost->pActiveClass->pData;
+  
+  switch(subtype)
+  {
+  case UAC_INPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
+    AUDIO_Handle->mem[0] = 0x00;
+    
+    wLength = 1;
+    break;
+  case UAC_FEATURE_UNIT:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    /*holds the CS(control selector ) and CN (channel number)*/
+    wValue =  (controlSelector << 8) | channel;
+    wLength = length;
+    break;
+    
+  case UAC_OUTPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
+    wLength = 1; 
+    break;
+  }
+  
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
+    USB_REQ_TYPE_CLASS;
+  
+  phost->Control.setup.b.bRequest = UAC_GET_MAX;
+  phost->Control.setup.b.wValue.w = wValue;
+  phost->Control.setup.b.wIndex.w = wIndex;
+  phost->Control.setup.b.wLength.w = wLength; 
+  
+  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
+  
+}
+
+
+
+/**
+  * @brief  Handle Get Res request
+  * @param  phost: Host handle
+  * @param  subtype: subtype index
+  * @param  feature: feature index
+  * @param  controlSelector: control code
+  * @param  channel: channel index
+  * @param  length: Command length
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length)
+{
+  uint16_t wValue = 0, wIndex = 0, wLength = 0;
+  uint8_t UnitID = 0, InterfaceNum = 0;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  AUDIO_Handle =  phost->pActiveClass->pData;
+  
+  switch(subtype)
+  {
+  case UAC_INPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
+    AUDIO_Handle->mem[0] = 0x00;
+    
+    wLength = 1;
+    break;
+  case UAC_FEATURE_UNIT:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    /*holds the CS(control selector ) and CN (channel number)*/
+    wValue =  (controlSelector << 8) | channel;
+    wLength = length;
+    break;
+    
+  case UAC_OUTPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
+    wLength = 1; 
+    break;
+  }
+  
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
+    USB_REQ_TYPE_CLASS;
+  
+  phost->Control.setup.b.bRequest = UAC_GET_RES;
+  phost->Control.setup.b.wValue.w = wValue;
+  phost->Control.setup.b.wIndex.w = wIndex;
+  phost->Control.setup.b.wLength.w = wLength; 
+  
+  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
+  
+}
+
+/**
+  * @brief  Handle Get Min request
+  * @param  phost: Host handle
+  * @param  subtype: subtype index
+  * @param  feature: feature index
+  * @param  controlSelector: control code
+  * @param  channel: channel index
+  * @param  length: Command length
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, 
+                                         uint8_t subtype, 
+                                         uint8_t feature,
+                                         uint8_t controlSelector,
+                                         uint8_t channel,
+                                         uint16_t length)
+{
+  uint16_t wValue = 0, wIndex = 0, wLength = 0;
+  uint8_t UnitID = 0, InterfaceNum = 0;
+  AUDIO_HandleTypeDef *AUDIO_Handle;
+  AUDIO_Handle =  phost->pActiveClass->pData;
+  
+  switch(subtype)
+  {
+  case UAC_INPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ;
+    AUDIO_Handle->mem[0] = 0x00;
+    
+    wLength = 1;
+    break;
+  case UAC_FEATURE_UNIT:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    /*holds the CS(control selector ) and CN (channel number)*/
+    wValue =  (controlSelector << 8) | channel;
+    wLength = length;
+    break;
+    
+  case UAC_OUTPUT_TERMINAL:
+    UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID;
+    InterfaceNum = 0; /*Always zero Control Interface */
+    wIndex = ( UnitID << 8 ) | InterfaceNum ;
+    wValue = (COPY_PROTECT_CONTROL << 8 ) ; 
+    wLength = 1; 
+    break;
+  }
+  
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \
+    USB_REQ_TYPE_CLASS;
+  
+  phost->Control.setup.b.bRequest = UAC_GET_MIN;
+  phost->Control.setup.b.wValue.w = wValue;
+  phost->Control.setup.b.wIndex.w = wIndex;
+  phost->Control.setup.b.wLength.w = wLength; 
+  
+  return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength ));    
+  
+}
+
+/**
+  * @brief  Handle Set Endpoint Controls Request
+  * @param  phost: Host handle
+  * @param  Ep: Endpoint address
+  * @param  buf: pointer to data
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost,
+                                               uint8_t  Ep,
+                                               uint8_t *buff) 
+{
+  uint16_t wValue, wIndex, wLength;
+  
+
+  wValue = SAMPLING_FREQ_CONTROL << 8;
+  wIndex = Ep; 
+  wLength = 3; /*length of the frequency parameter*/   
+  
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_ENDPOINT | \
+    USB_REQ_TYPE_CLASS;
+  
+  phost->Control.setup.b.bRequest = UAC_SET_CUR;
+  phost->Control.setup.b.wValue.w = wValue;
+  phost->Control.setup.b.wIndex.w = wIndex;
+  phost->Control.setup.b.wLength.w = wLength; 
+  
+  return(USBH_CtlReq(phost, (uint8_t *)buff, wLength ));
+    
+}
+
+/**
+  * @brief  Handle Input stream process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ; 
+  
+  return status;  
+}
+
+/**
+  * @brief  Handle HID Control process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ;
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData; 
+  uint16_t attribute  = 0; 
+ 
+  
+  switch(AUDIO_Handle->control_state)
+  {
+  case AUDIO_CONTROL_INIT:
+    if((phost->Timer & 1) == 0)
+    {
+      AUDIO_Handle->control.timer = phost->Timer;
+      USBH_InterruptReceiveData(phost, 
+                                (uint8_t *)(AUDIO_Handle->mem),
+                                AUDIO_Handle->control.EpSize,
+                                AUDIO_Handle->control.Pipe);
+      
+      AUDIO_Handle->temp_feature  = AUDIO_Handle->headphone.asociated_feature;
+      AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels;
+      
+      AUDIO_Handle->control_state = AUDIO_CONTROL_CHANGE ;
+    }
+    break;
+  case AUDIO_CONTROL_CHANGE:
+    if(USBH_LL_GetURBState(phost , AUDIO_Handle->control.Pipe) == USBH_URB_DONE)
+    {
+      attribute = LE16(&AUDIO_Handle->mem[0]); 
+      if(USBH_AUDIO_SetControlAttribute (phost, attribute) == USBH_BUSY)
+      {
+        break;
+      }
+    }
+    
+    if(( phost->Timer - AUDIO_Handle->control.timer) >= AUDIO_Handle->control.Poll)
+    {
+      AUDIO_Handle->control.timer = phost->Timer;
+      
+      USBH_InterruptReceiveData(phost, 
+                                (uint8_t *)(AUDIO_Handle->mem),
+                                AUDIO_Handle->control.EpSize,
+                                AUDIO_Handle->control.Pipe);      
+      
+    }
+    break;
+    
+  case AUDIO_CONTROL_VOLUME_UP:
+       if( USBH_AUDIO_SetControlAttribute (phost, 1) == USBH_OK)
+       {
+         AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
+        status = USBH_OK; 
+       }
+       break;
+       
+  case AUDIO_CONTROL_VOLUME_DOWN:
+       if( USBH_AUDIO_SetControlAttribute (phost, 2) == USBH_OK)
+       {
+         AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;         
+         status = USBH_OK; 
+       }     
+       break;
+       
+  case AUDIO_CONTROL_IDLE:
+  default:  
+    break; 
+  }
+    
+  return status;  
+}
+
+/**
+  * @brief  Handle Output stream process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ;
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;   
+  uint8_t *buff;
+  
+  
+  switch(AUDIO_Handle->play_state)
+  {
+  case AUDIO_PLAYBACK_INIT:
+    
+    if( AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0)
+    {
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP_FREQ;        
+    }
+    else
+    {
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP;
+    }
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif  
+    break;
+    
+  case AUDIO_PLAYBACK_SET_EP_FREQ:
+
+    buff = (uint8_t*)AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0];    
+
+    status = USBH_AUDIO_SetEndpointControls(phost, AUDIO_Handle->headphone.Ep, buff);
+    if(status == USBH_OK) 
+    {
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;    
+    }
+    break;
+    
+  case AUDIO_PLAYBACK_SET_EP:
+    buff = (uint8_t *)&AUDIO_Handle->headphone.frequency;    
+    status = USBH_AUDIO_SetEndpointControls(phost,AUDIO_Handle->headphone.Ep, buff);
+    if(status == USBH_OK)
+    {
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;
+      USBH_AUDIO_FrequencySet(phost);
+    }
+    break;
+  case AUDIO_PLAYBACK_IDLE:
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif      
+    status = USBH_OK;
+    break;
+    
+  case AUDIO_PLAYBACK_PLAY:
+    USBH_AUDIO_Transmit(phost);
+    status = USBH_OK;
+    break;
+    
+  default:
+    break;
+  }  
+  
+  return status;
+}
+
+/**
+  * @brief  Handle Transmission process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ;
+  AUDIO_HandleTypeDef *AUDIO_Handle =  phost->pActiveClass->pData;   
+  
+  switch(AUDIO_Handle->processing_state)
+  {
+  case AUDIO_DATA_START_OUT:
+    /* Sync with start of Even Frame */
+    if((phost->Timer & 1) == 0)
+    {
+      AUDIO_Handle->headphone.timer = phost->Timer;
+      AUDIO_Handle->processing_state = AUDIO_DATA_OUT;
+      USBH_IsocSendData(phost, 
+                       AUDIO_Handle->headphone.buf,
+                       AUDIO_Handle->headphone.frame_length,
+                       AUDIO_Handle->headphone.Pipe);
+      
+      AUDIO_Handle->headphone.partial_ptr = AUDIO_Handle->headphone.frame_length; 
+      AUDIO_Handle->headphone.global_ptr = AUDIO_Handle->headphone.frame_length; 
+      AUDIO_Handle->headphone.cbuf = AUDIO_Handle->headphone.buf;
+
+    }
+    break;
+    
+  case AUDIO_DATA_OUT:
+    if((USBH_LL_GetURBState(phost , AUDIO_Handle->headphone.Pipe) == USBH_URB_DONE)&&
+       (( phost->Timer - AUDIO_Handle->headphone.timer) >= AUDIO_Handle->headphone.Poll))
+    {
+      AUDIO_Handle->headphone.timer = phost->Timer;
+      
+      if(AUDIO_Handle->control.supported == 1)
+      {
+        USBH_AUDIO_Control (phost);
+      }
+      
+      if(AUDIO_Handle->headphone.global_ptr <= AUDIO_Handle->headphone.total_length)
+      {
+        USBH_IsocSendData(phost, 
+                          AUDIO_Handle->headphone.cbuf,
+                          AUDIO_Handle->headphone.frame_length,
+                          AUDIO_Handle->headphone.Pipe);
+        
+        AUDIO_Handle->headphone.cbuf += AUDIO_Handle->headphone.frame_length;
+        AUDIO_Handle->headphone.partial_ptr += AUDIO_Handle->headphone.frame_length;
+        AUDIO_Handle->headphone.global_ptr += AUDIO_Handle->headphone.frame_length;
+      }
+      else
+      {
+       AUDIO_Handle->headphone.partial_ptr = 0xFFFFFFFF;
+       AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;
+      }
+    }
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_AUDIO_SetFrequency 
+  *         Set Audio sampling parameters
+  * @param  phost: Host handle
+  * @param  SampleRate: Sample Rate
+  * @param  NbrChannels: Number of Channels
+  * @param  BitPerSample: Bit Per Sample
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, 
+                                            uint16_t SampleRate,
+                                            uint8_t  NbrChannels,
+                                            uint8_t  BitPerSample)
+{
+  USBH_StatusTypeDef Status = USBH_BUSY;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+  uint8_t              index; 
+  uint8_t              change_freq = FALSE;
+  uint32_t             freq_min, freq_max;
+  uint8_t              num_supported_freq;
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    AUDIO_Handle =  phost->pActiveClass->pData;
+    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE)
+    {
+      
+      if(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0)
+      { 
+        freq_min = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]); 
+        freq_max = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[1]);         
+        
+        if(( SampleRate >= freq_min)&& (SampleRate <= freq_max))
+        {
+          change_freq = TRUE;
+        }
+      }
+      else
+      {    
+        
+        num_supported_freq = (AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bLength - 8)/3;
+        
+        
+        for(index = 0; index < num_supported_freq; index++)
+        {
+          if(SampleRate == LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[index]))
+          {
+            change_freq = TRUE;            
+            break;
+          }
+        }  
+      }      
+      
+      if(change_freq == TRUE)
+      {
+        AUDIO_Handle->headphone.frequency = SampleRate;
+        AUDIO_Handle->headphone.frame_length    = (SampleRate * BitPerSample * NbrChannels) / 8000;
+        AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP;
+        Status = USBH_OK;  
+        
+      }
+    }
+  }
+   return Status;  
+}
+
+/**
+  * @brief  USBH_AUDIO_Play 
+  *         Start playback process
+  * @param  phost: Host handle
+  * @param  buf: pointer to raw audio data
+  * @param  length: total length of the audio data
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length)
+{
+  USBH_StatusTypeDef Status = USBH_FAIL;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    AUDIO_Handle =  phost->pActiveClass->pData;
+    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE)
+    {
+      AUDIO_Handle->headphone.buf = buf;
+      AUDIO_Handle->headphone.total_length = length;
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY;
+      AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
+      AUDIO_Handle->processing_state = AUDIO_DATA_START_OUT;
+      Status = USBH_OK;
+    }
+  }
+  return Status;  
+}
+
+/**
+  * @brief  USBH_AUDIO_Pause 
+  *         Stop the playback process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef Status = USBH_FAIL;
+  Status = USBH_AUDIO_Suspend(phost);
+  return Status;  
+}
+
+/**
+  * @brief  USBH_AUDIO_Suspend 
+  *         Suspend the playback process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef Status = USBH_FAIL;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    AUDIO_Handle =  phost->pActiveClass->pData;
+    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
+    {
+      AUDIO_Handle->control_state = AUDIO_CONTROL_IDLE;
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE;
+      Status = USBH_OK;      
+    }
+  }
+  return Status;  
+}
+/**
+  * @brief  USBH_AUDIO_Resume 
+  *         Resume the playback process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef Status = USBH_FAIL;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    AUDIO_Handle =  phost->pActiveClass->pData;
+    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE)
+    {
+      AUDIO_Handle->control_state = AUDIO_CONTROL_INIT;
+      AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY;
+    }
+  }
+  return Status;  
+}
+/**
+  * @brief  USBH_AUDIO_GetOutOffset 
+  *         return the current buffer pointer for OUT proces
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+int32_t USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost)
+{
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    AUDIO_Handle =  phost->pActiveClass->pData;
+    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
+    {
+      return AUDIO_Handle->headphone.partial_ptr;
+    }
+  }
+  return -1;  
+}
+
+/**
+  * @brief  USBH_AUDIO_ChangeOutBuffer 
+  *         Change audio data buffer address
+  * @param  phost: Host handle
+  * @param  buf: buffer address
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf)
+{
+  USBH_StatusTypeDef Status = USBH_FAIL;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    AUDIO_Handle =  phost->pActiveClass->pData;
+    if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
+    {
+      if(AUDIO_Handle->headphone.buf <= buf)
+      {
+        AUDIO_Handle->headphone.cbuf = buf;
+        if ( AUDIO_Handle->headphone.buf == buf)
+        {
+          AUDIO_Handle->headphone.partial_ptr = 0;
+        }
+        Status = USBH_OK;  
+      }    
+    }
+  }
+  return Status;  
+}
+
+/**
+  * @brief  USBH_AUDIO_SetControlAttribute 
+  *         Set Control Attribute
+  * @param  phost: Host handle
+  * @param  attrib: control attribute
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+
+  
+  AUDIO_Handle = phost->pActiveClass->pData;
+  
+  switch (attrib)
+  {
+  case 0x01:
+    AUDIO_Handle->headphone.attribute.volume += AUDIO_Handle->headphone.attribute.resolution;
+    break;
+    
+  case 0x02:
+    AUDIO_Handle->headphone.attribute.volume -= AUDIO_Handle->headphone.attribute.resolution; 
+    break;
+    
+  }
+  
+  if(AUDIO_Handle->headphone.attribute.volume > AUDIO_Handle->headphone.attribute.volumeMax)
+  {
+    AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMax;
+  }
+  
+  if(AUDIO_Handle->headphone.attribute.volume < AUDIO_Handle->headphone.attribute.volumeMin)
+  {
+    AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMin;
+  }
+  
+  if(AUDIO_SetVolume (phost, 
+                                 AUDIO_Handle->temp_feature, 
+                                 AUDIO_Handle->temp_channels, 
+                                 AUDIO_Handle->headphone.attribute.volume) != USBH_BUSY)
+  {
+    
+    if(AUDIO_Handle->temp_channels ==  1)
+    {
+      AUDIO_Handle->temp_feature  = AUDIO_Handle->headphone.asociated_feature;
+      AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels;
+      status = USBH_OK;
+    }
+    else
+    {
+      AUDIO_Handle->temp_channels--;
+    }
+    AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME;
+  }
+  
+ 
+  return status;
+}
+
+
+/**
+  * @brief  USBH_AUDIO_SetVolume 
+  *         Set Volume
+  * @param  phost: Host handle
+  * @param  volume: VOLUME_UP/ VOLUME_DOWN
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl)
+{
+  AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData;
+  
+  if((volume_ctl == VOLUME_UP) || (volume_ctl == VOLUME_DOWN))
+  {
+    if(phost->gState == HOST_CLASS)
+    {
+      AUDIO_Handle =  phost->pActiveClass->pData;
+      if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY)
+      {
+        AUDIO_Handle->control_state = (volume_ctl == VOLUME_UP)? AUDIO_CONTROL_VOLUME_UP : AUDIO_CONTROL_VOLUME_DOWN;
+        return USBH_OK;  
+      }
+    }
+  }
+  return USBH_FAIL;
+}
+/**
+  * @brief  AUDIO_SetVolume 
+  *         Set Volume
+  * @param  phost: Host handle
+  * @param  feature: feature Unit index
+  * @param  channel: channel index
+  * @param  volume: new volume
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ;
+  AUDIO_HandleTypeDef *AUDIO_Handle; 
+
+  
+  AUDIO_Handle = phost->pActiveClass->pData;
+
+  AUDIO_Handle->mem[0] = volume;
+  
+  status = USBH_AC_SetCur(phost, 
+                          UAC_FEATURE_UNIT, 
+                          feature,
+                          VOLUME_CONTROL,
+                          channel,
+                          2);
+    
+  return status; 
+}
+
+/**
+  * @brief  The function informs user that Settings have been changed
+  *  @param  pdev: Selected device
+  * @retval None
+  */
+__weak void USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost)
+{
+  
+}
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h b/micropython/ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h
index df11bfddac416a8bd15a19efadfefcde0b4477e3..d4e974cb4742dc3f2a9eb3373e2c39a5874472ed 100644
--- a/micropython/ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h
+++ b/micropython/ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h
@@ -1,449 +1,449 @@
-/**
-  ******************************************************************************
-  * @file    usbh_cdc.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_cdc.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_CDC_CORE_H
-#define __USBH_CDC_CORE_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_CDC_CLASS
-* @{
-*/
-
-/** @defgroup USBH_CDC_CORE
-* @brief This file is the Header file for USBH_CDC_CORE.c
-* @{
-*/ 
-
-
-
-
-/*Communication Class codes*/
-#define USB_CDC_CLASS                                           0x02
-#define COMMUNICATION_INTERFACE_CLASS_CODE                      0x02
-
-/*Data Interface Class Codes*/
-#define DATA_INTERFACE_CLASS_CODE                               0x0A
-
-/*Communcation sub class codes*/
-#define RESERVED                                                0x00
-#define DIRECT_LINE_CONTROL_MODEL                               0x01
-#define ABSTRACT_CONTROL_MODEL                                  0x02
-#define TELEPHONE_CONTROL_MODEL                                 0x03
-#define MULTICHANNEL_CONTROL_MODEL                              0x04   
-#define CAPI_CONTROL_MODEL                                      0x05
-#define ETHERNET_NETWORKING_CONTROL_MODEL                       0x06
-#define ATM_NETWORKING_CONTROL_MODEL                            0x07
-
-
-/*Communication Interface Class Control Protocol Codes*/
-#define NO_CLASS_SPECIFIC_PROTOCOL_CODE                         0x00
-#define COMMON_AT_COMMAND                                       0x01
-#define VENDOR_SPECIFIC                                         0xFF
-
-
-#define CS_INTERFACE                                            0x24
-#define CDC_PAGE_SIZE_64                                        0x40
-
-/*Class-Specific Request Codes*/
-#define CDC_SEND_ENCAPSULATED_COMMAND                           0x00
-#define CDC_GET_ENCAPSULATED_RESPONSE                           0x01
-#define CDC_SET_COMM_FEATURE                                    0x02
-#define CDC_GET_COMM_FEATURE                                    0x03
-#define CDC_CLEAR_COMM_FEATURE                                  0x04
-
-#define CDC_SET_AUX_LINE_STATE                                  0x10
-#define CDC_SET_HOOK_STATE                                      0x11
-#define CDC_PULSE_SETUP                                         0x12
-#define CDC_SEND_PULSE                                          0x13
-#define CDC_SET_PULSE_TIME                                      0x14
-#define CDC_RING_AUX_JACK                                       0x15
-
-#define CDC_SET_LINE_CODING                                     0x20
-#define CDC_GET_LINE_CODING                                     0x21
-#define CDC_SET_CONTROL_LINE_STATE                              0x22
-#define CDC_SEND_BREAK                                          0x23
-
-#define CDC_SET_RINGER_PARMS                                    0x30
-#define CDC_GET_RINGER_PARMS                                    0x31
-#define CDC_SET_OPERATION_PARMS                                 0x32
-#define CDC_GET_OPERATION_PARMS                                 0x33  
-#define CDC_SET_LINE_PARMS                                      0x34
-#define CDC_GET_LINE_PARMS                                      0x35
-#define CDC_DIAL_DIGITS                                         0x36
-#define CDC_SET_UNIT_PARAMETER                                  0x37  
-#define CDC_GET_UNIT_PARAMETER                                  0x38
-#define CDC_CLEAR_UNIT_PARAMETER                                0x39
-#define CDC_GET_PROFILE                                         0x3A
-
-#define CDC_SET_ETHERNET_MULTICAST_FILTERS                      0x40
-#define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER        0x41
-#define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER        0x42
-#define CDC_SET_ETHERNET_PACKET_FILTER                          0x43
-#define CDC_GET_ETHERNET_STATISTIC                              0x44
-
-#define CDC_SET_ATM_DATA_FORMAT                                 0x50  
-#define CDC_GET_ATM_DEVICE_STATISTICS                           0x51
-#define CDC_SET_ATM_DEFAULT_VC                                  0x52
-#define CDC_GET_ATM_VC_STATISTICS                               0x53
-
-
-/* wValue for SetControlLineState*/
-#define CDC_ACTIVATE_CARRIER_SIGNAL_RTS                         0x0002
-#define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS                       0x0000
-#define CDC_ACTIVATE_SIGNAL_DTR                                 0x0001
-#define CDC_DEACTIVATE_SIGNAL_DTR                               0x0000
-
-#define LINE_CODING_STRUCTURE_SIZE                              0x07
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CDC_CORE_Exported_Types
-* @{
-*/ 
-
-/* States for CDC State Machine */
-typedef enum
-{
-  CDC_IDLE= 0,
-  CDC_SEND_DATA,
-  CDC_SEND_DATA_WAIT,
-  CDC_RECEIVE_DATA,
-  CDC_RECEIVE_DATA_WAIT,  
-}
-CDC_DataStateTypeDef;
-
-typedef enum
-{
-  CDC_IDLE_STATE= 0,
-  CDC_SET_LINE_CODING_STATE,  
-  CDC_GET_LAST_LINE_CODING_STATE,    
-  CDC_TRANSFER_DATA, 
-  CDC_ERROR_STATE,  
-}
-CDC_StateTypeDef;
-
-
-/*Line coding structure*/
-typedef union _CDC_LineCodingStructure
-{
-  uint8_t Array[LINE_CODING_STRUCTURE_SIZE];
-  
-  struct
-  {
-    
-    uint32_t             dwDTERate;     /*Data terminal rate, in bits per second*/
-    uint8_t              bCharFormat;   /*Stop bits
-    0 - 1 Stop bit
-    1 - 1.5 Stop bits
-    2 - 2 Stop bits*/
-    uint8_t              bParityType;   /* Parity
-    0 - None
-    1 - Odd
-    2 - Even
-    3 - Mark
-    4 - Space*/
-    uint8_t                bDataBits;     /* Data bits (5, 6, 7, 8 or 16). */
-  }b;
-}
-CDC_LineCodingTypeDef;
-
-
-
-/* Header Functional Descriptor
---------------------------------------------------------------------------------
-Offset|  field              | Size  |    Value   |   Description                    
-------|---------------------|-------|------------|------------------------------
-0     |  bFunctionLength    | 1     |   number   |  Size of this descriptor.
-1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
-2     |  bDescriptorSubtype | 1     |   Constant |  Identifier (ID) of functional 
-      |                     |       |            | descriptor.
-3     |  bcdCDC             | 2     |            |
-      |                     |       |   Number   | USB Class Definitions for 
-      |                     |       |            | Communication Devices Specification 
-      |                     |       |            | release number in binary-coded 
-      |                     |       |            | decimal
-------|---------------------|-------|------------|------------------------------
-*/
-typedef struct _FunctionalDescriptorHeader
-{
-  uint8_t     bLength;            /*Size of this descriptor.*/
-  uint8_t     bDescriptorType;    /*CS_INTERFACE (0x24)*/
-  uint8_t     bDescriptorSubType; /* Header functional descriptor subtype as*/
-  uint16_t    bcdCDC;             /* USB Class Definitions for Communication
-                                    Devices Specification release number in
-                                  binary-coded decimal. */
-}
-CDC_HeaderFuncDesc_TypeDef;
-/* Call Management Functional Descriptor
---------------------------------------------------------------------------------
-Offset|  field              | Size  |    Value   |   Description                    
-------|---------------------|-------|------------|------------------------------
-0     |  bFunctionLength    | 1     |   number   |  Size of this descriptor.
-1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
-2     |  bDescriptorSubtype | 1     |   Constant |  Call Management functional 
-      |                     |       |            |  descriptor subtype.
-3     |  bmCapabilities     | 1     |   Bitmap   | The capabilities that this configuration
-      |                     |       |            | supports:
-      |                     |       |            | D7..D2: RESERVED (Reset to zero)
-      |                     |       |            | D1: 0 - Device sends/receives call
-      |                     |       |            | management information only over
-      |                     |       |            | the Communication Class
-      |                     |       |            | interface.
-      |                     |       |            | 1 - Device can send/receive call
-      |                     \       |            | management information over a
-      |                     |       |            | Data Class interface.
-      |                     |       |            | D0: 0 - Device does not handle call
-      |                     |       |            | management itself.
-      |                     |       |            | 1 - Device handles call
-      |                     |       |            | management itself.
-      |                     |       |            | The previous bits, in combination, identify
-      |                     |       |            | which call management scenario is used. If bit
-      |                     |       |            | D0 is reset to 0, then the value of bit D1 is
-      |                     |       |            | ignored. In this case, bit D1 is reset to zero for
-      |                     |       |            | future compatibility.
-4     | bDataInterface      | 1     | Number     | Interface number of Data Class interface
-      |                     |       |            | optionally used for call management.        
-------|---------------------|-------|------------|------------------------------
-*/
-typedef struct _CallMgmtFunctionalDescriptor
-{
-  uint8_t    bLength;            /*Size of this functional descriptor, in bytes.*/
-  uint8_t    bDescriptorType;    /*CS_INTERFACE (0x24)*/
-  uint8_t    bDescriptorSubType; /* Call Management functional descriptor subtype*/
-  uint8_t    bmCapabilities;      /* bmCapabilities: D0+D1 */
-  uint8_t    bDataInterface;      /*bDataInterface: 1*/
-}
-CDC_CallMgmtFuncDesc_TypeDef;
-/* Abstract Control Management Functional Descriptor
---------------------------------------------------------------------------------
-Offset|  field              | Size  |    Value   |   Description                    
-------|---------------------|-------|------------|------------------------------
-0     |  bFunctionLength    | 1     |   number   |  Size of functional descriptor, in bytes.
-1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
-2     |  bDescriptorSubtype | 1     |   Constant |  Abstract Control Management 
-      |                     |       |            |  functional  descriptor subtype.
-3     |  bmCapabilities     | 1     |   Bitmap   | The capabilities that this configuration
-      |                     |       |            | supports ((A bit value of zero means that the
-      |                     |       |            | request is not supported.) )
-                                                   D7..D4: RESERVED (Reset to zero)
-      |                     |       |            | D3: 1 - Device supports the notification
-      |                     |       |            | Network_Connection.
-      |                     |       |            | D2: 1 - Device supports the request
-      |                     |       |            | Send_Break
-      |                     |       |            | D1: 1 - Device supports the request
-      |                     \       |            | combination of Set_Line_Coding,
-      |                     |       |            | Set_Control_Line_State, Get_Line_Coding, and the
-                                                   notification Serial_State.
-      |                     |       |            | D0: 1 - Device supports the request
-      |                     |       |            | combination of Set_Comm_Feature,
-      |                     |       |            | Clear_Comm_Feature, and Get_Comm_Feature.
-      |                     |       |            | The previous bits, in combination, identify
-      |                     |       |            | which requests/notifications are supported by
-      |                     |       |            | a Communication Class interface with the
-      |                     |       |            |   SubClass code of Abstract Control Model.
-------|---------------------|-------|------------|------------------------------
-*/
-typedef struct _AbstractCntrlMgmtFunctionalDescriptor
-{
-  uint8_t    bLength;            /*Size of this functional descriptor, in bytes.*/
-  uint8_t    bDescriptorType;    /*CS_INTERFACE (0x24)*/
-  uint8_t    bDescriptorSubType; /* Abstract Control Management functional
-                                  descriptor subtype*/
-  uint8_t    bmCapabilities;      /* The capabilities that this configuration supports */
-}
-CDC_AbstCntrlMgmtFuncDesc_TypeDef;
-/* Union Functional Descriptor
---------------------------------------------------------------------------------
-Offset|  field              | Size  |    Value   |   Description                    
-------|---------------------|-------|------------|------------------------------
-0     |  bFunctionLength    | 1     |   number   |  Size of this descriptor.
-1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
-2     |  bDescriptorSubtype | 1     |   Constant |  Union functional 
-      |                     |       |            |  descriptor subtype.
-3     |  bMasterInterface   | 1     |   Constant | The interface number of the 
-      |                     |       |            | Communication or Data Class interface
-4     | bSlaveInterface0    | 1     | Number     | nterface number of first slave or associated
-      |                     |       |            | interface in the union.        
-------|---------------------|-------|------------|------------------------------
-*/
-typedef struct _UnionFunctionalDescriptor
-{
-  uint8_t    bLength;            /*Size of this functional descriptor, in bytes*/
-  uint8_t    bDescriptorType;    /*CS_INTERFACE (0x24)*/
-  uint8_t    bDescriptorSubType; /* Union functional descriptor SubType*/
-  uint8_t    bMasterInterface;   /* The interface number of the Communication or
-                                 Data Class interface,*/
-  uint8_t    bSlaveInterface0;   /*Interface number of first slave*/
-}
-CDC_UnionFuncDesc_TypeDef;
-
-typedef struct _USBH_CDCInterfaceDesc
-{
-  CDC_HeaderFuncDesc_TypeDef           CDC_HeaderFuncDesc;
-  CDC_CallMgmtFuncDesc_TypeDef         CDC_CallMgmtFuncDesc;
-  CDC_AbstCntrlMgmtFuncDesc_TypeDef    CDC_AbstCntrlMgmtFuncDesc;
-  CDC_UnionFuncDesc_TypeDef            CDC_UnionFuncDesc;  
-}
-CDC_InterfaceDesc_Typedef;
-
-
-/* Structure for CDC process */
-typedef struct
-{
-  uint8_t              NotifPipe; 
-  uint8_t              NotifEp;
-  uint8_t              buff[8];
-  uint16_t             NotifEpSize;
-}
-CDC_CommItfTypedef ;
-
-typedef struct
-{
-  uint8_t              InPipe; 
-  uint8_t              OutPipe;
-  uint8_t              OutEp;
-  uint8_t              InEp;
-  uint8_t              buff[8];
-  uint16_t             OutEpSize;
-  uint16_t             InEpSize;  
-}
-CDC_DataItfTypedef ;
-
-/* Structure for CDC process */
-typedef struct _CDC_Process
-{
-  CDC_CommItfTypedef                CommItf;
-  CDC_DataItfTypedef                DataItf;
-  uint8_t                           *pTxData;
-  uint8_t                           *pRxData; 
-  uint32_t                           TxDataLength;
-  uint32_t                           RxDataLength;  
-  CDC_InterfaceDesc_Typedef         CDC_Desc;
-  CDC_LineCodingTypeDef             LineCoding;
-  CDC_LineCodingTypeDef             *pUserLineCoding;  
-  CDC_StateTypeDef                  state;
-  CDC_DataStateTypeDef              data_tx_state;
-  CDC_DataStateTypeDef              data_rx_state; 
-  uint8_t                           Rx_Poll;
-}
-CDC_HandleTypeDef;
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_CDC_CORE_Exported_Defines
-* @{
-*/ 
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_CDC_CORE_Exported_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_CDC_CORE_Exported_Variables
-* @{
-*/ 
-extern USBH_ClassTypeDef  CDC_Class;
-#define USBH_CDC_CLASS    &CDC_Class
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_CDC_CORE_Exported_FunctionsPrototype
-* @{
-*/ 
-
-USBH_StatusTypeDef  USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, 
-                                           CDC_LineCodingTypeDef *linecoding);
-
-USBH_StatusTypeDef  USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, 
-                                           CDC_LineCodingTypeDef *linecoding);
-
-USBH_StatusTypeDef  USBH_CDC_Transmit(USBH_HandleTypeDef *phost, 
-                                      uint8_t *pbuff, 
-                                      uint32_t length);
-
-USBH_StatusTypeDef  USBH_CDC_Receive(USBH_HandleTypeDef *phost, 
-                                     uint8_t *pbuff, 
-                                     uint32_t length);
-
-
-uint16_t            USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost);
-
-USBH_StatusTypeDef  USBH_CDC_Stop(USBH_HandleTypeDef *phost);
-
-void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost);
-
-void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost);
-
-void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost);
-
-/**
-* @}
-*/ 
-
-
-#endif /* __USBH_CDC_CORE_H */
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_cdc.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_cdc.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_CDC_CORE_H
+#define __USBH_CDC_CORE_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_CDC_CLASS
+* @{
+*/
+
+/** @defgroup USBH_CDC_CORE
+* @brief This file is the Header file for USBH_CDC_CORE.c
+* @{
+*/ 
+
+
+
+
+/*Communication Class codes*/
+#define USB_CDC_CLASS                                           0x02
+#define COMMUNICATION_INTERFACE_CLASS_CODE                      0x02
+
+/*Data Interface Class Codes*/
+#define DATA_INTERFACE_CLASS_CODE                               0x0A
+
+/*Communcation sub class codes*/
+#define RESERVED                                                0x00
+#define DIRECT_LINE_CONTROL_MODEL                               0x01
+#define ABSTRACT_CONTROL_MODEL                                  0x02
+#define TELEPHONE_CONTROL_MODEL                                 0x03
+#define MULTICHANNEL_CONTROL_MODEL                              0x04   
+#define CAPI_CONTROL_MODEL                                      0x05
+#define ETHERNET_NETWORKING_CONTROL_MODEL                       0x06
+#define ATM_NETWORKING_CONTROL_MODEL                            0x07
+
+
+/*Communication Interface Class Control Protocol Codes*/
+#define NO_CLASS_SPECIFIC_PROTOCOL_CODE                         0x00
+#define COMMON_AT_COMMAND                                       0x01
+#define VENDOR_SPECIFIC                                         0xFF
+
+
+#define CS_INTERFACE                                            0x24
+#define CDC_PAGE_SIZE_64                                        0x40
+
+/*Class-Specific Request Codes*/
+#define CDC_SEND_ENCAPSULATED_COMMAND                           0x00
+#define CDC_GET_ENCAPSULATED_RESPONSE                           0x01
+#define CDC_SET_COMM_FEATURE                                    0x02
+#define CDC_GET_COMM_FEATURE                                    0x03
+#define CDC_CLEAR_COMM_FEATURE                                  0x04
+
+#define CDC_SET_AUX_LINE_STATE                                  0x10
+#define CDC_SET_HOOK_STATE                                      0x11
+#define CDC_PULSE_SETUP                                         0x12
+#define CDC_SEND_PULSE                                          0x13
+#define CDC_SET_PULSE_TIME                                      0x14
+#define CDC_RING_AUX_JACK                                       0x15
+
+#define CDC_SET_LINE_CODING                                     0x20
+#define CDC_GET_LINE_CODING                                     0x21
+#define CDC_SET_CONTROL_LINE_STATE                              0x22
+#define CDC_SEND_BREAK                                          0x23
+
+#define CDC_SET_RINGER_PARMS                                    0x30
+#define CDC_GET_RINGER_PARMS                                    0x31
+#define CDC_SET_OPERATION_PARMS                                 0x32
+#define CDC_GET_OPERATION_PARMS                                 0x33  
+#define CDC_SET_LINE_PARMS                                      0x34
+#define CDC_GET_LINE_PARMS                                      0x35
+#define CDC_DIAL_DIGITS                                         0x36
+#define CDC_SET_UNIT_PARAMETER                                  0x37  
+#define CDC_GET_UNIT_PARAMETER                                  0x38
+#define CDC_CLEAR_UNIT_PARAMETER                                0x39
+#define CDC_GET_PROFILE                                         0x3A
+
+#define CDC_SET_ETHERNET_MULTICAST_FILTERS                      0x40
+#define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER        0x41
+#define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER        0x42
+#define CDC_SET_ETHERNET_PACKET_FILTER                          0x43
+#define CDC_GET_ETHERNET_STATISTIC                              0x44
+
+#define CDC_SET_ATM_DATA_FORMAT                                 0x50  
+#define CDC_GET_ATM_DEVICE_STATISTICS                           0x51
+#define CDC_SET_ATM_DEFAULT_VC                                  0x52
+#define CDC_GET_ATM_VC_STATISTICS                               0x53
+
+
+/* wValue for SetControlLineState*/
+#define CDC_ACTIVATE_CARRIER_SIGNAL_RTS                         0x0002
+#define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS                       0x0000
+#define CDC_ACTIVATE_SIGNAL_DTR                                 0x0001
+#define CDC_DEACTIVATE_SIGNAL_DTR                               0x0000
+
+#define LINE_CODING_STRUCTURE_SIZE                              0x07
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CDC_CORE_Exported_Types
+* @{
+*/ 
+
+/* States for CDC State Machine */
+typedef enum
+{
+  CDC_IDLE= 0,
+  CDC_SEND_DATA,
+  CDC_SEND_DATA_WAIT,
+  CDC_RECEIVE_DATA,
+  CDC_RECEIVE_DATA_WAIT,  
+}
+CDC_DataStateTypeDef;
+
+typedef enum
+{
+  CDC_IDLE_STATE= 0,
+  CDC_SET_LINE_CODING_STATE,  
+  CDC_GET_LAST_LINE_CODING_STATE,    
+  CDC_TRANSFER_DATA, 
+  CDC_ERROR_STATE,  
+}
+CDC_StateTypeDef;
+
+
+/*Line coding structure*/
+typedef union _CDC_LineCodingStructure
+{
+  uint8_t Array[LINE_CODING_STRUCTURE_SIZE];
+  
+  struct
+  {
+    
+    uint32_t             dwDTERate;     /*Data terminal rate, in bits per second*/
+    uint8_t              bCharFormat;   /*Stop bits
+    0 - 1 Stop bit
+    1 - 1.5 Stop bits
+    2 - 2 Stop bits*/
+    uint8_t              bParityType;   /* Parity
+    0 - None
+    1 - Odd
+    2 - Even
+    3 - Mark
+    4 - Space*/
+    uint8_t                bDataBits;     /* Data bits (5, 6, 7, 8 or 16). */
+  }b;
+}
+CDC_LineCodingTypeDef;
+
+
+
+/* Header Functional Descriptor
+--------------------------------------------------------------------------------
+Offset|  field              | Size  |    Value   |   Description                    
+------|---------------------|-------|------------|------------------------------
+0     |  bFunctionLength    | 1     |   number   |  Size of this descriptor.
+1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
+2     |  bDescriptorSubtype | 1     |   Constant |  Identifier (ID) of functional 
+      |                     |       |            | descriptor.
+3     |  bcdCDC             | 2     |            |
+      |                     |       |   Number   | USB Class Definitions for 
+      |                     |       |            | Communication Devices Specification 
+      |                     |       |            | release number in binary-coded 
+      |                     |       |            | decimal
+------|---------------------|-------|------------|------------------------------
+*/
+typedef struct _FunctionalDescriptorHeader
+{
+  uint8_t     bLength;            /*Size of this descriptor.*/
+  uint8_t     bDescriptorType;    /*CS_INTERFACE (0x24)*/
+  uint8_t     bDescriptorSubType; /* Header functional descriptor subtype as*/
+  uint16_t    bcdCDC;             /* USB Class Definitions for Communication
+                                    Devices Specification release number in
+                                  binary-coded decimal. */
+}
+CDC_HeaderFuncDesc_TypeDef;
+/* Call Management Functional Descriptor
+--------------------------------------------------------------------------------
+Offset|  field              | Size  |    Value   |   Description                    
+------|---------------------|-------|------------|------------------------------
+0     |  bFunctionLength    | 1     |   number   |  Size of this descriptor.
+1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
+2     |  bDescriptorSubtype | 1     |   Constant |  Call Management functional 
+      |                     |       |            |  descriptor subtype.
+3     |  bmCapabilities     | 1     |   Bitmap   | The capabilities that this configuration
+      |                     |       |            | supports:
+      |                     |       |            | D7..D2: RESERVED (Reset to zero)
+      |                     |       |            | D1: 0 - Device sends/receives call
+      |                     |       |            | management information only over
+      |                     |       |            | the Communication Class
+      |                     |       |            | interface.
+      |                     |       |            | 1 - Device can send/receive call
+      |                     \       |            | management information over a
+      |                     |       |            | Data Class interface.
+      |                     |       |            | D0: 0 - Device does not handle call
+      |                     |       |            | management itself.
+      |                     |       |            | 1 - Device handles call
+      |                     |       |            | management itself.
+      |                     |       |            | The previous bits, in combination, identify
+      |                     |       |            | which call management scenario is used. If bit
+      |                     |       |            | D0 is reset to 0, then the value of bit D1 is
+      |                     |       |            | ignored. In this case, bit D1 is reset to zero for
+      |                     |       |            | future compatibility.
+4     | bDataInterface      | 1     | Number     | Interface number of Data Class interface
+      |                     |       |            | optionally used for call management.        
+------|---------------------|-------|------------|------------------------------
+*/
+typedef struct _CallMgmtFunctionalDescriptor
+{
+  uint8_t    bLength;            /*Size of this functional descriptor, in bytes.*/
+  uint8_t    bDescriptorType;    /*CS_INTERFACE (0x24)*/
+  uint8_t    bDescriptorSubType; /* Call Management functional descriptor subtype*/
+  uint8_t    bmCapabilities;      /* bmCapabilities: D0+D1 */
+  uint8_t    bDataInterface;      /*bDataInterface: 1*/
+}
+CDC_CallMgmtFuncDesc_TypeDef;
+/* Abstract Control Management Functional Descriptor
+--------------------------------------------------------------------------------
+Offset|  field              | Size  |    Value   |   Description                    
+------|---------------------|-------|------------|------------------------------
+0     |  bFunctionLength    | 1     |   number   |  Size of functional descriptor, in bytes.
+1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
+2     |  bDescriptorSubtype | 1     |   Constant |  Abstract Control Management 
+      |                     |       |            |  functional  descriptor subtype.
+3     |  bmCapabilities     | 1     |   Bitmap   | The capabilities that this configuration
+      |                     |       |            | supports ((A bit value of zero means that the
+      |                     |       |            | request is not supported.) )
+                                                   D7..D4: RESERVED (Reset to zero)
+      |                     |       |            | D3: 1 - Device supports the notification
+      |                     |       |            | Network_Connection.
+      |                     |       |            | D2: 1 - Device supports the request
+      |                     |       |            | Send_Break
+      |                     |       |            | D1: 1 - Device supports the request
+      |                     \       |            | combination of Set_Line_Coding,
+      |                     |       |            | Set_Control_Line_State, Get_Line_Coding, and the
+                                                   notification Serial_State.
+      |                     |       |            | D0: 1 - Device supports the request
+      |                     |       |            | combination of Set_Comm_Feature,
+      |                     |       |            | Clear_Comm_Feature, and Get_Comm_Feature.
+      |                     |       |            | The previous bits, in combination, identify
+      |                     |       |            | which requests/notifications are supported by
+      |                     |       |            | a Communication Class interface with the
+      |                     |       |            |   SubClass code of Abstract Control Model.
+------|---------------------|-------|------------|------------------------------
+*/
+typedef struct _AbstractCntrlMgmtFunctionalDescriptor
+{
+  uint8_t    bLength;            /*Size of this functional descriptor, in bytes.*/
+  uint8_t    bDescriptorType;    /*CS_INTERFACE (0x24)*/
+  uint8_t    bDescriptorSubType; /* Abstract Control Management functional
+                                  descriptor subtype*/
+  uint8_t    bmCapabilities;      /* The capabilities that this configuration supports */
+}
+CDC_AbstCntrlMgmtFuncDesc_TypeDef;
+/* Union Functional Descriptor
+--------------------------------------------------------------------------------
+Offset|  field              | Size  |    Value   |   Description                    
+------|---------------------|-------|------------|------------------------------
+0     |  bFunctionLength    | 1     |   number   |  Size of this descriptor.
+1     |  bDescriptorType    | 1     |   Constant |  CS_INTERFACE (0x24)
+2     |  bDescriptorSubtype | 1     |   Constant |  Union functional 
+      |                     |       |            |  descriptor subtype.
+3     |  bMasterInterface   | 1     |   Constant | The interface number of the 
+      |                     |       |            | Communication or Data Class interface
+4     | bSlaveInterface0    | 1     | Number     | nterface number of first slave or associated
+      |                     |       |            | interface in the union.        
+------|---------------------|-------|------------|------------------------------
+*/
+typedef struct _UnionFunctionalDescriptor
+{
+  uint8_t    bLength;            /*Size of this functional descriptor, in bytes*/
+  uint8_t    bDescriptorType;    /*CS_INTERFACE (0x24)*/
+  uint8_t    bDescriptorSubType; /* Union functional descriptor SubType*/
+  uint8_t    bMasterInterface;   /* The interface number of the Communication or
+                                 Data Class interface,*/
+  uint8_t    bSlaveInterface0;   /*Interface number of first slave*/
+}
+CDC_UnionFuncDesc_TypeDef;
+
+typedef struct _USBH_CDCInterfaceDesc
+{
+  CDC_HeaderFuncDesc_TypeDef           CDC_HeaderFuncDesc;
+  CDC_CallMgmtFuncDesc_TypeDef         CDC_CallMgmtFuncDesc;
+  CDC_AbstCntrlMgmtFuncDesc_TypeDef    CDC_AbstCntrlMgmtFuncDesc;
+  CDC_UnionFuncDesc_TypeDef            CDC_UnionFuncDesc;  
+}
+CDC_InterfaceDesc_Typedef;
+
+
+/* Structure for CDC process */
+typedef struct
+{
+  uint8_t              NotifPipe; 
+  uint8_t              NotifEp;
+  uint8_t              buff[8];
+  uint16_t             NotifEpSize;
+}
+CDC_CommItfTypedef ;
+
+typedef struct
+{
+  uint8_t              InPipe; 
+  uint8_t              OutPipe;
+  uint8_t              OutEp;
+  uint8_t              InEp;
+  uint8_t              buff[8];
+  uint16_t             OutEpSize;
+  uint16_t             InEpSize;  
+}
+CDC_DataItfTypedef ;
+
+/* Structure for CDC process */
+typedef struct _CDC_Process
+{
+  CDC_CommItfTypedef                CommItf;
+  CDC_DataItfTypedef                DataItf;
+  uint8_t                           *pTxData;
+  uint8_t                           *pRxData; 
+  uint32_t                           TxDataLength;
+  uint32_t                           RxDataLength;  
+  CDC_InterfaceDesc_Typedef         CDC_Desc;
+  CDC_LineCodingTypeDef             LineCoding;
+  CDC_LineCodingTypeDef             *pUserLineCoding;  
+  CDC_StateTypeDef                  state;
+  CDC_DataStateTypeDef              data_tx_state;
+  CDC_DataStateTypeDef              data_rx_state; 
+  uint8_t                           Rx_Poll;
+}
+CDC_HandleTypeDef;
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_CDC_CORE_Exported_Defines
+* @{
+*/ 
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_CDC_CORE_Exported_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_CDC_CORE_Exported_Variables
+* @{
+*/ 
+extern USBH_ClassTypeDef  CDC_Class;
+#define USBH_CDC_CLASS    &CDC_Class
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_CDC_CORE_Exported_FunctionsPrototype
+* @{
+*/ 
+
+USBH_StatusTypeDef  USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, 
+                                           CDC_LineCodingTypeDef *linecoding);
+
+USBH_StatusTypeDef  USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, 
+                                           CDC_LineCodingTypeDef *linecoding);
+
+USBH_StatusTypeDef  USBH_CDC_Transmit(USBH_HandleTypeDef *phost, 
+                                      uint8_t *pbuff, 
+                                      uint32_t length);
+
+USBH_StatusTypeDef  USBH_CDC_Receive(USBH_HandleTypeDef *phost, 
+                                     uint8_t *pbuff, 
+                                     uint32_t length);
+
+
+uint16_t            USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost);
+
+USBH_StatusTypeDef  USBH_CDC_Stop(USBH_HandleTypeDef *phost);
+
+void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost);
+
+void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost);
+
+void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost);
+
+/**
+* @}
+*/ 
+
+
+#endif /* __USBH_CDC_CORE_H */
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/CDC/Src/usbh_cdc.c b/micropython/ports/stm32/usbhost/Class/CDC/Src/usbh_cdc.c
index 250e1fc7bf0c7ffce74c5a5d99112d4792c612ce..cf31a24c7cc4ac948c68ffcba0c85584e5c7af46 100644
--- a/micropython/ports/stm32/usbhost/Class/CDC/Src/usbh_cdc.c
+++ b/micropython/ports/stm32/usbhost/Class/CDC/Src/usbh_cdc.c
@@ -1,755 +1,755 @@
-/**
-  ******************************************************************************
-  * @file    usbh_cdc.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the CDC Layer Handlers for USB Host CDC class.
-  *
-  * @verbatim
-  *      
-  *          ===================================================================      
-  *                                CDC Class  Description
-  *          =================================================================== 
-  *           This module manages the MSC class V1.11 following the "Device Class Definition
-  *           for Human Interface Devices (CDC) Version 1.11 Jun 27, 2001".
-  *           This driver implements the following aspects of the specification:
-  *             - The Boot Interface Subclass
-  *             - The Mouse and Keyboard protocols
-  *      
-  *  @endverbatim
-  *
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_cdc.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_CDC_CLASS
-* @{
-*/
-
-/** @defgroup USBH_CDC_CORE 
-* @brief    This file includes CDC Layer Handlers for USB Host CDC class.
-* @{
-*/ 
-
-/** @defgroup USBH_CDC_CORE_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CDC_CORE_Private_Defines
-* @{
-*/ 
-#define USBH_CDC_BUFFER_SIZE                 1024
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CDC_CORE_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CDC_CORE_Private_Variables
-* @{
-*/
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CDC_CORE_Private_FunctionPrototypes
-* @{
-*/ 
-
-static USBH_StatusTypeDef USBH_CDC_InterfaceInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_CDC_Process(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_CDC_SOFProcess(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, 
-                                                 CDC_LineCodingTypeDef *linecoding);
-
-static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost, 
-                                                 CDC_LineCodingTypeDef *linecoding);
-
-static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost);
-
-static void CDC_ProcessReception(USBH_HandleTypeDef *phost);
-
-USBH_ClassTypeDef  CDC_Class = 
-{
-  "CDC",
-  USB_CDC_CLASS,
-  USBH_CDC_InterfaceInit,
-  USBH_CDC_InterfaceDeInit,
-  USBH_CDC_ClassRequest,
-  USBH_CDC_Process,
-  USBH_CDC_SOFProcess,
-  NULL,
-};
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CDC_CORE_Private_Functions
-* @{
-*/ 
-
-/**
-  * @brief  USBH_CDC_InterfaceInit 
-  *         The function init the CDC class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost)
-{	
-
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  uint8_t interface;
-  CDC_HandleTypeDef *CDC_Handle;
-  
-  interface = USBH_FindInterface(phost, 
-                                 COMMUNICATION_INTERFACE_CLASS_CODE, 
-                                 ABSTRACT_CONTROL_MODEL, 
-                                 COMMON_AT_COMMAND);
-  
-  if(interface == 0xFF) /* No Valid Interface */
-  {
-    USBH_DbgLog ("Cannot Find the interface for Communication Interface Class.", phost->pActiveClass->Name);         
-  }
-  else
-  {
-    USBH_SelectInterface (phost, interface);
-    phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc (sizeof(CDC_HandleTypeDef));
-    CDC_Handle =  phost->pActiveClass->pData; 
-    
-    /*Collect the notification endpoint address and length*/
-    if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)
-    {
-      CDC_Handle->CommItf.NotifEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
-      CDC_Handle->CommItf.NotifEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
-    }
-    
-    /*Allocate the length for host channel number in*/
-    CDC_Handle->CommItf.NotifPipe = USBH_AllocPipe(phost, CDC_Handle->CommItf.NotifEp);
-    
-    /* Open pipe for Notification endpoint */
-    USBH_OpenPipe  (phost,
-                    CDC_Handle->CommItf.NotifPipe,
-                    CDC_Handle->CommItf.NotifEp,                            
-                    phost->device.address,
-                    phost->device.speed,
-                    USB_EP_TYPE_INTR,
-                    CDC_Handle->CommItf.NotifEpSize); 
-    
-    USBH_LL_SetToggle (phost, CDC_Handle->CommItf.NotifPipe, 0);    
-    
-    interface = USBH_FindInterface(phost, 
-                                   DATA_INTERFACE_CLASS_CODE, 
-                                   RESERVED, 
-                                   NO_CLASS_SPECIFIC_PROTOCOL_CODE);
-    
-    if(interface == 0xFF) /* No Valid Interface */
-    {
-      USBH_DbgLog ("Cannot Find the interface for Data Interface Class.", phost->pActiveClass->Name);         
-    }
-    else
-    {    
-      /*Collect the class specific endpoint address and length*/
-      if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)
-      {      
-        CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
-        CDC_Handle->DataItf.InEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
-      }
-      else
-      {
-        CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
-        CDC_Handle->DataItf.OutEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
-      }
-      
-      if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress & 0x80)
-      {      
-        CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress;
-        CDC_Handle->DataItf.InEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize;
-      }
-      else
-      {
-        CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress;
-        CDC_Handle->DataItf.OutEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize;
-      }    
-      
-      /*Allocate the length for host channel number out*/
-      CDC_Handle->DataItf.OutPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.OutEp);
-      
-      /*Allocate the length for host channel number in*/
-      CDC_Handle->DataItf.InPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.InEp);  
-      
-      /* Open channel for OUT endpoint */
-      USBH_OpenPipe  (phost,
-                      CDC_Handle->DataItf.OutPipe,
-                      CDC_Handle->DataItf.OutEp,
-                      phost->device.address,
-                      phost->device.speed,
-                      USB_EP_TYPE_BULK,
-                      CDC_Handle->DataItf.OutEpSize);  
-      /* Open channel for IN endpoint */
-      USBH_OpenPipe  (phost,
-                      CDC_Handle->DataItf.InPipe,
-                      CDC_Handle->DataItf.InEp,
-                      phost->device.address,
-                      phost->device.speed,
-                      USB_EP_TYPE_BULK,
-                      CDC_Handle->DataItf.InEpSize);
-      
-      CDC_Handle->state = CDC_IDLE_STATE;
-      
-      USBH_LL_SetToggle  (phost, CDC_Handle->DataItf.OutPipe,0);
-      USBH_LL_SetToggle  (phost, CDC_Handle->DataItf.InPipe,0);
-      status = USBH_OK; 
-    }
-  }
-  return status;
-}
-
-
-
-/**
-  * @brief  USBH_CDC_InterfaceDeInit 
-  *         The function DeInit the Pipes used for the CDC class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_CDC_InterfaceDeInit (USBH_HandleTypeDef *phost)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
-  
-  if ( CDC_Handle->CommItf.NotifPipe)
-  {
-    USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe);
-    USBH_FreePipe  (phost, CDC_Handle->CommItf.NotifPipe);
-    CDC_Handle->CommItf.NotifPipe = 0;     /* Reset the Channel as Free */
-  }
-  
-  if ( CDC_Handle->DataItf.InPipe)
-  {
-    USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe);
-    USBH_FreePipe  (phost, CDC_Handle->DataItf.InPipe);
-    CDC_Handle->DataItf.InPipe = 0;     /* Reset the Channel as Free */
-  }
-  
-  if ( CDC_Handle->DataItf.OutPipe)
-  {
-    USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe);
-    USBH_FreePipe  (phost, CDC_Handle->DataItf.OutPipe);
-    CDC_Handle->DataItf.OutPipe = 0;     /* Reset the Channel as Free */
-  } 
-  
-  if(phost->pActiveClass->pData)
-  {
-    USBH_free (phost->pActiveClass->pData);
-    phost->pActiveClass->pData = 0;
-  }
-   
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_CDC_ClassRequest 
-  *         The function is responsible for handling Standard requests
-  *         for CDC class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost)
-{   
-  USBH_StatusTypeDef status = USBH_FAIL ;  
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;  
-  
-  /*Issue the get line coding request*/
-  status =   GetLineCoding(phost, &CDC_Handle->LineCoding);
-  if(status == USBH_OK)
-  {
-    phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
-  }
-  return status;
-}
-
-
-/**
-  * @brief  USBH_CDC_Process 
-  *         The function is for managing state machine for CDC data transfers 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_CDC_Process (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY;
-  USBH_StatusTypeDef req_status = USBH_OK;
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
-  
-  switch(CDC_Handle->state)
-  {
-    
-  case CDC_IDLE_STATE:
-    status = USBH_OK;
-    break;
-    
-  case CDC_SET_LINE_CODING_STATE:
-    req_status = SetLineCoding(phost, CDC_Handle->pUserLineCoding);
-    
-    if(req_status == USBH_OK)
-    {
-      CDC_Handle->state = CDC_GET_LAST_LINE_CODING_STATE; 
-    }
-    
-    else if(req_status != USBH_BUSY)
-    {
-      CDC_Handle->state = CDC_ERROR_STATE; 
-    }
-    break;
-    
-    
-  case CDC_GET_LAST_LINE_CODING_STATE:
-    req_status = GetLineCoding(phost, &(CDC_Handle->LineCoding));
-    
-    if(req_status == USBH_OK)
-    {
-      CDC_Handle->state = CDC_IDLE_STATE; 
-      
-      if((CDC_Handle->LineCoding.b.bCharFormat == CDC_Handle->pUserLineCoding->b.bCharFormat) && 
-         (CDC_Handle->LineCoding.b.bDataBits == CDC_Handle->pUserLineCoding->b.bDataBits) &&
-         (CDC_Handle->LineCoding.b.bParityType == CDC_Handle->pUserLineCoding->b.bParityType) &&
-         (CDC_Handle->LineCoding.b.dwDTERate == CDC_Handle->pUserLineCoding->b.dwDTERate))
-      {
-        USBH_CDC_LineCodingChanged(phost);
-      }
-    }
-    
-    else if(req_status != USBH_BUSY)
-    {
-      CDC_Handle->state = CDC_ERROR_STATE; 
-    }   
-
-    break;
-    
-  case CDC_TRANSFER_DATA:
-    CDC_ProcessTransmission(phost);
-    CDC_ProcessReception(phost);
-    break;   
-    
-  case CDC_ERROR_STATE:
-    req_status = USBH_ClrFeature(phost, 0x00); 
-    
-    if(req_status == USBH_OK )
-    {        
-      /*Change the state to waiting*/
-      CDC_Handle->state = CDC_IDLE_STATE ;
-    }    
-    break;
-    
-  default:
-    break;
-    
-  }
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_CDC_SOFProcess 
-  *         The function is for managing SOF callback 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_CDC_SOFProcess (USBH_HandleTypeDef *phost)
-{
-  return USBH_OK;  
-}
-                                   
-  
-  /**
-  * @brief  USBH_CDC_Stop 
-  *         Stop current CDC Transmission 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_CDC_Stop(USBH_HandleTypeDef *phost)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    CDC_Handle->state = CDC_IDLE_STATE;
-    
-    USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe);
-    USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe);
-    USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe);
-  }
-  return USBH_OK;  
-}
-/**
-  * @brief  This request allows the host to find out the currently 
-  *         configured line coding.
-  * @param  pdev: Selected device
-  * @retval USBH_StatusTypeDef : USB ctl xfer status
-  */
-static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding)
-{
- 
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \
-                              USB_REQ_RECIPIENT_INTERFACE;
-  
-  phost->Control.setup.b.bRequest = CDC_GET_LINE_CODING;
-  phost->Control.setup.b.wValue.w = 0;
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE;           
- 
-  return USBH_CtlReq(phost, linecoding->Array, LINE_CODING_STRUCTURE_SIZE);
-}
-
-
-/**
-  * @brief  This request allows the host to specify typical asynchronous 
-  * line-character formatting properties 
-  * This request applies to asynchronous byte stream data class interfaces 
-  * and endpoints
-  * @param  pdev: Selected device
-  * @retval USBH_StatusTypeDef : USB ctl xfer status
-  */
-static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecodin)
-{
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | \
-                              USB_REQ_RECIPIENT_INTERFACE;
-  
-  phost->Control.setup.b.bRequest = CDC_SET_LINE_CODING;
-  phost->Control.setup.b.wValue.w = 0;
-
-  phost->Control.setup.b.wIndex.w = 0;
-
-  phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE;           
-  
-  return USBH_CtlReq(phost, linecodin->Array , LINE_CODING_STRUCTURE_SIZE );  
-}
-
-/**
-* @brief  This function prepares the state before issuing the class specific commands
-* @param  None
-* @retval None
-*/
-USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecodin)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
-  if(phost->gState == HOST_CLASS)
-  {
-    CDC_Handle->state = CDC_SET_LINE_CODING_STATE;
-    CDC_Handle->pUserLineCoding = linecodin;    
-    
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif  
-  }    
-  return USBH_OK;
-}
-
-/**
-* @brief  This function prepares the state before issuing the class specific commands
-* @param  None
-* @retval None
-*/
-USBH_StatusTypeDef  USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecodin)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
-  
-  if((phost->gState == HOST_CLASS) ||(phost->gState == HOST_CLASS_REQUEST))
-  {
-    *linecodin = CDC_Handle->LineCoding;
-    return USBH_OK;
-  }
-  else
-  {
-    return USBH_FAIL;
-  }
-}
-
-/**
-  * @brief  This function return last recieved data size
-  * @param  None
-  * @retval None
-  */
-uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    return USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);;
-  }
-  else
-  {
-    return 0;
-  }
-}
-
-/**
-  * @brief  This function prepares the state before issuing the class specific commands
-  * @param  None
-  * @retval None
-  */
-USBH_StatusTypeDef  USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
-{
-  USBH_StatusTypeDef Status = USBH_BUSY;
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
-  
-  if((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))
-  {
-    CDC_Handle->pTxData = pbuff;
-    CDC_Handle->TxDataLength = length;  
-    CDC_Handle->state = CDC_TRANSFER_DATA;
-    CDC_Handle->data_tx_state = CDC_SEND_DATA; 
-    Status = USBH_OK;
-  }
-  return Status;    
-}
-  
-  
-/**
-* @brief  This function prepares the state before issuing the class specific commands
-* @param  None
-* @retval None
-*/
-USBH_StatusTypeDef  USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
-{
-  USBH_StatusTypeDef Status = USBH_BUSY;
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
-  
-  if((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))
-  {
-    CDC_Handle->pRxData = pbuff;
-    CDC_Handle->RxDataLength = length;  
-    CDC_Handle->state = CDC_TRANSFER_DATA;
-    CDC_Handle->data_rx_state = CDC_RECEIVE_DATA;     
-    Status = USBH_OK;
-  }
-  return Status;    
-} 
-
-/**
-* @brief  The function is responsible for sending data to the device
-*  @param  pdev: Selected device
-* @retval None
-*/
-static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
-  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
-  
-  switch(CDC_Handle->data_tx_state)
-  {
- 
-  case CDC_SEND_DATA:
-    if(CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize)
-    {
-      USBH_BulkSendData (phost,
-                         CDC_Handle->pTxData, 
-                         CDC_Handle->DataItf.OutEpSize, 
-                         CDC_Handle->DataItf.OutPipe,
-                         1);
-    }
-    else
-    {
-      USBH_BulkSendData (phost,
-                         CDC_Handle->pTxData, 
-                         CDC_Handle->TxDataLength, 
-                         CDC_Handle->DataItf.OutPipe,
-                         1);
-    }
-    
-    CDC_Handle->data_tx_state = CDC_SEND_DATA_WAIT;
-    
-    break;
-    
-  case CDC_SEND_DATA_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.OutPipe); 
-    
-    /*Check the status done for transmssion*/
-    if(URB_Status == USBH_URB_DONE )
-    {         
-      if(CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize)
-      {
-        CDC_Handle->TxDataLength -= CDC_Handle->DataItf.OutEpSize ;
-        CDC_Handle->pTxData += CDC_Handle->DataItf.OutEpSize;
-      }
-      else
-      {
-        CDC_Handle->TxDataLength = 0;
-      }
-      
-      if( CDC_Handle->TxDataLength > 0)
-      {
-       CDC_Handle->data_tx_state = CDC_SEND_DATA; 
-      }
-      else
-      {
-        CDC_Handle->data_tx_state = CDC_IDLE;    
-        USBH_CDC_TransmitCallback(phost);
-
-      }
-    }
-    else if( URB_Status == USBH_URB_NOTREADY )
-    {
-      CDC_Handle->data_tx_state = CDC_SEND_DATA; 
-    }
-    break;
-  default:
-    break;
-  }
-}
-/**
-* @brief  This function responsible for reception of data from the device
-*  @param  pdev: Selected device
-* @retval None
-*/
-
-static void CDC_ProcessReception(USBH_HandleTypeDef *phost)
-{
-  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
-  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
-  uint16_t length;
-
-  switch(CDC_Handle->data_rx_state)
-  {
-    
-  case CDC_RECEIVE_DATA:
-
-    USBH_BulkReceiveData (phost,
-                          CDC_Handle->pRxData, 
-                          CDC_Handle->DataItf.InEpSize, 
-                          CDC_Handle->DataItf.InPipe);
-    
-    CDC_Handle->data_rx_state = CDC_RECEIVE_DATA_WAIT;
-    
-    break;
-    
-  case CDC_RECEIVE_DATA_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.InPipe); 
-    
-    /*Check the status done for reception*/
-    if(URB_Status == USBH_URB_DONE )
-    {  
-      length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);
-        
-      if(((CDC_Handle->RxDataLength - length) > 0) && (length > CDC_Handle->DataItf.InEpSize))
-      {
-        CDC_Handle->RxDataLength -= length ;
-        CDC_Handle->pRxData += length;
-        CDC_Handle->data_rx_state = CDC_RECEIVE_DATA; 
-      }
-      else
-      {
-        CDC_Handle->data_rx_state = CDC_IDLE;
-        USBH_CDC_ReceiveCallback(phost);
-      }
-    }
-    break;
-    
-  default:
-    break;
-  }
-}
-
-/**
-* @brief  The function informs user that data have been received
-*  @param  pdev: Selected device
-* @retval None
-*/
-__weak void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost)
-{
-  
-}
-  
-  /**
-* @brief  The function informs user that data have been sent
-*  @param  pdev: Selected device
-* @retval None
-*/
-__weak void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)
-{
-  
-}
-
-  /**
-* @brief  The function informs user that Settings have been changed
-*  @param  pdev: Selected device
-* @retval None
-*/
-__weak void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost)
-{
-  
-}
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_cdc.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the CDC Layer Handlers for USB Host CDC class.
+  *
+  * @verbatim
+  *      
+  *          ===================================================================      
+  *                                CDC Class  Description
+  *          =================================================================== 
+  *           This module manages the MSC class V1.11 following the "Device Class Definition
+  *           for Human Interface Devices (CDC) Version 1.11 Jun 27, 2001".
+  *           This driver implements the following aspects of the specification:
+  *             - The Boot Interface Subclass
+  *             - The Mouse and Keyboard protocols
+  *      
+  *  @endverbatim
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_cdc.h"
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_CDC_CLASS
+* @{
+*/
+
+/** @defgroup USBH_CDC_CORE 
+* @brief    This file includes CDC Layer Handlers for USB Host CDC class.
+* @{
+*/ 
+
+/** @defgroup USBH_CDC_CORE_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CDC_CORE_Private_Defines
+* @{
+*/ 
+#define USBH_CDC_BUFFER_SIZE                 1024
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CDC_CORE_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CDC_CORE_Private_Variables
+* @{
+*/
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CDC_CORE_Private_FunctionPrototypes
+* @{
+*/ 
+
+static USBH_StatusTypeDef USBH_CDC_InterfaceInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_CDC_Process(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_CDC_SOFProcess(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, 
+                                                 CDC_LineCodingTypeDef *linecoding);
+
+static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost, 
+                                                 CDC_LineCodingTypeDef *linecoding);
+
+static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost);
+
+static void CDC_ProcessReception(USBH_HandleTypeDef *phost);
+
+USBH_ClassTypeDef  CDC_Class = 
+{
+  "CDC",
+  USB_CDC_CLASS,
+  USBH_CDC_InterfaceInit,
+  USBH_CDC_InterfaceDeInit,
+  USBH_CDC_ClassRequest,
+  USBH_CDC_Process,
+  USBH_CDC_SOFProcess,
+  NULL,
+};
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CDC_CORE_Private_Functions
+* @{
+*/ 
+
+/**
+  * @brief  USBH_CDC_InterfaceInit 
+  *         The function init the CDC class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost)
+{	
+
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  uint8_t interface;
+  CDC_HandleTypeDef *CDC_Handle;
+  
+  interface = USBH_FindInterface(phost, 
+                                 COMMUNICATION_INTERFACE_CLASS_CODE, 
+                                 ABSTRACT_CONTROL_MODEL, 
+                                 COMMON_AT_COMMAND);
+  
+  if(interface == 0xFF) /* No Valid Interface */
+  {
+    USBH_DbgLog ("Cannot Find the interface for Communication Interface Class.", phost->pActiveClass->Name);         
+  }
+  else
+  {
+    USBH_SelectInterface (phost, interface);
+    phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc (sizeof(CDC_HandleTypeDef));
+    CDC_Handle =  phost->pActiveClass->pData; 
+    
+    /*Collect the notification endpoint address and length*/
+    if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)
+    {
+      CDC_Handle->CommItf.NotifEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
+      CDC_Handle->CommItf.NotifEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
+    }
+    
+    /*Allocate the length for host channel number in*/
+    CDC_Handle->CommItf.NotifPipe = USBH_AllocPipe(phost, CDC_Handle->CommItf.NotifEp);
+    
+    /* Open pipe for Notification endpoint */
+    USBH_OpenPipe  (phost,
+                    CDC_Handle->CommItf.NotifPipe,
+                    CDC_Handle->CommItf.NotifEp,                            
+                    phost->device.address,
+                    phost->device.speed,
+                    USB_EP_TYPE_INTR,
+                    CDC_Handle->CommItf.NotifEpSize); 
+    
+    USBH_LL_SetToggle (phost, CDC_Handle->CommItf.NotifPipe, 0);    
+    
+    interface = USBH_FindInterface(phost, 
+                                   DATA_INTERFACE_CLASS_CODE, 
+                                   RESERVED, 
+                                   NO_CLASS_SPECIFIC_PROTOCOL_CODE);
+    
+    if(interface == 0xFF) /* No Valid Interface */
+    {
+      USBH_DbgLog ("Cannot Find the interface for Data Interface Class.", phost->pActiveClass->Name);         
+    }
+    else
+    {    
+      /*Collect the class specific endpoint address and length*/
+      if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)
+      {      
+        CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
+        CDC_Handle->DataItf.InEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
+      }
+      else
+      {
+        CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
+        CDC_Handle->DataItf.OutEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
+      }
+      
+      if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress & 0x80)
+      {      
+        CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress;
+        CDC_Handle->DataItf.InEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize;
+      }
+      else
+      {
+        CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress;
+        CDC_Handle->DataItf.OutEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize;
+      }    
+      
+      /*Allocate the length for host channel number out*/
+      CDC_Handle->DataItf.OutPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.OutEp);
+      
+      /*Allocate the length for host channel number in*/
+      CDC_Handle->DataItf.InPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.InEp);  
+      
+      /* Open channel for OUT endpoint */
+      USBH_OpenPipe  (phost,
+                      CDC_Handle->DataItf.OutPipe,
+                      CDC_Handle->DataItf.OutEp,
+                      phost->device.address,
+                      phost->device.speed,
+                      USB_EP_TYPE_BULK,
+                      CDC_Handle->DataItf.OutEpSize);  
+      /* Open channel for IN endpoint */
+      USBH_OpenPipe  (phost,
+                      CDC_Handle->DataItf.InPipe,
+                      CDC_Handle->DataItf.InEp,
+                      phost->device.address,
+                      phost->device.speed,
+                      USB_EP_TYPE_BULK,
+                      CDC_Handle->DataItf.InEpSize);
+      
+      CDC_Handle->state = CDC_IDLE_STATE;
+      
+      USBH_LL_SetToggle  (phost, CDC_Handle->DataItf.OutPipe,0);
+      USBH_LL_SetToggle  (phost, CDC_Handle->DataItf.InPipe,0);
+      status = USBH_OK; 
+    }
+  }
+  return status;
+}
+
+
+
+/**
+  * @brief  USBH_CDC_InterfaceDeInit 
+  *         The function DeInit the Pipes used for the CDC class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_CDC_InterfaceDeInit (USBH_HandleTypeDef *phost)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
+  
+  if ( CDC_Handle->CommItf.NotifPipe)
+  {
+    USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe);
+    USBH_FreePipe  (phost, CDC_Handle->CommItf.NotifPipe);
+    CDC_Handle->CommItf.NotifPipe = 0;     /* Reset the Channel as Free */
+  }
+  
+  if ( CDC_Handle->DataItf.InPipe)
+  {
+    USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe);
+    USBH_FreePipe  (phost, CDC_Handle->DataItf.InPipe);
+    CDC_Handle->DataItf.InPipe = 0;     /* Reset the Channel as Free */
+  }
+  
+  if ( CDC_Handle->DataItf.OutPipe)
+  {
+    USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe);
+    USBH_FreePipe  (phost, CDC_Handle->DataItf.OutPipe);
+    CDC_Handle->DataItf.OutPipe = 0;     /* Reset the Channel as Free */
+  } 
+  
+  if(phost->pActiveClass->pData)
+  {
+    USBH_free (phost->pActiveClass->pData);
+    phost->pActiveClass->pData = 0;
+  }
+   
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_CDC_ClassRequest 
+  *         The function is responsible for handling Standard requests
+  *         for CDC class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost)
+{   
+  USBH_StatusTypeDef status = USBH_FAIL ;  
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;  
+  
+  /*Issue the get line coding request*/
+  status =   GetLineCoding(phost, &CDC_Handle->LineCoding);
+  if(status == USBH_OK)
+  {
+    phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
+  }
+  return status;
+}
+
+
+/**
+  * @brief  USBH_CDC_Process 
+  *         The function is for managing state machine for CDC data transfers 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_CDC_Process (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY;
+  USBH_StatusTypeDef req_status = USBH_OK;
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
+  
+  switch(CDC_Handle->state)
+  {
+    
+  case CDC_IDLE_STATE:
+    status = USBH_OK;
+    break;
+    
+  case CDC_SET_LINE_CODING_STATE:
+    req_status = SetLineCoding(phost, CDC_Handle->pUserLineCoding);
+    
+    if(req_status == USBH_OK)
+    {
+      CDC_Handle->state = CDC_GET_LAST_LINE_CODING_STATE; 
+    }
+    
+    else if(req_status != USBH_BUSY)
+    {
+      CDC_Handle->state = CDC_ERROR_STATE; 
+    }
+    break;
+    
+    
+  case CDC_GET_LAST_LINE_CODING_STATE:
+    req_status = GetLineCoding(phost, &(CDC_Handle->LineCoding));
+    
+    if(req_status == USBH_OK)
+    {
+      CDC_Handle->state = CDC_IDLE_STATE; 
+      
+      if((CDC_Handle->LineCoding.b.bCharFormat == CDC_Handle->pUserLineCoding->b.bCharFormat) && 
+         (CDC_Handle->LineCoding.b.bDataBits == CDC_Handle->pUserLineCoding->b.bDataBits) &&
+         (CDC_Handle->LineCoding.b.bParityType == CDC_Handle->pUserLineCoding->b.bParityType) &&
+         (CDC_Handle->LineCoding.b.dwDTERate == CDC_Handle->pUserLineCoding->b.dwDTERate))
+      {
+        USBH_CDC_LineCodingChanged(phost);
+      }
+    }
+    
+    else if(req_status != USBH_BUSY)
+    {
+      CDC_Handle->state = CDC_ERROR_STATE; 
+    }   
+
+    break;
+    
+  case CDC_TRANSFER_DATA:
+    CDC_ProcessTransmission(phost);
+    CDC_ProcessReception(phost);
+    break;   
+    
+  case CDC_ERROR_STATE:
+    req_status = USBH_ClrFeature(phost, 0x00); 
+    
+    if(req_status == USBH_OK )
+    {        
+      /*Change the state to waiting*/
+      CDC_Handle->state = CDC_IDLE_STATE ;
+    }    
+    break;
+    
+  default:
+    break;
+    
+  }
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_CDC_SOFProcess 
+  *         The function is for managing SOF callback 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_CDC_SOFProcess (USBH_HandleTypeDef *phost)
+{
+  return USBH_OK;  
+}
+                                   
+  
+  /**
+  * @brief  USBH_CDC_Stop 
+  *         Stop current CDC Transmission 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_CDC_Stop(USBH_HandleTypeDef *phost)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    CDC_Handle->state = CDC_IDLE_STATE;
+    
+    USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe);
+    USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe);
+    USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe);
+  }
+  return USBH_OK;  
+}
+/**
+  * @brief  This request allows the host to find out the currently 
+  *         configured line coding.
+  * @param  pdev: Selected device
+  * @retval USBH_StatusTypeDef : USB ctl xfer status
+  */
+static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding)
+{
+ 
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \
+                              USB_REQ_RECIPIENT_INTERFACE;
+  
+  phost->Control.setup.b.bRequest = CDC_GET_LINE_CODING;
+  phost->Control.setup.b.wValue.w = 0;
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE;           
+ 
+  return USBH_CtlReq(phost, linecoding->Array, LINE_CODING_STRUCTURE_SIZE);
+}
+
+
+/**
+  * @brief  This request allows the host to specify typical asynchronous 
+  * line-character formatting properties 
+  * This request applies to asynchronous byte stream data class interfaces 
+  * and endpoints
+  * @param  pdev: Selected device
+  * @retval USBH_StatusTypeDef : USB ctl xfer status
+  */
+static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecodin)
+{
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | \
+                              USB_REQ_RECIPIENT_INTERFACE;
+  
+  phost->Control.setup.b.bRequest = CDC_SET_LINE_CODING;
+  phost->Control.setup.b.wValue.w = 0;
+
+  phost->Control.setup.b.wIndex.w = 0;
+
+  phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE;           
+  
+  return USBH_CtlReq(phost, linecodin->Array , LINE_CODING_STRUCTURE_SIZE );  
+}
+
+/**
+* @brief  This function prepares the state before issuing the class specific commands
+* @param  None
+* @retval None
+*/
+USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecodin)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
+  if(phost->gState == HOST_CLASS)
+  {
+    CDC_Handle->state = CDC_SET_LINE_CODING_STATE;
+    CDC_Handle->pUserLineCoding = linecodin;    
+    
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif  
+  }    
+  return USBH_OK;
+}
+
+/**
+* @brief  This function prepares the state before issuing the class specific commands
+* @param  None
+* @retval None
+*/
+USBH_StatusTypeDef  USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecodin)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
+  
+  if((phost->gState == HOST_CLASS) ||(phost->gState == HOST_CLASS_REQUEST))
+  {
+    *linecodin = CDC_Handle->LineCoding;
+    return USBH_OK;
+  }
+  else
+  {
+    return USBH_FAIL;
+  }
+}
+
+/**
+  * @brief  This function return last recieved data size
+  * @param  None
+  * @retval None
+  */
+uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData; 
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    return USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);;
+  }
+  else
+  {
+    return 0;
+  }
+}
+
+/**
+  * @brief  This function prepares the state before issuing the class specific commands
+  * @param  None
+  * @retval None
+  */
+USBH_StatusTypeDef  USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
+{
+  USBH_StatusTypeDef Status = USBH_BUSY;
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
+  
+  if((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))
+  {
+    CDC_Handle->pTxData = pbuff;
+    CDC_Handle->TxDataLength = length;  
+    CDC_Handle->state = CDC_TRANSFER_DATA;
+    CDC_Handle->data_tx_state = CDC_SEND_DATA; 
+    Status = USBH_OK;
+  }
+  return Status;    
+}
+  
+  
+/**
+* @brief  This function prepares the state before issuing the class specific commands
+* @param  None
+* @retval None
+*/
+USBH_StatusTypeDef  USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
+{
+  USBH_StatusTypeDef Status = USBH_BUSY;
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
+  
+  if((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))
+  {
+    CDC_Handle->pRxData = pbuff;
+    CDC_Handle->RxDataLength = length;  
+    CDC_Handle->state = CDC_TRANSFER_DATA;
+    CDC_Handle->data_rx_state = CDC_RECEIVE_DATA;     
+    Status = USBH_OK;
+  }
+  return Status;    
+} 
+
+/**
+* @brief  The function is responsible for sending data to the device
+*  @param  pdev: Selected device
+* @retval None
+*/
+static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
+  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
+  
+  switch(CDC_Handle->data_tx_state)
+  {
+ 
+  case CDC_SEND_DATA:
+    if(CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize)
+    {
+      USBH_BulkSendData (phost,
+                         CDC_Handle->pTxData, 
+                         CDC_Handle->DataItf.OutEpSize, 
+                         CDC_Handle->DataItf.OutPipe,
+                         1);
+    }
+    else
+    {
+      USBH_BulkSendData (phost,
+                         CDC_Handle->pTxData, 
+                         CDC_Handle->TxDataLength, 
+                         CDC_Handle->DataItf.OutPipe,
+                         1);
+    }
+    
+    CDC_Handle->data_tx_state = CDC_SEND_DATA_WAIT;
+    
+    break;
+    
+  case CDC_SEND_DATA_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.OutPipe); 
+    
+    /*Check the status done for transmssion*/
+    if(URB_Status == USBH_URB_DONE )
+    {         
+      if(CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize)
+      {
+        CDC_Handle->TxDataLength -= CDC_Handle->DataItf.OutEpSize ;
+        CDC_Handle->pTxData += CDC_Handle->DataItf.OutEpSize;
+      }
+      else
+      {
+        CDC_Handle->TxDataLength = 0;
+      }
+      
+      if( CDC_Handle->TxDataLength > 0)
+      {
+       CDC_Handle->data_tx_state = CDC_SEND_DATA; 
+      }
+      else
+      {
+        CDC_Handle->data_tx_state = CDC_IDLE;    
+        USBH_CDC_TransmitCallback(phost);
+
+      }
+    }
+    else if( URB_Status == USBH_URB_NOTREADY )
+    {
+      CDC_Handle->data_tx_state = CDC_SEND_DATA; 
+    }
+    break;
+  default:
+    break;
+  }
+}
+/**
+* @brief  This function responsible for reception of data from the device
+*  @param  pdev: Selected device
+* @retval None
+*/
+
+static void CDC_ProcessReception(USBH_HandleTypeDef *phost)
+{
+  CDC_HandleTypeDef *CDC_Handle =  phost->pActiveClass->pData;
+  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
+  uint16_t length;
+
+  switch(CDC_Handle->data_rx_state)
+  {
+    
+  case CDC_RECEIVE_DATA:
+
+    USBH_BulkReceiveData (phost,
+                          CDC_Handle->pRxData, 
+                          CDC_Handle->DataItf.InEpSize, 
+                          CDC_Handle->DataItf.InPipe);
+    
+    CDC_Handle->data_rx_state = CDC_RECEIVE_DATA_WAIT;
+    
+    break;
+    
+  case CDC_RECEIVE_DATA_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.InPipe); 
+    
+    /*Check the status done for reception*/
+    if(URB_Status == USBH_URB_DONE )
+    {  
+      length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);
+        
+      if(((CDC_Handle->RxDataLength - length) > 0) && (length > CDC_Handle->DataItf.InEpSize))
+      {
+        CDC_Handle->RxDataLength -= length ;
+        CDC_Handle->pRxData += length;
+        CDC_Handle->data_rx_state = CDC_RECEIVE_DATA; 
+      }
+      else
+      {
+        CDC_Handle->data_rx_state = CDC_IDLE;
+        USBH_CDC_ReceiveCallback(phost);
+      }
+    }
+    break;
+    
+  default:
+    break;
+  }
+}
+
+/**
+* @brief  The function informs user that data have been received
+*  @param  pdev: Selected device
+* @retval None
+*/
+__weak void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost)
+{
+  
+}
+  
+  /**
+* @brief  The function informs user that data have been sent
+*  @param  pdev: Selected device
+* @retval None
+*/
+__weak void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)
+{
+  
+}
+
+  /**
+* @brief  The function informs user that Settings have been changed
+*  @param  pdev: Selected device
+* @retval None
+*/
+__weak void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost)
+{
+  
+}
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h
index 38302ad0d44b1f0b3cc211b8bf179f9224e42ffc..34b832094ec765d197a8e0583eada30b8bef2e1a 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h
+++ b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h
@@ -1,341 +1,341 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_hid.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_HID_H
-#define __USBH_HID_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-#include "usbh_hid_mouse.h"
-#include "usbh_hid_keybd.h"
- 
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_HID_CORE
-  * @brief This file is the Header file for USBH_HID_CORE.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_HID_CORE_Exported_Types
-  * @{
-  */ 
-
-#define HID_MIN_POLL                10
-#define HID_REPORT_SIZE             16    
-#define HID_MAX_USAGE               10
-#define HID_MAX_NBR_REPORT_FMT      10 
-#define HID_QUEUE_SIZE              10    
-    
-#define  HID_ITEM_LONG                              0xFE
-                                                                       
-#define  HID_ITEM_TYPE_MAIN                         0x00
-#define  HID_ITEM_TYPE_GLOBAL                       0x01
-#define  HID_ITEM_TYPE_LOCAL                        0x02
-#define  HID_ITEM_TYPE_RESERVED                     0x03
-
-                                                                         
-#define  HID_MAIN_ITEM_TAG_INPUT                    0x08
-#define  HID_MAIN_ITEM_TAG_OUTPUT                   0x09
-#define  HID_MAIN_ITEM_TAG_COLLECTION               0x0A
-#define  HID_MAIN_ITEM_TAG_FEATURE                  0x0B
-#define  HID_MAIN_ITEM_TAG_ENDCOLLECTION            0x0C
-
-                                                                         
-#define  HID_GLOBAL_ITEM_TAG_USAGE_PAGE             0x00
-#define  HID_GLOBAL_ITEM_TAG_LOG_MIN                0x01
-#define  HID_GLOBAL_ITEM_TAG_LOG_MAX                0x02
-#define  HID_GLOBAL_ITEM_TAG_PHY_MIN                0x03
-#define  HID_GLOBAL_ITEM_TAG_PHY_MAX                0x04
-#define  HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT          0x05
-#define  HID_GLOBAL_ITEM_TAG_UNIT                   0x06
-#define  HID_GLOBAL_ITEM_TAG_REPORT_SIZE            0x07
-#define  HID_GLOBAL_ITEM_TAG_REPORT_ID              0x08
-#define  HID_GLOBAL_ITEM_TAG_REPORT_COUNT           0x09
-#define  HID_GLOBAL_ITEM_TAG_PUSH                   0x0A
-#define  HID_GLOBAL_ITEM_TAG_POP                    0x0B
-
-                                                                         
-#define  HID_LOCAL_ITEM_TAG_USAGE                   0x00
-#define  HID_LOCAL_ITEM_TAG_USAGE_MIN               0x01
-#define  HID_LOCAL_ITEM_TAG_USAGE_MAX               0x02
-#define  HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX        0x03
-#define  HID_LOCAL_ITEM_TAG_DESIGNATOR_MIN          0x04
-#define  HID_LOCAL_ITEM_TAG_DESIGNATOR_MAX          0x05
-#define  HID_LOCAL_ITEM_TAG_STRING_INDEX            0x07
-#define  HID_LOCAL_ITEM_TAG_STRING_MIN              0x08
-#define  HID_LOCAL_ITEM_TAG_STRING_MAX              0x09
-#define  HID_LOCAL_ITEM_TAG_DELIMITER               0x0A
-    
-
-/* States for HID State Machine */
-typedef enum
-{
-  HID_INIT= 0,  
-  HID_IDLE,
-  HID_SEND_DATA,
-  HID_BUSY,
-  HID_GET_DATA,   
-  HID_SYNC,     
-  HID_POLL,
-  HID_ERROR,
-}
-HID_StateTypeDef;
-
-typedef enum
-{
-  HID_REQ_INIT = 0,
-  HID_REQ_IDLE, 
-  HID_REQ_GET_REPORT_DESC,
-  HID_REQ_GET_HID_DESC,
-  HID_REQ_SET_IDLE,
-  HID_REQ_SET_PROTOCOL,
-  HID_REQ_SET_REPORT,
-
-}
-HID_CtlStateTypeDef;
-
-typedef enum
-{
-  HID_MOUSE    = 0x01,
-  HID_KEYBOARD = 0x02,
-  HID_UNKNOWN = 0xFF,
-}
-HID_TypeTypeDef;
-
-
-typedef  struct  _HID_ReportData 
-{
-    uint8_t   ReportID;    
-    uint8_t   ReportType;  
-    uint16_t  UsagePage;   
-    uint32_t  Usage[HID_MAX_USAGE]; 
-    uint32_t  NbrUsage;                      
-    uint32_t  UsageMin;                      
-    uint32_t  UsageMax;                      
-    int32_t   LogMin;                        
-    int32_t   LogMax;                        
-    int32_t   PhyMin;                        
-    int32_t   PhyMax;                        
-    int32_t   UnitExp;                       
-    uint32_t  Unit;                          
-    uint32_t  ReportSize;                    
-    uint32_t  ReportCnt;                     
-    uint32_t  Flag;                          
-    uint32_t  PhyUsage;                      
-    uint32_t  AppUsage;                      
-    uint32_t  LogUsage;   
-} 
-HID_ReportDataTypeDef;
-
-typedef  struct  _HID_ReportIDTypeDef {
-    uint8_t  Size;         /* Report size return by the device id            */
-    uint8_t  ReportID;     /* Report Id                                      */
-    uint8_t  Type;         /* Report Type (INPUT/OUTPUT/FEATURE)             */
-} HID_ReportIDTypeDef;
-
-typedef struct  _HID_CollectionTypeDef 
-{
-    uint32_t                       Usage;                                               
-    uint8_t                        Type;                                                
-    struct _HID_CollectionTypeDef  *NextPtr;
-} HID_CollectionTypeDef;
-
-                                                                               
-typedef  struct  _HID_AppCollectionTypeDef {
-    uint32_t               Usage;                                                
-    uint8_t                Type;                                                 
-    uint8_t                NbrReportFmt;                                         
-    HID_ReportDataTypeDef  ReportData[HID_MAX_NBR_REPORT_FMT];               
-} HID_AppCollectionTypeDef;
-
-
-typedef struct _HIDDescriptor
-{
-  uint8_t   bLength;
-  uint8_t   bDescriptorType;
-  uint16_t  bcdHID;               /* indicates what endpoint this descriptor is describing */
-  uint8_t   bCountryCode;        /* specifies the transfer type. */
-  uint8_t   bNumDescriptors;     /* specifies the transfer type. */
-  uint8_t   bReportDescriptorType;    /* Maximum Packet Size this endpoint is capable of sending or receiving */  
-  uint16_t  wItemLength;          /* is used to specify the polling interval of certain transfers. */
-}
-HID_DescTypeDef;
-
-
-typedef struct 
-{
-     uint8_t  *buf;
-     uint16_t  head;
-     uint16_t tail;
-     uint16_t size;
-     uint8_t  lock;
-} FIFO_TypeDef;
-
-
-/* Structure for HID process */
-typedef struct _HID_Process
-{
-  uint8_t              OutPipe; 
-  uint8_t              InPipe; 
-  HID_StateTypeDef     state; 
-  uint8_t              OutEp;
-  uint8_t              InEp;
-  HID_CtlStateTypeDef  ctl_state;
-  FIFO_TypeDef         fifo; 
-  uint8_t              *pData;   
-  uint16_t             length;
-  uint8_t              ep_addr;
-  uint16_t             poll; 
-  uint16_t             timer;
-  uint8_t              DataReady;
-  HID_DescTypeDef      HID_Desc;  
-  USBH_StatusTypeDef  ( * Init)(USBH_HandleTypeDef *phost);
-}
-HID_HandleTypeDef;
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_CORE_Exported_Defines
-  * @{
-  */ 
-
-#define USB_HID_GET_REPORT           0x01
-#define USB_HID_GET_IDLE             0x02
-#define USB_HID_GET_PROTOCOL         0x03
-#define USB_HID_SET_REPORT           0x09
-#define USB_HID_SET_IDLE             0x0A
-#define USB_HID_SET_PROTOCOL         0x0B    
-
-
-
-
-/* HID Class Codes */
-#define USB_HID_CLASS                                   0x03
-
-/* Interface Descriptor field values for HID Boot Protocol */
-#define HID_BOOT_CODE                                  0x01    
-#define HID_KEYBRD_BOOT_CODE                           0x01
-#define HID_MOUSE_BOOT_CODE                            0x02
-
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_CORE_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_CORE_Exported_Variables
-  * @{
-  */ 
-extern USBH_ClassTypeDef  HID_Class;
-#define USBH_HID_CLASS    &HID_Class
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_CORE_Exported_FunctionsPrototype
-  * @{
-  */ 
-
-USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
-                                  uint8_t reportType,
-                                  uint8_t reportId,
-                                  uint8_t* reportBuff,
-                                  uint8_t reportLen);
-  
-USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
-                                  uint8_t reportType,
-                                  uint8_t reportId,
-                                  uint8_t* reportBuff,
-                                  uint8_t reportLen);  
-
-USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,  
-                                            uint16_t length);
-
-USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,  
-                                            uint16_t length);
-
-USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
-                                  uint8_t duration,
-                                  uint8_t reportId);
-
-USBH_StatusTypeDef USBH_HID_SetProtocol (USBH_HandleTypeDef *phost,
-                                      uint8_t protocol);
-
-void USBH_HID_EventCallback(USBH_HandleTypeDef *phost);
-
-HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost);
-
-void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size);
-
-uint16_t  fifo_read(FIFO_TypeDef * f, void * buf, uint16_t  nbytes);
-
-uint16_t  fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t  nbytes);
-
-/**
-  * @}
-  */ 
-
-
-#endif /* __USBH_HID_H */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_hid.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_hid.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_HID_H
+#define __USBH_HID_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+#include "usbh_hid_mouse.h"
+#include "usbh_hid_keybd.h"
+ 
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_HID_CORE
+  * @brief This file is the Header file for USBH_HID_CORE.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_HID_CORE_Exported_Types
+  * @{
+  */ 
+
+#define HID_MIN_POLL                10
+#define HID_REPORT_SIZE             16    
+#define HID_MAX_USAGE               10
+#define HID_MAX_NBR_REPORT_FMT      10 
+#define HID_QUEUE_SIZE              10    
+    
+#define  HID_ITEM_LONG                              0xFE
+                                                                       
+#define  HID_ITEM_TYPE_MAIN                         0x00
+#define  HID_ITEM_TYPE_GLOBAL                       0x01
+#define  HID_ITEM_TYPE_LOCAL                        0x02
+#define  HID_ITEM_TYPE_RESERVED                     0x03
+
+                                                                         
+#define  HID_MAIN_ITEM_TAG_INPUT                    0x08
+#define  HID_MAIN_ITEM_TAG_OUTPUT                   0x09
+#define  HID_MAIN_ITEM_TAG_COLLECTION               0x0A
+#define  HID_MAIN_ITEM_TAG_FEATURE                  0x0B
+#define  HID_MAIN_ITEM_TAG_ENDCOLLECTION            0x0C
+
+                                                                         
+#define  HID_GLOBAL_ITEM_TAG_USAGE_PAGE             0x00
+#define  HID_GLOBAL_ITEM_TAG_LOG_MIN                0x01
+#define  HID_GLOBAL_ITEM_TAG_LOG_MAX                0x02
+#define  HID_GLOBAL_ITEM_TAG_PHY_MIN                0x03
+#define  HID_GLOBAL_ITEM_TAG_PHY_MAX                0x04
+#define  HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT          0x05
+#define  HID_GLOBAL_ITEM_TAG_UNIT                   0x06
+#define  HID_GLOBAL_ITEM_TAG_REPORT_SIZE            0x07
+#define  HID_GLOBAL_ITEM_TAG_REPORT_ID              0x08
+#define  HID_GLOBAL_ITEM_TAG_REPORT_COUNT           0x09
+#define  HID_GLOBAL_ITEM_TAG_PUSH                   0x0A
+#define  HID_GLOBAL_ITEM_TAG_POP                    0x0B
+
+                                                                         
+#define  HID_LOCAL_ITEM_TAG_USAGE                   0x00
+#define  HID_LOCAL_ITEM_TAG_USAGE_MIN               0x01
+#define  HID_LOCAL_ITEM_TAG_USAGE_MAX               0x02
+#define  HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX        0x03
+#define  HID_LOCAL_ITEM_TAG_DESIGNATOR_MIN          0x04
+#define  HID_LOCAL_ITEM_TAG_DESIGNATOR_MAX          0x05
+#define  HID_LOCAL_ITEM_TAG_STRING_INDEX            0x07
+#define  HID_LOCAL_ITEM_TAG_STRING_MIN              0x08
+#define  HID_LOCAL_ITEM_TAG_STRING_MAX              0x09
+#define  HID_LOCAL_ITEM_TAG_DELIMITER               0x0A
+    
+
+/* States for HID State Machine */
+typedef enum
+{
+  HID_INIT= 0,  
+  HID_IDLE,
+  HID_SEND_DATA,
+  HID_BUSY,
+  HID_GET_DATA,   
+  HID_SYNC,     
+  HID_POLL,
+  HID_ERROR,
+}
+HID_StateTypeDef;
+
+typedef enum
+{
+  HID_REQ_INIT = 0,
+  HID_REQ_IDLE, 
+  HID_REQ_GET_REPORT_DESC,
+  HID_REQ_GET_HID_DESC,
+  HID_REQ_SET_IDLE,
+  HID_REQ_SET_PROTOCOL,
+  HID_REQ_SET_REPORT,
+
+}
+HID_CtlStateTypeDef;
+
+typedef enum
+{
+  HID_MOUSE    = 0x01,
+  HID_KEYBOARD = 0x02,
+  HID_UNKNOWN = 0xFF,
+}
+HID_TypeTypeDef;
+
+
+typedef  struct  _HID_ReportData 
+{
+    uint8_t   ReportID;    
+    uint8_t   ReportType;  
+    uint16_t  UsagePage;   
+    uint32_t  Usage[HID_MAX_USAGE]; 
+    uint32_t  NbrUsage;                      
+    uint32_t  UsageMin;                      
+    uint32_t  UsageMax;                      
+    int32_t   LogMin;                        
+    int32_t   LogMax;                        
+    int32_t   PhyMin;                        
+    int32_t   PhyMax;                        
+    int32_t   UnitExp;                       
+    uint32_t  Unit;                          
+    uint32_t  ReportSize;                    
+    uint32_t  ReportCnt;                     
+    uint32_t  Flag;                          
+    uint32_t  PhyUsage;                      
+    uint32_t  AppUsage;                      
+    uint32_t  LogUsage;   
+} 
+HID_ReportDataTypeDef;
+
+typedef  struct  _HID_ReportIDTypeDef {
+    uint8_t  Size;         /* Report size return by the device id            */
+    uint8_t  ReportID;     /* Report Id                                      */
+    uint8_t  Type;         /* Report Type (INPUT/OUTPUT/FEATURE)             */
+} HID_ReportIDTypeDef;
+
+typedef struct  _HID_CollectionTypeDef 
+{
+    uint32_t                       Usage;                                               
+    uint8_t                        Type;                                                
+    struct _HID_CollectionTypeDef  *NextPtr;
+} HID_CollectionTypeDef;
+
+                                                                               
+typedef  struct  _HID_AppCollectionTypeDef {
+    uint32_t               Usage;                                                
+    uint8_t                Type;                                                 
+    uint8_t                NbrReportFmt;                                         
+    HID_ReportDataTypeDef  ReportData[HID_MAX_NBR_REPORT_FMT];               
+} HID_AppCollectionTypeDef;
+
+
+typedef struct _HIDDescriptor
+{
+  uint8_t   bLength;
+  uint8_t   bDescriptorType;
+  uint16_t  bcdHID;               /* indicates what endpoint this descriptor is describing */
+  uint8_t   bCountryCode;        /* specifies the transfer type. */
+  uint8_t   bNumDescriptors;     /* specifies the transfer type. */
+  uint8_t   bReportDescriptorType;    /* Maximum Packet Size this endpoint is capable of sending or receiving */  
+  uint16_t  wItemLength;          /* is used to specify the polling interval of certain transfers. */
+}
+HID_DescTypeDef;
+
+
+typedef struct 
+{
+     uint8_t  *buf;
+     uint16_t  head;
+     uint16_t tail;
+     uint16_t size;
+     uint8_t  lock;
+} FIFO_TypeDef;
+
+
+/* Structure for HID process */
+typedef struct _HID_Process
+{
+  uint8_t              OutPipe; 
+  uint8_t              InPipe; 
+  HID_StateTypeDef     state; 
+  uint8_t              OutEp;
+  uint8_t              InEp;
+  HID_CtlStateTypeDef  ctl_state;
+  FIFO_TypeDef         fifo; 
+  uint8_t              *pData;   
+  uint16_t             length;
+  uint8_t              ep_addr;
+  uint16_t             poll; 
+  uint16_t             timer;
+  uint8_t              DataReady;
+  HID_DescTypeDef      HID_Desc;  
+  USBH_StatusTypeDef  ( * Init)(USBH_HandleTypeDef *phost);
+}
+HID_HandleTypeDef;
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_CORE_Exported_Defines
+  * @{
+  */ 
+
+#define USB_HID_GET_REPORT           0x01
+#define USB_HID_GET_IDLE             0x02
+#define USB_HID_GET_PROTOCOL         0x03
+#define USB_HID_SET_REPORT           0x09
+#define USB_HID_SET_IDLE             0x0A
+#define USB_HID_SET_PROTOCOL         0x0B    
+
+
+
+
+/* HID Class Codes */
+#define USB_HID_CLASS                                   0x03
+
+/* Interface Descriptor field values for HID Boot Protocol */
+#define HID_BOOT_CODE                                  0x01    
+#define HID_KEYBRD_BOOT_CODE                           0x01
+#define HID_MOUSE_BOOT_CODE                            0x02
+
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_CORE_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_CORE_Exported_Variables
+  * @{
+  */ 
+extern USBH_ClassTypeDef  HID_Class;
+#define USBH_HID_CLASS    &HID_Class
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_CORE_Exported_FunctionsPrototype
+  * @{
+  */ 
+
+USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
+                                  uint8_t reportType,
+                                  uint8_t reportId,
+                                  uint8_t* reportBuff,
+                                  uint8_t reportLen);
+  
+USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
+                                  uint8_t reportType,
+                                  uint8_t reportId,
+                                  uint8_t* reportBuff,
+                                  uint8_t reportLen);  
+
+USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,  
+                                            uint16_t length);
+
+USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,  
+                                            uint16_t length);
+
+USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
+                                  uint8_t duration,
+                                  uint8_t reportId);
+
+USBH_StatusTypeDef USBH_HID_SetProtocol (USBH_HandleTypeDef *phost,
+                                      uint8_t protocol);
+
+void USBH_HID_EventCallback(USBH_HandleTypeDef *phost);
+
+HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost);
+
+void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size);
+
+uint16_t  fifo_read(FIFO_TypeDef * f, void * buf, uint16_t  nbytes);
+
+uint16_t  fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t  nbytes);
+
+/**
+  * @}
+  */ 
+
+
+#endif /* __USBH_HID_H */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_keybd.h b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_keybd.h
index dc72ebb26b8c6b40851ca1167d563484531645d2..cea6a0751cd0d160ef598e2231a432a2d43ffee5 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_keybd.h
+++ b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_keybd.h
@@ -1,318 +1,318 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_keybd.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_hid_keybd.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Define to prevent recursive -----------------------------------------------*/
-#ifndef __USBH_HID_KEYBD_H
-#define __USBH_HID_KEYBD_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid.h"
-#include "usbh_hid_keybd.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_HID_KEYBD
-  * @brief This file is the Header file for USBH_HID_KEYBD.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_HID_KEYBD_Exported_Types
-  * @{
-  */ 
-#define KEY_NONE                               0x00
-#define KEY_ERRORROLLOVER                      0x01
-#define KEY_POSTFAIL                           0x02
-#define KEY_ERRORUNDEFINED                     0x03
-#define KEY_A                                  0x04
-#define KEY_B                                  0x05
-#define KEY_C                                  0x06
-#define KEY_D                                  0x07
-#define KEY_E                                  0x08
-#define KEY_F                                  0x09
-#define KEY_G                                  0x0A
-#define KEY_H                                  0x0B
-#define KEY_I                                  0x0C
-#define KEY_J                                  0x0D
-#define KEY_K                                  0x0E
-#define KEY_L                                  0x0F
-#define KEY_M                                  0x10 
-#define KEY_N                                  0x11 
-#define KEY_O                                  0x12 
-#define KEY_P                                  0x13
-#define KEY_Q                                  0x14
-#define KEY_R                                  0x15 
-#define KEY_S                                  0x16 
-#define KEY_T                                  0x17 
-#define KEY_U                                  0x18
-#define KEY_V                                  0x19
-#define KEY_W                                  0x1A 
-#define KEY_X                                  0x1B 
-#define KEY_Y                                  0x1C
-#define KEY_Z                                  0x1D
-#define KEY_1_EXCLAMATION_MARK                 0x1E
-#define KEY_2_AT                               0x1F
-#define KEY_3_NUMBER_SIGN                      0x20
-#define KEY_4_DOLLAR                           0x21
-#define KEY_5_PERCENT                          0x22
-#define KEY_6_CARET                            0x23
-#define KEY_7_AMPERSAND                        0x24
-#define KEY_8_ASTERISK                         0x25
-#define KEY_9_OPARENTHESIS                     0x26
-#define KEY_0_CPARENTHESIS                     0x27
-#define KEY_ENTER                              0x28
-#define KEY_ESCAPE                             0x29 
-#define KEY_BACKSPACE                          0x2A 
-#define KEY_TAB                                0x2B 
-#define KEY_SPACEBAR                           0x2C
-#define KEY_MINUS_UNDERSCORE                   0x2D
-#define KEY_EQUAL_PLUS                         0x2E
-#define KEY_OBRACKET_AND_OBRACE                0x2F 
-#define KEY_CBRACKET_AND_CBRACE                0x30 
-#define KEY_BACKSLASH_VERTICAL_BAR             0x31
-#define KEY_NONUS_NUMBER_SIGN_TILDE            0x32
-#define KEY_SEMICOLON_COLON                    0x33
-#define KEY_SINGLE_AND_DOUBLE_QUOTE            0x34
-#define KEY_GRAVE ACCENT AND TILDE             0x35 
-#define KEY_COMMA_AND_LESS                     0x36
-#define KEY_DOT_GREATER                        0x37
-#define KEY_SLASH_QUESTION                     0x38
-#define KEY_CAPS LOCK                          0x39
-#define KEY_F1                                 0x3A 
-#define KEY_F2                                 0x3B
-#define KEY_F3                                 0x3C
-#define KEY_F4                                 0x3D 
-#define KEY_F5                                 0x3E 
-#define KEY_F6                                 0x3F 
-#define KEY_F7                                 0x40
-#define KEY_F8                                 0x41
-#define KEY_F9                                 0x42 
-#define KEY_F10                                0x43
-#define KEY_F11                                0x44 
-#define KEY_F12                                0x45
-#define KEY_PRINTSCREEN                        0x46
-#define KEY_SCROLL LOCK                        0x47 
-#define KEY_PAUSE                              0x48 
-#define KEY_INSERT                             0x49 
-#define KEY_HOME                               0x4A
-#define KEY_PAGEUP                             0x4B
-#define KEY_DELETE                             0x4C 
-#define KEY_END1                               0x4D 
-#define KEY_PAGEDOWN                           0x4E 
-#define KEY_RIGHTARROW                         0x4F
-#define KEY_LEFTARROW                          0x50
-#define KEY_DOWNARROW                          0x51 
-#define KEY_UPARROW                            0x52
-#define KEY_KEYPAD_NUM_LOCK_AND_CLEAR          0x53
-#define KEY_KEYPAD_SLASH                       0x54
-#define KEY_KEYPAD_ASTERIKS                    0x55
-#define KEY_KEYPAD_MINUS                       0x56 
-#define KEY_KEYPAD_PLUS                        0x57 
-#define KEY_KEYPAD_ENTER                       0x58
-#define KEY_KEYPAD_1_END                       0x59
-#define KEY_KEYPAD_2_DOWN_ARROW                0x5A
-#define KEY_KEYPAD_3_PAGEDN                    0x5B
-#define KEY_KEYPAD_4_LEFT_ARROW                0x5C
-#define KEY_KEYPAD_5                           0x5D 
-#define KEY_KEYPAD_6_RIGHT_ARROW               0x5E
-#define KEY_KEYPAD_7_HOME                      0x5F
-#define KEY_KEYPAD_8_UP_ARROW                  0x60
-#define KEY_KEYPAD_9_PAGEUP                    0x61
-#define KEY_KEYPAD_0_INSERT                    0x62
-#define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE    0x63
-#define KEY_NONUS_BACK_SLASH_VERTICAL_BAR      0x64
-#define KEY_APPLICATION                        0x65
-#define KEY_POWER                              0x66 
-#define KEY_KEYPAD_EQUAL                       0x67 
-#define KEY_F13                                0x68
-#define KEY_F14                                0x69
-#define KEY_F15                                0x6A 
-#define KEY_F16                                0x6B 
-#define KEY_F17                                0x6C
-#define KEY_F18                                0x6D
-#define KEY_F19                                0x6E
-#define KEY_F20                                0x6F
-#define KEY_F21                                0x70 
-#define KEY_F22                                0x71 
-#define KEY_F23                                0x72
-#define KEY_F24                                0x73
-#define KEY_EXECUTE                            0x74 
-#define KEY_HELP                               0x75
-#define KEY_MENU                               0x76 
-#define KEY_SELECT                             0x77
-#define KEY_STOP                               0x78
-#define KEY_AGAIN                              0x79
-#define KEY_UNDO                               0x7A 
-#define KEY_CUT                                0x7B 
-#define KEY_COPY                               0x7C
-#define KEY_PASTE                              0x7D
-#define KEY_FIND                               0x7E 
-#define KEY_MUTE                               0x7F
-#define KEY_VOLUME_UP                          0x80 
-#define KEY_VOLUME_DOWN                        0x81
-#define KEY_LOCKING_CAPS_LOCK                  0x82
-#define KEY_LOCKING_NUM_LOCK                   0x83 
-#define KEY_LOCKING_SCROLL_LOCK                0x84 
-#define KEY_KEYPAD_COMMA                       0x85 
-#define KEY_KEYPAD_EQUAL_SIGN                  0x86
-#define KEY_INTERNATIONAL1                     0x87
-#define KEY_INTERNATIONAL2                     0x88
-#define KEY_INTERNATIONAL3                     0x89
-#define KEY_INTERNATIONAL4                     0x8A
-#define KEY_INTERNATIONAL5                     0x8B
-#define KEY_INTERNATIONAL6                     0x8C
-#define KEY_INTERNATIONAL7                     0x8D
-#define KEY_INTERNATIONAL8                     0x8E
-#define KEY_INTERNATIONAL9                     0x8F
-#define KEY_LANG1                              0x90
-#define KEY_LANG2                              0x91
-#define KEY_LANG3                              0x92
-#define KEY_LANG4                              0x93
-#define KEY_LANG5                              0x94
-#define KEY_LANG6                              0x95
-#define KEY_LANG7                              0x96
-#define KEY_LANG8                              0x97
-#define KEY_LANG9                              0x98
-#define KEY_ALTERNATE_ERASE                    0x99 
-#define KEY_SYSREQ                             0x9A
-#define KEY_CANCEL                             0x9B
-#define KEY_CLEAR                              0x9C
-#define KEY_PRIOR                              0x9D 
-#define KEY_RETURN                             0x9E
-#define KEY_SEPARATOR                          0x9F
-#define KEY_OUT                                0xA0
-#define KEY_OPER                               0xA1 
-#define KEY_CLEAR_AGAIN                        0xA2
-#define KEY_CRSEL                              0xA3
-#define KEY_EXSEL                              0xA4
-#define KEY_KEYPAD_00                          0xB0
-#define KEY_KEYPAD_000                         0xB1 
-#define KEY_THOUSANDS_SEPARATOR                0xB2 
-#define KEY_DECIMAL_SEPARATOR                  0xB3 
-#define KEY_CURRENCY_UNIT                      0xB4
-#define KEY_CURRENCY_SUB_UNIT                  0xB5
-#define KEY_KEYPAD_OPARENTHESIS                0xB6 
-#define KEY_KEYPAD_CPARENTHESIS                0xB7 
-#define KEY_KEYPAD_OBRACE                      0xB8 
-#define KEY_KEYPAD_CBRACE                      0xB9
-#define KEY_KEYPAD_TAB                         0xBA
-#define KEY_KEYPAD_BACKSPACE                   0xBB 
-#define KEY_KEYPAD_A                           0xBC 
-#define KEY_KEYPAD_B                           0xBD 
-#define KEY_KEYPAD_C                           0xBE
-#define KEY_KEYPAD_D                           0xBF
-#define KEY_KEYPAD_E                           0xC0 
-#define KEY_KEYPAD_F                           0xC1 
-#define KEY_KEYPAD_XOR                         0xC2
-#define KEY_KEYPAD_CARET                       0xC3
-#define KEY_KEYPAD_PERCENT                     0xC4
-#define KEY_KEYPAD_LESS                        0xC5
-#define KEY_KEYPAD_GREATER                     0xC6 
-#define KEY_KEYPAD_AMPERSAND                   0xC7 
-#define KEY_KEYPAD_LOGICAL_AND                 0xC8
-#define KEY_KEYPAD_VERTICAL_BAR                0xC9
-#define KEY_KEYPAD_LOGIACL_OR                  0xCA 
-#define KEY_KEYPAD_COLON                       0xCB 
-#define KEY_KEYPAD_NUMBER_SIGN                 0xCC 
-#define KEY_KEYPAD_SPACE                       0xCD
-#define KEY_KEYPAD_AT                          0xCE
-#define KEY_KEYPAD_EXCLAMATION_MARK            0xCF 
-#define KEY_KEYPAD_MEMORY_STORE                0xD0 
-#define KEY_KEYPAD_MEMORY_RECALL               0xD1 
-#define KEY_KEYPAD_MEMORY_CLEAR                0xD2
-#define KEY_KEYPAD_MEMORY_ADD                  0xD3
-#define KEY_KEYPAD_MEMORY_SUBTRACT             0xD4 
-#define KEY_KEYPAD_MEMORY_MULTIPLY             0xD5 
-#define KEY_KEYPAD_MEMORY_DIVIDE               0xD6
-#define KEY_KEYPAD_PLUSMINUS                   0xD7
-#define KEY_KEYPAD_CLEAR                       0xD8
-#define KEY_KEYPAD_CLEAR_ENTRY                 0xD9 
-#define KEY_KEYPAD_BINARY                      0xDA 
-#define KEY_KEYPAD_OCTAL                       0xDB 
-#define KEY_KEYPAD_DECIMAL                     0xDC
-#define KEY_KEYPAD_HEXADECIMAL                 0xDD
-#define KEY_LEFTCONTROL                        0xE0
-#define KEY_LEFTSHIFT                          0xE1
-#define KEY_LEFTALT                            0xE2
-#define KEY_LEFT_GUI                           0xE3
-#define KEY_RIGHTCONTROL                       0xE4
-#define KEY_RIGHTSHIFT                         0xE5
-#define KEY_RIGHTALT                           0xE6
-#define KEY_RIGHT_GUI                          0xE7
-
-typedef struct 
-{
-  uint8_t state;
-  uint8_t lctrl;
-  uint8_t lshift;
-  uint8_t lalt;
-  uint8_t lgui;
-  uint8_t rctrl;
-  uint8_t rshift;
-  uint8_t ralt;
-  uint8_t rgui;
-  uint8_t keys[6];
-} 
-HID_KEYBD_Info_TypeDef;
-
-USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
-HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost);
-uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info);
-
-/**
-  * @}
-  */ 
-
-#endif /* __USBH_HID_KEYBD_H */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_hid_keybd.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_hid_keybd.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive -----------------------------------------------*/
+#ifndef __USBH_HID_KEYBD_H
+#define __USBH_HID_KEYBD_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid.h"
+#include "usbh_hid_keybd.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_HID_KEYBD
+  * @brief This file is the Header file for USBH_HID_KEYBD.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_HID_KEYBD_Exported_Types
+  * @{
+  */ 
+#define KEY_NONE                               0x00
+#define KEY_ERRORROLLOVER                      0x01
+#define KEY_POSTFAIL                           0x02
+#define KEY_ERRORUNDEFINED                     0x03
+#define KEY_A                                  0x04
+#define KEY_B                                  0x05
+#define KEY_C                                  0x06
+#define KEY_D                                  0x07
+#define KEY_E                                  0x08
+#define KEY_F                                  0x09
+#define KEY_G                                  0x0A
+#define KEY_H                                  0x0B
+#define KEY_I                                  0x0C
+#define KEY_J                                  0x0D
+#define KEY_K                                  0x0E
+#define KEY_L                                  0x0F
+#define KEY_M                                  0x10 
+#define KEY_N                                  0x11 
+#define KEY_O                                  0x12 
+#define KEY_P                                  0x13
+#define KEY_Q                                  0x14
+#define KEY_R                                  0x15 
+#define KEY_S                                  0x16 
+#define KEY_T                                  0x17 
+#define KEY_U                                  0x18
+#define KEY_V                                  0x19
+#define KEY_W                                  0x1A 
+#define KEY_X                                  0x1B 
+#define KEY_Y                                  0x1C
+#define KEY_Z                                  0x1D
+#define KEY_1_EXCLAMATION_MARK                 0x1E
+#define KEY_2_AT                               0x1F
+#define KEY_3_NUMBER_SIGN                      0x20
+#define KEY_4_DOLLAR                           0x21
+#define KEY_5_PERCENT                          0x22
+#define KEY_6_CARET                            0x23
+#define KEY_7_AMPERSAND                        0x24
+#define KEY_8_ASTERISK                         0x25
+#define KEY_9_OPARENTHESIS                     0x26
+#define KEY_0_CPARENTHESIS                     0x27
+#define KEY_ENTER                              0x28
+#define KEY_ESCAPE                             0x29 
+#define KEY_BACKSPACE                          0x2A 
+#define KEY_TAB                                0x2B 
+#define KEY_SPACEBAR                           0x2C
+#define KEY_MINUS_UNDERSCORE                   0x2D
+#define KEY_EQUAL_PLUS                         0x2E
+#define KEY_OBRACKET_AND_OBRACE                0x2F 
+#define KEY_CBRACKET_AND_CBRACE                0x30 
+#define KEY_BACKSLASH_VERTICAL_BAR             0x31
+#define KEY_NONUS_NUMBER_SIGN_TILDE            0x32
+#define KEY_SEMICOLON_COLON                    0x33
+#define KEY_SINGLE_AND_DOUBLE_QUOTE            0x34
+#define KEY_GRAVE ACCENT AND TILDE             0x35 
+#define KEY_COMMA_AND_LESS                     0x36
+#define KEY_DOT_GREATER                        0x37
+#define KEY_SLASH_QUESTION                     0x38
+#define KEY_CAPS LOCK                          0x39
+#define KEY_F1                                 0x3A 
+#define KEY_F2                                 0x3B
+#define KEY_F3                                 0x3C
+#define KEY_F4                                 0x3D 
+#define KEY_F5                                 0x3E 
+#define KEY_F6                                 0x3F 
+#define KEY_F7                                 0x40
+#define KEY_F8                                 0x41
+#define KEY_F9                                 0x42 
+#define KEY_F10                                0x43
+#define KEY_F11                                0x44 
+#define KEY_F12                                0x45
+#define KEY_PRINTSCREEN                        0x46
+#define KEY_SCROLL LOCK                        0x47 
+#define KEY_PAUSE                              0x48 
+#define KEY_INSERT                             0x49 
+#define KEY_HOME                               0x4A
+#define KEY_PAGEUP                             0x4B
+#define KEY_DELETE                             0x4C 
+#define KEY_END1                               0x4D 
+#define KEY_PAGEDOWN                           0x4E 
+#define KEY_RIGHTARROW                         0x4F
+#define KEY_LEFTARROW                          0x50
+#define KEY_DOWNARROW                          0x51 
+#define KEY_UPARROW                            0x52
+#define KEY_KEYPAD_NUM_LOCK_AND_CLEAR          0x53
+#define KEY_KEYPAD_SLASH                       0x54
+#define KEY_KEYPAD_ASTERIKS                    0x55
+#define KEY_KEYPAD_MINUS                       0x56 
+#define KEY_KEYPAD_PLUS                        0x57 
+#define KEY_KEYPAD_ENTER                       0x58
+#define KEY_KEYPAD_1_END                       0x59
+#define KEY_KEYPAD_2_DOWN_ARROW                0x5A
+#define KEY_KEYPAD_3_PAGEDN                    0x5B
+#define KEY_KEYPAD_4_LEFT_ARROW                0x5C
+#define KEY_KEYPAD_5                           0x5D 
+#define KEY_KEYPAD_6_RIGHT_ARROW               0x5E
+#define KEY_KEYPAD_7_HOME                      0x5F
+#define KEY_KEYPAD_8_UP_ARROW                  0x60
+#define KEY_KEYPAD_9_PAGEUP                    0x61
+#define KEY_KEYPAD_0_INSERT                    0x62
+#define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE    0x63
+#define KEY_NONUS_BACK_SLASH_VERTICAL_BAR      0x64
+#define KEY_APPLICATION                        0x65
+#define KEY_POWER                              0x66 
+#define KEY_KEYPAD_EQUAL                       0x67 
+#define KEY_F13                                0x68
+#define KEY_F14                                0x69
+#define KEY_F15                                0x6A 
+#define KEY_F16                                0x6B 
+#define KEY_F17                                0x6C
+#define KEY_F18                                0x6D
+#define KEY_F19                                0x6E
+#define KEY_F20                                0x6F
+#define KEY_F21                                0x70 
+#define KEY_F22                                0x71 
+#define KEY_F23                                0x72
+#define KEY_F24                                0x73
+#define KEY_EXECUTE                            0x74 
+#define KEY_HELP                               0x75
+#define KEY_MENU                               0x76 
+#define KEY_SELECT                             0x77
+#define KEY_STOP                               0x78
+#define KEY_AGAIN                              0x79
+#define KEY_UNDO                               0x7A 
+#define KEY_CUT                                0x7B 
+#define KEY_COPY                               0x7C
+#define KEY_PASTE                              0x7D
+#define KEY_FIND                               0x7E 
+#define KEY_MUTE                               0x7F
+#define KEY_VOLUME_UP                          0x80 
+#define KEY_VOLUME_DOWN                        0x81
+#define KEY_LOCKING_CAPS_LOCK                  0x82
+#define KEY_LOCKING_NUM_LOCK                   0x83 
+#define KEY_LOCKING_SCROLL_LOCK                0x84 
+#define KEY_KEYPAD_COMMA                       0x85 
+#define KEY_KEYPAD_EQUAL_SIGN                  0x86
+#define KEY_INTERNATIONAL1                     0x87
+#define KEY_INTERNATIONAL2                     0x88
+#define KEY_INTERNATIONAL3                     0x89
+#define KEY_INTERNATIONAL4                     0x8A
+#define KEY_INTERNATIONAL5                     0x8B
+#define KEY_INTERNATIONAL6                     0x8C
+#define KEY_INTERNATIONAL7                     0x8D
+#define KEY_INTERNATIONAL8                     0x8E
+#define KEY_INTERNATIONAL9                     0x8F
+#define KEY_LANG1                              0x90
+#define KEY_LANG2                              0x91
+#define KEY_LANG3                              0x92
+#define KEY_LANG4                              0x93
+#define KEY_LANG5                              0x94
+#define KEY_LANG6                              0x95
+#define KEY_LANG7                              0x96
+#define KEY_LANG8                              0x97
+#define KEY_LANG9                              0x98
+#define KEY_ALTERNATE_ERASE                    0x99 
+#define KEY_SYSREQ                             0x9A
+#define KEY_CANCEL                             0x9B
+#define KEY_CLEAR                              0x9C
+#define KEY_PRIOR                              0x9D 
+#define KEY_RETURN                             0x9E
+#define KEY_SEPARATOR                          0x9F
+#define KEY_OUT                                0xA0
+#define KEY_OPER                               0xA1 
+#define KEY_CLEAR_AGAIN                        0xA2
+#define KEY_CRSEL                              0xA3
+#define KEY_EXSEL                              0xA4
+#define KEY_KEYPAD_00                          0xB0
+#define KEY_KEYPAD_000                         0xB1 
+#define KEY_THOUSANDS_SEPARATOR                0xB2 
+#define KEY_DECIMAL_SEPARATOR                  0xB3 
+#define KEY_CURRENCY_UNIT                      0xB4
+#define KEY_CURRENCY_SUB_UNIT                  0xB5
+#define KEY_KEYPAD_OPARENTHESIS                0xB6 
+#define KEY_KEYPAD_CPARENTHESIS                0xB7 
+#define KEY_KEYPAD_OBRACE                      0xB8 
+#define KEY_KEYPAD_CBRACE                      0xB9
+#define KEY_KEYPAD_TAB                         0xBA
+#define KEY_KEYPAD_BACKSPACE                   0xBB 
+#define KEY_KEYPAD_A                           0xBC 
+#define KEY_KEYPAD_B                           0xBD 
+#define KEY_KEYPAD_C                           0xBE
+#define KEY_KEYPAD_D                           0xBF
+#define KEY_KEYPAD_E                           0xC0 
+#define KEY_KEYPAD_F                           0xC1 
+#define KEY_KEYPAD_XOR                         0xC2
+#define KEY_KEYPAD_CARET                       0xC3
+#define KEY_KEYPAD_PERCENT                     0xC4
+#define KEY_KEYPAD_LESS                        0xC5
+#define KEY_KEYPAD_GREATER                     0xC6 
+#define KEY_KEYPAD_AMPERSAND                   0xC7 
+#define KEY_KEYPAD_LOGICAL_AND                 0xC8
+#define KEY_KEYPAD_VERTICAL_BAR                0xC9
+#define KEY_KEYPAD_LOGIACL_OR                  0xCA 
+#define KEY_KEYPAD_COLON                       0xCB 
+#define KEY_KEYPAD_NUMBER_SIGN                 0xCC 
+#define KEY_KEYPAD_SPACE                       0xCD
+#define KEY_KEYPAD_AT                          0xCE
+#define KEY_KEYPAD_EXCLAMATION_MARK            0xCF 
+#define KEY_KEYPAD_MEMORY_STORE                0xD0 
+#define KEY_KEYPAD_MEMORY_RECALL               0xD1 
+#define KEY_KEYPAD_MEMORY_CLEAR                0xD2
+#define KEY_KEYPAD_MEMORY_ADD                  0xD3
+#define KEY_KEYPAD_MEMORY_SUBTRACT             0xD4 
+#define KEY_KEYPAD_MEMORY_MULTIPLY             0xD5 
+#define KEY_KEYPAD_MEMORY_DIVIDE               0xD6
+#define KEY_KEYPAD_PLUSMINUS                   0xD7
+#define KEY_KEYPAD_CLEAR                       0xD8
+#define KEY_KEYPAD_CLEAR_ENTRY                 0xD9 
+#define KEY_KEYPAD_BINARY                      0xDA 
+#define KEY_KEYPAD_OCTAL                       0xDB 
+#define KEY_KEYPAD_DECIMAL                     0xDC
+#define KEY_KEYPAD_HEXADECIMAL                 0xDD
+#define KEY_LEFTCONTROL                        0xE0
+#define KEY_LEFTSHIFT                          0xE1
+#define KEY_LEFTALT                            0xE2
+#define KEY_LEFT_GUI                           0xE3
+#define KEY_RIGHTCONTROL                       0xE4
+#define KEY_RIGHTSHIFT                         0xE5
+#define KEY_RIGHTALT                           0xE6
+#define KEY_RIGHT_GUI                          0xE7
+
+typedef struct 
+{
+  uint8_t state;
+  uint8_t lctrl;
+  uint8_t lshift;
+  uint8_t lalt;
+  uint8_t lgui;
+  uint8_t rctrl;
+  uint8_t rshift;
+  uint8_t ralt;
+  uint8_t rgui;
+  uint8_t keys[6];
+} 
+HID_KEYBD_Info_TypeDef;
+
+USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
+HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost);
+uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info);
+
+/**
+  * @}
+  */ 
+
+#endif /* __USBH_HID_KEYBD_H */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_mouse.h b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_mouse.h
index 3a87d1a2db3df92a4166d575c03260abada66b02..aab8869d499ab26a9c429b9161d41e820181bf56 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_mouse.h
+++ b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_mouse.h
@@ -1,118 +1,118 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_mouse.h 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_hid_mouse.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_HID_MOUSE_H
-#define __USBH_HID_MOUSE_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-
-/** @defgroup USBH_HID_MOUSE
-  * @brief This file is the Header file for USBH_HID_MOUSE.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_HID_MOUSE_Exported_Types
-  * @{
-  */ 
-
-typedef struct _HID_MOUSE_Info
-{
-  uint8_t              x; 
-  uint8_t              y;  
-  uint8_t              buttons[3];
-}
-HID_MOUSE_Info_TypeDef;
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_MOUSE_Exported_Defines
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_MOUSE_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_MOUSE_Exported_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_MOUSE_Exported_FunctionsPrototype
-  * @{
-  */ 
-USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
-HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost);
-
-/**
-  * @}
-  */ 
-
-#endif /* __USBH_HID_MOUSE_H */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_hid_mouse.h 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_hid_mouse.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_HID_MOUSE_H
+#define __USBH_HID_MOUSE_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+
+/** @defgroup USBH_HID_MOUSE
+  * @brief This file is the Header file for USBH_HID_MOUSE.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_HID_MOUSE_Exported_Types
+  * @{
+  */ 
+
+typedef struct _HID_MOUSE_Info
+{
+  uint8_t              x; 
+  uint8_t              y;  
+  uint8_t              buttons[3];
+}
+HID_MOUSE_Info_TypeDef;
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_MOUSE_Exported_Defines
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_MOUSE_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_MOUSE_Exported_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_MOUSE_Exported_FunctionsPrototype
+  * @{
+  */ 
+USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
+HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost);
+
+/**
+  * @}
+  */ 
+
+#endif /* __USBH_HID_MOUSE_H */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_parser.h b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_parser.h
index 0bf5739afbaa1e3cca1d5c0b185cd1512a906741..a4040445ec78604e433bbf6c53d986e22372f647 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_parser.h
+++ b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_parser.h
@@ -1,96 +1,96 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_parser.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the header file of the usbh_hid_parser.c        
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-#ifndef _HID_PARSER_H_
-#define _HID_PARSER_H_
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid.h"
-#include "usbh_hid_usage.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_HID_PARSER
-  * @brief This file is the Header file for USBH_HID_PARSER.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_HID_PARSER_Exported_Types
-  * @{
-  */ 
-typedef struct 
-{
-  uint8_t  *data;
-  uint32_t size;
-  uint8_t  shift;
-  uint8_t  count;
-  uint8_t  sign;
-  uint32_t logical_min;  /*min value device can return*/
-  uint32_t logical_max;  /*max value device can return*/
-  uint32_t physical_min; /*min vale read can report*/
-  uint32_t physical_max; /*max value read can report*/
-  uint32_t resolution;
-} 
-HID_Report_ItemTypedef;
-
-
-uint32_t HID_ReadItem (HID_Report_ItemTypedef *ri, uint8_t ndx);
-uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx);
-
-
-/**
-  * @}
-  */ 
-
-#endif /* _HID_PARSER_H_ */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_hid_parser.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the header file of the usbh_hid_parser.c        
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+#ifndef _HID_PARSER_H_
+#define _HID_PARSER_H_
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid.h"
+#include "usbh_hid_usage.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_HID_PARSER
+  * @brief This file is the Header file for USBH_HID_PARSER.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_HID_PARSER_Exported_Types
+  * @{
+  */ 
+typedef struct 
+{
+  uint8_t  *data;
+  uint32_t size;
+  uint8_t  shift;
+  uint8_t  count;
+  uint8_t  sign;
+  uint32_t logical_min;  /*min value device can return*/
+  uint32_t logical_max;  /*max value device can return*/
+  uint32_t physical_min; /*min vale read can report*/
+  uint32_t physical_max; /*max value read can report*/
+  uint32_t resolution;
+} 
+HID_Report_ItemTypedef;
+
+
+uint32_t HID_ReadItem (HID_Report_ItemTypedef *ri, uint8_t ndx);
+uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx);
+
+
+/**
+  * @}
+  */ 
+
+#endif /* _HID_PARSER_H_ */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_usage.h b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_usage.h
index e1f7762f32591016d39a7ae195ead06f0621fabe..6a819d352b5ea9eafdc3231f33ddd32536e3786e 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_usage.h
+++ b/micropython/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_usage.h
@@ -1,191 +1,191 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_keybd.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contain the USAGE page codes              
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-#ifndef _HID_USAGE_H_
-#define _HID_USAGE_H_
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_HID_USAGE
-  * @brief This file is the Header file for USBH_HID_USAGE.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_HID_USAGE_Exported_Types
-  * @{
-  */
-
-/****************************************************/
-/* HID 1.11 usage pages                             */
-/****************************************************/
-
-#define HID_USAGE_PAGE_UNDEFINED  uint16_t (0x00)   /* Undefined */
-/**** Top level pages */
-#define HID_USAGE_PAGE_GEN_DES    uint16_t (0x01)   /* Generic Desktop Controls*/
-#define HID_USAGE_PAGE_SIM_CTR    uint16_t (0x02)   /* Simulation Controls */
-#define HID_USAGE_PAGE_VR_CTR     uint16_t (0x03)   /* VR Controls */
-#define HID_USAGE_PAGE_SPORT_CTR  uint16_t (0x04)   /* Sport Controls */
-#define HID_USAGE_PAGE_GAME_CTR   uint16_t (0x05)   /* Game Controls */
-#define HID_USAGE_PAGE_GEN_DEV    uint16_t (0x06)   /* Generic Device Controls */
-#define HID_USAGE_PAGE_KEYB       uint16_t (0x07)   /* Keyboard/Keypad */
-#define HID_USAGE_PAGE_LED        uint16_t (0x08)   /* LEDs */
-#define HID_USAGE_PAGE_BUTTON     uint16_t (0x09)   /* Button */
-#define HID_USAGE_PAGE_ORDINAL    uint16_t (0x0A)   /* Ordinal */
-#define HID_USAGE_PAGE_PHONE      uint16_t (0x0B)   /* Telephony */
-#define HID_USAGE_PAGE_CONSUMER   uint16_t (0x0C)   /* Consumer */
-#define HID_USAGE_PAGE_DIGITIZER  uint16_t (0x0D)   /* Digitizer*/
-/* 0E    Reserved */
-#define HID_USAGE_PAGE_PID        uint16_t (0x0F)   /* PID Page (force feedback and related devices) */
-#define HID_USAGE_PAGE_UNICODE    uint16_t (0x10)   /* Unicode */
-/* 11-13 Reserved */
-#define HID_USAGE_PAGE_ALNUM_DISP uint16_t (0x14)   /* Alphanumeric Display */
-/* 15-1f Reserved */
-/**** END of top level pages */
-/* 25-3f Reserved */
-#define HID_USAGE_PAGE_MEDICAL    uint16_t (0x40)   /* Medical Instruments */
-/* 41-7F Reserved */
-/*80-83 Monitor pages USB Device Class Definition for Monitor Devices
-  84-87 Power pages USB Device Class Definition for Power Devices */
-/* 88-8B Reserved */
-#define HID_USAGE_PAGE_BARCODE    uint16_t (0x8C)   /* Bar Code Scanner page */
-#define HID_USAGE_PAGE_SCALE      uint16_t (0x8D)   /* Scale page */
-#define HID_USAGE_PAGE_MSR        uint16_t (0x8E)   /* Magnetic Stripe Reading (MSR) Devices */
-#define HID_USAGE_PAGE_POS        uint16_t (0x8F)   /* Reserved Point of Sale pages */
-#define HID_USAGE_PAGE_CAMERA_CTR uint16_t (0x90)   /* Camera Control Page */
-#define HID_USAGE_PAGE_ARCADE     uint16_t (0x91)   /* Arcade Page */
-
-/****************************************************/
-/* Usage definitions for the "Generic Decktop" page */
-/****************************************************/
-#define HID_USAGE_UNDEFINED     uint16_t (0x00)   /* Undefined */
-#define HID_USAGE_POINTER       uint16_t (0x01)   /* Pointer (Physical Collection) */
-#define HID_USAGE_MOUSE         uint16_t (0x02)   /* Mouse (Application Collection) */
-/* 03 Reserved */
-#define HID_USAGE_JOYSTICK      uint16_t (0x04)   /* Joystick (Application Collection) */
-#define HID_USAGE_GAMEPAD       uint16_t (0x05)   /* Game Pad (Application Collection) */
-#define HID_USAGE_KBD           uint16_t (0x06)   /* Keyboard (Application Collection) */
-#define HID_USAGE_KEYPAD        uint16_t (0x07)   /* Keypad (Application Collection) */
-#define HID_USAGE_MAX_CTR       uint16_t (0x08)   /* Multi-axis Controller (Application Collection) */
-/* 09-2F Reserved */
-#define HID_USAGE_X             uint16_t (0x30)   /* X (Dynamic Value) */
-#define HID_USAGE_Y             uint16_t (0x31)   /* Y (Dynamic Value) */
-#define HID_USAGE_Z             uint16_t (0x32)   /* Z (Dynamic Value) */
-#define HID_USAGE_RX            uint16_t (0x33)   /* Rx (Dynamic Value) */
-#define HID_USAGE_RY            uint16_t (0x34)   /* Ry (Dynamic Value) */
-#define HID_USAGE_RZ            uint16_t (0x35)   /* Rz (Dynamic Value) */
-#define HID_USAGE_SLIDER        uint16_t (0x36)   /* Slider (Dynamic Value) */
-#define HID_USAGE_DIAL          uint16_t (0x37)   /* Dial (Dynamic Value) */
-#define HID_USAGE_WHEEL         uint16_t (0x38)   /* Wheel (Dynamic Value) */
-#define HID_USAGE_HATSW         uint16_t (0x39)   /* Hat switch (Dynamic Value) */
-#define HID_USAGE_COUNTEDBUF    uint16_t (0x3A)   /* Counted Buffer (Logical Collection) */
-#define HID_USAGE_BYTECOUNT     uint16_t (0x3B)   /* Byte Count (Dynamic Value) */
-#define HID_USAGE_MOTIONWAKE    uint16_t (0x3C)   /* Motion Wakeup (One Shot Control) */
-#define HID_USAGE_START         uint16_t (0x3D)   /* Start (On/Off Control) */
-#define HID_USAGE_SELECT        uint16_t (0x3E)   /* Select (On/Off Control) */
-/* 3F Reserved */
-#define HID_USAGE_VX            uint16_t (0x40)   /* Vx (Dynamic Value) */
-#define HID_USAGE_VY            uint16_t (0x41)   /* Vy (Dynamic Value) */
-#define HID_USAGE_VZ            uint16_t (0x42)   /* Vz (Dynamic Value) */
-#define HID_USAGE_VBRX          uint16_t (0x43)   /* Vbrx (Dynamic Value) */
-#define HID_USAGE_VBRY          uint16_t (0x44)   /* Vbry (Dynamic Value) */
-#define HID_USAGE_VBRZ          uint16_t (0x45)   /* Vbrz (Dynamic Value) */
-#define HID_USAGE_VNO           uint16_t (0x46)   /* Vno (Dynamic Value) */
-#define HID_USAGE_FEATNOTIF     uint16_t (0x47)   /* Feature Notification (Dynamic Value),(Dynamic Flag) */
-/* 48-7F Reserved */
-#define HID_USAGE_SYSCTL        uint16_t (0x80)   /* System Control (Application Collection) */
-#define HID_USAGE_PWDOWN        uint16_t (0x81)   /* System Power Down (One Shot Control) */
-#define HID_USAGE_SLEEP         uint16_t (0x82)   /* System Sleep (One Shot Control) */
-#define HID_USAGE_WAKEUP        uint16_t (0x83)   /* System Wake Up (One Shot Control)  */
-#define HID_USAGE_CONTEXTM      uint16_t (0x84)   /* System Context Menu (One Shot Control) */
-#define HID_USAGE_MAINM         uint16_t (0x85)   /* System Main Menu (One Shot Control) */
-#define HID_USAGE_APPM          uint16_t (0x86)   /* System App Menu (One Shot Control) */
-#define HID_USAGE_MENUHELP      uint16_t (0x87)   /* System Menu Help (One Shot Control) */
-#define HID_USAGE_MENUEXIT      uint16_t (0x88)   /* System Menu Exit (One Shot Control) */
-#define HID_USAGE_MENUSELECT    uint16_t (0x89)   /* System Menu Select (One Shot Control) */
-#define HID_USAGE_SYSM_RIGHT    uint16_t (0x8A)   /* System Menu Right (Re-Trigger Control) */
-#define HID_USAGE_SYSM_LEFT     uint16_t (0x8B)   /* System Menu Left (Re-Trigger Control) */
-#define HID_USAGE_SYSM_UP       uint16_t (0x8C)   /* System Menu Up (Re-Trigger Control) */
-#define HID_USAGE_SYSM_DOWN     uint16_t (0x8D)   /* System Menu Down (Re-Trigger Control) */
-#define HID_USAGE_COLDRESET     uint16_t (0x8E)   /* System Cold Restart (One Shot Control) */
-#define HID_USAGE_WARMRESET     uint16_t (0x8F)   /* System Warm Restart (One Shot Control) */
-#define HID_USAGE_DUP           uint16_t (0x90)   /* D-pad Up (On/Off Control) */
-#define HID_USAGE_DDOWN         uint16_t (0x91)   /* D-pad Down (On/Off Control) */
-#define HID_USAGE_DRIGHT        uint16_t (0x92)   /* D-pad Right (On/Off Control) */
-#define HID_USAGE_DLEFT         uint16_t (0x93)   /* D-pad Left (On/Off Control) */
-/* 94-9F Reserved */
-#define HID_USAGE_SYS_DOCK      uint16_t (0xA0)   /* System Dock (One Shot Control) */
-#define HID_USAGE_SYS_UNDOCK    uint16_t (0xA1)   /* System Undock (One Shot Control) */
-#define HID_USAGE_SYS_SETUP     uint16_t (0xA2)   /* System Setup (One Shot Control) */
-#define HID_USAGE_SYS_BREAK     uint16_t (0xA3)   /* System Break (One Shot Control) */
-#define HID_USAGE_SYS_DBGBRK    uint16_t (0xA4)   /* System Debugger Break (One Shot Control) */
-#define HID_USAGE_APP_BRK       uint16_t (0xA5)   /* Application Break (One Shot Control) */
-#define HID_USAGE_APP_DBGBRK    uint16_t (0xA6)   /* Application Debugger Break (One Shot Control) */
-#define HID_USAGE_SYS_SPKMUTE   uint16_t (0xA7)   /* System Speaker Mute (One Shot Control) */
-#define HID_USAGE_SYS_HIBERN    uint16_t (0xA8)   /* System Hibernate (One Shot Control) */
-/* A9-AF Reserved */
-#define HID_USAGE_SYS_SIDPINV   uint16_t (0xB0)   /* System Display Invert (One Shot Control) */
-#define HID_USAGE_SYS_DISPINT   uint16_t (0xB1)   /* System Display Internal (One Shot Control) */
-#define HID_USAGE_SYS_DISPEXT   uint16_t (0xB2)   /* System Display External (One Shot Control) */
-#define HID_USAGE_SYS_DISPBOTH  uint16_t (0xB3)   /* System Display Both (One Shot Control) */
-#define HID_USAGE_SYS_DISPDUAL  uint16_t (0xB4)   /* System Display Dual (One Shot Control) */
-#define HID_USAGE_SYS_DISPTGLIE uint16_t (0xB5)   /* System Display Toggle Int/Ext (One Shot Control) */
-#define HID_USAGE_SYS_DISP_SWAP uint16_t (0xB6)   /* System Display Swap Primary/Secondary (One Shot Control) */
-#define HID_USAGE_SYS_DIPS_LCDA uint16_t (0xB7)   /* System Display LCD Autoscale (One Shot Control) */
-/* B8-FFFF Reserved */
-
-/**
-  * @}
-  */ 
-
-#endif /* _HID_USAGE_H_ */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_hid_keybd.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contain the USAGE page codes              
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+#ifndef _HID_USAGE_H_
+#define _HID_USAGE_H_
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_HID_USAGE
+  * @brief This file is the Header file for USBH_HID_USAGE.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_HID_USAGE_Exported_Types
+  * @{
+  */
+
+/****************************************************/
+/* HID 1.11 usage pages                             */
+/****************************************************/
+
+#define HID_USAGE_PAGE_UNDEFINED  uint16_t (0x00)   /* Undefined */
+/**** Top level pages */
+#define HID_USAGE_PAGE_GEN_DES    uint16_t (0x01)   /* Generic Desktop Controls*/
+#define HID_USAGE_PAGE_SIM_CTR    uint16_t (0x02)   /* Simulation Controls */
+#define HID_USAGE_PAGE_VR_CTR     uint16_t (0x03)   /* VR Controls */
+#define HID_USAGE_PAGE_SPORT_CTR  uint16_t (0x04)   /* Sport Controls */
+#define HID_USAGE_PAGE_GAME_CTR   uint16_t (0x05)   /* Game Controls */
+#define HID_USAGE_PAGE_GEN_DEV    uint16_t (0x06)   /* Generic Device Controls */
+#define HID_USAGE_PAGE_KEYB       uint16_t (0x07)   /* Keyboard/Keypad */
+#define HID_USAGE_PAGE_LED        uint16_t (0x08)   /* LEDs */
+#define HID_USAGE_PAGE_BUTTON     uint16_t (0x09)   /* Button */
+#define HID_USAGE_PAGE_ORDINAL    uint16_t (0x0A)   /* Ordinal */
+#define HID_USAGE_PAGE_PHONE      uint16_t (0x0B)   /* Telephony */
+#define HID_USAGE_PAGE_CONSUMER   uint16_t (0x0C)   /* Consumer */
+#define HID_USAGE_PAGE_DIGITIZER  uint16_t (0x0D)   /* Digitizer*/
+/* 0E    Reserved */
+#define HID_USAGE_PAGE_PID        uint16_t (0x0F)   /* PID Page (force feedback and related devices) */
+#define HID_USAGE_PAGE_UNICODE    uint16_t (0x10)   /* Unicode */
+/* 11-13 Reserved */
+#define HID_USAGE_PAGE_ALNUM_DISP uint16_t (0x14)   /* Alphanumeric Display */
+/* 15-1f Reserved */
+/**** END of top level pages */
+/* 25-3f Reserved */
+#define HID_USAGE_PAGE_MEDICAL    uint16_t (0x40)   /* Medical Instruments */
+/* 41-7F Reserved */
+/*80-83 Monitor pages USB Device Class Definition for Monitor Devices
+  84-87 Power pages USB Device Class Definition for Power Devices */
+/* 88-8B Reserved */
+#define HID_USAGE_PAGE_BARCODE    uint16_t (0x8C)   /* Bar Code Scanner page */
+#define HID_USAGE_PAGE_SCALE      uint16_t (0x8D)   /* Scale page */
+#define HID_USAGE_PAGE_MSR        uint16_t (0x8E)   /* Magnetic Stripe Reading (MSR) Devices */
+#define HID_USAGE_PAGE_POS        uint16_t (0x8F)   /* Reserved Point of Sale pages */
+#define HID_USAGE_PAGE_CAMERA_CTR uint16_t (0x90)   /* Camera Control Page */
+#define HID_USAGE_PAGE_ARCADE     uint16_t (0x91)   /* Arcade Page */
+
+/****************************************************/
+/* Usage definitions for the "Generic Decktop" page */
+/****************************************************/
+#define HID_USAGE_UNDEFINED     uint16_t (0x00)   /* Undefined */
+#define HID_USAGE_POINTER       uint16_t (0x01)   /* Pointer (Physical Collection) */
+#define HID_USAGE_MOUSE         uint16_t (0x02)   /* Mouse (Application Collection) */
+/* 03 Reserved */
+#define HID_USAGE_JOYSTICK      uint16_t (0x04)   /* Joystick (Application Collection) */
+#define HID_USAGE_GAMEPAD       uint16_t (0x05)   /* Game Pad (Application Collection) */
+#define HID_USAGE_KBD           uint16_t (0x06)   /* Keyboard (Application Collection) */
+#define HID_USAGE_KEYPAD        uint16_t (0x07)   /* Keypad (Application Collection) */
+#define HID_USAGE_MAX_CTR       uint16_t (0x08)   /* Multi-axis Controller (Application Collection) */
+/* 09-2F Reserved */
+#define HID_USAGE_X             uint16_t (0x30)   /* X (Dynamic Value) */
+#define HID_USAGE_Y             uint16_t (0x31)   /* Y (Dynamic Value) */
+#define HID_USAGE_Z             uint16_t (0x32)   /* Z (Dynamic Value) */
+#define HID_USAGE_RX            uint16_t (0x33)   /* Rx (Dynamic Value) */
+#define HID_USAGE_RY            uint16_t (0x34)   /* Ry (Dynamic Value) */
+#define HID_USAGE_RZ            uint16_t (0x35)   /* Rz (Dynamic Value) */
+#define HID_USAGE_SLIDER        uint16_t (0x36)   /* Slider (Dynamic Value) */
+#define HID_USAGE_DIAL          uint16_t (0x37)   /* Dial (Dynamic Value) */
+#define HID_USAGE_WHEEL         uint16_t (0x38)   /* Wheel (Dynamic Value) */
+#define HID_USAGE_HATSW         uint16_t (0x39)   /* Hat switch (Dynamic Value) */
+#define HID_USAGE_COUNTEDBUF    uint16_t (0x3A)   /* Counted Buffer (Logical Collection) */
+#define HID_USAGE_BYTECOUNT     uint16_t (0x3B)   /* Byte Count (Dynamic Value) */
+#define HID_USAGE_MOTIONWAKE    uint16_t (0x3C)   /* Motion Wakeup (One Shot Control) */
+#define HID_USAGE_START         uint16_t (0x3D)   /* Start (On/Off Control) */
+#define HID_USAGE_SELECT        uint16_t (0x3E)   /* Select (On/Off Control) */
+/* 3F Reserved */
+#define HID_USAGE_VX            uint16_t (0x40)   /* Vx (Dynamic Value) */
+#define HID_USAGE_VY            uint16_t (0x41)   /* Vy (Dynamic Value) */
+#define HID_USAGE_VZ            uint16_t (0x42)   /* Vz (Dynamic Value) */
+#define HID_USAGE_VBRX          uint16_t (0x43)   /* Vbrx (Dynamic Value) */
+#define HID_USAGE_VBRY          uint16_t (0x44)   /* Vbry (Dynamic Value) */
+#define HID_USAGE_VBRZ          uint16_t (0x45)   /* Vbrz (Dynamic Value) */
+#define HID_USAGE_VNO           uint16_t (0x46)   /* Vno (Dynamic Value) */
+#define HID_USAGE_FEATNOTIF     uint16_t (0x47)   /* Feature Notification (Dynamic Value),(Dynamic Flag) */
+/* 48-7F Reserved */
+#define HID_USAGE_SYSCTL        uint16_t (0x80)   /* System Control (Application Collection) */
+#define HID_USAGE_PWDOWN        uint16_t (0x81)   /* System Power Down (One Shot Control) */
+#define HID_USAGE_SLEEP         uint16_t (0x82)   /* System Sleep (One Shot Control) */
+#define HID_USAGE_WAKEUP        uint16_t (0x83)   /* System Wake Up (One Shot Control)  */
+#define HID_USAGE_CONTEXTM      uint16_t (0x84)   /* System Context Menu (One Shot Control) */
+#define HID_USAGE_MAINM         uint16_t (0x85)   /* System Main Menu (One Shot Control) */
+#define HID_USAGE_APPM          uint16_t (0x86)   /* System App Menu (One Shot Control) */
+#define HID_USAGE_MENUHELP      uint16_t (0x87)   /* System Menu Help (One Shot Control) */
+#define HID_USAGE_MENUEXIT      uint16_t (0x88)   /* System Menu Exit (One Shot Control) */
+#define HID_USAGE_MENUSELECT    uint16_t (0x89)   /* System Menu Select (One Shot Control) */
+#define HID_USAGE_SYSM_RIGHT    uint16_t (0x8A)   /* System Menu Right (Re-Trigger Control) */
+#define HID_USAGE_SYSM_LEFT     uint16_t (0x8B)   /* System Menu Left (Re-Trigger Control) */
+#define HID_USAGE_SYSM_UP       uint16_t (0x8C)   /* System Menu Up (Re-Trigger Control) */
+#define HID_USAGE_SYSM_DOWN     uint16_t (0x8D)   /* System Menu Down (Re-Trigger Control) */
+#define HID_USAGE_COLDRESET     uint16_t (0x8E)   /* System Cold Restart (One Shot Control) */
+#define HID_USAGE_WARMRESET     uint16_t (0x8F)   /* System Warm Restart (One Shot Control) */
+#define HID_USAGE_DUP           uint16_t (0x90)   /* D-pad Up (On/Off Control) */
+#define HID_USAGE_DDOWN         uint16_t (0x91)   /* D-pad Down (On/Off Control) */
+#define HID_USAGE_DRIGHT        uint16_t (0x92)   /* D-pad Right (On/Off Control) */
+#define HID_USAGE_DLEFT         uint16_t (0x93)   /* D-pad Left (On/Off Control) */
+/* 94-9F Reserved */
+#define HID_USAGE_SYS_DOCK      uint16_t (0xA0)   /* System Dock (One Shot Control) */
+#define HID_USAGE_SYS_UNDOCK    uint16_t (0xA1)   /* System Undock (One Shot Control) */
+#define HID_USAGE_SYS_SETUP     uint16_t (0xA2)   /* System Setup (One Shot Control) */
+#define HID_USAGE_SYS_BREAK     uint16_t (0xA3)   /* System Break (One Shot Control) */
+#define HID_USAGE_SYS_DBGBRK    uint16_t (0xA4)   /* System Debugger Break (One Shot Control) */
+#define HID_USAGE_APP_BRK       uint16_t (0xA5)   /* Application Break (One Shot Control) */
+#define HID_USAGE_APP_DBGBRK    uint16_t (0xA6)   /* Application Debugger Break (One Shot Control) */
+#define HID_USAGE_SYS_SPKMUTE   uint16_t (0xA7)   /* System Speaker Mute (One Shot Control) */
+#define HID_USAGE_SYS_HIBERN    uint16_t (0xA8)   /* System Hibernate (One Shot Control) */
+/* A9-AF Reserved */
+#define HID_USAGE_SYS_SIDPINV   uint16_t (0xB0)   /* System Display Invert (One Shot Control) */
+#define HID_USAGE_SYS_DISPINT   uint16_t (0xB1)   /* System Display Internal (One Shot Control) */
+#define HID_USAGE_SYS_DISPEXT   uint16_t (0xB2)   /* System Display External (One Shot Control) */
+#define HID_USAGE_SYS_DISPBOTH  uint16_t (0xB3)   /* System Display Both (One Shot Control) */
+#define HID_USAGE_SYS_DISPDUAL  uint16_t (0xB4)   /* System Display Dual (One Shot Control) */
+#define HID_USAGE_SYS_DISPTGLIE uint16_t (0xB5)   /* System Display Toggle Int/Ext (One Shot Control) */
+#define HID_USAGE_SYS_DISP_SWAP uint16_t (0xB6)   /* System Display Swap Primary/Secondary (One Shot Control) */
+#define HID_USAGE_SYS_DIPS_LCDA uint16_t (0xB7)   /* System Display LCD Autoscale (One Shot Control) */
+/* B8-FFFF Reserved */
+
+/**
+  * @}
+  */ 
+
+#endif /* _HID_USAGE_H_ */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid.c b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid.c
index a56f45c5c79295eef8cbf8de548eaf38deb901d5..45b5448eb919e83466833b5d069a579ee3a9e0ab 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid.c
+++ b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid.c
@@ -1,800 +1,800 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the HID Layer Handlers for USB Host HID class.
-  *
-  * @verbatim
-  *      
-  *          ===================================================================      
-  *                                HID Class  Description
-  *          =================================================================== 
-  *           This module manages the MSC class V1.11 following the "Device Class Definition
-  *           for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
-  *           This driver implements the following aspects of the specification:
-  *             - The Boot Interface Subclass
-  *             - The Mouse and Keyboard protocols
-  *      
-  *  @endverbatim
-  *
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid.h"
-#include "usbh_hid_parser.h"
-
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_HID_CLASS
-* @{
-*/
-
-/** @defgroup USBH_HID_CORE 
-* @brief    This file includes HID Layer Handlers for USB Host HID class.
-* @{
-*/ 
-
-/** @defgroup USBH_HID_CORE_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_HID_CORE_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_HID_CORE_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_HID_CORE_Private_Variables
-* @{
-*/
-
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_HID_CORE_Private_FunctionPrototypes
-* @{
-*/ 
-
-static USBH_StatusTypeDef USBH_HID_InterfaceInit  (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_InterfaceDeInit  (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost);
-static void  USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf);
-
-extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
-extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
-
-USBH_ClassTypeDef  HID_Class = 
-{
-  "HID",
-  USB_HID_CLASS,
-  USBH_HID_InterfaceInit,
-  USBH_HID_InterfaceDeInit,
-  USBH_HID_ClassRequest,
-  USBH_HID_Process,
-  USBH_HID_SOFProcess,
-  NULL,
-};
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_HID_CORE_Private_Functions
-* @{
-*/ 
-
-
-/**
-  * @brief  USBH_HID_InterfaceInit 
-  *         The function init the HID class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
-{	
-  uint8_t max_ep;
-  uint8_t num = 0;
-  uint8_t interface;
-  
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  HID_HandleTypeDef *HID_Handle;
-  
-  interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);
-  
-  if(interface == 0xFF) /* No Valid Interface */
-  {
-    status = USBH_FAIL;  
-    USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);         
-  }
-  else
-  {
-    USBH_SelectInterface (phost, interface);
-    phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef));
-    HID_Handle =  phost->pActiveClass->pData; 
-    HID_Handle->state = HID_ERROR;
-    
-    /*Decode Bootclass Protocl: Mouse or Keyboard*/
-    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
-    {
-      USBH_UsrLog ("KeyBoard device found!"); 
-      HID_Handle->Init =  USBH_HID_KeybdInit;     
-    }
-    else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol  == HID_MOUSE_BOOT_CODE)		  
-    {
-      USBH_UsrLog ("Mouse device found!");         
-      HID_Handle->Init =  USBH_HID_MouseInit;     
-    }
-    else
-    {
-      USBH_UsrLog ("Protocol not supported.");  
-      return USBH_FAIL;
-    }
-    
-    HID_Handle->state     = HID_INIT;
-    HID_Handle->ctl_state = HID_REQ_INIT; 
-    HID_Handle->ep_addr   = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress;
-    HID_Handle->length    = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
-    HID_Handle->poll      = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bInterval ;
-    
-    if (HID_Handle->poll  < HID_MIN_POLL) 
-    {
-      HID_Handle->poll = HID_MIN_POLL;
-    }
-    
-    /* Check fo available number of endpoints */
-    /* Find the number of EPs in the Interface Descriptor */      
-    /* Choose the lower number in order not to overrun the buffer allocated */
-    max_ep = ( (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ? 
-              phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints :
-                  USBH_MAX_NUM_ENDPOINTS); 
-    
-    
-    /* Decode endpoint IN and OUT address from interface descriptor */
-    for ( ;num < max_ep; num++)
-    {
-      if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80)
-      {
-        HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
-        HID_Handle->InPipe  =\
-          USBH_AllocPipe(phost, HID_Handle->InEp);
-        
-        /* Open pipe for IN endpoint */
-        USBH_OpenPipe  (phost,
-                        HID_Handle->InPipe,
-                        HID_Handle->InEp,
-                        phost->device.address,
-                        phost->device.speed,
-                        USB_EP_TYPE_INTR,
-                        HID_Handle->length); 
-        
-        USBH_LL_SetToggle (phost, HID_Handle->InPipe, 0);
-        
-      }
-      else
-      {
-        HID_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
-        HID_Handle->OutPipe  =\
-          USBH_AllocPipe(phost, HID_Handle->OutEp);
-        
-        /* Open pipe for OUT endpoint */
-        USBH_OpenPipe  (phost,
-                        HID_Handle->OutPipe,
-                        HID_Handle->OutEp,                            
-                        phost->device.address,
-                        phost->device.speed,
-                        USB_EP_TYPE_INTR,
-                        HID_Handle->length); 
-        
-        USBH_LL_SetToggle (phost, HID_Handle->OutPipe, 0);        
-      }
-      
-    }  
-    status = USBH_OK;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_HID_InterfaceDeInit 
-  *         The function DeInit the Pipes used for the HID class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost )
-{	
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData; 
-  
-  if(HID_Handle->InPipe != 0x00)
-  {   
-    USBH_ClosePipe  (phost, HID_Handle->InPipe);
-    USBH_FreePipe  (phost, HID_Handle->InPipe);
-    HID_Handle->InPipe = 0;     /* Reset the pipe as Free */  
-  }
-  
-  if(HID_Handle->OutPipe != 0x00)
-  {   
-    USBH_ClosePipe(phost, HID_Handle->OutPipe);
-    USBH_FreePipe  (phost, HID_Handle->OutPipe);
-    HID_Handle->OutPipe = 0;     /* Reset the pipe as Free */  
-  }
-  
-  if(phost->pActiveClass->pData)
-  {
-    USBH_free (phost->pActiveClass->pData);
-  }
-
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_HID_ClassRequest 
-  *         The function is responsible for handling Standard requests
-  *         for HID class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
-{   
-  
-  USBH_StatusTypeDef status         = USBH_BUSY;
-  USBH_StatusTypeDef classReqStatus = USBH_BUSY;
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData; 
-
-  /* Switch HID state machine */
-  switch (HID_Handle->ctl_state)
-  {
-  case HID_REQ_INIT:  
-  case HID_REQ_GET_HID_DESC:
-    
-    /* Get HID Desc */ 
-    if (USBH_HID_GetHIDDescriptor (phost, USB_HID_DESC_SIZE)== USBH_OK)
-    {
-      
-      USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data);
-      HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC;
-    }
-    
-    break;     
-  case HID_REQ_GET_REPORT_DESC:
-    
-    
-    /* Get Report Desc */ 
-    if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK)
-    {
-      /* The decriptor is available in phost->device.Data */
-
-      HID_Handle->ctl_state = HID_REQ_SET_IDLE;
-    }
-    
-    break;
-    
-  case HID_REQ_SET_IDLE:
-    
-    classReqStatus = USBH_HID_SetIdle (phost, 0, 0);
-    
-    /* set Idle */
-    if (classReqStatus == USBH_OK)
-    {
-      HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;  
-    }
-    else if(classReqStatus == USBH_NOT_SUPPORTED) 
-    {
-      HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;        
-    } 
-    break; 
-    
-  case HID_REQ_SET_PROTOCOL:
-    /* set protocol */
-    if (USBH_HID_SetProtocol (phost, 0) == USBH_OK)
-    {
-      HID_Handle->ctl_state = HID_REQ_IDLE;
-      
-      /* all requests performed*/
-      phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
-      status = USBH_OK; 
-    } 
-    break;
-    
-  case HID_REQ_IDLE:
-  default:
-    break;
-  }
-  
-  return status; 
-}
-
-/**
-  * @brief  USBH_HID_Process 
-  *         The function is for managing state machine for HID data transfers 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_OK;
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
-  
-  switch (HID_Handle->state)
-  {
-  case HID_INIT:
-    HID_Handle->Init(phost); 
-  case HID_IDLE:
-    if(USBH_HID_GetReport (phost,
-                           0x01,
-                            0,
-                            HID_Handle->pData,
-                            HID_Handle->length) == USBH_OK)
-    {
-      
-      fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);  
-      HID_Handle->state = HID_SYNC;
-    }
-    
-    break;
-    
-  case HID_SYNC:
-
-    /* Sync with start of Even Frame */
-    if(phost->Timer & 1)
-    {
-      HID_Handle->state = HID_GET_DATA; 
-    }
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif   
-    break;
-    
-  case HID_GET_DATA:
-
-    USBH_InterruptReceiveData(phost, 
-                              HID_Handle->pData,
-                              HID_Handle->length,
-                              HID_Handle->InPipe);
-    
-    HID_Handle->state = HID_POLL;
-    HID_Handle->timer = phost->Timer;
-    HID_Handle->DataReady = 0;
-    break;
-    
-  case HID_POLL:
-    
-    if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_DONE)
-    {
-      if(HID_Handle->DataReady == 0)
-      {
-        fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
-        HID_Handle->DataReady = 1;
-        USBH_HID_EventCallback(phost);
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif          
-      }
-    }
-    else if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_STALL) /* IN Endpoint Stalled */
-    {
-      
-      /* Issue Clear Feature on interrupt IN endpoint */ 
-      if(USBH_ClrFeature(phost,
-                         HID_Handle->ep_addr) == USBH_OK)
-      {
-        /* Change state to issue next IN token */
-        HID_Handle->state = HID_GET_DATA;
-      }
-    } 
-    
-
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_HID_SOFProcess 
-  *         The function is for managing the SOF Process 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost)
-{
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
-  
-  if(HID_Handle->state == HID_POLL)
-  {
-    if(( phost->Timer - HID_Handle->timer) >= HID_Handle->poll)
-    {
-      HID_Handle->state = HID_GET_DATA;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-  }
-  return USBH_OK;
-}
-
-/**
-* @brief  USBH_Get_HID_ReportDescriptor
-  *         Issue report Descriptor command to the device. Once the response 
-  *         received, parse the report descriptor and update the status.
-  * @param  phost: Host handle
-  * @param  Length : HID Report Descriptor Length
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
-                                                         uint16_t length)
-{
-  
-  USBH_StatusTypeDef status;
-  
-  status = USBH_GetDescriptor(phost,
-                              USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,                                  
-                              USB_DESC_HID_REPORT, 
-                              phost->device.Data,
-                              length);
-  
-  /* HID report descriptor is available in phost->device.Data.
-  In case of USB Boot Mode devices for In report handling ,
-  HID report descriptor parsing is not required.
-  In case, for supporting Non-Boot Protocol devices and output reports,
-  user may parse the report descriptor*/
-  
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_Get_HID_Descriptor
-  *         Issue HID Descriptor command to the device. Once the response 
-  *         received, parse the report descriptor and update the status.
-  * @param  phost: Host handle
-  * @param  Length : HID Descriptor Length
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
-                                            uint16_t length)
-{
-  
-  USBH_StatusTypeDef status;
-  
-  status = USBH_GetDescriptor( phost,
-                              USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,                                  
-                              USB_DESC_HID,
-                              phost->device.Data,
-                              length);
- 
-  return status;
-}
-
-/**
-  * @brief  USBH_Set_Idle
-  *         Set Idle State. 
-  * @param  phost: Host handle
-  * @param  duration: Duration for HID Idle request
-  * @param  reportId : Targetted report ID for Set Idle request
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
-                                         uint8_t duration,
-                                         uint8_t reportId)
-{
-  
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
-    USB_REQ_TYPE_CLASS;
-  
-  
-  phost->Control.setup.b.bRequest = USB_HID_SET_IDLE;
-  phost->Control.setup.b.wValue.w = (duration << 8 ) | reportId;
-  
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = 0;
-  
-  return USBH_CtlReq(phost, 0 , 0 );
-}
-
-
-/**
-  * @brief  USBH_HID_Set_Report
-  *         Issues Set Report 
-  * @param  phost: Host handle
-  * @param  reportType  : Report type to be sent
-  * @param  reportId    : Targetted report ID for Set Report request
-  * @param  reportBuff  : Report Buffer
-  * @param  reportLen   : Length of data report to be send
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
-                                    uint8_t reportType,
-                                    uint8_t reportId,
-                                    uint8_t* reportBuff,
-                                    uint8_t reportLen)
-{
-  
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
-    USB_REQ_TYPE_CLASS;
-  
-  
-  phost->Control.setup.b.bRequest = USB_HID_SET_REPORT;
-  phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
-  
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = reportLen;
-  
-  return USBH_CtlReq(phost, reportBuff , reportLen );
-}
-
-
-/**
-  * @brief  USBH_HID_GetReport
-  *         retreive Set Report 
-  * @param  phost: Host handle
-  * @param  reportType  : Report type to be sent
-  * @param  reportId    : Targetted report ID for Set Report request
-  * @param  reportBuff  : Report Buffer
-  * @param  reportLen   : Length of data report to be send
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
-                                    uint8_t reportType,
-                                    uint8_t reportId,
-                                    uint8_t* reportBuff,
-                                    uint8_t reportLen)
-{
-  
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE |\
-    USB_REQ_TYPE_CLASS;
-  
-  
-  phost->Control.setup.b.bRequest = USB_HID_GET_REPORT;
-  phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
-  
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = reportLen;
-  
-  return USBH_CtlReq(phost, reportBuff , reportLen );
-}
-
-/**
-  * @brief  USBH_Set_Protocol
-  *         Set protocol State.
-  * @param  phost: Host handle
-  * @param  protocol : Set Protocol for HID : boot/report protocol
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost,
-                                            uint8_t protocol)
-{
-  
-  
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
-    USB_REQ_TYPE_CLASS;
-  
-  
-  phost->Control.setup.b.bRequest = USB_HID_SET_PROTOCOL;
-  phost->Control.setup.b.wValue.w = protocol != 0 ? 0 : 1;
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = 0;
-  
-  return USBH_CtlReq(phost, 0 , 0 );
-  
-}
-
-/**
-  * @brief  USBH_ParseHIDDesc 
-  *         This function Parse the HID descriptor
-  * @param  desc: HID Descriptor
-  * @param  buf: Buffer where the source descriptor is available
-  * @retval None
-  */
-static void  USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf)
-{
-  
-  desc->bLength                  = *(uint8_t  *) (buf + 0);
-  desc->bDescriptorType          = *(uint8_t  *) (buf + 1);
-  desc->bcdHID                   =  LE16  (buf + 2);
-  desc->bCountryCode             = *(uint8_t  *) (buf + 4);
-  desc->bNumDescriptors          = *(uint8_t  *) (buf + 5);
-  desc->bReportDescriptorType    = *(uint8_t  *) (buf + 6);
-  desc->wItemLength              =  LE16  (buf + 7);
-} 
-
-/**
-  * @brief  USBH_HID_GetDeviceType
-  *         Return Device function.
-  * @param  phost: Host handle
-  * @retval HID function: HID_MOUSE / HID_KEYBOARD
-  */
-HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost)
-{
-  HID_TypeTypeDef   type = HID_UNKNOWN;
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    
-    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
-      == HID_KEYBRD_BOOT_CODE)
-    {
-      type = HID_KEYBOARD;  
-    }
-    else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
-      == HID_MOUSE_BOOT_CODE)		  
-    {
-      type=  HID_MOUSE;  
-    }
-  }
-  return type;
-}
-
-/**
-  * @brief  fifo_init
-  *         Initialize FIFO.
-  * @param  f: Fifo address
-  * @param  buf: Fifo buffer
-  * @param  size: Fifo Size
-  * @retval none
-  */
-void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size)
-{
-     f->head = 0;
-     f->tail = 0;
-     f->lock = 0;
-     f->size = size;
-     f->buf = buf;
-}
-
-/**
-  * @brief  fifo_read
-  *         Read from FIFO.
-  * @param  f: Fifo address
-  * @param  buf: read buffer 
-  * @param  nbytes: number of item to read
-  * @retval number of read items
-  */
-uint16_t  fifo_read(FIFO_TypeDef * f, void * buf, uint16_t  nbytes)
-{
-  uint16_t  i;
-  uint8_t * p;
-  p = buf;
-  
-  if(f->lock == 0)
-  {
-    f->lock = 1;
-    for(i=0; i < nbytes; i++)
-    {
-      if( f->tail != f->head )
-      { 
-        *p++ = f->buf[f->tail];  
-        f->tail++;  
-        if( f->tail == f->size )
-        {  
-          f->tail = 0;
-        }
-      } else 
-      {
-        f->lock = 0;
-        return i; 
-      }
-    }
-  }
-  f->lock = 0;
-  return nbytes;
-}
- 
-/**
-  * @brief  fifo_write
-  *         Read from FIFO.
-  * @param  f: Fifo address
-  * @param  buf: read buffer 
-  * @param  nbytes: number of item to write
-  * @retval number of written items
-  */
-uint16_t  fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t  nbytes)
-{
-  uint16_t  i;
-  const uint8_t * p;
-  p = buf;
-  if(f->lock == 0)
-  {
-    f->lock = 1;
-    for(i=0; i < nbytes; i++)
-    {
-      if( (f->head + 1 == f->tail) ||
-         ( (f->head + 1 == f->size) && (f->tail == 0)) )
-      {
-        f->lock = 0;
-        return i;
-      } 
-      else 
-      {
-        f->buf[f->head] = *p++;
-        f->head++;
-        if( f->head == f->size )
-        {
-          f->head = 0;
-        }
-      }
-    }
-  }
-  f->lock = 0;
-  return nbytes;
-}
-
-
-/**
-* @brief  The function is a callback about HID Data events
-*  @param  phost: Selected device
-* @retval None
-*/
-__weak void USBH_HID_EventCallback(USBH_HandleTypeDef *phost)
-{
-  
-}
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_hid.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the HID Layer Handlers for USB Host HID class.
+  *
+  * @verbatim
+  *      
+  *          ===================================================================      
+  *                                HID Class  Description
+  *          =================================================================== 
+  *           This module manages the MSC class V1.11 following the "Device Class Definition
+  *           for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
+  *           This driver implements the following aspects of the specification:
+  *             - The Boot Interface Subclass
+  *             - The Mouse and Keyboard protocols
+  *      
+  *  @endverbatim
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid.h"
+#include "usbh_hid_parser.h"
+
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_HID_CLASS
+* @{
+*/
+
+/** @defgroup USBH_HID_CORE 
+* @brief    This file includes HID Layer Handlers for USB Host HID class.
+* @{
+*/ 
+
+/** @defgroup USBH_HID_CORE_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_HID_CORE_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_HID_CORE_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_HID_CORE_Private_Variables
+* @{
+*/
+
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_HID_CORE_Private_FunctionPrototypes
+* @{
+*/ 
+
+static USBH_StatusTypeDef USBH_HID_InterfaceInit  (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_HID_InterfaceDeInit  (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost);
+static void  USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf);
+
+extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
+extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
+
+USBH_ClassTypeDef  HID_Class = 
+{
+  "HID",
+  USB_HID_CLASS,
+  USBH_HID_InterfaceInit,
+  USBH_HID_InterfaceDeInit,
+  USBH_HID_ClassRequest,
+  USBH_HID_Process,
+  USBH_HID_SOFProcess,
+  NULL,
+};
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_HID_CORE_Private_Functions
+* @{
+*/ 
+
+
+/**
+  * @brief  USBH_HID_InterfaceInit 
+  *         The function init the HID class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
+{	
+  uint8_t max_ep;
+  uint8_t num = 0;
+  uint8_t interface;
+  
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  HID_HandleTypeDef *HID_Handle;
+  
+  interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);
+  
+  if(interface == 0xFF) /* No Valid Interface */
+  {
+    status = USBH_FAIL;  
+    USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);         
+  }
+  else
+  {
+    USBH_SelectInterface (phost, interface);
+    phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef));
+    HID_Handle =  phost->pActiveClass->pData; 
+    HID_Handle->state = HID_ERROR;
+    
+    /*Decode Bootclass Protocl: Mouse or Keyboard*/
+    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
+    {
+      USBH_UsrLog ("KeyBoard device found!"); 
+      HID_Handle->Init =  USBH_HID_KeybdInit;     
+    }
+    else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol  == HID_MOUSE_BOOT_CODE)		  
+    {
+      USBH_UsrLog ("Mouse device found!");         
+      HID_Handle->Init =  USBH_HID_MouseInit;     
+    }
+    else
+    {
+      USBH_UsrLog ("Protocol not supported.");  
+      return USBH_FAIL;
+    }
+    
+    HID_Handle->state     = HID_INIT;
+    HID_Handle->ctl_state = HID_REQ_INIT; 
+    HID_Handle->ep_addr   = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress;
+    HID_Handle->length    = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
+    HID_Handle->poll      = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bInterval ;
+    
+    if (HID_Handle->poll  < HID_MIN_POLL) 
+    {
+      HID_Handle->poll = HID_MIN_POLL;
+    }
+    
+    /* Check fo available number of endpoints */
+    /* Find the number of EPs in the Interface Descriptor */      
+    /* Choose the lower number in order not to overrun the buffer allocated */
+    max_ep = ( (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ? 
+              phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints :
+                  USBH_MAX_NUM_ENDPOINTS); 
+    
+    
+    /* Decode endpoint IN and OUT address from interface descriptor */
+    for ( ;num < max_ep; num++)
+    {
+      if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80)
+      {
+        HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
+        HID_Handle->InPipe  =\
+          USBH_AllocPipe(phost, HID_Handle->InEp);
+        
+        /* Open pipe for IN endpoint */
+        USBH_OpenPipe  (phost,
+                        HID_Handle->InPipe,
+                        HID_Handle->InEp,
+                        phost->device.address,
+                        phost->device.speed,
+                        USB_EP_TYPE_INTR,
+                        HID_Handle->length); 
+        
+        USBH_LL_SetToggle (phost, HID_Handle->InPipe, 0);
+        
+      }
+      else
+      {
+        HID_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
+        HID_Handle->OutPipe  =\
+          USBH_AllocPipe(phost, HID_Handle->OutEp);
+        
+        /* Open pipe for OUT endpoint */
+        USBH_OpenPipe  (phost,
+                        HID_Handle->OutPipe,
+                        HID_Handle->OutEp,                            
+                        phost->device.address,
+                        phost->device.speed,
+                        USB_EP_TYPE_INTR,
+                        HID_Handle->length); 
+        
+        USBH_LL_SetToggle (phost, HID_Handle->OutPipe, 0);        
+      }
+      
+    }  
+    status = USBH_OK;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_HID_InterfaceDeInit 
+  *         The function DeInit the Pipes used for the HID class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost )
+{	
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData; 
+  
+  if(HID_Handle->InPipe != 0x00)
+  {   
+    USBH_ClosePipe  (phost, HID_Handle->InPipe);
+    USBH_FreePipe  (phost, HID_Handle->InPipe);
+    HID_Handle->InPipe = 0;     /* Reset the pipe as Free */  
+  }
+  
+  if(HID_Handle->OutPipe != 0x00)
+  {   
+    USBH_ClosePipe(phost, HID_Handle->OutPipe);
+    USBH_FreePipe  (phost, HID_Handle->OutPipe);
+    HID_Handle->OutPipe = 0;     /* Reset the pipe as Free */  
+  }
+  
+  if(phost->pActiveClass->pData)
+  {
+    USBH_free (phost->pActiveClass->pData);
+  }
+
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_HID_ClassRequest 
+  *         The function is responsible for handling Standard requests
+  *         for HID class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
+{   
+  
+  USBH_StatusTypeDef status         = USBH_BUSY;
+  USBH_StatusTypeDef classReqStatus = USBH_BUSY;
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData; 
+
+  /* Switch HID state machine */
+  switch (HID_Handle->ctl_state)
+  {
+  case HID_REQ_INIT:  
+  case HID_REQ_GET_HID_DESC:
+    
+    /* Get HID Desc */ 
+    if (USBH_HID_GetHIDDescriptor (phost, USB_HID_DESC_SIZE)== USBH_OK)
+    {
+      
+      USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data);
+      HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC;
+    }
+    
+    break;     
+  case HID_REQ_GET_REPORT_DESC:
+    
+    
+    /* Get Report Desc */ 
+    if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK)
+    {
+      /* The decriptor is available in phost->device.Data */
+
+      HID_Handle->ctl_state = HID_REQ_SET_IDLE;
+    }
+    
+    break;
+    
+  case HID_REQ_SET_IDLE:
+    
+    classReqStatus = USBH_HID_SetIdle (phost, 0, 0);
+    
+    /* set Idle */
+    if (classReqStatus == USBH_OK)
+    {
+      HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;  
+    }
+    else if(classReqStatus == USBH_NOT_SUPPORTED) 
+    {
+      HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;        
+    } 
+    break; 
+    
+  case HID_REQ_SET_PROTOCOL:
+    /* set protocol */
+    if (USBH_HID_SetProtocol (phost, 0) == USBH_OK)
+    {
+      HID_Handle->ctl_state = HID_REQ_IDLE;
+      
+      /* all requests performed*/
+      phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
+      status = USBH_OK; 
+    } 
+    break;
+    
+  case HID_REQ_IDLE:
+  default:
+    break;
+  }
+  
+  return status; 
+}
+
+/**
+  * @brief  USBH_HID_Process 
+  *         The function is for managing state machine for HID data transfers 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_OK;
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
+  
+  switch (HID_Handle->state)
+  {
+  case HID_INIT:
+    HID_Handle->Init(phost); 
+  case HID_IDLE:
+    if(USBH_HID_GetReport (phost,
+                           0x01,
+                            0,
+                            HID_Handle->pData,
+                            HID_Handle->length) == USBH_OK)
+    {
+      
+      fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);  
+      HID_Handle->state = HID_SYNC;
+    }
+    
+    break;
+    
+  case HID_SYNC:
+
+    /* Sync with start of Even Frame */
+    if(phost->Timer & 1)
+    {
+      HID_Handle->state = HID_GET_DATA; 
+    }
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif   
+    break;
+    
+  case HID_GET_DATA:
+
+    USBH_InterruptReceiveData(phost, 
+                              HID_Handle->pData,
+                              HID_Handle->length,
+                              HID_Handle->InPipe);
+    
+    HID_Handle->state = HID_POLL;
+    HID_Handle->timer = phost->Timer;
+    HID_Handle->DataReady = 0;
+    break;
+    
+  case HID_POLL:
+    
+    if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_DONE)
+    {
+      if(HID_Handle->DataReady == 0)
+      {
+        fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
+        HID_Handle->DataReady = 1;
+        USBH_HID_EventCallback(phost);
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif          
+      }
+    }
+    else if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_STALL) /* IN Endpoint Stalled */
+    {
+      
+      /* Issue Clear Feature on interrupt IN endpoint */ 
+      if(USBH_ClrFeature(phost,
+                         HID_Handle->ep_addr) == USBH_OK)
+      {
+        /* Change state to issue next IN token */
+        HID_Handle->state = HID_GET_DATA;
+      }
+    } 
+    
+
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_HID_SOFProcess 
+  *         The function is for managing the SOF Process 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost)
+{
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
+  
+  if(HID_Handle->state == HID_POLL)
+  {
+    if(( phost->Timer - HID_Handle->timer) >= HID_Handle->poll)
+    {
+      HID_Handle->state = HID_GET_DATA;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+  }
+  return USBH_OK;
+}
+
+/**
+* @brief  USBH_Get_HID_ReportDescriptor
+  *         Issue report Descriptor command to the device. Once the response 
+  *         received, parse the report descriptor and update the status.
+  * @param  phost: Host handle
+  * @param  Length : HID Report Descriptor Length
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
+                                                         uint16_t length)
+{
+  
+  USBH_StatusTypeDef status;
+  
+  status = USBH_GetDescriptor(phost,
+                              USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,                                  
+                              USB_DESC_HID_REPORT, 
+                              phost->device.Data,
+                              length);
+  
+  /* HID report descriptor is available in phost->device.Data.
+  In case of USB Boot Mode devices for In report handling ,
+  HID report descriptor parsing is not required.
+  In case, for supporting Non-Boot Protocol devices and output reports,
+  user may parse the report descriptor*/
+  
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_Get_HID_Descriptor
+  *         Issue HID Descriptor command to the device. Once the response 
+  *         received, parse the report descriptor and update the status.
+  * @param  phost: Host handle
+  * @param  Length : HID Descriptor Length
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
+                                            uint16_t length)
+{
+  
+  USBH_StatusTypeDef status;
+  
+  status = USBH_GetDescriptor( phost,
+                              USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,                                  
+                              USB_DESC_HID,
+                              phost->device.Data,
+                              length);
+ 
+  return status;
+}
+
+/**
+  * @brief  USBH_Set_Idle
+  *         Set Idle State. 
+  * @param  phost: Host handle
+  * @param  duration: Duration for HID Idle request
+  * @param  reportId : Targetted report ID for Set Idle request
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
+                                         uint8_t duration,
+                                         uint8_t reportId)
+{
+  
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
+    USB_REQ_TYPE_CLASS;
+  
+  
+  phost->Control.setup.b.bRequest = USB_HID_SET_IDLE;
+  phost->Control.setup.b.wValue.w = (duration << 8 ) | reportId;
+  
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = 0;
+  
+  return USBH_CtlReq(phost, 0 , 0 );
+}
+
+
+/**
+  * @brief  USBH_HID_Set_Report
+  *         Issues Set Report 
+  * @param  phost: Host handle
+  * @param  reportType  : Report type to be sent
+  * @param  reportId    : Targetted report ID for Set Report request
+  * @param  reportBuff  : Report Buffer
+  * @param  reportLen   : Length of data report to be send
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
+                                    uint8_t reportType,
+                                    uint8_t reportId,
+                                    uint8_t* reportBuff,
+                                    uint8_t reportLen)
+{
+  
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
+    USB_REQ_TYPE_CLASS;
+  
+  
+  phost->Control.setup.b.bRequest = USB_HID_SET_REPORT;
+  phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
+  
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = reportLen;
+  
+  return USBH_CtlReq(phost, reportBuff , reportLen );
+}
+
+
+/**
+  * @brief  USBH_HID_GetReport
+  *         retreive Set Report 
+  * @param  phost: Host handle
+  * @param  reportType  : Report type to be sent
+  * @param  reportId    : Targetted report ID for Set Report request
+  * @param  reportBuff  : Report Buffer
+  * @param  reportLen   : Length of data report to be send
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
+                                    uint8_t reportType,
+                                    uint8_t reportId,
+                                    uint8_t* reportBuff,
+                                    uint8_t reportLen)
+{
+  
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE |\
+    USB_REQ_TYPE_CLASS;
+  
+  
+  phost->Control.setup.b.bRequest = USB_HID_GET_REPORT;
+  phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
+  
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = reportLen;
+  
+  return USBH_CtlReq(phost, reportBuff , reportLen );
+}
+
+/**
+  * @brief  USBH_Set_Protocol
+  *         Set protocol State.
+  * @param  phost: Host handle
+  * @param  protocol : Set Protocol for HID : boot/report protocol
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost,
+                                            uint8_t protocol)
+{
+  
+  
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
+    USB_REQ_TYPE_CLASS;
+  
+  
+  phost->Control.setup.b.bRequest = USB_HID_SET_PROTOCOL;
+  phost->Control.setup.b.wValue.w = protocol != 0 ? 0 : 1;
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = 0;
+  
+  return USBH_CtlReq(phost, 0 , 0 );
+  
+}
+
+/**
+  * @brief  USBH_ParseHIDDesc 
+  *         This function Parse the HID descriptor
+  * @param  desc: HID Descriptor
+  * @param  buf: Buffer where the source descriptor is available
+  * @retval None
+  */
+static void  USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf)
+{
+  
+  desc->bLength                  = *(uint8_t  *) (buf + 0);
+  desc->bDescriptorType          = *(uint8_t  *) (buf + 1);
+  desc->bcdHID                   =  LE16  (buf + 2);
+  desc->bCountryCode             = *(uint8_t  *) (buf + 4);
+  desc->bNumDescriptors          = *(uint8_t  *) (buf + 5);
+  desc->bReportDescriptorType    = *(uint8_t  *) (buf + 6);
+  desc->wItemLength              =  LE16  (buf + 7);
+} 
+
+/**
+  * @brief  USBH_HID_GetDeviceType
+  *         Return Device function.
+  * @param  phost: Host handle
+  * @retval HID function: HID_MOUSE / HID_KEYBOARD
+  */
+HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost)
+{
+  HID_TypeTypeDef   type = HID_UNKNOWN;
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    
+    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
+      == HID_KEYBRD_BOOT_CODE)
+    {
+      type = HID_KEYBOARD;  
+    }
+    else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
+      == HID_MOUSE_BOOT_CODE)		  
+    {
+      type=  HID_MOUSE;  
+    }
+  }
+  return type;
+}
+
+/**
+  * @brief  fifo_init
+  *         Initialize FIFO.
+  * @param  f: Fifo address
+  * @param  buf: Fifo buffer
+  * @param  size: Fifo Size
+  * @retval none
+  */
+void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size)
+{
+     f->head = 0;
+     f->tail = 0;
+     f->lock = 0;
+     f->size = size;
+     f->buf = buf;
+}
+
+/**
+  * @brief  fifo_read
+  *         Read from FIFO.
+  * @param  f: Fifo address
+  * @param  buf: read buffer 
+  * @param  nbytes: number of item to read
+  * @retval number of read items
+  */
+uint16_t  fifo_read(FIFO_TypeDef * f, void * buf, uint16_t  nbytes)
+{
+  uint16_t  i;
+  uint8_t * p;
+  p = buf;
+  
+  if(f->lock == 0)
+  {
+    f->lock = 1;
+    for(i=0; i < nbytes; i++)
+    {
+      if( f->tail != f->head )
+      { 
+        *p++ = f->buf[f->tail];  
+        f->tail++;  
+        if( f->tail == f->size )
+        {  
+          f->tail = 0;
+        }
+      } else 
+      {
+        f->lock = 0;
+        return i; 
+      }
+    }
+  }
+  f->lock = 0;
+  return nbytes;
+}
+ 
+/**
+  * @brief  fifo_write
+  *         Read from FIFO.
+  * @param  f: Fifo address
+  * @param  buf: read buffer 
+  * @param  nbytes: number of item to write
+  * @retval number of written items
+  */
+uint16_t  fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t  nbytes)
+{
+  uint16_t  i;
+  const uint8_t * p;
+  p = buf;
+  if(f->lock == 0)
+  {
+    f->lock = 1;
+    for(i=0; i < nbytes; i++)
+    {
+      if( (f->head + 1 == f->tail) ||
+         ( (f->head + 1 == f->size) && (f->tail == 0)) )
+      {
+        f->lock = 0;
+        return i;
+      } 
+      else 
+      {
+        f->buf[f->head] = *p++;
+        f->head++;
+        if( f->head == f->size )
+        {
+          f->head = 0;
+        }
+      }
+    }
+  }
+  f->lock = 0;
+  return nbytes;
+}
+
+
+/**
+* @brief  The function is a callback about HID Data events
+*  @param  phost: Selected device
+* @retval None
+*/
+__weak void USBH_HID_EventCallback(USBH_HandleTypeDef *phost)
+{
+  
+}
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_keybd.c b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_keybd.c
index 79104767bf90d51e2cd9ace9eb3e4fc2812d98eb..d2a54aaecacf7b3dc9fa1acf2a7c6ee7474c31a5 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_keybd.c
+++ b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_keybd.c
@@ -1,418 +1,418 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_keybd.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the application layer for USB Host HID Keyboard handling
-  *          QWERTY and AZERTY Keyboard are supported as per the selection in 
-  *          usbh_hid_keybd.h              
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid_keybd.h"
-#include "usbh_hid_parser.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_HID_CLASS
-* @{
-*/
-
-/** @defgroup USBH_HID_KEYBD 
-* @brief    This file includes HID Layer Handlers for USB Host HID class.
-* @{
-*/ 
-
-/** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_HID_KEYBD_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-#ifndef AZERTY_KEYBOARD
-  #define QWERTY_KEYBOARD
-#endif
-#define  KBD_LEFT_CTRL                                  0x01
-#define  KBD_LEFT_SHIFT                                 0x02
-#define  KBD_LEFT_ALT                                   0x04
-#define  KBD_LEFT_GUI                                   0x08
-#define  KBD_RIGHT_CTRL                                 0x10
-#define  KBD_RIGHT_SHIFT                                0x20
-#define  KBD_RIGHT_ALT                                  0x40
-#define  KBD_RIGHT_GUI                                  0x80
-#define  KBR_MAX_NBR_PRESSED                            6
-
-/** @defgroup USBH_HID_KEYBD_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes
-* @{
-*/ 
-static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost);
-/**
-* @}
-*/ 
- 
-/** @defgroup USBH_HID_KEYBD_Private_Variables
-* @{
-*/
-
-HID_KEYBD_Info_TypeDef     keybd_info;
-uint32_t                   keybd_report_data[2];
-
-static const HID_Report_ItemTypedef imp_0_lctrl={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  0,     /*shift*/
-  0,     /*count (only for array items)*/ 
-  0,     /*signed?*/ 
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_lshift={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  1,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/ 
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_lalt={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  2,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/   
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_lgui={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  3,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_rctrl={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  4,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_rshift={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  5,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_ralt={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  6,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_rgui={
-  (uint8_t*)keybd_report_data+0, /*data*/
-  1,     /*size*/
-  7,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-
-static const HID_Report_ItemTypedef imp_0_key_array={
-  (uint8_t*)keybd_report_data+2, /*data*/
-  8,     /*size*/
-  0,     /*shift*/
-  6,     /*count (only for array items)*/
-  0,     /*signed?*/  
-  0,     /*min value read can return*/
-  101,   /*max value read can return*/
-  0,     /*min vale device can report*/
-  101,   /*max value device can report*/
-  1      /*resolution*/
-};
-
-#ifdef QWERTY_KEYBOARD
-static  const  int8_t  HID_KEYBRD_Key[] = {
-  '\0',  '`',  '1',  '2',  '3',  '4',  '5',  '6',
-  '7',  '8',  '9',  '0',  '-',  '=',  '\0', '\r',
-  '\t',  'q',  'w',  'e',  'r',  't',  'y',  'u', 
-  'i',  'o',  'p',  '[',  ']',  '\\',
-  '\0',  'a',  's',  'd',  'f',  'g',  'h',  'j',  
-  'k',  'l',  ';',  '\'', '\0', '\n',
-  '\0',  '\0', 'z',  'x',  'c',  'v',  'b',  'n', 
-  'm',  ',',  '.',  '/',  '\0', '\0',
-  '\0',  '\0', '\0', ' ',  '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0',  '\0', '\0', '\0', '\0', '\r', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0',  '\0', '7',  '4',  '1',
-  '\0',  '/',  '8',  '5',  '2',
-  '0',   '*',  '9',  '6',  '3',
-  '.',   '-',  '+',  '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0'
-};
-
-static  const  int8_t  HID_KEYBRD_ShiftKey[] = {
-  '\0', '~',  '!',  '@',  '#',  '$',  '%',  '^',  '&',  '*',  '(',  ')',
-  '_',  '+',  '\0', '\0', '\0', 'Q',  'W',  'E',  'R',  'T',  'Y',  'U', 
-  'I',  'O',  'P',  '{',  '}',  '|',  '\0', 'A',  'S',  'D',  'F',  'G', 
-  'H',  'J',  'K',  'L',  ':',  '"',  '\0', '\n', '\0', '\0', 'Z',  'X',  
-  'C',  'V',  'B',  'N',  'M',  '<',  '>',  '?',  '\0', '\0',  '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0',    '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
-};
-
-#else
-
-static  const  int8_t  HID_KEYBRD_Key[] = {
-  '\0',  '`',  '1',  '2',  '3',  '4',  '5',  '6',  '7',  '8',  '9',  '0',
-  '-',  '=',  '\0', '\r', '\t',  'a',  'z',  'e',  'r',  't',  'y',  'u', 
-  'i',  'o',  'p',  '[',  ']', '\\', '\0',  'q',  's',  'd',  'f',  'g', 
-  'h',  'j',  'k',  'l',  'm',  '\0', '\0', '\n', '\0',  '\0', 'w',  'x', 
-  'c',  'v',  'b',  'n',  ',',  ';',  ':',  '!',  '\0', '\0', '\0',  '\0', 
-  '\0', ' ',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0',  '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0',  '\0', '7',  '4',  '1','\0',  '/', 
-  '8',  '5',  '2', '0',   '*',  '9',  '6',  '3', '.',   '-',  '+',  '\0', 
-  '\n', '\0', '\0', '\0', '\0', '\0', '\0','\0',  '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
-};
-
-static  const  int8_t  HID_KEYBRD_ShiftKey[] = {
-  '\0', '~',  '!',  '@',  '#',  '$',  '%',  '^',  '&',  '*',  '(',  ')',  '_',
-  '+',  '\0', '\0', '\0', 'A',  'Z',  'E',  'R',  'T',  'Y',  'U',  'I',  'O',
-  'P',  '{',  '}',  '*', '\0', 'Q',  'S',  'D',  'F',  'G',  'H',  'J',  'K', 
-  'L',  'M',  '%',  '\0', '\n', '\0', '\0', 'W',  'X',  'C',  'V',  'B',  'N',
-  '?',  '.',  '/',  '\0',  '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
-  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
-};
-#endif
-
-static  const  uint8_t  HID_KEYBRD_Codes[] = {
-  0,     0,    0,    0,   31,   50,   48,   33, 
-  19,   34,   35,   36,   24,   37,   38,   39,       /* 0x00 - 0x0F */
-  52,    51,   25,   26,   17,   20,   32,   21,
-  23,   49,   18,   47,   22,   46,    2,    3,       /* 0x10 - 0x1F */
-  4,    5,    6,    7,    8,    9,   10,   11, 
-  43,  110,   15,   16,   61,   12,   13,   27,       /* 0x20 - 0x2F */
-  28,   29,   42,   40,   41,    1,   53,   54,  
-  55,   30,  112,  113,  114,  115,  116,  117,       /* 0x30 - 0x3F */
-  118,  119,  120,  121,  122,  123,  124,  125,  
-  126,   75,   80,   85,   76,   81,   86,   89,       /* 0x40 - 0x4F */
-  79,   84,   83,   90,   95,  100,  105,  106,
-  108,   93,   98,  103,   92,   97,  102,   91,       /* 0x50 - 0x5F */
-  96,  101,   99,  104,   45,  129,    0,    0, 
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x60 - 0x6F */
-  0,    0,    0,    0,    0,    0,    0,    0,
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x70 - 0x7F */
-  0,    0,    0,    0,    0,  107,    0,   56,
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x80 - 0x8F */
-  0,    0,    0,    0,    0,    0,    0,    0,
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x90 - 0x9F */
-  0,    0,    0,    0,    0,    0,    0,    0,
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xA0 - 0xAF */
-  0,    0,    0,    0,    0,    0,    0,    0, 
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xB0 - 0xBF */
-  0,    0,    0,    0,    0,    0,    0,    0, 
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xC0 - 0xCF */
-  0,    0,    0,    0,    0,    0,    0,    0, 
-  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xD0 - 0xDF */
-  58,   44,   60,  127,   64,   57,   62,  128        /* 0xE0 - 0xE7 */
-};
-
-/**
-  * @brief  USBH_HID_KeybdInit 
-  *         The function init the HID keyboard.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost)
-{
-  uint32_t x;
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;  
-    
-  keybd_info.lctrl=keybd_info.lshift= 0;
-  keybd_info.lalt=keybd_info.lgui= 0;
-  keybd_info.rctrl=keybd_info.rshift= 0;
-  keybd_info.ralt=keybd_info.rgui=0;
-  
-  
-  for(x=0; x< (sizeof(keybd_report_data)/sizeof(uint32_t)); x++)
-  {
-    keybd_report_data[x]=0;
-  }
-  
-  if(HID_Handle->length > (sizeof(keybd_report_data)/sizeof(uint32_t)))
-  {
-    HID_Handle->length = (sizeof(keybd_report_data)/sizeof(uint32_t));
-  }
-  HID_Handle->pData = (uint8_t*)keybd_report_data;
-  fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(keybd_report_data));
-  
-  return USBH_OK;    
-}
-
-/**
-  * @brief  USBH_HID_GetKeybdInfo 
-  *         The function return keyboard information.
-  * @param  phost: Host handle
-  * @retval keyboard information
-  */
-HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost)
-{
-  if(USBH_HID_KeybdDecode(phost) == USBH_OK)
- {
-  return &keybd_info;
- }
- else
- {
-  return NULL; 
- }  
-}
-
-/**
-  * @brief  USBH_HID_KeybdDecode 
-  *         The function decode keyboard data.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost)
-{
-  uint8_t x;
-  
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
-  if(HID_Handle->length == 0)
-  {
-    return USBH_FAIL;
-  }
-  /*Fill report */
-  if(fifo_read(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) ==  HID_Handle->length)
-  {
-    
-    keybd_info.lctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0);
-    keybd_info.lshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0);
-    keybd_info.lalt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0);
-    keybd_info.lgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0);
-    keybd_info.rctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0);
-    keybd_info.rshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0);
-    keybd_info.ralt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0);
-    keybd_info.rgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0);
-    
-    for(x=0; x < sizeof(keybd_info.keys); x++)
-    {    
-      keybd_info.keys[x]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x);
-    }
-    
-    return USBH_OK; 
-  }
-  return   USBH_FAIL;  
-}
-
-/**
-  * @brief  USBH_HID_GetASCIICode 
-  *         The function decode keyboard data into ASCII characters.
-  * @param  phost: Host handle
-  * @param  info: Keyboard information
-  * @retval ASCII code
-  */
-uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info)
-{
-  uint8_t   output;  
-  if((info->lshift == 1) || (info->rshift))
-  {
-  output =  HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]];
-  }
-  else
-  {
-  output =  HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]];
-  }
-  return output;  
-}
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_hid_keybd.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the application layer for USB Host HID Keyboard handling
+  *          QWERTY and AZERTY Keyboard are supported as per the selection in 
+  *          usbh_hid_keybd.h              
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid_keybd.h"
+#include "usbh_hid_parser.h"
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_HID_CLASS
+* @{
+*/
+
+/** @defgroup USBH_HID_KEYBD 
+* @brief    This file includes HID Layer Handlers for USB Host HID class.
+* @{
+*/ 
+
+/** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_HID_KEYBD_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+#ifndef AZERTY_KEYBOARD
+  #define QWERTY_KEYBOARD
+#endif
+#define  KBD_LEFT_CTRL                                  0x01
+#define  KBD_LEFT_SHIFT                                 0x02
+#define  KBD_LEFT_ALT                                   0x04
+#define  KBD_LEFT_GUI                                   0x08
+#define  KBD_RIGHT_CTRL                                 0x10
+#define  KBD_RIGHT_SHIFT                                0x20
+#define  KBD_RIGHT_ALT                                  0x40
+#define  KBD_RIGHT_GUI                                  0x80
+#define  KBR_MAX_NBR_PRESSED                            6
+
+/** @defgroup USBH_HID_KEYBD_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes
+* @{
+*/ 
+static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost);
+/**
+* @}
+*/ 
+ 
+/** @defgroup USBH_HID_KEYBD_Private_Variables
+* @{
+*/
+
+HID_KEYBD_Info_TypeDef     keybd_info;
+uint32_t                   keybd_report_data[2];
+
+static const HID_Report_ItemTypedef imp_0_lctrl={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  0,     /*shift*/
+  0,     /*count (only for array items)*/ 
+  0,     /*signed?*/ 
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_lshift={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  1,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/ 
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_lalt={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  2,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/   
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_lgui={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  3,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_rctrl={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  4,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_rshift={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  5,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_ralt={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  6,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+static const HID_Report_ItemTypedef imp_0_rgui={
+  (uint8_t*)keybd_report_data+0, /*data*/
+  1,     /*size*/
+  7,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+
+static const HID_Report_ItemTypedef imp_0_key_array={
+  (uint8_t*)keybd_report_data+2, /*data*/
+  8,     /*size*/
+  0,     /*shift*/
+  6,     /*count (only for array items)*/
+  0,     /*signed?*/  
+  0,     /*min value read can return*/
+  101,   /*max value read can return*/
+  0,     /*min vale device can report*/
+  101,   /*max value device can report*/
+  1      /*resolution*/
+};
+
+#ifdef QWERTY_KEYBOARD
+static  const  int8_t  HID_KEYBRD_Key[] = {
+  '\0',  '`',  '1',  '2',  '3',  '4',  '5',  '6',
+  '7',  '8',  '9',  '0',  '-',  '=',  '\0', '\r',
+  '\t',  'q',  'w',  'e',  'r',  't',  'y',  'u', 
+  'i',  'o',  'p',  '[',  ']',  '\\',
+  '\0',  'a',  's',  'd',  'f',  'g',  'h',  'j',  
+  'k',  'l',  ';',  '\'', '\0', '\n',
+  '\0',  '\0', 'z',  'x',  'c',  'v',  'b',  'n', 
+  'm',  ',',  '.',  '/',  '\0', '\0',
+  '\0',  '\0', '\0', ' ',  '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0',  '\0', '\0', '\0', '\0', '\r', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0',  '\0', '7',  '4',  '1',
+  '\0',  '/',  '8',  '5',  '2',
+  '0',   '*',  '9',  '6',  '3',
+  '.',   '-',  '+',  '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0'
+};
+
+static  const  int8_t  HID_KEYBRD_ShiftKey[] = {
+  '\0', '~',  '!',  '@',  '#',  '$',  '%',  '^',  '&',  '*',  '(',  ')',
+  '_',  '+',  '\0', '\0', '\0', 'Q',  'W',  'E',  'R',  'T',  'Y',  'U', 
+  'I',  'O',  'P',  '{',  '}',  '|',  '\0', 'A',  'S',  'D',  'F',  'G', 
+  'H',  'J',  'K',  'L',  ':',  '"',  '\0', '\n', '\0', '\0', 'Z',  'X',  
+  'C',  'V',  'B',  'N',  'M',  '<',  '>',  '?',  '\0', '\0',  '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0',    '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
+};
+
+#else
+
+static  const  int8_t  HID_KEYBRD_Key[] = {
+  '\0',  '`',  '1',  '2',  '3',  '4',  '5',  '6',  '7',  '8',  '9',  '0',
+  '-',  '=',  '\0', '\r', '\t',  'a',  'z',  'e',  'r',  't',  'y',  'u', 
+  'i',  'o',  'p',  '[',  ']', '\\', '\0',  'q',  's',  'd',  'f',  'g', 
+  'h',  'j',  'k',  'l',  'm',  '\0', '\0', '\n', '\0',  '\0', 'w',  'x', 
+  'c',  'v',  'b',  'n',  ',',  ';',  ':',  '!',  '\0', '\0', '\0',  '\0', 
+  '\0', ' ',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0',  '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0',  '\0', '7',  '4',  '1','\0',  '/', 
+  '8',  '5',  '2', '0',   '*',  '9',  '6',  '3', '.',   '-',  '+',  '\0', 
+  '\n', '\0', '\0', '\0', '\0', '\0', '\0','\0',  '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
+};
+
+static  const  int8_t  HID_KEYBRD_ShiftKey[] = {
+  '\0', '~',  '!',  '@',  '#',  '$',  '%',  '^',  '&',  '*',  '(',  ')',  '_',
+  '+',  '\0', '\0', '\0', 'A',  'Z',  'E',  'R',  'T',  'Y',  'U',  'I',  'O',
+  'P',  '{',  '}',  '*', '\0', 'Q',  'S',  'D',  'F',  'G',  'H',  'J',  'K', 
+  'L',  'M',  '%',  '\0', '\n', '\0', '\0', 'W',  'X',  'C',  'V',  'B',  'N',
+  '?',  '.',  '/',  '\0',  '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 
+  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
+};
+#endif
+
+static  const  uint8_t  HID_KEYBRD_Codes[] = {
+  0,     0,    0,    0,   31,   50,   48,   33, 
+  19,   34,   35,   36,   24,   37,   38,   39,       /* 0x00 - 0x0F */
+  52,    51,   25,   26,   17,   20,   32,   21,
+  23,   49,   18,   47,   22,   46,    2,    3,       /* 0x10 - 0x1F */
+  4,    5,    6,    7,    8,    9,   10,   11, 
+  43,  110,   15,   16,   61,   12,   13,   27,       /* 0x20 - 0x2F */
+  28,   29,   42,   40,   41,    1,   53,   54,  
+  55,   30,  112,  113,  114,  115,  116,  117,       /* 0x30 - 0x3F */
+  118,  119,  120,  121,  122,  123,  124,  125,  
+  126,   75,   80,   85,   76,   81,   86,   89,       /* 0x40 - 0x4F */
+  79,   84,   83,   90,   95,  100,  105,  106,
+  108,   93,   98,  103,   92,   97,  102,   91,       /* 0x50 - 0x5F */
+  96,  101,   99,  104,   45,  129,    0,    0, 
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x60 - 0x6F */
+  0,    0,    0,    0,    0,    0,    0,    0,
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x70 - 0x7F */
+  0,    0,    0,    0,    0,  107,    0,   56,
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x80 - 0x8F */
+  0,    0,    0,    0,    0,    0,    0,    0,
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0x90 - 0x9F */
+  0,    0,    0,    0,    0,    0,    0,    0,
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xA0 - 0xAF */
+  0,    0,    0,    0,    0,    0,    0,    0, 
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xB0 - 0xBF */
+  0,    0,    0,    0,    0,    0,    0,    0, 
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xC0 - 0xCF */
+  0,    0,    0,    0,    0,    0,    0,    0, 
+  0,    0,    0,    0,    0,    0,    0,    0,       /* 0xD0 - 0xDF */
+  58,   44,   60,  127,   64,   57,   62,  128        /* 0xE0 - 0xE7 */
+};
+
+/**
+  * @brief  USBH_HID_KeybdInit 
+  *         The function init the HID keyboard.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost)
+{
+  uint32_t x;
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;  
+    
+  keybd_info.lctrl=keybd_info.lshift= 0;
+  keybd_info.lalt=keybd_info.lgui= 0;
+  keybd_info.rctrl=keybd_info.rshift= 0;
+  keybd_info.ralt=keybd_info.rgui=0;
+  
+  
+  for(x=0; x< (sizeof(keybd_report_data)/sizeof(uint32_t)); x++)
+  {
+    keybd_report_data[x]=0;
+  }
+  
+  if(HID_Handle->length > (sizeof(keybd_report_data)/sizeof(uint32_t)))
+  {
+    HID_Handle->length = (sizeof(keybd_report_data)/sizeof(uint32_t));
+  }
+  HID_Handle->pData = (uint8_t*)keybd_report_data;
+  fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(keybd_report_data));
+  
+  return USBH_OK;    
+}
+
+/**
+  * @brief  USBH_HID_GetKeybdInfo 
+  *         The function return keyboard information.
+  * @param  phost: Host handle
+  * @retval keyboard information
+  */
+HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost)
+{
+  if(USBH_HID_KeybdDecode(phost) == USBH_OK)
+ {
+  return &keybd_info;
+ }
+ else
+ {
+  return NULL; 
+ }  
+}
+
+/**
+  * @brief  USBH_HID_KeybdDecode 
+  *         The function decode keyboard data.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost)
+{
+  uint8_t x;
+  
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
+  if(HID_Handle->length == 0)
+  {
+    return USBH_FAIL;
+  }
+  /*Fill report */
+  if(fifo_read(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) ==  HID_Handle->length)
+  {
+    
+    keybd_info.lctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0);
+    keybd_info.lshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0);
+    keybd_info.lalt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0);
+    keybd_info.lgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0);
+    keybd_info.rctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0);
+    keybd_info.rshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0);
+    keybd_info.ralt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0);
+    keybd_info.rgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0);
+    
+    for(x=0; x < sizeof(keybd_info.keys); x++)
+    {    
+      keybd_info.keys[x]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x);
+    }
+    
+    return USBH_OK; 
+  }
+  return   USBH_FAIL;  
+}
+
+/**
+  * @brief  USBH_HID_GetASCIICode 
+  *         The function decode keyboard data into ASCII characters.
+  * @param  phost: Host handle
+  * @param  info: Keyboard information
+  * @retval ASCII code
+  */
+uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info)
+{
+  uint8_t   output;  
+  if((info->lshift == 1) || (info->rshift))
+  {
+  output =  HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]];
+  }
+  else
+  {
+  output =  HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]];
+  }
+  return output;  
+}
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c
index 0851714afe5336454d92dfe368188b1530c7adae..cff7813c23c31d9845cb141fe7d506da06de4354 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c
+++ b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c
@@ -1,267 +1,267 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_mouse.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the application layer for USB Host HID Mouse Handling.                  
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid_mouse.h"
-#include "usbh_hid_parser.h"
-
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_HID_MOUSE 
-  * @brief    This file includes HID Layer Handlers for USB Host HID class.
-  * @{
-  */ 
-
-/** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Defines
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes
-  * @{
-  */ 
-static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Variables
-  * @{
-  */
-HID_MOUSE_Info_TypeDef    mouse_info;
-uint32_t                  mouse_report_data[1];
-
-/* Structures defining how to access items in a HID mouse report */
-/* Access button 1 state. */
-static const HID_Report_ItemTypedef prop_b1={
-  (uint8_t *)mouse_report_data+0, /*data*/
-  1,     /*size*/
-  0,     /*shift*/
-  0,     /*count (only for array items)*/
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min value device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-
-/* Access button 2 state. */
-static const HID_Report_ItemTypedef prop_b2={
-  (uint8_t *)mouse_report_data+0, /*data*/
-  1,     /*size*/
-  1,     /*shift*/
-  0,     /*count (only for array items)*/  
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min value device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-
-/* Access button 3 state. */   
-static const HID_Report_ItemTypedef prop_b3={
-  (uint8_t *)mouse_report_data+0, /*data*/
-  1,     /*size*/
-  2,     /*shift*/
-  0,     /*count (only for array items)*/
-  0,     /*signed?*/
-  0,     /*min value read can return*/
-  1,     /*max value read can return*/
-  0,     /*min vale device can report*/
-  1,     /*max value device can report*/
-  1      /*resolution*/
-};
-
-/* Access x coordinate change. */
-static const HID_Report_ItemTypedef prop_x={
-  (uint8_t *)mouse_report_data+1, /*data*/
-  8,     /*size*/
-  0,     /*shift*/
-  0,     /*count (only for array items)*/  
-  1,     /*signed?*/
-  0,     /*min value read can return*/
-  0xFFFF,/*max value read can return*/
-  0,     /*min vale device can report*/
-  0xFFFF,/*max value device can report*/
-  1      /*resolution*/
-};
-
-/* Access y coordinate change. */
-static const HID_Report_ItemTypedef prop_y={
-  (uint8_t *)mouse_report_data+2, /*data*/
-  8,     /*size*/
-  0,     /*shift*/
-  0,     /*count (only for array items)*/  
-  1,     /*signed?*/
-  0,     /*min value read can return*/
-  0xFFFF,/*max value read can return*/
-  0,     /*min vale device can report*/
-  0xFFFF,/*max value device can report*/
-  1      /*resolution*/
-};
-
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Functions
-  * @{
-  */ 
-
-/**
-  * @brief  USBH_HID_MouseInit 
-  *         The function init the HID mouse.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost)
-{
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
-
-  mouse_info.x=0;
-  mouse_info.y=0;
-  mouse_info.buttons[0]=0;
-  mouse_info.buttons[1]=0;
-  mouse_info.buttons[2]=0;
-  
-  mouse_report_data[0]=0;
-  
-  if(HID_Handle->length > sizeof(mouse_report_data))
-  {
-    HID_Handle->length = sizeof(mouse_report_data);
-  }
-  HID_Handle->pData = (uint8_t *)mouse_report_data;
-  fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(mouse_report_data));
-
-  return USBH_OK;  
-}
-
-/**
-  * @brief  USBH_HID_GetMouseInfo 
-  *         The function return mouse information.
-  * @param  phost: Host handle
-  * @retval mouse information
-  */
-HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost)
-{
- if(USBH_HID_MouseDecode(phost)== USBH_OK)
- {
-  return &mouse_info;
- }
- else
- {
-  return NULL; 
- }
-}
-
-/**
-  * @brief  USBH_HID_MouseDecode 
-  *         The function decode mouse data.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost)
-{
-  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
-  
-  if(HID_Handle->length == 0)
-  {
-    return USBH_FAIL;
-  }
-  /*Fill report */
-  if(fifo_read(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) ==  HID_Handle->length)
-  {
-    
-    /*Decode report */
-    mouse_info.x = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0);
-    mouse_info.y = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0);
-    
-    mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0);
-    mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0);
-    mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0);
-    
-    return USBH_OK;  
-  }
-  return   USBH_FAIL;
-}
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-
-
-/**
-  * @}
-  */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_hid_mouse.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the application layer for USB Host HID Mouse Handling.                  
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid_mouse.h"
+#include "usbh_hid_parser.h"
+
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_HID_MOUSE 
+  * @brief    This file includes HID Layer Handlers for USB Host HID class.
+  * @{
+  */ 
+
+/** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_MOUSE_Private_Defines
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_MOUSE_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes
+  * @{
+  */ 
+static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_MOUSE_Private_Variables
+  * @{
+  */
+HID_MOUSE_Info_TypeDef    mouse_info;
+uint32_t                  mouse_report_data[1];
+
+/* Structures defining how to access items in a HID mouse report */
+/* Access button 1 state. */
+static const HID_Report_ItemTypedef prop_b1={
+  (uint8_t *)mouse_report_data+0, /*data*/
+  1,     /*size*/
+  0,     /*shift*/
+  0,     /*count (only for array items)*/
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min value device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+
+/* Access button 2 state. */
+static const HID_Report_ItemTypedef prop_b2={
+  (uint8_t *)mouse_report_data+0, /*data*/
+  1,     /*size*/
+  1,     /*shift*/
+  0,     /*count (only for array items)*/  
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min value device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+
+/* Access button 3 state. */   
+static const HID_Report_ItemTypedef prop_b3={
+  (uint8_t *)mouse_report_data+0, /*data*/
+  1,     /*size*/
+  2,     /*shift*/
+  0,     /*count (only for array items)*/
+  0,     /*signed?*/
+  0,     /*min value read can return*/
+  1,     /*max value read can return*/
+  0,     /*min vale device can report*/
+  1,     /*max value device can report*/
+  1      /*resolution*/
+};
+
+/* Access x coordinate change. */
+static const HID_Report_ItemTypedef prop_x={
+  (uint8_t *)mouse_report_data+1, /*data*/
+  8,     /*size*/
+  0,     /*shift*/
+  0,     /*count (only for array items)*/  
+  1,     /*signed?*/
+  0,     /*min value read can return*/
+  0xFFFF,/*max value read can return*/
+  0,     /*min vale device can report*/
+  0xFFFF,/*max value device can report*/
+  1      /*resolution*/
+};
+
+/* Access y coordinate change. */
+static const HID_Report_ItemTypedef prop_y={
+  (uint8_t *)mouse_report_data+2, /*data*/
+  8,     /*size*/
+  0,     /*shift*/
+  0,     /*count (only for array items)*/  
+  1,     /*signed?*/
+  0,     /*min value read can return*/
+  0xFFFF,/*max value read can return*/
+  0,     /*min vale device can report*/
+  0xFFFF,/*max value device can report*/
+  1      /*resolution*/
+};
+
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_MOUSE_Private_Functions
+  * @{
+  */ 
+
+/**
+  * @brief  USBH_HID_MouseInit 
+  *         The function init the HID mouse.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost)
+{
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
+
+  mouse_info.x=0;
+  mouse_info.y=0;
+  mouse_info.buttons[0]=0;
+  mouse_info.buttons[1]=0;
+  mouse_info.buttons[2]=0;
+  
+  mouse_report_data[0]=0;
+  
+  if(HID_Handle->length > sizeof(mouse_report_data))
+  {
+    HID_Handle->length = sizeof(mouse_report_data);
+  }
+  HID_Handle->pData = (uint8_t *)mouse_report_data;
+  fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(mouse_report_data));
+
+  return USBH_OK;  
+}
+
+/**
+  * @brief  USBH_HID_GetMouseInfo 
+  *         The function return mouse information.
+  * @param  phost: Host handle
+  * @retval mouse information
+  */
+HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost)
+{
+ if(USBH_HID_MouseDecode(phost)== USBH_OK)
+ {
+  return &mouse_info;
+ }
+ else
+ {
+  return NULL; 
+ }
+}
+
+/**
+  * @brief  USBH_HID_MouseDecode 
+  *         The function decode mouse data.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost)
+{
+  HID_HandleTypeDef *HID_Handle =  phost->pActiveClass->pData;
+  
+  if(HID_Handle->length == 0)
+  {
+    return USBH_FAIL;
+  }
+  /*Fill report */
+  if(fifo_read(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) ==  HID_Handle->length)
+  {
+    
+    /*Decode report */
+    mouse_info.x = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0);
+    mouse_info.y = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0);
+    
+    mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0);
+    mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0);
+    mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0);
+    
+    return USBH_OK;  
+  }
+  return   USBH_FAIL;
+}
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+
+/**
+  * @}
+  */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_parser.c b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_parser.c
index a050f95e9716c0ea65cffa349a5dcc15e96bf683..140473dce14dc925b13597061dc9f637b9d0426b 100644
--- a/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_parser.c
+++ b/micropython/ports/stm32/usbhost/Class/HID/Src/usbh_hid_parser.c
@@ -1,235 +1,235 @@
-/**
-  ******************************************************************************
-  * @file    usbh_hid_parser.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the HID Layer Handlers for USB Host HID class.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid_parser.h"
-
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_HID_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_HID_PARSER 
-  * @brief    This file includes HID parsers for USB Host HID class.
-  * @{
-  */ 
-
-/** @defgroup USBH_HID_PARSER_Private_TypesDefinitions
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_PARSER_Private_Defines
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_PARSER_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_HID_PARSER_Private_FunctionPrototypes
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_PARSER_Private_Variables
-  * @{
-  */
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_HID_PARSER_Private_Functions
-  * @{
-  */ 
-
-/**
-  * @brief  HID_ReadItem 
-  *         The function read a report item.
-  * @param  ri: report item
-  * @param  ndx: report index
-* @retval status (0 : fail / otherwise: item value)
-  */
-uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx)
-{
-  uint32_t val=0;
-  uint32_t x=0;
-  uint32_t bofs;
-  uint8_t *data=ri->data;
-  uint8_t shift=ri->shift;
-  
-  /* get the logical value of the item */
-  
-  /* if this is an array, wee may need to offset ri->data.*/
-  if (ri->count > 0)
-  { 
-    /* If app tries to read outside of the array. */
-    if (ri->count <= ndx)
-    {
-      return(0);
-    }
-    
-    /* calculate bit offset */
-    bofs = ndx*ri->size;
-    bofs += shift;
-    /* calculate byte offset + shift pair from bit offset. */    
-    data+=bofs/8;
-    shift=(uint8_t)(bofs%8);
-  }
-  /* read data bytes in little endian order */
-  for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
-  {
-    val=(uint32_t)(*data << (x*8));
-  }    
-  val=(val >> shift) & ((1<<ri->size)-1);
-  
-  if (val < ri->logical_min || val > ri->logical_max)
-  {
-    return(0);
-  }
-  
-  /* convert logical value to physical value */
-  /* See if the number is negative or not. */
-  if ((ri->sign) && (val & (1<<(ri->size-1))))
-  {
-    /* yes, so sign extend value to 32 bits. */
-    int vs=(int)((-1 & ~((1<<(ri->size))-1)) | val);
-    
-    if(ri->resolution == 1)
-    {
-      return((uint32_t)vs);
-    }
-    return((uint32_t)(vs*ri->resolution));
-  }
-  else
-  {
-    if(ri->resolution == 1)
-    {
-      return(val);
-    }
-    return(val*ri->resolution);    
-  }  
-}
-
-/**
-  * @brief  HID_WriteItem 
-  *         The function write a report item.
-  * @param  ri: report item
-  * @param  ndx: report index
-  * @retval status (1: fail/ 0 : Ok)
-  */
-uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx)
-{
-  uint32_t x;
-  uint32_t mask;
-  uint32_t bofs;
-  uint8_t *data=ri->data;
-  uint8_t shift=ri->shift;
-  
-  if (value < ri->physical_min || value > ri->physical_max)  
-  {
-    return(1);
-  }
-  
-    /* if this is an array, wee may need to offset ri->data.*/
-  if (ri->count > 0)
-  { 
-    /* If app tries to read outside of the array. */
-    if (ri->count >= ndx)
-    {
-      return(0);
-    }
-    /* calculate bit offset */
-    bofs = ndx*ri->size;
-    bofs += shift;
-    /* calculate byte offset + shift pair from bit offset. */    
-    data+=bofs/8;
-    shift=(uint8_t)(bofs%8);
-
-  }
-
-  /* Convert physical value to logical value. */  
-  if (ri->resolution != 1)
-  {
-    value=value/ri->resolution;
-  }
-
-  /* Write logical value to report in little endian order. */
-  mask=(uint32_t)((1<<ri->size)-1);
-  value = (value & mask) << shift;
-  
-  for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
-  {
-    *(ri->data+x)=(uint8_t)((*(ri->data+x) & ~(mask>>(x*8))) | ((value>>(x*8)) & (mask>>(x*8))));
-  }
-  return(0);
-}
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-
-
-/**
-  * @}
-  */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_hid_parser.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the HID Layer Handlers for USB Host HID class.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_hid_parser.h"
+
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_HID_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_HID_PARSER 
+  * @brief    This file includes HID parsers for USB Host HID class.
+  * @{
+  */ 
+
+/** @defgroup USBH_HID_PARSER_Private_TypesDefinitions
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_PARSER_Private_Defines
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_PARSER_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_HID_PARSER_Private_FunctionPrototypes
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_PARSER_Private_Variables
+  * @{
+  */
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_HID_PARSER_Private_Functions
+  * @{
+  */ 
+
+/**
+  * @brief  HID_ReadItem 
+  *         The function read a report item.
+  * @param  ri: report item
+  * @param  ndx: report index
+* @retval status (0 : fail / otherwise: item value)
+  */
+uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx)
+{
+  uint32_t val=0;
+  uint32_t x=0;
+  uint32_t bofs;
+  uint8_t *data=ri->data;
+  uint8_t shift=ri->shift;
+  
+  /* get the logical value of the item */
+  
+  /* if this is an array, wee may need to offset ri->data.*/
+  if (ri->count > 0)
+  { 
+    /* If app tries to read outside of the array. */
+    if (ri->count <= ndx)
+    {
+      return(0);
+    }
+    
+    /* calculate bit offset */
+    bofs = ndx*ri->size;
+    bofs += shift;
+    /* calculate byte offset + shift pair from bit offset. */    
+    data+=bofs/8;
+    shift=(uint8_t)(bofs%8);
+  }
+  /* read data bytes in little endian order */
+  for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
+  {
+    val=(uint32_t)(*data << (x*8));
+  }    
+  val=(val >> shift) & ((1<<ri->size)-1);
+  
+  if (val < ri->logical_min || val > ri->logical_max)
+  {
+    return(0);
+  }
+  
+  /* convert logical value to physical value */
+  /* See if the number is negative or not. */
+  if ((ri->sign) && (val & (1<<(ri->size-1))))
+  {
+    /* yes, so sign extend value to 32 bits. */
+    int vs=(int)((-1 & ~((1<<(ri->size))-1)) | val);
+    
+    if(ri->resolution == 1)
+    {
+      return((uint32_t)vs);
+    }
+    return((uint32_t)(vs*ri->resolution));
+  }
+  else
+  {
+    if(ri->resolution == 1)
+    {
+      return(val);
+    }
+    return(val*ri->resolution);    
+  }  
+}
+
+/**
+  * @brief  HID_WriteItem 
+  *         The function write a report item.
+  * @param  ri: report item
+  * @param  ndx: report index
+  * @retval status (1: fail/ 0 : Ok)
+  */
+uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx)
+{
+  uint32_t x;
+  uint32_t mask;
+  uint32_t bofs;
+  uint8_t *data=ri->data;
+  uint8_t shift=ri->shift;
+  
+  if (value < ri->physical_min || value > ri->physical_max)  
+  {
+    return(1);
+  }
+  
+    /* if this is an array, wee may need to offset ri->data.*/
+  if (ri->count > 0)
+  { 
+    /* If app tries to read outside of the array. */
+    if (ri->count >= ndx)
+    {
+      return(0);
+    }
+    /* calculate bit offset */
+    bofs = ndx*ri->size;
+    bofs += shift;
+    /* calculate byte offset + shift pair from bit offset. */    
+    data+=bofs/8;
+    shift=(uint8_t)(bofs%8);
+
+  }
+
+  /* Convert physical value to logical value. */  
+  if (ri->resolution != 1)
+  {
+    value=value/ri->resolution;
+  }
+
+  /* Write logical value to report in little endian order. */
+  mask=(uint32_t)((1<<ri->size)-1);
+  value = (value & mask) << shift;
+  
+  for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
+  {
+    *(ri->data+x)=(uint8_t)((*(ri->data+x) & ~(mask>>(x*8))) | ((value>>(x*8)) & (mask>>(x*8))));
+  }
+  return(0);
+}
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+
+/**
+  * @}
+  */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc.h b/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc.h
index ea173a7da8a2de9a1fc126f002cfe766088507e2..e5b38899cbeb0b8629425e46b41e5dd09cbddb3f 100644
--- a/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc.h
+++ b/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc.h
@@ -1,222 +1,222 @@
-/**
-  ******************************************************************************
-  * @file    usbh_msc.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_msc_core.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_MSC_H
-#define __USBH_MSC_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-#include "usbh_msc_bot.h"
-#include "usbh_msc_scsi.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_MSC_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_MSC_CORE
-  * @brief This file is the Header file for usbh_msc_core.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_MSC_CORE_Exported_Types
-  * @{
-  */ 
-
-typedef enum
-{
-  MSC_INIT = 0,     
-  MSC_IDLE,    
-  MSC_TEST_UNIT_READY,          
-  MSC_READ_CAPACITY10,
-  MSC_READ_INQUIRY,
-  MSC_REQUEST_SENSE,
-  MSC_READ,
-  MSC_WRITE,
-  MSC_UNRECOVERED_ERROR,  
-  MSC_PERIODIC_CHECK,    
-}
-MSC_StateTypeDef;
-
-typedef enum
-{
-  MSC_OK,
-  MSC_NOT_READY,
-  MSC_ERROR,  
-
-}
-MSC_ErrorTypeDef;
-
-typedef enum
-{
-  MSC_REQ_IDLE = 0,
-  MSC_REQ_RESET,                
-  MSC_REQ_GET_MAX_LUN,  
-  MSC_REQ_ERROR,  
-}
-MSC_ReqStateTypeDef;
-
-#define MAX_SUPPORTED_LUN       2
-
-/* Structure for LUN */
-typedef struct
-{
-  MSC_StateTypeDef            state; 
-  MSC_ErrorTypeDef            error;   
-  USBH_StatusTypeDef          prev_ready_state;
-  SCSI_CapacityTypeDef        capacity;
-  SCSI_SenseTypeDef           sense;  
-  SCSI_StdInquiryDataTypeDef  inquiry;
-  uint8_t                     state_changed; 
-  
-}
-MSC_LUNTypeDef; 
-
-/* Structure for MSC process */
-typedef struct _MSC_Process
-{
-  uint32_t             max_lun;   
-  uint8_t              InPipe; 
-  uint8_t              OutPipe; 
-  uint8_t              OutEp;
-  uint8_t              InEp;
-  uint16_t             OutEpSize;
-  uint16_t             InEpSize;
-  MSC_StateTypeDef     state;
-  MSC_ErrorTypeDef     error;
-  MSC_ReqStateTypeDef  req_state;
-  MSC_ReqStateTypeDef  prev_req_state;  
-  BOT_HandleTypeDef    hbot;
-  MSC_LUNTypeDef       unit[MAX_SUPPORTED_LUN];
-  uint16_t             current_lun; 
-  uint16_t             rw_lun;   
-  uint32_t             timer;
-}
-MSC_HandleTypeDef; 
-
-
-/**
-  * @}
-  */ 
-
-
-
-/** @defgroup USBH_MSC_CORE_Exported_Defines
-  * @{
-  */
-
-#define USB_REQ_BOT_RESET                0xFF
-#define USB_REQ_GET_MAX_LUN              0xFE
-   
-
-/* MSC Class Codes */
-#define USB_MSC_CLASS                                   0x08
-
-/* Interface Descriptor field values for HID Boot Protocol */
-#define MSC_BOT                                        0x50 
-#define MSC_TRANSPARENT                                0x06     
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_CORE_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_CORE_Exported_Variables
-  * @{
-  */ 
-extern USBH_ClassTypeDef  USBH_msc;
-#define USBH_MSC_CLASS    &USBH_msc
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_CORE_Exported_FunctionsPrototype
-  * @{
-  */ 
-
-/* Common APIs */     
-uint8_t            USBH_MSC_IsReady (USBH_HandleTypeDef *phost);
-
-/* APIs for LUN */
-int8_t             USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost);
-
-uint8_t            USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun);
-
-USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info);
-                                 
-USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length);
-
-USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length);
-/**
-  * @}
-  */ 
-
-#endif  /* __USBH_MSC_H */
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_msc.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_msc_core.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_MSC_H
+#define __USBH_MSC_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+#include "usbh_msc_bot.h"
+#include "usbh_msc_scsi.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_MSC_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_MSC_CORE
+  * @brief This file is the Header file for usbh_msc_core.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_MSC_CORE_Exported_Types
+  * @{
+  */ 
+
+typedef enum
+{
+  MSC_INIT = 0,     
+  MSC_IDLE,    
+  MSC_TEST_UNIT_READY,          
+  MSC_READ_CAPACITY10,
+  MSC_READ_INQUIRY,
+  MSC_REQUEST_SENSE,
+  MSC_READ,
+  MSC_WRITE,
+  MSC_UNRECOVERED_ERROR,  
+  MSC_PERIODIC_CHECK,    
+}
+MSC_StateTypeDef;
+
+typedef enum
+{
+  MSC_OK,
+  MSC_NOT_READY,
+  MSC_ERROR,  
+
+}
+MSC_ErrorTypeDef;
+
+typedef enum
+{
+  MSC_REQ_IDLE = 0,
+  MSC_REQ_RESET,                
+  MSC_REQ_GET_MAX_LUN,  
+  MSC_REQ_ERROR,  
+}
+MSC_ReqStateTypeDef;
+
+#define MAX_SUPPORTED_LUN       2
+
+/* Structure for LUN */
+typedef struct
+{
+  MSC_StateTypeDef            state; 
+  MSC_ErrorTypeDef            error;   
+  USBH_StatusTypeDef          prev_ready_state;
+  SCSI_CapacityTypeDef        capacity;
+  SCSI_SenseTypeDef           sense;  
+  SCSI_StdInquiryDataTypeDef  inquiry;
+  uint8_t                     state_changed; 
+  
+}
+MSC_LUNTypeDef; 
+
+/* Structure for MSC process */
+typedef struct _MSC_Process
+{
+  uint32_t             max_lun;   
+  uint8_t              InPipe; 
+  uint8_t              OutPipe; 
+  uint8_t              OutEp;
+  uint8_t              InEp;
+  uint16_t             OutEpSize;
+  uint16_t             InEpSize;
+  MSC_StateTypeDef     state;
+  MSC_ErrorTypeDef     error;
+  MSC_ReqStateTypeDef  req_state;
+  MSC_ReqStateTypeDef  prev_req_state;  
+  BOT_HandleTypeDef    hbot;
+  MSC_LUNTypeDef       unit[MAX_SUPPORTED_LUN];
+  uint16_t             current_lun; 
+  uint16_t             rw_lun;   
+  uint32_t             timer;
+}
+MSC_HandleTypeDef; 
+
+
+/**
+  * @}
+  */ 
+
+
+
+/** @defgroup USBH_MSC_CORE_Exported_Defines
+  * @{
+  */
+
+#define USB_REQ_BOT_RESET                0xFF
+#define USB_REQ_GET_MAX_LUN              0xFE
+   
+
+/* MSC Class Codes */
+#define USB_MSC_CLASS                                   0x08
+
+/* Interface Descriptor field values for HID Boot Protocol */
+#define MSC_BOT                                        0x50 
+#define MSC_TRANSPARENT                                0x06     
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_CORE_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_CORE_Exported_Variables
+  * @{
+  */ 
+extern USBH_ClassTypeDef  USBH_msc;
+#define USBH_MSC_CLASS    &USBH_msc
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_CORE_Exported_FunctionsPrototype
+  * @{
+  */ 
+
+/* Common APIs */     
+uint8_t            USBH_MSC_IsReady (USBH_HandleTypeDef *phost);
+
+/* APIs for LUN */
+int8_t             USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost);
+
+uint8_t            USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun);
+
+USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info);
+                                 
+USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length);
+
+USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length);
+/**
+  * @}
+  */ 
+
+#endif  /* __USBH_MSC_H */
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_bot.h b/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_bot.h
index 5422c80eb707c84ac0f648d5b1edf1ee667822b9..09b5dc35a380c037dd3c121a752f66882c2e0502 100644
--- a/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_bot.h
+++ b/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_bot.h
@@ -1,233 +1,233 @@
-/**
-  ******************************************************************************
-  * @file    usbh_msc_bot.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_msc_bot.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_MSC_BOT_H__
-#define __USBH_MSC_BOT_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-#include "usbh_msc_bot.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_MSC_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_MSC_BOT
-  * @brief This file is the Header file for usbh_msc_core.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_MSC_BOT_Exported_Types
-  * @{
-  */ 
-    
-typedef enum {
-  BOT_OK          = 0,
-  BOT_FAIL        = 1,
-  BOT_PHASE_ERROR = 2,
-  BOT_BUSY        = 3
-}
-BOT_StatusTypeDef;
-
-typedef enum {
-  BOT_CMD_IDLE  = 0,
-  BOT_CMD_SEND,
-  BOT_CMD_WAIT,
-} 
-BOT_CMDStateTypeDef;  
-
-/* CSW Status Definitions */
-typedef enum 
-{
-
-   BOT_CSW_CMD_PASSED   =        0x00,
-   BOT_CSW_CMD_FAILED   =        0x01,
-   BOT_CSW_PHASE_ERROR  =        0x02,
-} 
-BOT_CSWStatusTypeDef;  
-
-typedef enum {
-  BOT_SEND_CBW  = 1,
-  BOT_SEND_CBW_WAIT,         
-  BOT_DATA_IN,    
-  BOT_DATA_IN_WAIT,    
-  BOT_DATA_OUT, 
-  BOT_DATA_OUT_WAIT,     
-  BOT_RECEIVE_CSW,
-  BOT_RECEIVE_CSW_WAIT,       
-  BOT_ERROR_IN,         
-  BOT_ERROR_OUT, 
-  BOT_UNRECOVERED_ERROR
-} 
-BOT_StateTypeDef;  
-  
-typedef union 
-{
-  struct __CBW
-  {
-    uint32_t Signature;
-    uint32_t Tag;
-    uint32_t DataTransferLength;
-    uint8_t  Flags;
-    uint8_t  LUN; 
-    uint8_t  CBLength;
-    uint8_t  CB[16];
-  }field;
-  uint8_t data[31];
-}
-BOT_CBWTypeDef;
-
-typedef union 
-{
-  struct __CSW
-  {
-    uint32_t Signature;
-    uint32_t Tag;
-    uint32_t DataResidue;
-    uint8_t  Status;
-  }field;
-  uint8_t data[13];
-}
-BOT_CSWTypeDef;
-
-typedef struct
-{
-  uint32_t                   data[16];    
-  BOT_StateTypeDef           state;
-  BOT_StateTypeDef           prev_state;  
-  BOT_CMDStateTypeDef        cmd_state;
-  BOT_CBWTypeDef             cbw;
-  uint8_t                    Reserved1;
-  BOT_CSWTypeDef             csw; 
-  uint8_t                    Reserved2[3];  
-  uint8_t                    *pbuf;
-} 
-BOT_HandleTypeDef;
-
-/**
-  * @}
-  */ 
-
-
-
-/** @defgroup USBH_MSC_BOT_Exported_Defines
-  * @{
-  */ 
-#define BOT_CBW_SIGNATURE            0x43425355
-#define BOT_CBW_TAG                  0x20304050             
-#define BOT_CSW_SIGNATURE            0x53425355           
-#define BOT_CBW_LENGTH               31
-#define BOT_CSW_LENGTH               13     
-
-
-
-#define BOT_SEND_CSW_DISABLE         0
-#define BOT_SEND_CSW_ENABLE          1
-
-#define BOT_DIR_IN                   0
-#define BOT_DIR_OUT                  1
-#define BOT_DIR_BOTH                 2
-
-#define BOT_PAGE_LENGTH              512
-
-
-#define BOT_CBW_CB_LENGTH            16
-
-
-#define USB_REQ_BOT_RESET                0xFF
-#define USB_REQ_GET_MAX_LUN              0xFE
-
-#define MAX_BULK_STALL_COUNT_LIMIT       0x04   /* If STALL is seen on Bulk 
-                                         Endpoint continously, this means 
-                                         that device and Host has phase error
-                                         Hence a Reset is needed */
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_BOT_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_BOT_Exported_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_BOT_Exported_FunctionsPrototype
-  * @{
-  */ 
-USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun);
-
-USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun);
-USBH_StatusTypeDef USBH_MSC_BOT_Error(USBH_HandleTypeDef *phost, uint8_t lun);
-
-
-
-/**
-  * @}
-  */ 
-
-#endif  //__USBH_MSC_BOT_H__
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_msc_bot.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_msc_bot.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_MSC_BOT_H__
+#define __USBH_MSC_BOT_H__
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+#include "usbh_msc_bot.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_MSC_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_MSC_BOT
+  * @brief This file is the Header file for usbh_msc_core.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_MSC_BOT_Exported_Types
+  * @{
+  */ 
+    
+typedef enum {
+  BOT_OK          = 0,
+  BOT_FAIL        = 1,
+  BOT_PHASE_ERROR = 2,
+  BOT_BUSY        = 3
+}
+BOT_StatusTypeDef;
+
+typedef enum {
+  BOT_CMD_IDLE  = 0,
+  BOT_CMD_SEND,
+  BOT_CMD_WAIT,
+} 
+BOT_CMDStateTypeDef;  
+
+/* CSW Status Definitions */
+typedef enum 
+{
+
+   BOT_CSW_CMD_PASSED   =        0x00,
+   BOT_CSW_CMD_FAILED   =        0x01,
+   BOT_CSW_PHASE_ERROR  =        0x02,
+} 
+BOT_CSWStatusTypeDef;  
+
+typedef enum {
+  BOT_SEND_CBW  = 1,
+  BOT_SEND_CBW_WAIT,         
+  BOT_DATA_IN,    
+  BOT_DATA_IN_WAIT,    
+  BOT_DATA_OUT, 
+  BOT_DATA_OUT_WAIT,     
+  BOT_RECEIVE_CSW,
+  BOT_RECEIVE_CSW_WAIT,       
+  BOT_ERROR_IN,         
+  BOT_ERROR_OUT, 
+  BOT_UNRECOVERED_ERROR
+} 
+BOT_StateTypeDef;  
+  
+typedef union 
+{
+  struct __CBW
+  {
+    uint32_t Signature;
+    uint32_t Tag;
+    uint32_t DataTransferLength;
+    uint8_t  Flags;
+    uint8_t  LUN; 
+    uint8_t  CBLength;
+    uint8_t  CB[16];
+  }field;
+  uint8_t data[31];
+}
+BOT_CBWTypeDef;
+
+typedef union 
+{
+  struct __CSW
+  {
+    uint32_t Signature;
+    uint32_t Tag;
+    uint32_t DataResidue;
+    uint8_t  Status;
+  }field;
+  uint8_t data[13];
+}
+BOT_CSWTypeDef;
+
+typedef struct
+{
+  uint32_t                   data[16];    
+  BOT_StateTypeDef           state;
+  BOT_StateTypeDef           prev_state;  
+  BOT_CMDStateTypeDef        cmd_state;
+  BOT_CBWTypeDef             cbw;
+  uint8_t                    Reserved1;
+  BOT_CSWTypeDef             csw; 
+  uint8_t                    Reserved2[3];  
+  uint8_t                    *pbuf;
+} 
+BOT_HandleTypeDef;
+
+/**
+  * @}
+  */ 
+
+
+
+/** @defgroup USBH_MSC_BOT_Exported_Defines
+  * @{
+  */ 
+#define BOT_CBW_SIGNATURE            0x43425355
+#define BOT_CBW_TAG                  0x20304050             
+#define BOT_CSW_SIGNATURE            0x53425355           
+#define BOT_CBW_LENGTH               31
+#define BOT_CSW_LENGTH               13     
+
+
+
+#define BOT_SEND_CSW_DISABLE         0
+#define BOT_SEND_CSW_ENABLE          1
+
+#define BOT_DIR_IN                   0
+#define BOT_DIR_OUT                  1
+#define BOT_DIR_BOTH                 2
+
+#define BOT_PAGE_LENGTH              512
+
+
+#define BOT_CBW_CB_LENGTH            16
+
+
+#define USB_REQ_BOT_RESET                0xFF
+#define USB_REQ_GET_MAX_LUN              0xFE
+
+#define MAX_BULK_STALL_COUNT_LIMIT       0x04   /* If STALL is seen on Bulk 
+                                         Endpoint continously, this means 
+                                         that device and Host has phase error
+                                         Hence a Reset is needed */
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_BOT_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_BOT_Exported_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_BOT_Exported_FunctionsPrototype
+  * @{
+  */ 
+USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun);
+
+USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun);
+USBH_StatusTypeDef USBH_MSC_BOT_Error(USBH_HandleTypeDef *phost, uint8_t lun);
+
+
+
+/**
+  * @}
+  */ 
+
+#endif  //__USBH_MSC_BOT_H__
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_scsi.h b/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_scsi.h
index 76b51902a10ee7e4fdfe2249d4e599dd396990c3..7844c4e7510ca6a78d14983e6c63e954988bf1f7 100644
--- a/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_scsi.h
+++ b/micropython/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_scsi.h
@@ -1,218 +1,218 @@
-/**
-  ******************************************************************************
-  * @file    usbh_msc_scsi.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_msc_scsi.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_MSC_SCSI_H__
-#define __USBH_MSC_SCSI_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_MSC_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_MSC_SCSI
-  * @brief This file is the Header file for usbh_msc_scsi.c
-  * @{
-  */ 
-    
-    
-// Capacity data.
-typedef struct
-{
-  uint32_t block_nbr;   
-  uint16_t block_size;   
-} SCSI_CapacityTypeDef;
-
-
-// Sense data.
-typedef struct
-{
-  uint8_t key;   
-  uint8_t asc;   
-  uint8_t ascq;  
-} SCSI_SenseTypeDef;
-
-// INQUIRY data.
-typedef struct
-{
-  uint8_t PeripheralQualifier;
-  uint8_t DeviceType;
-  uint8_t RemovableMedia;
-  uint8_t vendor_id[9];
-  uint8_t product_id[17];
-  uint8_t revision_id[5];
-}SCSI_StdInquiryDataTypeDef;
-
-/** @defgroup USBH_MSC_SCSI_Exported_Defines
-  * @{
-  */ 
-#define OPCODE_TEST_UNIT_READY            0x00
-#define OPCODE_READ_CAPACITY10            0x25
-#define OPCODE_READ10                     0x28
-#define OPCODE_WRITE10                    0x2A
-#define OPCODE_REQUEST_SENSE              0x03
-#define OPCODE_INQUIRY                    0x12    
-
-#define DATA_LEN_MODE_TEST_UNIT_READY        0
-#define DATA_LEN_READ_CAPACITY10             8
-#define DATA_LEN_INQUIRY                    36  
-#define DATA_LEN_REQUEST_SENSE              14       
-
-#define CBW_CB_LENGTH                       16
-#define CBW_LENGTH                          10    
-
-/** @defgroup USBH_MSC_SCSI_Exported_Defines
-  * @{
-  */ 
-#define SCSI_SENSE_KEY_NO_SENSE                          0x00
-#define SCSI_SENSE_KEY_RECOVERED_ERROR                   0x01
-#define SCSI_SENSE_KEY_NOT_READY                         0x02
-#define SCSI_SENSE_KEY_MEDIUM_ERROR                      0x03
-#define SCSI_SENSE_KEY_HARDWARE_ERROR                    0x04
-#define SCSI_SENSE_KEY_ILLEGAL_REQUEST                   0x05
-#define SCSI_SENSE_KEY_UNIT_ATTENTION                    0x06
-#define SCSI_SENSE_KEY_DATA_PROTECT                      0x07
-#define SCSI_SENSE_KEY_BLANK_CHECK                       0x08
-#define SCSI_SENSE_KEY_VENDOR_SPECIFIC                   0x09
-#define SCSI_SENSE_KEY_COPY_ABORTED                      0x0A
-#define SCSI_SENSE_KEY_ABORTED_COMMAND                   0x0B
-#define SCSI_SENSE_KEY_VOLUME_OVERFLOW                   0x0D
-#define SCSI_SENSE_KEY_MISCOMPARE                        0x0E
-/**
-  * @}
-  */ 
-    
-    
-/** @defgroup USBH_MSC_SCSI_Exported_Defines
-  * @{
-  */     
-#define SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION         0x00
-#define SCSI_ASC_LOGICAL_UNIT_NOT_READY                  0x04
-#define SCSI_ASC_INVALID_FIELD_IN_CDB                    0x24
-#define SCSI_ASC_WRITE_PROTECTED                         0x27
-#define SCSI_ASC_FORMAT_ERROR                            0x31
-#define SCSI_ASC_INVALID_COMMAND_OPERATION_CODE          0x20
-#define SCSI_ASC_NOT_READY_TO_READY_CHANGE               0x28
-#define SCSI_ASC_MEDIUM_NOT_PRESENT                      0x3A
-/**
-  * @}
-  */ 
-    
-    
-/** @defgroup USBH_MSC_SCSI_Exported_Defines
-  * @{
-  */     
-#define SCSI_ASCQ_FORMAT_COMMAND_FAILED                  0x01
-#define SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED          0x02
-#define SCSI_ASCQ_OPERATION_IN_PROGRESS                  0x07
-    
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_SCSI_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup _Exported_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_SCSI_Exported_FunctionsPrototype
-  * @{
-  */ 
-USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, 
-                                                uint8_t lun);
-
-USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, 
-                                               uint8_t lun, 
-                                               SCSI_CapacityTypeDef *capacity);
-
-USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, 
-                                               uint8_t lun, 
-                                               SCSI_StdInquiryDataTypeDef *inquiry);
-
-USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, 
-                                               uint8_t lun, 
-                                               SCSI_SenseTypeDef *sense_data);
-
-USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length);
-
-USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length);
-
-
-/**
-  * @}
-  */ 
-
-#endif  //__USBH_MSC_SCSI_H__
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_msc_scsi.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_msc_scsi.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_MSC_SCSI_H__
+#define __USBH_MSC_SCSI_H__
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_MSC_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_MSC_SCSI
+  * @brief This file is the Header file for usbh_msc_scsi.c
+  * @{
+  */ 
+    
+    
+// Capacity data.
+typedef struct
+{
+  uint32_t block_nbr;   
+  uint16_t block_size;   
+} SCSI_CapacityTypeDef;
+
+
+// Sense data.
+typedef struct
+{
+  uint8_t key;   
+  uint8_t asc;   
+  uint8_t ascq;  
+} SCSI_SenseTypeDef;
+
+// INQUIRY data.
+typedef struct
+{
+  uint8_t PeripheralQualifier;
+  uint8_t DeviceType;
+  uint8_t RemovableMedia;
+  uint8_t vendor_id[9];
+  uint8_t product_id[17];
+  uint8_t revision_id[5];
+}SCSI_StdInquiryDataTypeDef;
+
+/** @defgroup USBH_MSC_SCSI_Exported_Defines
+  * @{
+  */ 
+#define OPCODE_TEST_UNIT_READY            0x00
+#define OPCODE_READ_CAPACITY10            0x25
+#define OPCODE_READ10                     0x28
+#define OPCODE_WRITE10                    0x2A
+#define OPCODE_REQUEST_SENSE              0x03
+#define OPCODE_INQUIRY                    0x12    
+
+#define DATA_LEN_MODE_TEST_UNIT_READY        0
+#define DATA_LEN_READ_CAPACITY10             8
+#define DATA_LEN_INQUIRY                    36  
+#define DATA_LEN_REQUEST_SENSE              14       
+
+#define CBW_CB_LENGTH                       16
+#define CBW_LENGTH                          10    
+
+/** @defgroup USBH_MSC_SCSI_Exported_Defines
+  * @{
+  */ 
+#define SCSI_SENSE_KEY_NO_SENSE                          0x00
+#define SCSI_SENSE_KEY_RECOVERED_ERROR                   0x01
+#define SCSI_SENSE_KEY_NOT_READY                         0x02
+#define SCSI_SENSE_KEY_MEDIUM_ERROR                      0x03
+#define SCSI_SENSE_KEY_HARDWARE_ERROR                    0x04
+#define SCSI_SENSE_KEY_ILLEGAL_REQUEST                   0x05
+#define SCSI_SENSE_KEY_UNIT_ATTENTION                    0x06
+#define SCSI_SENSE_KEY_DATA_PROTECT                      0x07
+#define SCSI_SENSE_KEY_BLANK_CHECK                       0x08
+#define SCSI_SENSE_KEY_VENDOR_SPECIFIC                   0x09
+#define SCSI_SENSE_KEY_COPY_ABORTED                      0x0A
+#define SCSI_SENSE_KEY_ABORTED_COMMAND                   0x0B
+#define SCSI_SENSE_KEY_VOLUME_OVERFLOW                   0x0D
+#define SCSI_SENSE_KEY_MISCOMPARE                        0x0E
+/**
+  * @}
+  */ 
+    
+    
+/** @defgroup USBH_MSC_SCSI_Exported_Defines
+  * @{
+  */     
+#define SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION         0x00
+#define SCSI_ASC_LOGICAL_UNIT_NOT_READY                  0x04
+#define SCSI_ASC_INVALID_FIELD_IN_CDB                    0x24
+#define SCSI_ASC_WRITE_PROTECTED                         0x27
+#define SCSI_ASC_FORMAT_ERROR                            0x31
+#define SCSI_ASC_INVALID_COMMAND_OPERATION_CODE          0x20
+#define SCSI_ASC_NOT_READY_TO_READY_CHANGE               0x28
+#define SCSI_ASC_MEDIUM_NOT_PRESENT                      0x3A
+/**
+  * @}
+  */ 
+    
+    
+/** @defgroup USBH_MSC_SCSI_Exported_Defines
+  * @{
+  */     
+#define SCSI_ASCQ_FORMAT_COMMAND_FAILED                  0x01
+#define SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED          0x02
+#define SCSI_ASCQ_OPERATION_IN_PROGRESS                  0x07
+    
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_SCSI_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup _Exported_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_SCSI_Exported_FunctionsPrototype
+  * @{
+  */ 
+USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, 
+                                                uint8_t lun);
+
+USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, 
+                                               uint8_t lun, 
+                                               SCSI_CapacityTypeDef *capacity);
+
+USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, 
+                                               uint8_t lun, 
+                                               SCSI_StdInquiryDataTypeDef *inquiry);
+
+USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, 
+                                               uint8_t lun, 
+                                               SCSI_SenseTypeDef *sense_data);
+
+USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length);
+
+USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length);
+
+
+/**
+  * @}
+  */ 
+
+#endif  //__USBH_MSC_SCSI_H__
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc.c b/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc.c
index 53a2cd81df182fe1846860ee4ba5b7545ba8edd5..880d72034146f3805d55d70da0a52ae227bab2c1 100644
--- a/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc.c
+++ b/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc.c
@@ -1,795 +1,795 @@
-/**
-  ******************************************************************************
-  * @file    usbh_msc.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file implements the MSC class driver functions
-  *          ===================================================================      
-  *                                MSC Class  Description
-  *          =================================================================== 
-  *           This module manages the MSC class V1.0 following the "Universal 
-  *           Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0
-  *           Sep. 31, 1999".
-  *           This driver implements the following aspects of the specification:
-  *             - Bulk-Only Transport protocol
-  *             - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3))
-  *      
-  *  @endverbatim
-  *
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Includes ------------------------------------------------------------------*/
-
-#include "usbh_msc.h"
-#include "usbh_msc_bot.h"    
-#include "usbh_msc_scsi.h"
-
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_MSC_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_MSC_CORE 
-  * @brief    This file includes the mass storage related functions
-  * @{
-  */ 
-
-
-/** @defgroup USBH_MSC_CORE_Private_TypesDefinitions
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_CORE_Private_Defines
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_CORE_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_CORE_Private_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_CORE_Private_FunctionPrototypes
-  * @{
-  */ 
-
-static USBH_StatusTypeDef USBH_MSC_InterfaceInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun);
-
-USBH_ClassTypeDef  USBH_msc = 
-{
-  "MSC",
-  USB_MSC_CLASS,
-  USBH_MSC_InterfaceInit,
-  USBH_MSC_InterfaceDeInit,
-  USBH_MSC_ClassRequest,
-  USBH_MSC_Process,
-  USBH_MSC_SOFProcess,
-  NULL,
-};
-
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_CORE_Exported_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_CORE_Private_Functions
-  * @{
-  */ 
-
-
-/**
-  * @brief  USBH_MSC_InterfaceInit 
-  *         The function init the MSC class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost)
-{	 
-  uint8_t interface = 0; 
-  USBH_StatusTypeDef status = USBH_FAIL ;
-  MSC_HandleTypeDef *MSC_Handle;
-  
-  interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT);
-  
-  if(interface == 0xFF) /* Not Valid Interface */
-  {
-    USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
-    status = USBH_FAIL;      
-  }
-  else
-  {
-    USBH_SelectInterface (phost, interface);
-    
-    phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc (sizeof(MSC_HandleTypeDef));
-    MSC_Handle =  phost->pActiveClass->pData;
-    
-    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress & 0x80)
-    {
-      MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
-      MSC_Handle->InEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
-    }
-    else
-    {
-      MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
-      MSC_Handle->OutEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;      
-    }
-    
-    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress & 0x80)
-    {
-      MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
-      MSC_Handle->InEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize;      
-    }
-    else
-    {
-      MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
-      MSC_Handle->OutEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize;      
-    }
-    
-    MSC_Handle->current_lun = 0;
-    MSC_Handle->rw_lun = 0;
-    MSC_Handle->state = MSC_INIT;
-    MSC_Handle->error = MSC_OK;
-    MSC_Handle->req_state = MSC_REQ_IDLE;
-    MSC_Handle->OutPipe = USBH_AllocPipe(phost, MSC_Handle->OutEp);
-    MSC_Handle->InPipe = USBH_AllocPipe(phost, MSC_Handle->InEp);
-
-    USBH_MSC_BOT_Init(phost);
-    
-    /* De-Initialize LUNs information */
-    USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit));
-    
-    /* Open the new channels */
-    USBH_OpenPipe  (phost,
-                    MSC_Handle->OutPipe,
-                    MSC_Handle->OutEp,
-                    phost->device.address,
-                    phost->device.speed,
-                    USB_EP_TYPE_BULK,
-                    MSC_Handle->OutEpSize);  
-    
-    USBH_OpenPipe  (phost,
-                    MSC_Handle->InPipe,
-                    MSC_Handle->InEp,
-                    phost->device.address,
-                    phost->device.speed,
-                    USB_EP_TYPE_BULK,
-                    MSC_Handle->InEpSize);     
-    
-    
-    USBH_LL_SetToggle  (phost, MSC_Handle->InPipe,0);
-    USBH_LL_SetToggle  (phost, MSC_Handle->OutPipe,0);
-    status = USBH_OK; 
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MSC_InterfaceDeInit 
-  *         The function DeInit the Pipes used for the MSC class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-
-  if ( MSC_Handle->OutPipe)
-  {
-    USBH_ClosePipe(phost, MSC_Handle->OutPipe);
-    USBH_FreePipe  (phost, MSC_Handle->OutPipe);
-    MSC_Handle->OutPipe = 0;     /* Reset the Channel as Free */
-  }
-  
-  if ( MSC_Handle->InPipe)
-  {
-    USBH_ClosePipe(phost, MSC_Handle->InPipe);
-    USBH_FreePipe  (phost, MSC_Handle->InPipe);
-    MSC_Handle->InPipe = 0;     /* Reset the Channel as Free */
-  } 
-
-  if(phost->pActiveClass->pData)
-  {
-    USBH_free (phost->pActiveClass->pData);
-    phost->pActiveClass->pData = 0;
-  }
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_MSC_ClassRequest 
-  *         The function is responsible for handling Standard requests
-  *         for MSC class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost)
-{   
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;  
-  USBH_StatusTypeDef status = USBH_BUSY;
-  uint8_t i;
-  
-  /* Switch MSC REQ state machine */
-  switch (MSC_Handle->req_state)
-  {
-  case MSC_REQ_IDLE:
-  case MSC_REQ_GET_MAX_LUN:   
-    /* Issue GetMaxLUN request */
-    if(USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)&MSC_Handle->max_lun) == USBH_OK )
-    {
-      MSC_Handle->max_lun = (uint8_t )(MSC_Handle->max_lun) + 1;
-      USBH_UsrLog ("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun));
-      
-      for(i = 0; i < MSC_Handle->max_lun; i++)
-      {
-        MSC_Handle->unit[i].prev_ready_state = USBH_FAIL;
-        MSC_Handle->unit[i].state_changed = 0;
-      }
-      status = USBH_OK;
-    }
-    break;
-    
-  case MSC_REQ_ERROR :
-    /* a Clear Feature should be issued here */
-    if(USBH_ClrFeature(phost, 0x00) == USBH_OK)
-    {
-      MSC_Handle->req_state = MSC_Handle->prev_req_state; 
-    }    
-    break;
-    
-  default:
-    break;
-  }
-  
-  return status; 
-}
-
-/**
-  * @brief  USBH_MSC_Process 
-  *         The function is for managing state machine for MSC data transfers 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  USBH_StatusTypeDef error = USBH_BUSY ;
-  USBH_StatusTypeDef scsi_status = USBH_BUSY ;  
-  USBH_StatusTypeDef ready_status = USBH_BUSY ;
-  
-  switch (MSC_Handle->state)
-  {
-  case MSC_INIT:
-    
-    if(MSC_Handle->current_lun < MSC_Handle->max_lun)
-    {
-
-      MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
-      /* Switch MSC REQ state machine */
-      switch (MSC_Handle->unit[MSC_Handle->current_lun].state)
-      {
-      case MSC_INIT:
-        USBH_UsrLog ("LUN #%d: ", MSC_Handle->current_lun);
-        MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY;
-        MSC_Handle->timer = phost->Timer + 10000;
-        
-      case MSC_READ_INQUIRY:
-        scsi_status = USBH_MSC_SCSI_Inquiry(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry);
-        
-        if( scsi_status == USBH_OK)
-        {
-          USBH_UsrLog ("Inquiry Vendor  : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.vendor_id);
-          USBH_UsrLog ("Inquiry Product : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.product_id);
-          USBH_UsrLog ("Inquiry Version : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.revision_id);
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;        
-        }
-        if( scsi_status == USBH_FAIL)
-        {
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;         
-        }
-        else if(scsi_status == USBH_UNRECOVERED_ERROR)
-        {
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
-          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
-        }
-        break;    
-        
-      case MSC_TEST_UNIT_READY:
-        ready_status = USBH_MSC_SCSI_TestUnitReady(phost, MSC_Handle->current_lun);
-        
-        if( ready_status == USBH_OK)
-        {
-          if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_OK)
-          {
-            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
-            USBH_UsrLog ("Mass Storage Device ready");
-          }
-          else
-          {
-            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
-          }
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_CAPACITY10;
-          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
-          MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_OK;
-        }
-        if( ready_status == USBH_FAIL)
-        {
-          /* Media not ready, so try to check again during 10s */
-          if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_FAIL)
-          {
-            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
-            USBH_UsrLog ("Mass Storage Device NOT ready");
-          }
-          else
-          {
-            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
-          }         
-            MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; 
-            MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
-            MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_FAIL;
-        }
-        else if(ready_status == USBH_UNRECOVERED_ERROR)
-        {
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
-          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
-        }
-        break;
-        
-      case MSC_READ_CAPACITY10:   
-        scsi_status = USBH_MSC_SCSI_ReadCapacity(phost,MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].capacity) ;
-        
-        if(scsi_status == USBH_OK)
-        {
-          if(MSC_Handle->unit[MSC_Handle->current_lun].state_changed == 1)
-          {
-            USBH_UsrLog ("Mass Storage Device capacity : %lu MB", \
-              (int32_t)((MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr * MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size)/1024/1024));
-            USBH_UsrLog ("Block number : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr));
-            USBH_UsrLog ("Block Size   : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size));
-          }
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
-          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
-          MSC_Handle->current_lun++;
-        }
-        else if( scsi_status == USBH_FAIL)
-        {
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
-        }
-        else if(scsi_status == USBH_UNRECOVERED_ERROR)
-        {
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
-          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
-        }
-        break;
-        
-      case MSC_REQUEST_SENSE:
-        scsi_status = USBH_MSC_SCSI_RequestSense(phost,  MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].sense);
-        
-        if( scsi_status == USBH_OK)
-        {
-          if((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) ||
-             (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY) )   
-          {
-            
-            if(phost->Timer <= MSC_Handle->timer)
-            {
-              MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;
-              break;
-            }        
-          }
-          
-          USBH_UsrLog ("Sense Key  : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.key);
-          USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.asc);
-          USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.ascq);
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
-          MSC_Handle->current_lun++;
-        }
-        if( scsi_status == USBH_FAIL)
-        {
-          USBH_UsrLog ("Mass Storage Device NOT ready");
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_UNRECOVERED_ERROR; 
-        }
-        else if(scsi_status == USBH_UNRECOVERED_ERROR)
-        {
-          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
-          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;   
-        }
-        break;  
-    
-      case MSC_UNRECOVERED_ERROR: 
-        MSC_Handle->current_lun++;
-        break;  
-        
-      default:
-        break;
-      }
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif       
-    }
-    else
-    {
-      MSC_Handle->current_lun = 0;
-    MSC_Handle->state = MSC_IDLE;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif 
-    phost->pUser(phost, HOST_USER_CLASS_ACTIVE);     
-    }
-    break;
-
-  case MSC_IDLE:
-    error = USBH_OK;  
-    break;
-    
-  default:
-    break; 
-  }
-  return error;
-}
-
-
-/**
-  * @brief  USBH_MSC_SOFProcess 
-  *         The function is for SOF state
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost)
-{
-
-  return USBH_OK;
-}
-/**
-  * @brief  USBH_MSC_RdWrProcess 
-  *         The function is for managing state machine for MSC I/O Process
-  * @param  phost: Host handle
-  * @param  lun: logical Unit Number
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  USBH_StatusTypeDef error = USBH_BUSY ;
-  USBH_StatusTypeDef scsi_status = USBH_BUSY ;  
-  
-  /* Switch MSC REQ state machine */
-  switch (MSC_Handle->unit[lun].state)
-  {
- 
-  case MSC_READ: 
-    scsi_status = USBH_MSC_SCSI_Read(phost,lun, 0, NULL, 0) ;
-    
-    if(scsi_status == USBH_OK)
-    {
-      MSC_Handle->unit[lun].state = MSC_IDLE;
-      error = USBH_OK;     
-    }
-    else if( scsi_status == USBH_FAIL)
-    {
-      MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;  
-    }
-    else if(scsi_status == USBH_UNRECOVERED_ERROR)
-    {
-      MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
-          error = USBH_FAIL;
-    }
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif   
-    break;     
-    
-  case MSC_WRITE: 
-    scsi_status = USBH_MSC_SCSI_Write(phost,lun, 0, NULL, 0) ;
-    
-    if(scsi_status == USBH_OK)
-    {
-        MSC_Handle->unit[lun].state = MSC_IDLE;
-        error = USBH_OK;             
-    }
-    else if( scsi_status == USBH_FAIL)
-    {
-      MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;  
-    }
-    else if(scsi_status == USBH_UNRECOVERED_ERROR)
-    {
-      MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
-          error = USBH_FAIL;
-    }
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif       
-    break; 
-  
-  case MSC_REQUEST_SENSE:
-    scsi_status = USBH_MSC_SCSI_RequestSense(phost, lun, &MSC_Handle->unit[lun].sense);
-    
-    if( scsi_status == USBH_OK)
-    {
-      USBH_UsrLog ("Sense Key  : %x", MSC_Handle->unit[lun].sense.key);
-      USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[lun].sense.asc);
-      USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[lun].sense.ascq);
-      MSC_Handle->unit[lun].state = MSC_IDLE;
-      MSC_Handle->unit[lun].error = MSC_ERROR;
-      
-      error = USBH_FAIL;
-    }
-    if( scsi_status == USBH_FAIL)
-    {
-      USBH_UsrLog ("Mass Storage Device NOT ready");
-    }
-    else if(scsi_status == USBH_UNRECOVERED_ERROR)
-    {
-      MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;  
-          error = USBH_FAIL;
-    }
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
-#endif       
-    break;  
-    
-  default:
-    break;  
-    
-  }
-  return error;
-}
-
-/**
-  * @brief  USBH_MSC_IsReady 
-  *         The function check if the MSC function is ready
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-uint8_t  USBH_MSC_IsReady (USBH_HandleTypeDef *phost)
-{
-    MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;  
-    
-  if(phost->gState == HOST_CLASS)
-  {
-    return (MSC_Handle->state == MSC_IDLE);
-  }
-  else
-  {
-    return 0;
-  }
-}
-
-/**
-  * @brief  USBH_MSC_GetMaxLUN 
-  *         The function return the Max LUN supported
-  * @param  phost: Host handle
-  * @retval logical Unit Number supported
-  */
-int8_t  USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;    
-  
-  if ((phost->gState != HOST_CLASS) && (MSC_Handle->state == MSC_IDLE))
-  {
-    return  MSC_Handle->max_lun;
-  }  
-  return 0xFF;
-}
-
-/**
-  * @brief  USBH_MSC_UnitIsReady 
-  *         The function check whether a LUN is ready
-  * @param  phost: Host handle
-  * @param  lun: logical Unit Number
-  * @retval Lun status (0: not ready / 1: ready)
-  */
-uint8_t  USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;  
-  
-  if(phost->gState == HOST_CLASS)
-  {
-    return (MSC_Handle->unit[lun].error == MSC_OK);
-  }
-  else
-  {
-    return 0;
-  }
-}
-      
-/**
-  * @brief  USBH_MSC_GetLUNInfo 
-  *         The function return a LUN information
-  * @param  phost: Host handle
-  * @param  lun: logical Unit Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;    
-  if(phost->gState == HOST_CLASS)
-  {
-    USBH_memcpy(info,&MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef));
-    return USBH_OK;
-  }
-  else
-  {
-    return USBH_FAIL;
-  }
-}
-
-/**
-  * @brief  USBH_MSC_Read 
-  *         The function performs a Read operation 
-  * @param  phost: Host handle
-  * @param  lun: logical Unit Number
-  * @param  address: sector address
-  * @param  pbuf: pointer to data
-  * @param  length: number of sector to read
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length)
-{
-  uint32_t timeout;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;   
-  
-  if ((phost->device.is_connected == 0) || 
-      (phost->gState != HOST_CLASS) || 
-      (MSC_Handle->unit[lun].state != MSC_IDLE))
-  {
-    return  USBH_FAIL;
-  }
-  MSC_Handle->state = MSC_READ;
-  MSC_Handle->unit[lun].state = MSC_READ;
-  MSC_Handle->rw_lun = lun;
-  USBH_MSC_SCSI_Read(phost,
-                     lun,
-                     address,
-                     pbuf,
-                     length);
-  
-  timeout = phost->Timer + (10000 * length);
-  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
-  {
-    if((phost->Timer > timeout) || (phost->device.is_connected == 0))
-    {
-      MSC_Handle->state = MSC_IDLE;
-      return USBH_FAIL;
-    }
-  }
-  MSC_Handle->state = MSC_IDLE;
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_MSC_Write 
-  *         The function performs a Write operation 
-  * @param  phost: Host handle
-  * @param  lun: logical Unit Number
-  * @param  address: sector address
-  * @param  pbuf: pointer to data
-  * @param  length: number of sector to write
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length)
-{
-  uint32_t timeout;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;   
-  
-  if ((phost->device.is_connected == 0) || 
-      (phost->gState != HOST_CLASS) || 
-      (MSC_Handle->unit[lun].state != MSC_IDLE))
-  {
-    return  USBH_FAIL;
-  }
-  MSC_Handle->state = MSC_WRITE;
-  MSC_Handle->unit[lun].state = MSC_WRITE;
-  MSC_Handle->rw_lun = lun;
-  USBH_MSC_SCSI_Write(phost,
-                     lun,
-                     address,
-                     pbuf,
-                     length);
-  
-  timeout = phost->Timer + (10000 * length);
-  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
-  {
-    if((phost->Timer > timeout) || (phost->device.is_connected == 0))
-    {
-      MSC_Handle->state = MSC_IDLE;
-      return USBH_FAIL;
-    }
-  }
-  MSC_Handle->state = MSC_IDLE;
-  return USBH_OK;
-}
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_msc.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file implements the MSC class driver functions
+  *          ===================================================================      
+  *                                MSC Class  Description
+  *          =================================================================== 
+  *           This module manages the MSC class V1.0 following the "Universal 
+  *           Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0
+  *           Sep. 31, 1999".
+  *           This driver implements the following aspects of the specification:
+  *             - Bulk-Only Transport protocol
+  *             - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3))
+  *      
+  *  @endverbatim
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "usbh_msc.h"
+#include "usbh_msc_bot.h"    
+#include "usbh_msc_scsi.h"
+
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_MSC_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_MSC_CORE 
+  * @brief    This file includes the mass storage related functions
+  * @{
+  */ 
+
+
+/** @defgroup USBH_MSC_CORE_Private_TypesDefinitions
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_CORE_Private_Defines
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_CORE_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_CORE_Private_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_CORE_Private_FunctionPrototypes
+  * @{
+  */ 
+
+static USBH_StatusTypeDef USBH_MSC_InterfaceInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun);
+
+USBH_ClassTypeDef  USBH_msc = 
+{
+  "MSC",
+  USB_MSC_CLASS,
+  USBH_MSC_InterfaceInit,
+  USBH_MSC_InterfaceDeInit,
+  USBH_MSC_ClassRequest,
+  USBH_MSC_Process,
+  USBH_MSC_SOFProcess,
+  NULL,
+};
+
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_CORE_Exported_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_CORE_Private_Functions
+  * @{
+  */ 
+
+
+/**
+  * @brief  USBH_MSC_InterfaceInit 
+  *         The function init the MSC class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost)
+{	 
+  uint8_t interface = 0; 
+  USBH_StatusTypeDef status = USBH_FAIL ;
+  MSC_HandleTypeDef *MSC_Handle;
+  
+  interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT);
+  
+  if(interface == 0xFF) /* Not Valid Interface */
+  {
+    USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
+    status = USBH_FAIL;      
+  }
+  else
+  {
+    USBH_SelectInterface (phost, interface);
+    
+    phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc (sizeof(MSC_HandleTypeDef));
+    MSC_Handle =  phost->pActiveClass->pData;
+    
+    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress & 0x80)
+    {
+      MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
+      MSC_Handle->InEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
+    }
+    else
+    {
+      MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
+      MSC_Handle->OutEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;      
+    }
+    
+    if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress & 0x80)
+    {
+      MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
+      MSC_Handle->InEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize;      
+    }
+    else
+    {
+      MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
+      MSC_Handle->OutEpSize  = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize;      
+    }
+    
+    MSC_Handle->current_lun = 0;
+    MSC_Handle->rw_lun = 0;
+    MSC_Handle->state = MSC_INIT;
+    MSC_Handle->error = MSC_OK;
+    MSC_Handle->req_state = MSC_REQ_IDLE;
+    MSC_Handle->OutPipe = USBH_AllocPipe(phost, MSC_Handle->OutEp);
+    MSC_Handle->InPipe = USBH_AllocPipe(phost, MSC_Handle->InEp);
+
+    USBH_MSC_BOT_Init(phost);
+    
+    /* De-Initialize LUNs information */
+    USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit));
+    
+    /* Open the new channels */
+    USBH_OpenPipe  (phost,
+                    MSC_Handle->OutPipe,
+                    MSC_Handle->OutEp,
+                    phost->device.address,
+                    phost->device.speed,
+                    USB_EP_TYPE_BULK,
+                    MSC_Handle->OutEpSize);  
+    
+    USBH_OpenPipe  (phost,
+                    MSC_Handle->InPipe,
+                    MSC_Handle->InEp,
+                    phost->device.address,
+                    phost->device.speed,
+                    USB_EP_TYPE_BULK,
+                    MSC_Handle->InEpSize);     
+    
+    
+    USBH_LL_SetToggle  (phost, MSC_Handle->InPipe,0);
+    USBH_LL_SetToggle  (phost, MSC_Handle->OutPipe,0);
+    status = USBH_OK; 
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MSC_InterfaceDeInit 
+  *         The function DeInit the Pipes used for the MSC class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+
+  if ( MSC_Handle->OutPipe)
+  {
+    USBH_ClosePipe(phost, MSC_Handle->OutPipe);
+    USBH_FreePipe  (phost, MSC_Handle->OutPipe);
+    MSC_Handle->OutPipe = 0;     /* Reset the Channel as Free */
+  }
+  
+  if ( MSC_Handle->InPipe)
+  {
+    USBH_ClosePipe(phost, MSC_Handle->InPipe);
+    USBH_FreePipe  (phost, MSC_Handle->InPipe);
+    MSC_Handle->InPipe = 0;     /* Reset the Channel as Free */
+  } 
+
+  if(phost->pActiveClass->pData)
+  {
+    USBH_free (phost->pActiveClass->pData);
+    phost->pActiveClass->pData = 0;
+  }
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_MSC_ClassRequest 
+  *         The function is responsible for handling Standard requests
+  *         for MSC class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost)
+{   
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;  
+  USBH_StatusTypeDef status = USBH_BUSY;
+  uint8_t i;
+  
+  /* Switch MSC REQ state machine */
+  switch (MSC_Handle->req_state)
+  {
+  case MSC_REQ_IDLE:
+  case MSC_REQ_GET_MAX_LUN:   
+    /* Issue GetMaxLUN request */
+    if(USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)&MSC_Handle->max_lun) == USBH_OK )
+    {
+      MSC_Handle->max_lun = (uint8_t )(MSC_Handle->max_lun) + 1;
+      USBH_UsrLog ("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun));
+      
+      for(i = 0; i < MSC_Handle->max_lun; i++)
+      {
+        MSC_Handle->unit[i].prev_ready_state = USBH_FAIL;
+        MSC_Handle->unit[i].state_changed = 0;
+      }
+      status = USBH_OK;
+    }
+    break;
+    
+  case MSC_REQ_ERROR :
+    /* a Clear Feature should be issued here */
+    if(USBH_ClrFeature(phost, 0x00) == USBH_OK)
+    {
+      MSC_Handle->req_state = MSC_Handle->prev_req_state; 
+    }    
+    break;
+    
+  default:
+    break;
+  }
+  
+  return status; 
+}
+
+/**
+  * @brief  USBH_MSC_Process 
+  *         The function is for managing state machine for MSC data transfers 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  USBH_StatusTypeDef error = USBH_BUSY ;
+  USBH_StatusTypeDef scsi_status = USBH_BUSY ;  
+  USBH_StatusTypeDef ready_status = USBH_BUSY ;
+  
+  switch (MSC_Handle->state)
+  {
+  case MSC_INIT:
+    
+    if(MSC_Handle->current_lun < MSC_Handle->max_lun)
+    {
+
+      MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
+      /* Switch MSC REQ state machine */
+      switch (MSC_Handle->unit[MSC_Handle->current_lun].state)
+      {
+      case MSC_INIT:
+        USBH_UsrLog ("LUN #%d: ", MSC_Handle->current_lun);
+        MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY;
+        MSC_Handle->timer = phost->Timer + 10000;
+        
+      case MSC_READ_INQUIRY:
+        scsi_status = USBH_MSC_SCSI_Inquiry(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry);
+        
+        if( scsi_status == USBH_OK)
+        {
+          USBH_UsrLog ("Inquiry Vendor  : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.vendor_id);
+          USBH_UsrLog ("Inquiry Product : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.product_id);
+          USBH_UsrLog ("Inquiry Version : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.revision_id);
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;        
+        }
+        if( scsi_status == USBH_FAIL)
+        {
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;         
+        }
+        else if(scsi_status == USBH_UNRECOVERED_ERROR)
+        {
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
+          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
+        }
+        break;    
+        
+      case MSC_TEST_UNIT_READY:
+        ready_status = USBH_MSC_SCSI_TestUnitReady(phost, MSC_Handle->current_lun);
+        
+        if( ready_status == USBH_OK)
+        {
+          if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_OK)
+          {
+            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
+            USBH_UsrLog ("Mass Storage Device ready");
+          }
+          else
+          {
+            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
+          }
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_CAPACITY10;
+          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
+          MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_OK;
+        }
+        if( ready_status == USBH_FAIL)
+        {
+          /* Media not ready, so try to check again during 10s */
+          if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_FAIL)
+          {
+            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
+            USBH_UsrLog ("Mass Storage Device NOT ready");
+          }
+          else
+          {
+            MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
+          }         
+            MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; 
+            MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
+            MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_FAIL;
+        }
+        else if(ready_status == USBH_UNRECOVERED_ERROR)
+        {
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
+          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
+        }
+        break;
+        
+      case MSC_READ_CAPACITY10:   
+        scsi_status = USBH_MSC_SCSI_ReadCapacity(phost,MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].capacity) ;
+        
+        if(scsi_status == USBH_OK)
+        {
+          if(MSC_Handle->unit[MSC_Handle->current_lun].state_changed == 1)
+          {
+            USBH_UsrLog ("Mass Storage Device capacity : %lu MB", \
+              (int32_t)((MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr * MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size)/1024/1024));
+            USBH_UsrLog ("Block number : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr));
+            USBH_UsrLog ("Block Size   : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size));
+          }
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
+          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
+          MSC_Handle->current_lun++;
+        }
+        else if( scsi_status == USBH_FAIL)
+        {
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
+        }
+        else if(scsi_status == USBH_UNRECOVERED_ERROR)
+        {
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
+          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
+        }
+        break;
+        
+      case MSC_REQUEST_SENSE:
+        scsi_status = USBH_MSC_SCSI_RequestSense(phost,  MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].sense);
+        
+        if( scsi_status == USBH_OK)
+        {
+          if((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) ||
+             (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY) )   
+          {
+            
+            if(phost->Timer <= MSC_Handle->timer)
+            {
+              MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;
+              break;
+            }        
+          }
+          
+          USBH_UsrLog ("Sense Key  : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.key);
+          USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.asc);
+          USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.ascq);
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
+          MSC_Handle->current_lun++;
+        }
+        if( scsi_status == USBH_FAIL)
+        {
+          USBH_UsrLog ("Mass Storage Device NOT ready");
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_UNRECOVERED_ERROR; 
+        }
+        else if(scsi_status == USBH_UNRECOVERED_ERROR)
+        {
+          MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
+          MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;   
+        }
+        break;  
+    
+      case MSC_UNRECOVERED_ERROR: 
+        MSC_Handle->current_lun++;
+        break;  
+        
+      default:
+        break;
+      }
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif       
+    }
+    else
+    {
+      MSC_Handle->current_lun = 0;
+    MSC_Handle->state = MSC_IDLE;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif 
+    phost->pUser(phost, HOST_USER_CLASS_ACTIVE);     
+    }
+    break;
+
+  case MSC_IDLE:
+    error = USBH_OK;  
+    break;
+    
+  default:
+    break; 
+  }
+  return error;
+}
+
+
+/**
+  * @brief  USBH_MSC_SOFProcess 
+  *         The function is for SOF state
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost)
+{
+
+  return USBH_OK;
+}
+/**
+  * @brief  USBH_MSC_RdWrProcess 
+  *         The function is for managing state machine for MSC I/O Process
+  * @param  phost: Host handle
+  * @param  lun: logical Unit Number
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  USBH_StatusTypeDef error = USBH_BUSY ;
+  USBH_StatusTypeDef scsi_status = USBH_BUSY ;  
+  
+  /* Switch MSC REQ state machine */
+  switch (MSC_Handle->unit[lun].state)
+  {
+ 
+  case MSC_READ: 
+    scsi_status = USBH_MSC_SCSI_Read(phost,lun, 0, NULL, 0) ;
+    
+    if(scsi_status == USBH_OK)
+    {
+      MSC_Handle->unit[lun].state = MSC_IDLE;
+      error = USBH_OK;     
+    }
+    else if( scsi_status == USBH_FAIL)
+    {
+      MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;  
+    }
+    else if(scsi_status == USBH_UNRECOVERED_ERROR)
+    {
+      MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
+          error = USBH_FAIL;
+    }
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif   
+    break;     
+    
+  case MSC_WRITE: 
+    scsi_status = USBH_MSC_SCSI_Write(phost,lun, 0, NULL, 0) ;
+    
+    if(scsi_status == USBH_OK)
+    {
+        MSC_Handle->unit[lun].state = MSC_IDLE;
+        error = USBH_OK;             
+    }
+    else if( scsi_status == USBH_FAIL)
+    {
+      MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;  
+    }
+    else if(scsi_status == USBH_UNRECOVERED_ERROR)
+    {
+      MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
+          error = USBH_FAIL;
+    }
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif       
+    break; 
+  
+  case MSC_REQUEST_SENSE:
+    scsi_status = USBH_MSC_SCSI_RequestSense(phost, lun, &MSC_Handle->unit[lun].sense);
+    
+    if( scsi_status == USBH_OK)
+    {
+      USBH_UsrLog ("Sense Key  : %x", MSC_Handle->unit[lun].sense.key);
+      USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[lun].sense.asc);
+      USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[lun].sense.ascq);
+      MSC_Handle->unit[lun].state = MSC_IDLE;
+      MSC_Handle->unit[lun].error = MSC_ERROR;
+      
+      error = USBH_FAIL;
+    }
+    if( scsi_status == USBH_FAIL)
+    {
+      USBH_UsrLog ("Mass Storage Device NOT ready");
+    }
+    else if(scsi_status == USBH_UNRECOVERED_ERROR)
+    {
+      MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;  
+          error = USBH_FAIL;
+    }
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
+#endif       
+    break;  
+    
+  default:
+    break;  
+    
+  }
+  return error;
+}
+
+/**
+  * @brief  USBH_MSC_IsReady 
+  *         The function check if the MSC function is ready
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+uint8_t  USBH_MSC_IsReady (USBH_HandleTypeDef *phost)
+{
+    MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;  
+    
+  if(phost->gState == HOST_CLASS)
+  {
+    return (MSC_Handle->state == MSC_IDLE);
+  }
+  else
+  {
+    return 0;
+  }
+}
+
+/**
+  * @brief  USBH_MSC_GetMaxLUN 
+  *         The function return the Max LUN supported
+  * @param  phost: Host handle
+  * @retval logical Unit Number supported
+  */
+int8_t  USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;    
+  
+  if ((phost->gState != HOST_CLASS) && (MSC_Handle->state == MSC_IDLE))
+  {
+    return  MSC_Handle->max_lun;
+  }  
+  return 0xFF;
+}
+
+/**
+  * @brief  USBH_MSC_UnitIsReady 
+  *         The function check whether a LUN is ready
+  * @param  phost: Host handle
+  * @param  lun: logical Unit Number
+  * @retval Lun status (0: not ready / 1: ready)
+  */
+uint8_t  USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;  
+  
+  if(phost->gState == HOST_CLASS)
+  {
+    return (MSC_Handle->unit[lun].error == MSC_OK);
+  }
+  else
+  {
+    return 0;
+  }
+}
+      
+/**
+  * @brief  USBH_MSC_GetLUNInfo 
+  *         The function return a LUN information
+  * @param  phost: Host handle
+  * @param  lun: logical Unit Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;    
+  if(phost->gState == HOST_CLASS)
+  {
+    USBH_memcpy(info,&MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef));
+    return USBH_OK;
+  }
+  else
+  {
+    return USBH_FAIL;
+  }
+}
+
+/**
+  * @brief  USBH_MSC_Read 
+  *         The function performs a Read operation 
+  * @param  phost: Host handle
+  * @param  lun: logical Unit Number
+  * @param  address: sector address
+  * @param  pbuf: pointer to data
+  * @param  length: number of sector to read
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length)
+{
+  uint32_t timeout;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;   
+  
+  if ((phost->device.is_connected == 0) || 
+      (phost->gState != HOST_CLASS) || 
+      (MSC_Handle->unit[lun].state != MSC_IDLE))
+  {
+    return  USBH_FAIL;
+  }
+  MSC_Handle->state = MSC_READ;
+  MSC_Handle->unit[lun].state = MSC_READ;
+  MSC_Handle->rw_lun = lun;
+  USBH_MSC_SCSI_Read(phost,
+                     lun,
+                     address,
+                     pbuf,
+                     length);
+  
+  timeout = phost->Timer + (10000 * length);
+  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
+  {
+    if((phost->Timer > timeout) || (phost->device.is_connected == 0))
+    {
+      MSC_Handle->state = MSC_IDLE;
+      return USBH_FAIL;
+    }
+  }
+  MSC_Handle->state = MSC_IDLE;
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_MSC_Write 
+  *         The function performs a Write operation 
+  * @param  phost: Host handle
+  * @param  lun: logical Unit Number
+  * @param  address: sector address
+  * @param  pbuf: pointer to data
+  * @param  length: number of sector to write
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length)
+{
+  uint32_t timeout;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;   
+  
+  if ((phost->device.is_connected == 0) || 
+      (phost->gState != HOST_CLASS) || 
+      (MSC_Handle->unit[lun].state != MSC_IDLE))
+  {
+    return  USBH_FAIL;
+  }
+  MSC_Handle->state = MSC_WRITE;
+  MSC_Handle->unit[lun].state = MSC_WRITE;
+  MSC_Handle->rw_lun = lun;
+  USBH_MSC_SCSI_Write(phost,
+                     lun,
+                     address,
+                     pbuf,
+                     length);
+  
+  timeout = phost->Timer + (10000 * length);
+  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
+  {
+    if((phost->Timer > timeout) || (phost->device.is_connected == 0))
+    {
+      MSC_Handle->state = MSC_IDLE;
+      return USBH_FAIL;
+    }
+  }
+  MSC_Handle->state = MSC_IDLE;
+  return USBH_OK;
+}
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_bot.c b/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_bot.c
index 5489ce29780aa4e819cbe90de6dc078e937b982d..e9d6af9e4e937d6120c18bd90079867cbe6d3466 100644
--- a/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_bot.c
+++ b/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_bot.c
@@ -1,633 +1,633 @@
-/**
-  ******************************************************************************
-  * @file    usbh_msc_bot.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file includes the BOT protocol related functions
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_msc_bot.h"
-#include "usbh_msc.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_MSC_CLASS
-* @{
-*/
-
-/** @defgroup USBH_MSC_BOT 
-* @brief    This file includes the mass storage related functions
-* @{
-*/ 
-
-
-/** @defgroup USBH_MSC_BOT_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MSC_BOT_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MSC_BOT_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MSC_BOT_Private_Variables
-* @{
-*/ 
-
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MSC_BOT_Private_FunctionPrototypes
-* @{
-*/ 
-static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir);
-static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost);
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MSC_BOT_Exported_Variables
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MSC_BOT_Private_Functions
-* @{
-*/ 
-
-/**
-  * @brief  USBH_MSC_BOT_REQ_Reset 
-  *         The function the MSC BOT Reset request.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost)
-{
-  
-  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | \
-                              USB_REQ_RECIPIENT_INTERFACE;
-  
-  phost->Control.setup.b.bRequest = USB_REQ_BOT_RESET;
-  phost->Control.setup.b.wValue.w = 0;
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = 0;           
-  
-  return USBH_CtlReq(phost, 0 , 0 );  
-}
-
-/**
-  * @brief  USBH_MSC_BOT_REQ_GetMaxLUN 
-  *         The function the MSC BOT GetMaxLUN request.
-  * @param  phost: Host handle
-  * @param  Maxlun: pointer to Maxlun variable
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun)
-{
-  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \
-                              USB_REQ_RECIPIENT_INTERFACE;
-  
-  phost->Control.setup.b.bRequest = USB_REQ_GET_MAX_LUN;
-  phost->Control.setup.b.wValue.w = 0;
-  phost->Control.setup.b.wIndex.w = 0;
-  phost->Control.setup.b.wLength.w = 1;           
-  
-  return USBH_CtlReq(phost, Maxlun , 1 ); 
-}
-
-
-
-/**
-  * @brief  USBH_MSC_BOT_Init 
-  *         The function Initializes the BOT protocol.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost)
-{
-  
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  MSC_Handle->hbot.cbw.field.Signature = BOT_CBW_SIGNATURE;
-  MSC_Handle->hbot.cbw.field.Tag = BOT_CBW_TAG;
-  MSC_Handle->hbot.state = BOT_SEND_CBW;    
-  MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;   
-  
-  return USBH_OK;
-}
-
-
-
-/**
-  * @brief  USBH_MSC_BOT_Process 
-  *         The function handle the BOT protocol.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY;
-  USBH_StatusTypeDef   error  = USBH_BUSY;  
-  BOT_CSWStatusTypeDef CSW_Status = BOT_CSW_CMD_FAILED;
-  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  uint8_t toggle = 0;
-  
-  switch (MSC_Handle->hbot.state)
-  {
-  case BOT_SEND_CBW:
-    MSC_Handle->hbot.cbw.field.LUN = lun;
-    MSC_Handle->hbot.state = BOT_SEND_CBW_WAIT;    
-    USBH_BulkSendData (phost,
-                       MSC_Handle->hbot.cbw.data, 
-                       BOT_CBW_LENGTH, 
-                       MSC_Handle->OutPipe,
-                       1);
-    
-    break;
-    
-  case BOT_SEND_CBW_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); 
-    
-    if(URB_Status == USBH_URB_DONE)
-    { 
-      if ( MSC_Handle->hbot.cbw.field.DataTransferLength != 0 )
-      {
-        /* If there is Data Transfer Stage */
-        if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H)
-        {
-          /* Data Direction is IN */
-          MSC_Handle->hbot.state = BOT_DATA_IN;
-        }
-        else
-        {
-          /* Data Direction is OUT */
-          MSC_Handle->hbot.state = BOT_DATA_OUT;
-        } 
-      }
-      
-      else
-      {/* If there is NO Data Transfer Stage */
-        MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
-      }
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif   
-    
-    }   
-    else if(URB_Status == USBH_URB_NOTREADY)
-    {
-      /* Re-send CBW */
-      MSC_Handle->hbot.state = BOT_SEND_CBW;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }     
-    else if(URB_Status == USBH_URB_STALL)
-    {
-      MSC_Handle->hbot.state  = BOT_ERROR_OUT;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case BOT_DATA_IN:   
-    /* Send first packet */        
-    USBH_BulkReceiveData (phost,
-                          MSC_Handle->hbot.pbuf, 
-                          MSC_Handle->InEpSize , 
-                          MSC_Handle->InPipe);
-    
-    MSC_Handle->hbot.state  = BOT_DATA_IN_WAIT;
-    
-    break;   
-    
-  case BOT_DATA_IN_WAIT:  
-    
-    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); 
-    
-    if(URB_Status == USBH_URB_DONE) 
-    {
-      /* Adjudt Data pointer and data length */
-      if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize)
-      {
-          MSC_Handle->hbot.pbuf += MSC_Handle->InEpSize;
-          MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->InEpSize;  
-      }
-      else
-      {
-        MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
-      }
-        
-      /* More Data To be Received */
-      if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
-      {
-        /* Send next packet */        
-        USBH_BulkReceiveData (phost,
-                              MSC_Handle->hbot.pbuf, 
-                              MSC_Handle->InEpSize , 
-                              MSC_Handle->InPipe);
-        
-      }
-      else
-      {
-        /* If value was 0, and successful transfer, then change the state */
-        MSC_Handle->hbot.state  = BOT_RECEIVE_CSW;
-#if (USBH_USE_OS == 1)
-        osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif 
-      }
-    }
-    else if(URB_Status == USBH_URB_STALL)
-    {
-      /* This is Data IN Stage STALL Condition */
-      MSC_Handle->hbot.state  = BOT_ERROR_IN;
-      
-      /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
-      6.7.2 Host expects to receive data from the device
-      3. On a STALL condition receiving data, then:
-      The host shall accept the data received.
-      The host shall clear the Bulk-In pipe.
-      4. The host shall attempt to receive a CSW.*/
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }     
-    break;  
-    
-  case BOT_DATA_OUT:
-    
-    USBH_BulkSendData (phost,
-                       MSC_Handle->hbot.pbuf, 
-                       MSC_Handle->OutEpSize , 
-                       MSC_Handle->OutPipe,
-                       1);
-    
-    
-    MSC_Handle->hbot.state  = BOT_DATA_OUT_WAIT;
-    break;
-    
-  case BOT_DATA_OUT_WAIT:
-    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe);     
-    
-    if(URB_Status == USBH_URB_DONE)
-    {
-      /* Adjudt Data pointer and data length */
-      if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize)
-      {
-          MSC_Handle->hbot.pbuf += MSC_Handle->OutEpSize;
-          MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->OutEpSize; 
-      }
-      else
-      {
-        MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
-      } 
-      
-      /* More Data To be Sent */
-      if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
-      {
-        USBH_BulkSendData (phost,
-                           MSC_Handle->hbot.pbuf, 
-                           MSC_Handle->OutEpSize , 
-                           MSC_Handle->OutPipe,
-                           1);
-      }
-      else
-      {
-        /* If value was 0, and successful transfer, then change the state */
-        MSC_Handle->hbot.state  = BOT_RECEIVE_CSW;
-      }  
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    
-    else if(URB_Status == USBH_URB_NOTREADY)
-    {
-      /* Re-send same data */      
-      MSC_Handle->hbot.state  = BOT_DATA_OUT;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    
-    else if(URB_Status == USBH_URB_STALL)
-    {
-      MSC_Handle->hbot.state  = BOT_ERROR_OUT;
-      
-      /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
-      6.7.3 Ho - Host expects to send data to the device
-      3. On a STALL condition sending data, then:
-      " The host shall clear the Bulk-Out pipe.
-      4. The host shall attempt to receive a CSW.
-      */      
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case BOT_RECEIVE_CSW:
-    
-    USBH_BulkReceiveData (phost,
-                          MSC_Handle->hbot.csw.data, 
-                          BOT_CSW_LENGTH , 
-                          MSC_Handle->InPipe);
-    
-    MSC_Handle->hbot.state  = BOT_RECEIVE_CSW_WAIT;
-    break;
-    
-  case BOT_RECEIVE_CSW_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); 
-    
-    /* Decode CSW */
-    if(URB_Status == USBH_URB_DONE)
-    {
-      MSC_Handle->hbot.state = BOT_SEND_CBW;    
-      MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;        
-      CSW_Status = USBH_MSC_DecodeCSW(phost);
-      
-      if(CSW_Status == BOT_CSW_CMD_PASSED)
-      {
-        status = USBH_OK;
-      }
-      else
-      {
-        status = USBH_FAIL;
-      }
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    else if(URB_Status == USBH_URB_STALL)     
-    {
-      MSC_Handle->hbot.state  = BOT_ERROR_IN;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case BOT_ERROR_IN: 
-    error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_IN);
-    
-    if (error == USBH_OK)
-    {
-      MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
-    }
-    else if (error == USBH_UNRECOVERED_ERROR)
-    {
-      /* This means that there is a STALL Error limit, Do Reset Recovery */
-      MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
-    }
-    break;
-    
-  case BOT_ERROR_OUT: 
-    error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT);
-    
-    if ( error == USBH_OK)
-    { 
-      
-      toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe); 
-      USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1- toggle);   
-      USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0);  
-      MSC_Handle->hbot.state = BOT_ERROR_IN;        
-    }
-    else if (error == USBH_UNRECOVERED_ERROR)
-    {
-      MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
-    }
-    break;
-    
-    
-  case BOT_UNRECOVERED_ERROR: 
-    status = USBH_MSC_BOT_REQ_Reset(phost);
-    if ( status == USBH_OK)
-    {
-      MSC_Handle->hbot.state = BOT_SEND_CBW; 
-    }
-    break;
-    
-  default:      
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MSC_BOT_Abort 
-  *         The function handle the BOT Abort process.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @param  dir: direction (0: out / 1 : in)
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  switch (dir)
-  {
-  case BOT_DIR_IN :
-    /* send ClrFeture on Bulk IN endpoint */
-    status = USBH_ClrFeature(phost, MSC_Handle->InEp);
-    
-    break;
-    
-  case BOT_DIR_OUT :
-    /*send ClrFeature on Bulk OUT endpoint */
-    status = USBH_ClrFeature(phost, MSC_Handle->OutEp);
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MSC_BOT_DecodeCSW
-  *         This function decodes the CSW received by the device and updates the
-  *         same to upper layer.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  * @notes
-  *     Refer to USB Mass-Storage Class : BOT (www.usb.org)
-  *    6.3.1 Valid CSW Conditions :
-  *     The host shall consider the CSW valid when:
-  *     1. dCSWSignature is equal to 53425355h
-  *     2. the CSW is 13 (Dh) bytes in length,
-  *     3. dCSWTag matches the dCBWTag from the corresponding CBW.
-  */
-
-static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost)
-{
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  BOT_CSWStatusTypeDef status = BOT_CSW_CMD_FAILED;
-  
-    /*Checking if the transfer length is diffrent than 13*/    
-    if(USBH_LL_GetLastXferSize(phost, MSC_Handle->InPipe) != BOT_CSW_LENGTH)
-    {
-      /*(4) Hi > Dn (Host expects to receive data from the device,
-      Device intends to transfer no data)
-      (5) Hi > Di (Host expects to receive data from the device,
-      Device intends to send data to the host)
-      (9) Ho > Dn (Host expects to send data to the device,
-      Device intends to transfer no data)
-      (11) Ho > Do  (Host expects to send data to the device,
-      Device intends to receive data from the host)*/
-      
-      
-      status = BOT_CSW_PHASE_ERROR;
-    }
-    else
-    { /* CSW length is Correct */
-      
-      /* Check validity of the CSW Signature and CSWStatus */
-      if(MSC_Handle->hbot.csw.field.Signature == BOT_CSW_SIGNATURE)
-      {/* Check Condition 1. dCSWSignature is equal to 53425355h */
-        
-        if(MSC_Handle->hbot.csw.field.Tag == MSC_Handle->hbot.cbw.field.Tag)
-        {
-          /* Check Condition 3. dCSWTag matches the dCBWTag from the 
-          corresponding CBW */
-
-          if(MSC_Handle->hbot.csw.field.Status == 0) 
-          {
-            /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
-            
-            Hn Host expects no data transfers
-            Hi Host expects to receive data from the device
-            Ho Host expects to send data to the device
-            
-            Dn Device intends to transfer no data
-            Di Device intends to send data to the host
-            Do Device intends to receive data from the host
-            
-            Section 6.7 
-            (1) Hn = Dn (Host expects no data transfers,
-            Device intends to transfer no data)
-            (6) Hi = Di (Host expects to receive data from the device,
-            Device intends to send data to the host)
-            (12) Ho = Do (Host expects to send data to the device, 
-            Device intends to receive data from the host)
-            
-            */
-            
-            status = BOT_CSW_CMD_PASSED;
-          }
-          else if(MSC_Handle->hbot.csw.field.Status == 1)
-          {
-            status = BOT_CSW_CMD_FAILED;
-          }
-          
-          else if(MSC_Handle->hbot.csw.field.Status == 2)
-          { 
-            /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
-            Section 6.7 
-            (2) Hn < Di ( Host expects no data transfers, 
-            Device intends to send data to the host)
-            (3) Hn < Do ( Host expects no data transfers, 
-            Device intends to receive data from the host)
-            (7) Hi < Di ( Host expects to receive data from the device, 
-            Device intends to send data to the host)
-            (8) Hi <> Do ( Host expects to receive data from the device, 
-            Device intends to receive data from the host)
-            (10) Ho <> Di (Host expects to send data to the device,
-            Di Device intends to send data to the host)
-            (13) Ho < Do (Host expects to send data to the device, 
-            Device intends to receive data from the host)
-            */
-            
-            status = BOT_CSW_PHASE_ERROR;
-          }
-        } /* CSW Tag Matching is Checked  */
-      } /* CSW Signature Correct Checking */
-      else
-      {
-        /* If the CSW Signature is not valid, We sall return the Phase Error to
-        Upper Layers for Reset Recovery */
-        
-        status = BOT_CSW_PHASE_ERROR;
-      }
-    } /* CSW Length Check*/
-    
-  return status;
-}
-
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_msc_bot.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file includes the BOT protocol related functions
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_msc_bot.h"
+#include "usbh_msc.h"
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_MSC_CLASS
+* @{
+*/
+
+/** @defgroup USBH_MSC_BOT 
+* @brief    This file includes the mass storage related functions
+* @{
+*/ 
+
+
+/** @defgroup USBH_MSC_BOT_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MSC_BOT_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MSC_BOT_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MSC_BOT_Private_Variables
+* @{
+*/ 
+
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MSC_BOT_Private_FunctionPrototypes
+* @{
+*/ 
+static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir);
+static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost);
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MSC_BOT_Exported_Variables
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MSC_BOT_Private_Functions
+* @{
+*/ 
+
+/**
+  * @brief  USBH_MSC_BOT_REQ_Reset 
+  *         The function the MSC BOT Reset request.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost)
+{
+  
+  phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | \
+                              USB_REQ_RECIPIENT_INTERFACE;
+  
+  phost->Control.setup.b.bRequest = USB_REQ_BOT_RESET;
+  phost->Control.setup.b.wValue.w = 0;
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = 0;           
+  
+  return USBH_CtlReq(phost, 0 , 0 );  
+}
+
+/**
+  * @brief  USBH_MSC_BOT_REQ_GetMaxLUN 
+  *         The function the MSC BOT GetMaxLUN request.
+  * @param  phost: Host handle
+  * @param  Maxlun: pointer to Maxlun variable
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun)
+{
+  phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \
+                              USB_REQ_RECIPIENT_INTERFACE;
+  
+  phost->Control.setup.b.bRequest = USB_REQ_GET_MAX_LUN;
+  phost->Control.setup.b.wValue.w = 0;
+  phost->Control.setup.b.wIndex.w = 0;
+  phost->Control.setup.b.wLength.w = 1;           
+  
+  return USBH_CtlReq(phost, Maxlun , 1 ); 
+}
+
+
+
+/**
+  * @brief  USBH_MSC_BOT_Init 
+  *         The function Initializes the BOT protocol.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost)
+{
+  
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  MSC_Handle->hbot.cbw.field.Signature = BOT_CBW_SIGNATURE;
+  MSC_Handle->hbot.cbw.field.Tag = BOT_CBW_TAG;
+  MSC_Handle->hbot.state = BOT_SEND_CBW;    
+  MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;   
+  
+  return USBH_OK;
+}
+
+
+
+/**
+  * @brief  USBH_MSC_BOT_Process 
+  *         The function handle the BOT protocol.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY;
+  USBH_StatusTypeDef   error  = USBH_BUSY;  
+  BOT_CSWStatusTypeDef CSW_Status = BOT_CSW_CMD_FAILED;
+  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  uint8_t toggle = 0;
+  
+  switch (MSC_Handle->hbot.state)
+  {
+  case BOT_SEND_CBW:
+    MSC_Handle->hbot.cbw.field.LUN = lun;
+    MSC_Handle->hbot.state = BOT_SEND_CBW_WAIT;    
+    USBH_BulkSendData (phost,
+                       MSC_Handle->hbot.cbw.data, 
+                       BOT_CBW_LENGTH, 
+                       MSC_Handle->OutPipe,
+                       1);
+    
+    break;
+    
+  case BOT_SEND_CBW_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); 
+    
+    if(URB_Status == USBH_URB_DONE)
+    { 
+      if ( MSC_Handle->hbot.cbw.field.DataTransferLength != 0 )
+      {
+        /* If there is Data Transfer Stage */
+        if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H)
+        {
+          /* Data Direction is IN */
+          MSC_Handle->hbot.state = BOT_DATA_IN;
+        }
+        else
+        {
+          /* Data Direction is OUT */
+          MSC_Handle->hbot.state = BOT_DATA_OUT;
+        } 
+      }
+      
+      else
+      {/* If there is NO Data Transfer Stage */
+        MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
+      }
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif   
+    
+    }   
+    else if(URB_Status == USBH_URB_NOTREADY)
+    {
+      /* Re-send CBW */
+      MSC_Handle->hbot.state = BOT_SEND_CBW;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }     
+    else if(URB_Status == USBH_URB_STALL)
+    {
+      MSC_Handle->hbot.state  = BOT_ERROR_OUT;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case BOT_DATA_IN:   
+    /* Send first packet */        
+    USBH_BulkReceiveData (phost,
+                          MSC_Handle->hbot.pbuf, 
+                          MSC_Handle->InEpSize , 
+                          MSC_Handle->InPipe);
+    
+    MSC_Handle->hbot.state  = BOT_DATA_IN_WAIT;
+    
+    break;   
+    
+  case BOT_DATA_IN_WAIT:  
+    
+    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); 
+    
+    if(URB_Status == USBH_URB_DONE) 
+    {
+      /* Adjudt Data pointer and data length */
+      if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize)
+      {
+          MSC_Handle->hbot.pbuf += MSC_Handle->InEpSize;
+          MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->InEpSize;  
+      }
+      else
+      {
+        MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
+      }
+        
+      /* More Data To be Received */
+      if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
+      {
+        /* Send next packet */        
+        USBH_BulkReceiveData (phost,
+                              MSC_Handle->hbot.pbuf, 
+                              MSC_Handle->InEpSize , 
+                              MSC_Handle->InPipe);
+        
+      }
+      else
+      {
+        /* If value was 0, and successful transfer, then change the state */
+        MSC_Handle->hbot.state  = BOT_RECEIVE_CSW;
+#if (USBH_USE_OS == 1)
+        osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif 
+      }
+    }
+    else if(URB_Status == USBH_URB_STALL)
+    {
+      /* This is Data IN Stage STALL Condition */
+      MSC_Handle->hbot.state  = BOT_ERROR_IN;
+      
+      /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
+      6.7.2 Host expects to receive data from the device
+      3. On a STALL condition receiving data, then:
+      The host shall accept the data received.
+      The host shall clear the Bulk-In pipe.
+      4. The host shall attempt to receive a CSW.*/
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }     
+    break;  
+    
+  case BOT_DATA_OUT:
+    
+    USBH_BulkSendData (phost,
+                       MSC_Handle->hbot.pbuf, 
+                       MSC_Handle->OutEpSize , 
+                       MSC_Handle->OutPipe,
+                       1);
+    
+    
+    MSC_Handle->hbot.state  = BOT_DATA_OUT_WAIT;
+    break;
+    
+  case BOT_DATA_OUT_WAIT:
+    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe);     
+    
+    if(URB_Status == USBH_URB_DONE)
+    {
+      /* Adjudt Data pointer and data length */
+      if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize)
+      {
+          MSC_Handle->hbot.pbuf += MSC_Handle->OutEpSize;
+          MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->OutEpSize; 
+      }
+      else
+      {
+        MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
+      } 
+      
+      /* More Data To be Sent */
+      if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
+      {
+        USBH_BulkSendData (phost,
+                           MSC_Handle->hbot.pbuf, 
+                           MSC_Handle->OutEpSize , 
+                           MSC_Handle->OutPipe,
+                           1);
+      }
+      else
+      {
+        /* If value was 0, and successful transfer, then change the state */
+        MSC_Handle->hbot.state  = BOT_RECEIVE_CSW;
+      }  
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    
+    else if(URB_Status == USBH_URB_NOTREADY)
+    {
+      /* Re-send same data */      
+      MSC_Handle->hbot.state  = BOT_DATA_OUT;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    
+    else if(URB_Status == USBH_URB_STALL)
+    {
+      MSC_Handle->hbot.state  = BOT_ERROR_OUT;
+      
+      /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
+      6.7.3 Ho - Host expects to send data to the device
+      3. On a STALL condition sending data, then:
+      " The host shall clear the Bulk-Out pipe.
+      4. The host shall attempt to receive a CSW.
+      */      
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case BOT_RECEIVE_CSW:
+    
+    USBH_BulkReceiveData (phost,
+                          MSC_Handle->hbot.csw.data, 
+                          BOT_CSW_LENGTH , 
+                          MSC_Handle->InPipe);
+    
+    MSC_Handle->hbot.state  = BOT_RECEIVE_CSW_WAIT;
+    break;
+    
+  case BOT_RECEIVE_CSW_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); 
+    
+    /* Decode CSW */
+    if(URB_Status == USBH_URB_DONE)
+    {
+      MSC_Handle->hbot.state = BOT_SEND_CBW;    
+      MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;        
+      CSW_Status = USBH_MSC_DecodeCSW(phost);
+      
+      if(CSW_Status == BOT_CSW_CMD_PASSED)
+      {
+        status = USBH_OK;
+      }
+      else
+      {
+        status = USBH_FAIL;
+      }
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    else if(URB_Status == USBH_URB_STALL)     
+    {
+      MSC_Handle->hbot.state  = BOT_ERROR_IN;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case BOT_ERROR_IN: 
+    error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_IN);
+    
+    if (error == USBH_OK)
+    {
+      MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
+    }
+    else if (error == USBH_UNRECOVERED_ERROR)
+    {
+      /* This means that there is a STALL Error limit, Do Reset Recovery */
+      MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
+    }
+    break;
+    
+  case BOT_ERROR_OUT: 
+    error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT);
+    
+    if ( error == USBH_OK)
+    { 
+      
+      toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe); 
+      USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1- toggle);   
+      USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0);  
+      MSC_Handle->hbot.state = BOT_ERROR_IN;        
+    }
+    else if (error == USBH_UNRECOVERED_ERROR)
+    {
+      MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
+    }
+    break;
+    
+    
+  case BOT_UNRECOVERED_ERROR: 
+    status = USBH_MSC_BOT_REQ_Reset(phost);
+    if ( status == USBH_OK)
+    {
+      MSC_Handle->hbot.state = BOT_SEND_CBW; 
+    }
+    break;
+    
+  default:      
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MSC_BOT_Abort 
+  *         The function handle the BOT Abort process.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @param  dir: direction (0: out / 1 : in)
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  switch (dir)
+  {
+  case BOT_DIR_IN :
+    /* send ClrFeture on Bulk IN endpoint */
+    status = USBH_ClrFeature(phost, MSC_Handle->InEp);
+    
+    break;
+    
+  case BOT_DIR_OUT :
+    /*send ClrFeature on Bulk OUT endpoint */
+    status = USBH_ClrFeature(phost, MSC_Handle->OutEp);
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MSC_BOT_DecodeCSW
+  *         This function decodes the CSW received by the device and updates the
+  *         same to upper layer.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  * @notes
+  *     Refer to USB Mass-Storage Class : BOT (www.usb.org)
+  *    6.3.1 Valid CSW Conditions :
+  *     The host shall consider the CSW valid when:
+  *     1. dCSWSignature is equal to 53425355h
+  *     2. the CSW is 13 (Dh) bytes in length,
+  *     3. dCSWTag matches the dCBWTag from the corresponding CBW.
+  */
+
+static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost)
+{
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  BOT_CSWStatusTypeDef status = BOT_CSW_CMD_FAILED;
+  
+    /*Checking if the transfer length is diffrent than 13*/    
+    if(USBH_LL_GetLastXferSize(phost, MSC_Handle->InPipe) != BOT_CSW_LENGTH)
+    {
+      /*(4) Hi > Dn (Host expects to receive data from the device,
+      Device intends to transfer no data)
+      (5) Hi > Di (Host expects to receive data from the device,
+      Device intends to send data to the host)
+      (9) Ho > Dn (Host expects to send data to the device,
+      Device intends to transfer no data)
+      (11) Ho > Do  (Host expects to send data to the device,
+      Device intends to receive data from the host)*/
+      
+      
+      status = BOT_CSW_PHASE_ERROR;
+    }
+    else
+    { /* CSW length is Correct */
+      
+      /* Check validity of the CSW Signature and CSWStatus */
+      if(MSC_Handle->hbot.csw.field.Signature == BOT_CSW_SIGNATURE)
+      {/* Check Condition 1. dCSWSignature is equal to 53425355h */
+        
+        if(MSC_Handle->hbot.csw.field.Tag == MSC_Handle->hbot.cbw.field.Tag)
+        {
+          /* Check Condition 3. dCSWTag matches the dCBWTag from the 
+          corresponding CBW */
+
+          if(MSC_Handle->hbot.csw.field.Status == 0) 
+          {
+            /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
+            
+            Hn Host expects no data transfers
+            Hi Host expects to receive data from the device
+            Ho Host expects to send data to the device
+            
+            Dn Device intends to transfer no data
+            Di Device intends to send data to the host
+            Do Device intends to receive data from the host
+            
+            Section 6.7 
+            (1) Hn = Dn (Host expects no data transfers,
+            Device intends to transfer no data)
+            (6) Hi = Di (Host expects to receive data from the device,
+            Device intends to send data to the host)
+            (12) Ho = Do (Host expects to send data to the device, 
+            Device intends to receive data from the host)
+            
+            */
+            
+            status = BOT_CSW_CMD_PASSED;
+          }
+          else if(MSC_Handle->hbot.csw.field.Status == 1)
+          {
+            status = BOT_CSW_CMD_FAILED;
+          }
+          
+          else if(MSC_Handle->hbot.csw.field.Status == 2)
+          { 
+            /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 
+            Section 6.7 
+            (2) Hn < Di ( Host expects no data transfers, 
+            Device intends to send data to the host)
+            (3) Hn < Do ( Host expects no data transfers, 
+            Device intends to receive data from the host)
+            (7) Hi < Di ( Host expects to receive data from the device, 
+            Device intends to send data to the host)
+            (8) Hi <> Do ( Host expects to receive data from the device, 
+            Device intends to receive data from the host)
+            (10) Ho <> Di (Host expects to send data to the device,
+            Di Device intends to send data to the host)
+            (13) Ho < Do (Host expects to send data to the device, 
+            Device intends to receive data from the host)
+            */
+            
+            status = BOT_CSW_PHASE_ERROR;
+          }
+        } /* CSW Tag Matching is Checked  */
+      } /* CSW Signature Correct Checking */
+      else
+      {
+        /* If the CSW Signature is not valid, We sall return the Phase Error to
+        Upper Layers for Reset Recovery */
+        
+        status = BOT_CSW_PHASE_ERROR;
+      }
+    } /* CSW Length Check*/
+    
+  return status;
+}
+
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_scsi.c b/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_scsi.c
index 5d069b40a8e61505d999280da2c53c68e0cafe1d..ec8bf7f09ce2af0e4230b36e333859df43be4357 100644
--- a/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_scsi.c
+++ b/micropython/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_scsi.c
@@ -1,458 +1,458 @@
-/**
-  ******************************************************************************
-  * @file    usbh_msc_scsi.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file implements the SCSI commands
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_msc.h"
-#include "usbh_msc_scsi.h"
-#include "usbh_msc_bot.h"
-
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_MSC_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_MSC_SCSI 
-  * @brief    This file includes the mass storage related functions
-  * @{
-  */ 
-
-
-/** @defgroup USBH_MSC_SCSI_Private_TypesDefinitions
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_SCSI_Private_Defines
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MSC_SCSI_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_SCSI_Private_FunctionPrototypes
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_SCSI_Exported_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_MSC_SCSI_Private_Functions
-  * @{
-  */ 
-
-
-/**
-  * @brief  USBH_MSC_SCSI_TestUnitReady 
-  *         Issue TestUnitReady command.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, 
-                                                uint8_t lun)
-{
-  USBH_StatusTypeDef    error = USBH_FAIL ;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  switch(MSC_Handle->hbot.cmd_state)
-  {
-  case BOT_CMD_SEND:  
-    
-    /*Prepare the CBW and relevent field*/
-    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_MODE_TEST_UNIT_READY;     
-    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT;
-    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
-    
-    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
-    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_TEST_UNIT_READY; 
-    
-    MSC_Handle->hbot.state = BOT_SEND_CBW;
-    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
-    error = USBH_BUSY; 
-    break;
-    
-  case BOT_CMD_WAIT: 
-    error = USBH_MSC_BOT_Process(phost, lun);
-    break;
-    
-  default:
-    break;
-  }
-  
-  return error;
-}
-
-/**
-  * @brief  USBH_MSC_SCSI_ReadCapacity 
-  *         Issue Read Capacity command.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @param  capacity: pointer to the capacity structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, 
-                                               uint8_t lun,
-                                               SCSI_CapacityTypeDef *capacity)
-{
-  USBH_StatusTypeDef    error = USBH_BUSY ;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  switch(MSC_Handle->hbot.cmd_state)
-  {
-  case BOT_CMD_SEND:  
-    
-    /*Prepare the CBW and relevent field*/
-    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_READ_CAPACITY10;
-    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
-    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
-    
-    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
-    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_READ_CAPACITY10; 
-    
-    MSC_Handle->hbot.state = BOT_SEND_CBW;
-    
-    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
-    MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
-    error = USBH_BUSY; 
-    break;
-    
-  case BOT_CMD_WAIT: 
-    
-    error = USBH_MSC_BOT_Process(phost, lun);
-    
-    if(error == USBH_OK)
-    {
-      /*assign the capacity*/
-      capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | (MSC_Handle->hbot.pbuf[2] << 8) |\
-                           (MSC_Handle->hbot.pbuf[1] << 16) | (MSC_Handle->hbot.pbuf[0] << 24);
-
-      /*assign the page length*/
-      capacity->block_size = MSC_Handle->hbot.pbuf[7] | (MSC_Handle->hbot.pbuf[6] << 8); 
-    }
-    break;
-    
-  default:
-    break;
-  }
-  
-  return error;
-}
-
-/**
-  * @brief  USBH_MSC_SCSI_Inquiry 
-  *         Issue Inquiry command.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @param  capacity: pointer to the inquiry structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, 
-                                               uint8_t lun, 
-                                               SCSI_StdInquiryDataTypeDef *inquiry)
-{
-  USBH_StatusTypeDef    error = USBH_FAIL ;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  switch(MSC_Handle->hbot.cmd_state)
-  {
-  case BOT_CMD_SEND:  
-    
-    /*Prepare the CBW and relevent field*/
-    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_INQUIRY;
-    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
-    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
-    
-    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_LENGTH);
-    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_INQUIRY; 
-    MSC_Handle->hbot.cbw.field.CB[1]  = (lun << 5);    
-    MSC_Handle->hbot.cbw.field.CB[2]  = 0;    
-    MSC_Handle->hbot.cbw.field.CB[3]  = 0;    
-    MSC_Handle->hbot.cbw.field.CB[4]  = 0x24;    
-    MSC_Handle->hbot.cbw.field.CB[5]  = 0;    
-        
-    MSC_Handle->hbot.state = BOT_SEND_CBW;
-
-    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
-    MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
-    error = USBH_BUSY; 
-    break;
-    
-  case BOT_CMD_WAIT: 
-    
-    error = USBH_MSC_BOT_Process(phost, lun);
-    
-    if(error == USBH_OK)
-    {
-      USBH_memset(inquiry, 0, sizeof(SCSI_StdInquiryDataTypeDef));
-      /*assign Inquiry Data */
-      inquiry->DeviceType = MSC_Handle->hbot.pbuf[0] & 0x1F;
-      inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5;  
-      inquiry->RemovableMedia = (MSC_Handle->hbot.pbuf[1] & 0x80)== 0x80;
-      USBH_memcpy (inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8);
-      USBH_memcpy (inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16);
-      USBH_memcpy (inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4);    
-    }
-    break;
-    
-  default:
-    break;
-  }
-  
-  return error;
-}
-
-/**
-  * @brief  USBH_MSC_SCSI_RequestSense 
-  *         Issue RequestSense command.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @param  capacity: pointer to the sense data structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, 
-                                               uint8_t lun, 
-                                               SCSI_SenseTypeDef *sense_data)
-{
-  USBH_StatusTypeDef    error = USBH_FAIL ;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  switch(MSC_Handle->hbot.cmd_state)
-  {
-  case BOT_CMD_SEND:  
-    
-    /*Prepare the CBW and relevent field*/
-    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_REQUEST_SENSE;
-    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
-    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
-    
-    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
-    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_REQUEST_SENSE; 
-    MSC_Handle->hbot.cbw.field.CB[1]  = (lun << 5); 
-    MSC_Handle->hbot.cbw.field.CB[2]  = 0; 
-    MSC_Handle->hbot.cbw.field.CB[3]  = 0; 
-    MSC_Handle->hbot.cbw.field.CB[4]  = DATA_LEN_REQUEST_SENSE;
-    MSC_Handle->hbot.cbw.field.CB[5]  = 0;       
-    
-    MSC_Handle->hbot.state = BOT_SEND_CBW;
-    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
-    MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
-    error = USBH_BUSY; 
-    break;
-    
-  case BOT_CMD_WAIT: 
-    
-    error = USBH_MSC_BOT_Process(phost, lun);
-    
-    if(error == USBH_OK)
-    {
-      sense_data->key  = MSC_Handle->hbot.pbuf[2] & 0x0F;  
-      sense_data->asc  = MSC_Handle->hbot.pbuf[12];
-      sense_data->ascq = MSC_Handle->hbot.pbuf[13];
-    }
-    break;
-    
-  default:
-    break;
-  }
-  
-  return error;
-}
-
-/**
-  * @brief  USBH_MSC_SCSI_Write 
-  *         Issue write10 command.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @param  address: sector address
-  * @param  pbuf: pointer to data
-  * @param  length: number of sector to write
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length)
-{
-  USBH_StatusTypeDef    error = USBH_FAIL ;
-
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  switch(MSC_Handle->hbot.cmd_state)
-  {
-  case BOT_CMD_SEND:  
-    
-    /*Prepare the CBW and relevent field*/
-    MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
-    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT;
-    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
-    
-    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
-    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_WRITE10; 
-    
-    /*logical block address*/
-    MSC_Handle->hbot.cbw.field.CB[2]  = (((uint8_t*)&address)[3]);
-    MSC_Handle->hbot.cbw.field.CB[3]  = (((uint8_t*)&address)[2]);
-    MSC_Handle->hbot.cbw.field.CB[4]  = (((uint8_t*)&address)[1]);
-    MSC_Handle->hbot.cbw.field.CB[5]  = (((uint8_t*)&address)[0]);
-    
-    
-    /*Tranfer length */
-    MSC_Handle->hbot.cbw.field.CB[7]  = (((uint8_t *)&length)[1]) ; 
-    MSC_Handle->hbot.cbw.field.CB[8]  = (((uint8_t *)&length)[0]) ; 
-
-    
-    MSC_Handle->hbot.state = BOT_SEND_CBW;
-    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
-    MSC_Handle->hbot.pbuf = pbuf;
-    error = USBH_BUSY; 
-    break;
-    
-  case BOT_CMD_WAIT: 
-    error = USBH_MSC_BOT_Process(phost, lun);
-    break;
-    
-  default:
-    break;
-  }
-  
-  return error;
-}
-
-/**
-  * @brief  USBH_MSC_SCSI_Read 
-  *         Issue Read10 command.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @param  address: sector address
-  * @param  pbuf: pointer to data
-  * @param  length: number of sector to read
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost,
-                                     uint8_t lun,
-                                     uint32_t address,
-                                     uint8_t *pbuf,
-                                     uint32_t length)
-{
-  USBH_StatusTypeDef    error = USBH_FAIL ;
-  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
-  
-  switch(MSC_Handle->hbot.cmd_state)
-  {
-  case BOT_CMD_SEND:  
-    
-    /*Prepare the CBW and relevent field*/
-    MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
-    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
-    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
-    
-    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
-    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_READ10; 
-    
-    /*logical block address*/
-    MSC_Handle->hbot.cbw.field.CB[2]  = (((uint8_t*)&address)[3]);
-    MSC_Handle->hbot.cbw.field.CB[3]  = (((uint8_t*)&address)[2]);
-    MSC_Handle->hbot.cbw.field.CB[4]  = (((uint8_t*)&address)[1]);
-    MSC_Handle->hbot.cbw.field.CB[5]  = (((uint8_t*)&address)[0]);
-    
-    
-    /*Tranfer length */
-    MSC_Handle->hbot.cbw.field.CB[7]  = (((uint8_t *)&length)[1]) ; 
-    MSC_Handle->hbot.cbw.field.CB[8]  = (((uint8_t *)&length)[0]) ; 
-
-    
-    MSC_Handle->hbot.state = BOT_SEND_CBW;
-    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
-    MSC_Handle->hbot.pbuf = pbuf;
-    error = USBH_BUSY; 
-    break;
-    
-  case BOT_CMD_WAIT: 
-    error = USBH_MSC_BOT_Process(phost, lun);
-    break;
-    
-  default:
-    break;
-  }
-  
-  return error;
-}
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_msc_scsi.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file implements the SCSI commands
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_msc.h"
+#include "usbh_msc_scsi.h"
+#include "usbh_msc_bot.h"
+
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_MSC_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_MSC_SCSI 
+  * @brief    This file includes the mass storage related functions
+  * @{
+  */ 
+
+
+/** @defgroup USBH_MSC_SCSI_Private_TypesDefinitions
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_SCSI_Private_Defines
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MSC_SCSI_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_SCSI_Private_FunctionPrototypes
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_SCSI_Exported_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_MSC_SCSI_Private_Functions
+  * @{
+  */ 
+
+
+/**
+  * @brief  USBH_MSC_SCSI_TestUnitReady 
+  *         Issue TestUnitReady command.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, 
+                                                uint8_t lun)
+{
+  USBH_StatusTypeDef    error = USBH_FAIL ;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  switch(MSC_Handle->hbot.cmd_state)
+  {
+  case BOT_CMD_SEND:  
+    
+    /*Prepare the CBW and relevent field*/
+    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_MODE_TEST_UNIT_READY;     
+    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT;
+    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
+    
+    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
+    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_TEST_UNIT_READY; 
+    
+    MSC_Handle->hbot.state = BOT_SEND_CBW;
+    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
+    error = USBH_BUSY; 
+    break;
+    
+  case BOT_CMD_WAIT: 
+    error = USBH_MSC_BOT_Process(phost, lun);
+    break;
+    
+  default:
+    break;
+  }
+  
+  return error;
+}
+
+/**
+  * @brief  USBH_MSC_SCSI_ReadCapacity 
+  *         Issue Read Capacity command.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @param  capacity: pointer to the capacity structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, 
+                                               uint8_t lun,
+                                               SCSI_CapacityTypeDef *capacity)
+{
+  USBH_StatusTypeDef    error = USBH_BUSY ;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  switch(MSC_Handle->hbot.cmd_state)
+  {
+  case BOT_CMD_SEND:  
+    
+    /*Prepare the CBW and relevent field*/
+    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_READ_CAPACITY10;
+    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
+    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
+    
+    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
+    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_READ_CAPACITY10; 
+    
+    MSC_Handle->hbot.state = BOT_SEND_CBW;
+    
+    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
+    MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
+    error = USBH_BUSY; 
+    break;
+    
+  case BOT_CMD_WAIT: 
+    
+    error = USBH_MSC_BOT_Process(phost, lun);
+    
+    if(error == USBH_OK)
+    {
+      /*assign the capacity*/
+      capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | (MSC_Handle->hbot.pbuf[2] << 8) |\
+                           (MSC_Handle->hbot.pbuf[1] << 16) | (MSC_Handle->hbot.pbuf[0] << 24);
+
+      /*assign the page length*/
+      capacity->block_size = MSC_Handle->hbot.pbuf[7] | (MSC_Handle->hbot.pbuf[6] << 8); 
+    }
+    break;
+    
+  default:
+    break;
+  }
+  
+  return error;
+}
+
+/**
+  * @brief  USBH_MSC_SCSI_Inquiry 
+  *         Issue Inquiry command.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @param  capacity: pointer to the inquiry structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, 
+                                               uint8_t lun, 
+                                               SCSI_StdInquiryDataTypeDef *inquiry)
+{
+  USBH_StatusTypeDef    error = USBH_FAIL ;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  switch(MSC_Handle->hbot.cmd_state)
+  {
+  case BOT_CMD_SEND:  
+    
+    /*Prepare the CBW and relevent field*/
+    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_INQUIRY;
+    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
+    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
+    
+    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_LENGTH);
+    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_INQUIRY; 
+    MSC_Handle->hbot.cbw.field.CB[1]  = (lun << 5);    
+    MSC_Handle->hbot.cbw.field.CB[2]  = 0;    
+    MSC_Handle->hbot.cbw.field.CB[3]  = 0;    
+    MSC_Handle->hbot.cbw.field.CB[4]  = 0x24;    
+    MSC_Handle->hbot.cbw.field.CB[5]  = 0;    
+        
+    MSC_Handle->hbot.state = BOT_SEND_CBW;
+
+    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
+    MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
+    error = USBH_BUSY; 
+    break;
+    
+  case BOT_CMD_WAIT: 
+    
+    error = USBH_MSC_BOT_Process(phost, lun);
+    
+    if(error == USBH_OK)
+    {
+      USBH_memset(inquiry, 0, sizeof(SCSI_StdInquiryDataTypeDef));
+      /*assign Inquiry Data */
+      inquiry->DeviceType = MSC_Handle->hbot.pbuf[0] & 0x1F;
+      inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5;  
+      inquiry->RemovableMedia = (MSC_Handle->hbot.pbuf[1] & 0x80)== 0x80;
+      USBH_memcpy (inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8);
+      USBH_memcpy (inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16);
+      USBH_memcpy (inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4);    
+    }
+    break;
+    
+  default:
+    break;
+  }
+  
+  return error;
+}
+
+/**
+  * @brief  USBH_MSC_SCSI_RequestSense 
+  *         Issue RequestSense command.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @param  capacity: pointer to the sense data structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, 
+                                               uint8_t lun, 
+                                               SCSI_SenseTypeDef *sense_data)
+{
+  USBH_StatusTypeDef    error = USBH_FAIL ;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  switch(MSC_Handle->hbot.cmd_state)
+  {
+  case BOT_CMD_SEND:  
+    
+    /*Prepare the CBW and relevent field*/
+    MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_REQUEST_SENSE;
+    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
+    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
+    
+    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
+    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_REQUEST_SENSE; 
+    MSC_Handle->hbot.cbw.field.CB[1]  = (lun << 5); 
+    MSC_Handle->hbot.cbw.field.CB[2]  = 0; 
+    MSC_Handle->hbot.cbw.field.CB[3]  = 0; 
+    MSC_Handle->hbot.cbw.field.CB[4]  = DATA_LEN_REQUEST_SENSE;
+    MSC_Handle->hbot.cbw.field.CB[5]  = 0;       
+    
+    MSC_Handle->hbot.state = BOT_SEND_CBW;
+    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
+    MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
+    error = USBH_BUSY; 
+    break;
+    
+  case BOT_CMD_WAIT: 
+    
+    error = USBH_MSC_BOT_Process(phost, lun);
+    
+    if(error == USBH_OK)
+    {
+      sense_data->key  = MSC_Handle->hbot.pbuf[2] & 0x0F;  
+      sense_data->asc  = MSC_Handle->hbot.pbuf[12];
+      sense_data->ascq = MSC_Handle->hbot.pbuf[13];
+    }
+    break;
+    
+  default:
+    break;
+  }
+  
+  return error;
+}
+
+/**
+  * @brief  USBH_MSC_SCSI_Write 
+  *         Issue write10 command.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @param  address: sector address
+  * @param  pbuf: pointer to data
+  * @param  length: number of sector to write
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length)
+{
+  USBH_StatusTypeDef    error = USBH_FAIL ;
+
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  switch(MSC_Handle->hbot.cmd_state)
+  {
+  case BOT_CMD_SEND:  
+    
+    /*Prepare the CBW and relevent field*/
+    MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
+    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT;
+    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
+    
+    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
+    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_WRITE10; 
+    
+    /*logical block address*/
+    MSC_Handle->hbot.cbw.field.CB[2]  = (((uint8_t*)&address)[3]);
+    MSC_Handle->hbot.cbw.field.CB[3]  = (((uint8_t*)&address)[2]);
+    MSC_Handle->hbot.cbw.field.CB[4]  = (((uint8_t*)&address)[1]);
+    MSC_Handle->hbot.cbw.field.CB[5]  = (((uint8_t*)&address)[0]);
+    
+    
+    /*Tranfer length */
+    MSC_Handle->hbot.cbw.field.CB[7]  = (((uint8_t *)&length)[1]) ; 
+    MSC_Handle->hbot.cbw.field.CB[8]  = (((uint8_t *)&length)[0]) ; 
+
+    
+    MSC_Handle->hbot.state = BOT_SEND_CBW;
+    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
+    MSC_Handle->hbot.pbuf = pbuf;
+    error = USBH_BUSY; 
+    break;
+    
+  case BOT_CMD_WAIT: 
+    error = USBH_MSC_BOT_Process(phost, lun);
+    break;
+    
+  default:
+    break;
+  }
+  
+  return error;
+}
+
+/**
+  * @brief  USBH_MSC_SCSI_Read 
+  *         Issue Read10 command.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @param  address: sector address
+  * @param  pbuf: pointer to data
+  * @param  length: number of sector to read
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost,
+                                     uint8_t lun,
+                                     uint32_t address,
+                                     uint8_t *pbuf,
+                                     uint32_t length)
+{
+  USBH_StatusTypeDef    error = USBH_FAIL ;
+  MSC_HandleTypeDef *MSC_Handle =  phost->pActiveClass->pData;
+  
+  switch(MSC_Handle->hbot.cmd_state)
+  {
+  case BOT_CMD_SEND:  
+    
+    /*Prepare the CBW and relevent field*/
+    MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
+    MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
+    MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
+    
+    USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
+    MSC_Handle->hbot.cbw.field.CB[0]  = OPCODE_READ10; 
+    
+    /*logical block address*/
+    MSC_Handle->hbot.cbw.field.CB[2]  = (((uint8_t*)&address)[3]);
+    MSC_Handle->hbot.cbw.field.CB[3]  = (((uint8_t*)&address)[2]);
+    MSC_Handle->hbot.cbw.field.CB[4]  = (((uint8_t*)&address)[1]);
+    MSC_Handle->hbot.cbw.field.CB[5]  = (((uint8_t*)&address)[0]);
+    
+    
+    /*Tranfer length */
+    MSC_Handle->hbot.cbw.field.CB[7]  = (((uint8_t *)&length)[1]) ; 
+    MSC_Handle->hbot.cbw.field.CB[8]  = (((uint8_t *)&length)[0]) ; 
+
+    
+    MSC_Handle->hbot.state = BOT_SEND_CBW;
+    MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
+    MSC_Handle->hbot.pbuf = pbuf;
+    error = USBH_BUSY; 
+    break;
+    
+  case BOT_CMD_WAIT: 
+    error = USBH_MSC_BOT_Process(phost, lun);
+    break;
+    
+  default:
+    break;
+  }
+  
+  return error;
+}
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp.h b/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp.h
index 704a410fdf31c005fb73d0c92a32fa634bd545cd..7514f9e4cbfa1a14f775a341877b69c09171262d 100644
--- a/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp.h
+++ b/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp.h
@@ -1,263 +1,263 @@
-/**
-  ******************************************************************************
-  * @file    usbh_mtp.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_mtp.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_MTP_CORE_H
-#define __USBH_MTP_CORE_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_mtp_ptp.h"
-#include "usbh_core.h"
-
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_MTP_CLASS
-* @{
-*/
-
-/** @defgroup USBH_MTP_CORE
-* @brief This file is the Header file for USBH_MTP_CORE.c
-* @{
-*/ 
-
-
-
-
-/*Communication Class codes*/
-#define USB_MTP_CLASS                                           0x06 /* Still Image Class)*/
-#define MTP_MAX_STORAGE_UNITS_NBR                               PTP_MAX_STORAGE_UNITS_NBR
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MTP_CORE_Exported_Types
-* @{
-*/ 
-typedef enum
-{   
-  MTP_IDLE = 0,
-  MTP_GETDEVICEINFO ,           
-  MTP_OPENSESSION ,             
-  MTP_CLOSESESSION ,            
-  MTP_GETSTORAGEIDS ,           
-  MTP_GETSTORAGEINFO ,          
-}
-MTP_StateTypeDef;
-
-
-typedef enum
-{   
-  MTP_EVENTS_INIT = 0,
-  MTP_EVENTS_GETDATA ,                   
-}
-MTP_EventsStateTypeDef;
-
-
-typedef struct
-{
-   MTP_EventsStateTypeDef   state;
-   uint32_t timer;
-   uint16_t poll;
-   PTP_EventContainerTypedef  container;       
-} 
-MTP_EventHandleTypedef;
-
-typedef struct
-{
-    
-  uint32_t        CurrentStorageId;
-  uint32_t        ObjectFormatCode;
-  uint32_t        CurrentObjectHandler;
-  uint8_t         ObjectHandlerNbr;
-  uint32_t        Objdepth;
-} 
-MTP_ParamsTypedef;
-
-
-typedef struct
-{
-  PTP_DeviceInfoTypedef     devinfo;
-  PTP_StorageIDsTypedef     storids;
-  PTP_StorageInfoTypedef    storinfo[MTP_MAX_STORAGE_UNITS_NBR]; 
-  PTP_ObjectHandlesTypedef  Handles;
-} 
-MTP_InfoTypedef;
-
-/* Structure for MTP process */
-typedef struct _MTP_Process
-{
-  MTP_InfoTypedef       info;
-  MTP_ParamsTypedef     params;
-  
-  uint8_t               DataInPipe; 
-  uint8_t               DataOutPipe;
-  uint8_t               NotificationPipe;  
-  
-  uint8_t               DataOutEp;
-  uint8_t               DataInEp;
-  uint8_t               NotificationEp;  
-
-  uint16_t              DataOutEpSize;
-  uint16_t              DataInEpSize;
-  uint16_t              NotificationEpSize; 
-  MTP_StateTypeDef      state;
-  MTP_EventHandleTypedef events;
-  PTP_HandleTypeDef     ptp;
-  uint32_t              current_storage_unit;
-  uint32_t              is_ready;  
-}
-MTP_HandleTypeDef;
-
-#define MTP_StorageInfoTypedef      PTP_StorageInfoTypedef
-#define MTP_ObjectHandlesTypedef    PTP_ObjectHandlesTypedef
-#define MTP_ObjectInfoTypedef       PTP_ObjectInfoTypedef
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MTP_CORE_Exported_Defines
-* @{
-*/ 
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MTP_CORE_Exported_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MTP_CORE_Exported_Variables
-* @{
-*/ 
-extern USBH_ClassTypeDef  MTP_Class;
-#define USBH_MTP_CLASS    &MTP_Class
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MTP_CORE_Exported_FunctionsPrototype
-* @{
-*/ 
-uint8_t            USBH_MTP_IsReady (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t storage_idx);
-USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *storage_num);
-USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_id, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           uint32_t* numobs);
-USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, 
-                                            uint8_t storage_idx, 
-                                            MTP_StorageInfoTypedef *info);
-
-USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_id, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           PTP_ObjectHandlesTypedef* objecthandles);
-
-USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           PTP_ObjectInfoTypedef* objectinfo);
-
-USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost,
-                                          uint32_t handle,
-                                          uint32_t objectformatcode);
-
-USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object);
-
-USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint32_t offset,
-                                           uint32_t maxbytes, 
-                                           uint8_t *object,
-                                           uint32_t *len);
-
-USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
-                                                     uint16_t ofc,
-                                                     uint32_t *propnum, 
-                                                     uint16_t *props);
-
-USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t opc, 
-                                                uint16_t ofc, 
-                                                PTP_ObjectPropDescTypeDef *opd);
-
-USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost,
-                                                uint32_t handle, 
-                                                MTP_PropertiesTypedef *pprops, 
-                                                uint32_t *nrofprops);
-
-USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object,
-                                           uint32_t size);
-
-USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t propcode, 
-			                        PTP_DevicePropDescTypdef* devicepropertydesc);
-
-void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param);
-/**
-* @}
-*/ 
-
-
-#endif /* __USBH_MTP_CORE_H */
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_mtp.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_mtp.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_MTP_CORE_H
+#define __USBH_MTP_CORE_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_mtp_ptp.h"
+#include "usbh_core.h"
+
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_MTP_CLASS
+* @{
+*/
+
+/** @defgroup USBH_MTP_CORE
+* @brief This file is the Header file for USBH_MTP_CORE.c
+* @{
+*/ 
+
+
+
+
+/*Communication Class codes*/
+#define USB_MTP_CLASS                                           0x06 /* Still Image Class)*/
+#define MTP_MAX_STORAGE_UNITS_NBR                               PTP_MAX_STORAGE_UNITS_NBR
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MTP_CORE_Exported_Types
+* @{
+*/ 
+typedef enum
+{   
+  MTP_IDLE = 0,
+  MTP_GETDEVICEINFO ,           
+  MTP_OPENSESSION ,             
+  MTP_CLOSESESSION ,            
+  MTP_GETSTORAGEIDS ,           
+  MTP_GETSTORAGEINFO ,          
+}
+MTP_StateTypeDef;
+
+
+typedef enum
+{   
+  MTP_EVENTS_INIT = 0,
+  MTP_EVENTS_GETDATA ,                   
+}
+MTP_EventsStateTypeDef;
+
+
+typedef struct
+{
+   MTP_EventsStateTypeDef   state;
+   uint32_t timer;
+   uint16_t poll;
+   PTP_EventContainerTypedef  container;       
+} 
+MTP_EventHandleTypedef;
+
+typedef struct
+{
+    
+  uint32_t        CurrentStorageId;
+  uint32_t        ObjectFormatCode;
+  uint32_t        CurrentObjectHandler;
+  uint8_t         ObjectHandlerNbr;
+  uint32_t        Objdepth;
+} 
+MTP_ParamsTypedef;
+
+
+typedef struct
+{
+  PTP_DeviceInfoTypedef     devinfo;
+  PTP_StorageIDsTypedef     storids;
+  PTP_StorageInfoTypedef    storinfo[MTP_MAX_STORAGE_UNITS_NBR]; 
+  PTP_ObjectHandlesTypedef  Handles;
+} 
+MTP_InfoTypedef;
+
+/* Structure for MTP process */
+typedef struct _MTP_Process
+{
+  MTP_InfoTypedef       info;
+  MTP_ParamsTypedef     params;
+  
+  uint8_t               DataInPipe; 
+  uint8_t               DataOutPipe;
+  uint8_t               NotificationPipe;  
+  
+  uint8_t               DataOutEp;
+  uint8_t               DataInEp;
+  uint8_t               NotificationEp;  
+
+  uint16_t              DataOutEpSize;
+  uint16_t              DataInEpSize;
+  uint16_t              NotificationEpSize; 
+  MTP_StateTypeDef      state;
+  MTP_EventHandleTypedef events;
+  PTP_HandleTypeDef     ptp;
+  uint32_t              current_storage_unit;
+  uint32_t              is_ready;  
+}
+MTP_HandleTypeDef;
+
+#define MTP_StorageInfoTypedef      PTP_StorageInfoTypedef
+#define MTP_ObjectHandlesTypedef    PTP_ObjectHandlesTypedef
+#define MTP_ObjectInfoTypedef       PTP_ObjectInfoTypedef
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MTP_CORE_Exported_Defines
+* @{
+*/ 
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MTP_CORE_Exported_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MTP_CORE_Exported_Variables
+* @{
+*/ 
+extern USBH_ClassTypeDef  MTP_Class;
+#define USBH_MTP_CLASS    &MTP_Class
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MTP_CORE_Exported_FunctionsPrototype
+* @{
+*/ 
+uint8_t            USBH_MTP_IsReady (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t storage_idx);
+USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *storage_num);
+USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_id, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           uint32_t* numobs);
+USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, 
+                                            uint8_t storage_idx, 
+                                            MTP_StorageInfoTypedef *info);
+
+USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_id, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           PTP_ObjectHandlesTypedef* objecthandles);
+
+USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           PTP_ObjectInfoTypedef* objectinfo);
+
+USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost,
+                                          uint32_t handle,
+                                          uint32_t objectformatcode);
+
+USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object);
+
+USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint32_t offset,
+                                           uint32_t maxbytes, 
+                                           uint8_t *object,
+                                           uint32_t *len);
+
+USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
+                                                     uint16_t ofc,
+                                                     uint32_t *propnum, 
+                                                     uint16_t *props);
+
+USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t opc, 
+                                                uint16_t ofc, 
+                                                PTP_ObjectPropDescTypeDef *opd);
+
+USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost,
+                                                uint32_t handle, 
+                                                MTP_PropertiesTypedef *pprops, 
+                                                uint32_t *nrofprops);
+
+USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object,
+                                           uint32_t size);
+
+USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t propcode, 
+			                        PTP_DevicePropDescTypdef* devicepropertydesc);
+
+void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param);
+/**
+* @}
+*/ 
+
+
+#endif /* __USBH_MTP_CORE_H */
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h b/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h
index 3fbddd87bff2a643319c5007c28fe877b6d372ce..80e366de70acbbd302035a6bfaacfd4eeff41763 100644
--- a/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h
+++ b/micropython/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h
@@ -1,1038 +1,1038 @@
-/**
-  ******************************************************************************
-  * @file    usbh_mtp_ptp.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_mtp_ptp.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_MTP_PTP_H__
-#define __USBH_MTP_PTP_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_CLASS
-  * @{
-  */
-
-/** @addtogroup USBH_MTP_PTP_CLASS
-  * @{
-  */
-  
-/** @defgroup USBH_MTP_PTP
-  * @brief This file is the Header file for usbh_mtp_ptp.c
-  * @{
-  */ 
-
-
-/* Operation Codes */
-
-/* PTP v1.0 operation codes */
-#define PTP_OC_Undefined                0x1000
-#define PTP_OC_GetDeviceInfo            0x1001
-#define PTP_OC_OpenSession              0x1002
-#define PTP_OC_CloseSession             0x1003
-#define PTP_OC_GetStorageIDs            0x1004
-#define PTP_OC_GetStorageInfo           0x1005
-#define PTP_OC_GetNumObjects            0x1006
-#define PTP_OC_GetObjectHandles         0x1007
-#define PTP_OC_GetObjectInfo            0x1008
-#define PTP_OC_GetObject                0x1009
-#define PTP_OC_GetThumb                 0x100A
-#define PTP_OC_DeleteObject             0x100B
-#define PTP_OC_SendObjectInfo           0x100C
-#define PTP_OC_SendObject               0x100D
-#define PTP_OC_InitiateCapture          0x100E
-#define PTP_OC_FormatStore              0x100F
-#define PTP_OC_ResetDevice              0x1010
-#define PTP_OC_SelfTest                 0x1011
-#define PTP_OC_SetObjectProtection      0x1012
-#define PTP_OC_PowerDown                0x1013
-#define PTP_OC_GetDevicePropDesc        0x1014
-#define PTP_OC_GetDevicePropValue       0x1015
-#define PTP_OC_SetDevicePropValue       0x1016
-#define PTP_OC_ResetDevicePropValue     0x1017
-#define PTP_OC_TerminateOpenCapture     0x1018
-#define PTP_OC_MoveObject               0x1019
-#define PTP_OC_CopyObject               0x101A
-#define PTP_OC_GetPartialObject         0x101B
-#define PTP_OC_InitiateOpenCapture      0x101C
-    
-/* PTP v1.1 operation codes */
-#define PTP_OC_StartEnumHandles		0x101D
-#define PTP_OC_EnumHandles		0x101E
-#define PTP_OC_StopEnumHandles		0x101F
-#define PTP_OC_GetVendorExtensionMaps	0x1020
-#define PTP_OC_GetVendorDeviceInfo	0x1021
-#define PTP_OC_GetResizedImageObject	0x1022
-#define PTP_OC_GetFilesystemManifest	0x1023
-#define PTP_OC_GetStreamInfo		0x1024
-#define PTP_OC_GetStream		0x1025
-
-    /* Microsoft / MTP extension codes */
-#define PTP_OC_GetObjectPropsSupported	 0x9801
-#define PTP_OC_GetObjectPropDesc	 0x9802
-#define PTP_OC_GetObjectPropValue	 0x9803
-#define PTP_OC_SetObjectPropValue	 0x9804
-#define PTP_OC_GetObjPropList		 0x9805
-#define PTP_OC_SetObjPropList		 0x9806
-#define PTP_OC_GetInterdependendPropdesc 0x9807
-#define PTP_OC_SendObjectPropList	 0x9808
-#define PTP_OC_GetObjectReferences	 0x9810
-#define PTP_OC_SetObjectReferences	 0x9811
-#define PTP_OC_UpdateDeviceFirmware	 0x9812
-#define PTP_OC_Skip			 0x9820
-
-    
-/* Response Codes */
-
-/* PTP v1.0 response codes */
-#define PTP_RC_Undefined                0x2000
-#define PTP_RC_OK                       0x2001
-#define PTP_RC_GeneralError             0x2002
-#define PTP_RC_SessionNotOpen           0x2003
-#define PTP_RC_InvalidTransactionID	0x2004
-#define PTP_RC_OperationNotSupported    0x2005
-#define PTP_RC_ParameterNotSupported    0x2006
-#define PTP_RC_IncompleteTransfer       0x2007
-#define PTP_RC_InvalidStorageId         0x2008
-#define PTP_RC_InvalidObjectHandle      0x2009
-#define PTP_RC_DevicePropNotSupported   0x200A
-#define PTP_RC_InvalidObjectFormatCode  0x200B
-#define PTP_RC_StoreFull                0x200C
-#define PTP_RC_ObjectWriteProtected     0x200D
-#define PTP_RC_StoreReadOnly            0x200E
-#define PTP_RC_AccessDenied             0x200F
-#define PTP_RC_NoThumbnailPresent       0x2010
-#define PTP_RC_SelfTestFailed           0x2011
-#define PTP_RC_PartialDeletion          0x2012
-#define PTP_RC_StoreNotAvailable        0x2013
-#define PTP_RC_SpecificationByFormatUnsupported         0x2014
-#define PTP_RC_NoValidObjectInfo        0x2015
-#define PTP_RC_InvalidCodeFormat        0x2016
-#define PTP_RC_UnknownVendorCode        0x2017
-#define PTP_RC_CaptureAlreadyTerminated 0x2018
-#define PTP_RC_DeviceBusy               0x2019
-#define PTP_RC_InvalidParentObject      0x201A
-#define PTP_RC_InvalidDevicePropFormat  0x201B
-#define PTP_RC_InvalidDevicePropValue   0x201C
-#define PTP_RC_InvalidParameter         0x201D
-#define PTP_RC_SessionAlreadyOpened     0x201E
-#define PTP_RC_TransactionCanceled      0x201F
-#define PTP_RC_SpecificationOfDestinationUnsupported       0x2020
-/* PTP v1.1 response codes */
-#define PTP_RC_InvalidEnumHandle	0x2021
-#define PTP_RC_NoStreamEnabled		0x2022
-#define PTP_RC_InvalidDataSet		0x2023
-    
-/* USB container types */
-
-#define PTP_USB_CONTAINER_UNDEFINED	 0x0000
-#define PTP_USB_CONTAINER_COMMAND	 0x0001
-#define PTP_USB_CONTAINER_DATA		 0x0002
-#define PTP_USB_CONTAINER_RESPONSE	 0x0003
-#define PTP_USB_CONTAINER_EVENT		 0x0004
-
-/* PTP/IP definitions */
-#define PTPIP_INIT_COMMAND_REQUEST	1
-#define PTPIP_INIT_COMMAND_ACK		2
-#define PTPIP_INIT_EVENT_REQUEST	3
-#define PTPIP_INIT_EVENT_ACK		4
-#define PTPIP_INIT_FAIL			5
-#define PTPIP_CMD_REQUEST		6
-#define PTPIP_CMD_RESPONSE		7
-#define PTPIP_EVENT			8
-#define PTPIP_START_DATA_PACKET		9
-#define PTPIP_DATA_PACKET		10
-#define PTPIP_CANCEL_TRANSACTION	11
-#define PTPIP_END_DATA_PACKET		12
-#define PTPIP_PING			13
-#define PTPIP_PONG			14
-
-/* Transaction data phase description */
-#define PTP_DP_NODATA		0x0000	/* no data phase */
-#define PTP_DP_SENDDATA		0x0001	/* sending data */
-#define PTP_DP_GETDATA		0x0002	/* receiving data */
-#define PTP_DP_DATA_MASK	0x00ff	/* data phase mask */
-    
-/** @defgroup USBH_MTP_PTP_Exported_Types
-  * @{
-  */ 
-
-typedef enum 
-{
-  PTP_REQ_IDLE = 0,   
-  PTP_REQ_SEND = 1,  
-  PTP_REQ_WAIT,   
-  PTP_REQ_ERROR,         
-} 
-PTP_RequestStateTypeDef;  
-
-typedef enum 
-{
-  PTP_IDLE = 0,   
-  PTP_OP_REQUEST_STATE,  
-  PTP_OP_REQUEST_WAIT_STATE,   
-  PTP_DATA_OUT_PHASE_STATE,
-  PTP_DATA_OUT_PHASE_WAIT_STATE,  
-  PTP_DATA_IN_PHASE_STATE,
-  PTP_DATA_IN_PHASE_WAIT_STATE,  
-  PTP_RESPONSE_STATE, 
-  PTP_RESPONSE_WAIT_STATE,  
-  PTP_ERROR,         
-} 
-PTP_ProcessStateTypeDef;  
-
-/* PTP request/response/event general PTP container (transport independent) */
-typedef struct 
-{
-	uint16_t Code;
-	uint32_t SessionID;
-	uint32_t Transaction_ID;
-	/* params  may be of any type of size less or equal to uint32_t */
-	uint32_t Param1;
-	uint32_t Param2;
-	uint32_t Param3;
-	/* events can only have three parameters */
-	uint32_t Param4;
-	uint32_t Param5;
-	/* the number of meaningfull parameters */
-	uint8_t	 Nparam;
-}
-PTP_ContainerTypedef; 
-
-#define PTP_USB_BULK_HS_MAX_PACKET_LEN_WRITE	1024
-#define PTP_USB_BULK_HS_MAX_PACKET_LEN_READ     1024
-#define PTP_USB_BULK_HDR_LEN		       (2*sizeof(uint32_t)+2*sizeof(uint16_t))
-#define PTP_USB_BULK_PAYLOAD_LEN_WRITE	       (PTP_USB_BULK_HS_MAX_PACKET_LEN_WRITE-PTP_USB_BULK_HDR_LEN)
-#define PTP_USB_BULK_PAYLOAD_LEN_READ	       (PTP_USB_BULK_HS_MAX_PACKET_LEN_READ-PTP_USB_BULK_HDR_LEN)
-#define PTP_USB_BULK_REQ_LEN	               (PTP_USB_BULK_HDR_LEN+5*sizeof(uint32_t))
-#define PTP_USB_BULK_REQ_RESP_MAX_LEN           63
-
-typedef struct 
-{
-  uint32_t length;
-  uint16_t type;
-  uint16_t code;
-  uint32_t trans_id;
-  uint32_t param1;
-  uint32_t param2;
-  uint32_t param3;
-  uint32_t param4;
-  uint32_t param5;
-}
-PTP_RespContainerTypedef;
-
-
-typedef struct 
-{
-  uint32_t length;
-  uint16_t type;
-  uint16_t code;
-  uint32_t trans_id;
-  uint32_t param1;
-  uint32_t param2;
-  uint32_t param3;
-  uint32_t param4;
-  uint32_t param5;
-}
-PTP_OpContainerTypedef;
-
-typedef struct 
-{
-  uint32_t length;
-  uint16_t type;
-  uint16_t code;
-  uint32_t trans_id;
-  union {
-    struct {
-      uint32_t param1;
-      uint32_t param2;
-      uint32_t param3;
-      uint32_t param4;
-      uint32_t param5;
-    } params;  
-    uint8_t  data[PTP_USB_BULK_PAYLOAD_LEN_READ];
-  }payload;
-}
-PTP_DataContainerTypedef;
-
-/* PTP USB Asynchronous Event Interrupt Data Format */
-typedef struct 
-{
-  uint32_t length;
-  uint16_t type;
-  uint16_t code;
-  uint32_t trans_id;
-  uint32_t param1;
-  uint32_t param2;
-  uint32_t param3;
-}
-PTP_EventContainerTypedef;
-
-/* Structure for PTP Transport process */
-typedef struct
-{
-  PTP_ProcessStateTypeDef      state;
-  PTP_RequestStateTypeDef      req_state;
-  PTP_OpContainerTypedef       op_container;    
-  PTP_DataContainerTypedef     data_container;  
-  PTP_RespContainerTypedef     resp_container;    
-
-  /* ptp transaction ID */
-  uint32_t	transaction_id;
-  
-  /* ptp session ID */
-  uint32_t	session_id; 
-  
-  /* device flags */
-  uint32_t	flags;  
-
-  /****** PTP transfer control *******/ 
-  
-  /* Data pointer */
-  uint8_t	*data_ptr;  
-
-  /* Data length */
-  int32_t	data_length;
-  
-  /* Data length */
-  uint32_t	data_packet;
-  
-  /* Data length */
-  uint32_t	iteration;  
-  
-  /* Packet Index */
-  uint32_t   data_packet_counter;
-  
-  /****** Object transfer control *******/
-  
-  /* object pointer */
-  uint8_t	*object_ptr;
-
-}
-PTP_HandleTypeDef;
-
-/* DeviceInfo data offset */
-#define PTP_di_StandardVersion		 0
-#define PTP_di_VendorExtensionID	 2
-#define PTP_di_VendorExtensionVersion	 6
-#define PTP_di_VendorExtensionDesc	 8
-#define PTP_di_FunctionalMode		 8
-#define PTP_di_OperationsSupported	10
-
-/* Max info items size */
-#define PTP_SUPPORTED_OPERATIONS_NBR    100
-#define PTP_SUPPORTED_EVENTS_NBR        100
-#define PTP_SUPPORTED_PROPRIETIES_NBR   100
-#define PTP_CAPTURE_FORMATS_NBR         100
-#define PTP_IMAGE_FORMATS_NBR           100
-#define PTP_MAX_STR_SIZE                255
-/* PTP device info structure */
-typedef struct
-{
-  uint16_t StandardVersion;
-  uint32_t VendorExtensionID;
-  uint16_t VendorExtensionVersion;
-  uint8_t  VendorExtensionDesc[PTP_MAX_STR_SIZE];
-  uint16_t FunctionalMode;
-  uint32_t OperationsSupported_len;
-  uint16_t OperationsSupported[PTP_SUPPORTED_OPERATIONS_NBR];
-  uint32_t EventsSupported_len;
-  uint16_t EventsSupported[PTP_SUPPORTED_EVENTS_NBR];
-  uint32_t DevicePropertiesSupported_len;
-  uint16_t DevicePropertiesSupported[PTP_SUPPORTED_PROPRIETIES_NBR];
-  uint32_t CaptureFormats_len;
-  uint16_t CaptureFormats[PTP_CAPTURE_FORMATS_NBR];
-  uint32_t ImageFormats_len;
-  uint16_t ImageFormats[PTP_IMAGE_FORMATS_NBR];
-  uint8_t  Manufacturer[PTP_MAX_STR_SIZE];
-  uint8_t  Model[PTP_MAX_STR_SIZE];
-  uint8_t  DeviceVersion[PTP_MAX_STR_SIZE];
-  uint8_t  SerialNumber[PTP_MAX_STR_SIZE];
-}
-PTP_DeviceInfoTypedef;
-
-#define PTP_MAX_STORAGE_UNITS_NBR      5
-/* PTP storageIDs structute (returned by GetStorageIDs) */
-typedef struct
-{
-  uint32_t n;
-  uint32_t Storage [PTP_MAX_STORAGE_UNITS_NBR];
-}
-PTP_StorageIDsTypedef;
-
-/* PTP StorageInfo structure (returned by GetStorageInfo) */
-
-#define PTP_si_StorageType		 0
-#define PTP_si_FilesystemType		 2
-#define PTP_si_AccessCapability		 4
-#define PTP_si_MaxCapability		 6
-#define PTP_si_FreeSpaceInBytes		14
-#define PTP_si_FreeSpaceInImages	22
-#define PTP_si_StorageDescription	26
-
-
-/* PTP Storage Types */
-
-#define PTP_ST_Undefined			0x0000
-#define PTP_ST_FixedROM				0x0001
-#define PTP_ST_RemovableROM			0x0002
-#define PTP_ST_FixedRAM				0x0003
-#define PTP_ST_RemovableRAM			0x0004
-
-/* PTP FilesystemType Values */
-
-#define PTP_FST_Undefined			0x0000
-#define PTP_FST_GenericFlat			0x0001
-#define PTP_FST_GenericHierarchical		0x0002
-#define PTP_FST_DCF				0x0003
-
-/* PTP StorageInfo AccessCapability Values */
-
-#define PTP_AC_ReadWrite			0x0000
-#define PTP_AC_ReadOnly				0x0001
-#define PTP_AC_ReadOnly_with_Object_Deletion	0x0002
-
-typedef struct
-{
-  uint16_t StorageType;
-  uint16_t FilesystemType;
-  uint16_t AccessCapability;
-  uint64_t MaxCapability;
-  uint64_t FreeSpaceInBytes;
-  uint32_t FreeSpaceInImages;
-  uint8_t  StorageDescription[PTP_MAX_STR_SIZE];
-  uint8_t  VolumeLabel[PTP_MAX_STR_SIZE];
-}
-PTP_StorageInfoTypedef;
-
-/* PTP Object Format Codes */
-
-/* ancillary formats */
-#define PTP_OFC_Undefined			0x3000
-#define PTP_OFC_Defined				0x3800
-#define PTP_OFC_Association			0x3001
-#define PTP_OFC_Script				0x3002
-#define PTP_OFC_Executable			0x3003
-#define PTP_OFC_Text				0x3004
-#define PTP_OFC_HTML				0x3005
-#define PTP_OFC_DPOF				0x3006
-#define PTP_OFC_AIFF	 			0x3007
-#define PTP_OFC_WAV				0x3008
-#define PTP_OFC_MP3				0x3009
-#define PTP_OFC_AVI				0x300A
-#define PTP_OFC_MPEG				0x300B
-#define PTP_OFC_ASF				0x300C
-#define PTP_OFC_QT				0x300D /* guessing */
-/* image formats */
-#define PTP_OFC_EXIF_JPEG			0x3801
-#define PTP_OFC_TIFF_EP				0x3802
-#define PTP_OFC_FlashPix			0x3803
-#define PTP_OFC_BMP				0x3804
-#define PTP_OFC_CIFF				0x3805
-#define PTP_OFC_Undefined_0x3806		0x3806
-#define PTP_OFC_GIF				0x3807
-#define PTP_OFC_JFIF				0x3808
-#define PTP_OFC_PCD				0x3809
-#define PTP_OFC_PICT				0x380A
-#define PTP_OFC_PNG				0x380B
-#define PTP_OFC_Undefined_0x380C		0x380C
-#define PTP_OFC_TIFF				0x380D
-#define PTP_OFC_TIFF_IT				0x380E
-#define PTP_OFC_JP2				0x380F
-#define PTP_OFC_JPX				0x3810
-/* ptp v1.1 has only DNG new */
-#define PTP_OFC_DNG				0x3811
-
-/* MTP extensions */
-#define PTP_OFC_MTP_MediaCard			0xb211
-#define PTP_OFC_MTP_MediaCardGroup		0xb212
-#define PTP_OFC_MTP_Encounter			0xb213
-#define PTP_OFC_MTP_EncounterBox		0xb214
-#define PTP_OFC_MTP_M4A				0xb215
-#define PTP_OFC_MTP_ZUNEUNDEFINED		0xb217 /* Unknown file type */
-#define PTP_OFC_MTP_Firmware			0xb802
-#define PTP_OFC_MTP_WindowsImageFormat		0xb881
-#define PTP_OFC_MTP_UndefinedAudio		0xb900
-#define PTP_OFC_MTP_WMA				0xb901
-#define PTP_OFC_MTP_OGG				0xb902
-#define PTP_OFC_MTP_AAC				0xb903
-#define PTP_OFC_MTP_AudibleCodec		0xb904
-#define PTP_OFC_MTP_FLAC			0xb906
-#define PTP_OFC_MTP_SamsungPlaylist		0xb909
-#define PTP_OFC_MTP_UndefinedVideo		0xb980
-#define PTP_OFC_MTP_WMV				0xb981
-#define PTP_OFC_MTP_MP4				0xb982
-#define PTP_OFC_MTP_MP2				0xb983
-#define PTP_OFC_MTP_3GP				0xb984
-#define PTP_OFC_MTP_UndefinedCollection		0xba00
-#define PTP_OFC_MTP_AbstractMultimediaAlbum	0xba01
-#define PTP_OFC_MTP_AbstractImageAlbum		0xba02
-#define PTP_OFC_MTP_AbstractAudioAlbum		0xba03
-#define PTP_OFC_MTP_AbstractVideoAlbum		0xba04
-#define PTP_OFC_MTP_AbstractAudioVideoPlaylist	0xba05
-#define PTP_OFC_MTP_AbstractContactGroup	0xba06
-#define PTP_OFC_MTP_AbstractMessageFolder	0xba07
-#define PTP_OFC_MTP_AbstractChapteredProduction	0xba08
-#define PTP_OFC_MTP_AbstractAudioPlaylist	0xba09
-#define PTP_OFC_MTP_AbstractVideoPlaylist	0xba0a
-#define PTP_OFC_MTP_AbstractMediacast		0xba0b
-#define PTP_OFC_MTP_WPLPlaylist			0xba10
-#define PTP_OFC_MTP_M3UPlaylist			0xba11
-#define PTP_OFC_MTP_MPLPlaylist			0xba12
-#define PTP_OFC_MTP_ASXPlaylist			0xba13
-#define PTP_OFC_MTP_PLSPlaylist			0xba14
-#define PTP_OFC_MTP_UndefinedDocument		0xba80
-#define PTP_OFC_MTP_AbstractDocument		0xba81
-#define PTP_OFC_MTP_XMLDocument			0xba82
-#define PTP_OFC_MTP_MSWordDocument		0xba83
-#define PTP_OFC_MTP_MHTCompiledHTMLDocument	0xba84
-#define PTP_OFC_MTP_MSExcelSpreadsheetXLS	0xba85
-#define PTP_OFC_MTP_MSPowerpointPresentationPPT	0xba86
-#define PTP_OFC_MTP_UndefinedMessage		0xbb00
-#define PTP_OFC_MTP_AbstractMessage		0xbb01
-#define PTP_OFC_MTP_UndefinedContact		0xbb80
-#define PTP_OFC_MTP_AbstractContact		0xbb81
-#define PTP_OFC_MTP_vCard2			0xbb82
-#define PTP_OFC_MTP_vCard3			0xbb83
-#define PTP_OFC_MTP_UndefinedCalendarItem	0xbe00
-#define PTP_OFC_MTP_AbstractCalendarItem	0xbe01
-#define PTP_OFC_MTP_vCalendar1			0xbe02
-#define PTP_OFC_MTP_vCalendar2			0xbe03
-#define PTP_OFC_MTP_UndefinedWindowsExecutable	0xbe80
-#define PTP_OFC_MTP_MediaCast			0xbe81
-#define PTP_OFC_MTP_Section			0xbe82
-
-/* MTP specific Object Properties */
-#define PTP_OPC_StorageID				0xDC01
-#define PTP_OPC_ObjectFormat				0xDC02
-#define PTP_OPC_ProtectionStatus			0xDC03
-#define PTP_OPC_ObjectSize				0xDC04
-#define PTP_OPC_AssociationType				0xDC05
-#define PTP_OPC_AssociationDesc				0xDC06
-#define PTP_OPC_ObjectFileName				0xDC07
-#define PTP_OPC_DateCreated				0xDC08
-#define PTP_OPC_DateModified				0xDC09
-#define PTP_OPC_Keywords				0xDC0A
-#define PTP_OPC_ParentObject				0xDC0B
-#define PTP_OPC_AllowedFolderContents			0xDC0C
-#define PTP_OPC_Hidden					0xDC0D
-#define PTP_OPC_SystemObject				0xDC0E
-#define PTP_OPC_PersistantUniqueObjectIdentifier	0xDC41
-#define PTP_OPC_SyncID					0xDC42
-#define PTP_OPC_PropertyBag				0xDC43
-#define PTP_OPC_Name					0xDC44
-#define PTP_OPC_CreatedBy				0xDC45
-#define PTP_OPC_Artist					0xDC46
-#define PTP_OPC_DateAuthored				0xDC47
-#define PTP_OPC_Description				0xDC48
-#define PTP_OPC_URLReference				0xDC49
-#define PTP_OPC_LanguageLocale				0xDC4A
-#define PTP_OPC_CopyrightInformation			0xDC4B
-#define PTP_OPC_Source					0xDC4C
-#define PTP_OPC_OriginLocation				0xDC4D
-#define PTP_OPC_DateAdded				0xDC4E
-#define PTP_OPC_NonConsumable				0xDC4F
-#define PTP_OPC_CorruptOrUnplayable			0xDC50
-#define PTP_OPC_ProducerSerialNumber			0xDC51
-#define PTP_OPC_RepresentativeSampleFormat		0xDC81
-#define PTP_OPC_RepresentativeSampleSize		0xDC82
-#define PTP_OPC_RepresentativeSampleHeight		0xDC83
-#define PTP_OPC_RepresentativeSampleWidth		0xDC84
-#define PTP_OPC_RepresentativeSampleDuration		0xDC85
-#define PTP_OPC_RepresentativeSampleData		0xDC86
-#define PTP_OPC_Width					0xDC87
-#define PTP_OPC_Height					0xDC88
-#define PTP_OPC_Duration				0xDC89
-#define PTP_OPC_Rating					0xDC8A
-#define PTP_OPC_Track					0xDC8B
-#define PTP_OPC_Genre					0xDC8C
-#define PTP_OPC_Credits					0xDC8D
-#define PTP_OPC_Lyrics					0xDC8E
-#define PTP_OPC_SubscriptionContentID			0xDC8F
-#define PTP_OPC_ProducedBy				0xDC90
-#define PTP_OPC_UseCount				0xDC91
-#define PTP_OPC_SkipCount				0xDC92
-#define PTP_OPC_LastAccessed				0xDC93
-#define PTP_OPC_ParentalRating				0xDC94
-#define PTP_OPC_MetaGenre				0xDC95
-#define PTP_OPC_Composer				0xDC96
-#define PTP_OPC_EffectiveRating				0xDC97
-#define PTP_OPC_Subtitle				0xDC98
-#define PTP_OPC_OriginalReleaseDate			0xDC99
-#define PTP_OPC_AlbumName				0xDC9A
-#define PTP_OPC_AlbumArtist				0xDC9B
-#define PTP_OPC_Mood					0xDC9C
-#define PTP_OPC_DRMStatus				0xDC9D
-#define PTP_OPC_SubDescription				0xDC9E
-#define PTP_OPC_IsCropped				0xDCD1
-#define PTP_OPC_IsColorCorrected			0xDCD2
-#define PTP_OPC_ImageBitDepth				0xDCD3
-#define PTP_OPC_Fnumber					0xDCD4
-#define PTP_OPC_ExposureTime				0xDCD5
-#define PTP_OPC_ExposureIndex				0xDCD6
-#define PTP_OPC_DisplayName				0xDCE0
-#define PTP_OPC_BodyText				0xDCE1
-#define PTP_OPC_Subject					0xDCE2
-#define PTP_OPC_Priority				0xDCE3
-#define PTP_OPC_GivenName				0xDD00
-#define PTP_OPC_MiddleNames				0xDD01
-#define PTP_OPC_FamilyName				0xDD02
-#define PTP_OPC_Prefix					0xDD03
-#define PTP_OPC_Suffix					0xDD04
-#define PTP_OPC_PhoneticGivenName			0xDD05
-#define PTP_OPC_PhoneticFamilyName			0xDD06
-#define PTP_OPC_EmailPrimary				0xDD07
-#define PTP_OPC_EmailPersonal1				0xDD08
-#define PTP_OPC_EmailPersonal2				0xDD09
-#define PTP_OPC_EmailBusiness1				0xDD0A
-#define PTP_OPC_EmailBusiness2				0xDD0B
-#define PTP_OPC_EmailOthers				0xDD0C
-#define PTP_OPC_PhoneNumberPrimary			0xDD0D
-#define PTP_OPC_PhoneNumberPersonal			0xDD0E
-#define PTP_OPC_PhoneNumberPersonal2			0xDD0F
-#define PTP_OPC_PhoneNumberBusiness			0xDD10
-#define PTP_OPC_PhoneNumberBusiness2			0xDD11
-#define PTP_OPC_PhoneNumberMobile			0xDD12
-#define PTP_OPC_PhoneNumberMobile2			0xDD13
-#define PTP_OPC_FaxNumberPrimary			0xDD14
-#define PTP_OPC_FaxNumberPersonal			0xDD15
-#define PTP_OPC_FaxNumberBusiness			0xDD16
-#define PTP_OPC_PagerNumber				0xDD17
-#define PTP_OPC_PhoneNumberOthers			0xDD18
-#define PTP_OPC_PrimaryWebAddress			0xDD19
-#define PTP_OPC_PersonalWebAddress			0xDD1A
-#define PTP_OPC_BusinessWebAddress			0xDD1B
-#define PTP_OPC_InstantMessengerAddress			0xDD1C
-#define PTP_OPC_InstantMessengerAddress2		0xDD1D
-#define PTP_OPC_InstantMessengerAddress3		0xDD1E
-#define PTP_OPC_PostalAddressPersonalFull		0xDD1F
-#define PTP_OPC_PostalAddressPersonalFullLine1		0xDD20
-#define PTP_OPC_PostalAddressPersonalFullLine2		0xDD21
-#define PTP_OPC_PostalAddressPersonalFullCity		0xDD22
-#define PTP_OPC_PostalAddressPersonalFullRegion		0xDD23
-#define PTP_OPC_PostalAddressPersonalFullPostalCode	0xDD24
-#define PTP_OPC_PostalAddressPersonalFullCountry	0xDD25
-#define PTP_OPC_PostalAddressBusinessFull		0xDD26
-#define PTP_OPC_PostalAddressBusinessLine1		0xDD27
-#define PTP_OPC_PostalAddressBusinessLine2		0xDD28
-#define PTP_OPC_PostalAddressBusinessCity		0xDD29
-#define PTP_OPC_PostalAddressBusinessRegion		0xDD2A
-#define PTP_OPC_PostalAddressBusinessPostalCode		0xDD2B
-#define PTP_OPC_PostalAddressBusinessCountry		0xDD2C
-#define PTP_OPC_PostalAddressOtherFull			0xDD2D
-#define PTP_OPC_PostalAddressOtherLine1			0xDD2E
-#define PTP_OPC_PostalAddressOtherLine2			0xDD2F
-#define PTP_OPC_PostalAddressOtherCity			0xDD30
-#define PTP_OPC_PostalAddressOtherRegion		0xDD31
-#define PTP_OPC_PostalAddressOtherPostalCode		0xDD32
-#define PTP_OPC_PostalAddressOtherCountry		0xDD33
-#define PTP_OPC_OrganizationName			0xDD34
-#define PTP_OPC_PhoneticOrganizationName		0xDD35
-#define PTP_OPC_Role					0xDD36
-#define PTP_OPC_Birthdate				0xDD37
-#define PTP_OPC_MessageTo				0xDD40
-#define PTP_OPC_MessageCC				0xDD41
-#define PTP_OPC_MessageBCC				0xDD42
-#define PTP_OPC_MessageRead				0xDD43
-#define PTP_OPC_MessageReceivedTime			0xDD44
-#define PTP_OPC_MessageSender				0xDD45
-#define PTP_OPC_ActivityBeginTime			0xDD50
-#define PTP_OPC_ActivityEndTime				0xDD51
-#define PTP_OPC_ActivityLocation			0xDD52
-#define PTP_OPC_ActivityRequiredAttendees		0xDD54
-#define PTP_OPC_ActivityOptionalAttendees		0xDD55
-#define PTP_OPC_ActivityResources			0xDD56
-#define PTP_OPC_ActivityAccepted			0xDD57
-#define PTP_OPC_Owner					0xDD5D
-#define PTP_OPC_Editor					0xDD5E
-#define PTP_OPC_Webmaster				0xDD5F
-#define PTP_OPC_URLSource				0xDD60
-#define PTP_OPC_URLDestination				0xDD61
-#define PTP_OPC_TimeBookmark				0xDD62
-#define PTP_OPC_ObjectBookmark				0xDD63
-#define PTP_OPC_ByteBookmark				0xDD64
-#define PTP_OPC_LastBuildDate				0xDD70
-#define PTP_OPC_TimetoLive				0xDD71
-#define PTP_OPC_MediaGUID				0xDD72
-#define PTP_OPC_TotalBitRate				0xDE91
-#define PTP_OPC_BitRateType				0xDE92
-#define PTP_OPC_SampleRate				0xDE93
-#define PTP_OPC_NumberOfChannels			0xDE94
-#define PTP_OPC_AudioBitDepth				0xDE95
-#define PTP_OPC_ScanDepth				0xDE97
-#define PTP_OPC_AudioWAVECodec				0xDE99
-#define PTP_OPC_AudioBitRate				0xDE9A
-#define PTP_OPC_VideoFourCCCodec			0xDE9B
-#define PTP_OPC_VideoBitRate				0xDE9C
-#define PTP_OPC_FramesPerThousandSeconds		0xDE9D
-#define PTP_OPC_KeyFrameDistance			0xDE9E
-#define PTP_OPC_BufferSize				0xDE9F
-#define PTP_OPC_EncodingQuality				0xDEA0
-#define PTP_OPC_EncodingProfile				0xDEA1
-#define PTP_OPC_BuyFlag					0xD901
-
-/* WiFi Provisioning MTP Extension property codes */
-#define PTP_OPC_WirelessConfigurationFile		0xB104
-
-
-/* PTP Association Types */
-#define PTP_AT_Undefined			0x0000
-#define PTP_AT_GenericFolder			0x0001
-#define PTP_AT_Album				0x0002
-#define PTP_AT_TimeSequence			0x0003
-#define PTP_AT_HorizontalPanoramic		0x0004
-#define PTP_AT_VerticalPanoramic		0x0005
-#define PTP_AT_2DPanoramic			0x0006
-#define PTP_AT_AncillaryData			0x0007
-
-#define PTP_MAX_HANDLER_NBR                      0x255
-typedef struct 
-{
-  uint32_t n;
-  uint32_t Handler[PTP_MAX_HANDLER_NBR];
-}
-PTP_ObjectHandlesTypedef;
-
-
-#define PTP_oi_StorageID		 0
-#define PTP_oi_ObjectFormat		 4
-#define PTP_oi_ProtectionStatus		 6
-#define PTP_oi_ObjectCompressedSize	 8
-#define PTP_oi_ThumbFormat		12
-#define PTP_oi_ThumbCompressedSize	14
-#define PTP_oi_ThumbPixWidth		18
-#define PTP_oi_ThumbPixHeight		22
-#define PTP_oi_ImagePixWidth		26
-#define PTP_oi_ImagePixHeight		30
-#define PTP_oi_ImageBitDepth		34
-#define PTP_oi_ParentObject		38
-#define PTP_oi_AssociationType		42
-#define PTP_oi_AssociationDesc		44
-#define PTP_oi_SequenceNumber		48
-#define PTP_oi_filenamelen		52
-#define PTP_oi_Filename			53
-
-typedef struct 
-{
-  uint32_t StorageID;
-  uint16_t ObjectFormat;
-  uint16_t ProtectionStatus;
-  /* In the regular objectinfo this is 32bit, but we keep the general object size here
-     that also arrives via other methods and so use 64bit */
-  uint64_t ObjectCompressedSize;
-  uint16_t ThumbFormat;
-  uint32_t ThumbCompressedSize;
-  uint32_t ThumbPixWidth;
-  uint32_t ThumbPixHeight;
-  uint32_t ImagePixWidth;
-  uint32_t ImagePixHeight;
-  uint32_t ImageBitDepth;
-  uint32_t ParentObject;
-  uint16_t AssociationType;
-  uint32_t AssociationDesc;
-  uint32_t SequenceNumber;
-  uint8_t  Filename[PTP_MAX_STR_SIZE];
-  uint32_t CaptureDate;
-  uint32_t ModificationDate;
-  uint8_t  Keywords[PTP_MAX_STR_SIZE];
-}
-PTP_ObjectInfoTypedef;
-
-/* Object Property Describing Dataset (DevicePropDesc) */
-
-typedef union  _PTP_PropertyValueTypedef
-{
-	char		str[PTP_MAX_STR_SIZE];
-	uint8_t		u8;
-	int8_t		i8;
-	uint16_t	u16;
-	int16_t		i16;
-	uint32_t	u32;
-	int32_t		i32;
-	uint64_t	u64;
-	int64_t		i64;
-
-	struct array {
-		uint32_t	count;
-		union _PTP_PropertyValueTypedef *v;
-	} a;
-}PTP_PropertyValueTypedef;
-
-typedef struct 
-{
-	PTP_PropertyValueTypedef 	MinimumValue;
-	PTP_PropertyValueTypedef 	MaximumValue;
-	PTP_PropertyValueTypedef 	StepSize;
-}
-PTP_PropDescRangeFormTypedef;
-
-/* Property Describing Dataset, Enum Form */
-
-typedef struct 
-{
-	uint16_t		 NumberOfValues;
-	PTP_PropertyValueTypedef SupportedValue[PTP_SUPPORTED_PROPRIETIES_NBR];
-}
-PTP_PropDescEnumFormTypedef;
-
-/* (MTP) Object Property pack/unpack */
-#define PTP_opd_ObjectPropertyCode	0
-#define PTP_opd_DataType		2
-#define PTP_opd_GetSet			4
-#define PTP_opd_FactoryDefaultValue	5
-
-typedef struct
-{
-	uint16_t		ObjectPropertyCode;
-	uint16_t		DataType;
-	uint8_t			GetSet;
-	PTP_PropertyValueTypedef FactoryDefaultValue;
-	uint32_t		GroupCode;
-	uint8_t			FormFlag;
-	union	{
-		PTP_PropDescEnumFormTypedef	Enum;
-		PTP_PropDescRangeFormTypedef	Range;
-	} FORM;
-}
-PTP_ObjectPropDescTypeDef;
-
-/* Metadata lists for MTP operations */
-typedef struct
-{
-	uint16_t 	 	property;
-	uint16_t 	 	datatype;
-	uint32_t 	 	ObjectHandle;
-	PTP_PropertyValueTypedef propval;
-}
-MTP_PropertiesTypedef;
-
-
-/* Device Property Form Flag */
-
-#define PTP_DPFF_None			0x00
-#define PTP_DPFF_Range			0x01
-#define PTP_DPFF_Enumeration		0x02
-
-/* Object Property Codes used by MTP (first 3 are same as DPFF codes) */
-#define PTP_OPFF_None			0x00
-#define PTP_OPFF_Range			0x01
-#define PTP_OPFF_Enumeration		0x02
-#define PTP_OPFF_DateTime		0x03
-#define PTP_OPFF_FixedLengthArray	0x04
-#define PTP_OPFF_RegularExpression	0x05
-#define PTP_OPFF_ByteArray		0x06
-#define PTP_OPFF_LongString		0xFF
-
-/* Device Property pack/unpack */
-
-#define PTP_dpd_DevicePropertyCode	0
-#define PTP_dpd_DataType		2
-#define PTP_dpd_GetSet			4
-#define PTP_dpd_FactoryDefaultValue	5
-
-/* Device Property Describing Dataset (DevicePropDesc) */
-
-typedef struct 
-{
-	uint16_t		DevicePropertyCode;
-	uint16_t		DataType;
-	uint8_t			GetSet;
-	PTP_PropertyValueTypedef FactoryDefaultValue;
-	PTP_PropertyValueTypedef CurrentValue;
-	uint8_t			FormFlag;
-	union	{
-		PTP_PropDescEnumFormTypedef	Enum;
-		PTP_PropDescRangeFormTypedef	Range;
-	} FORM;
-}
-PTP_DevicePropDescTypdef;
-
-/* DataType Codes */
-
-#define PTP_DTC_UNDEF		0x0000
-#define PTP_DTC_INT8		0x0001
-#define PTP_DTC_UINT8		0x0002
-#define PTP_DTC_INT16		0x0003
-#define PTP_DTC_UINT16		0x0004
-#define PTP_DTC_INT32		0x0005
-#define PTP_DTC_UINT32		0x0006
-#define PTP_DTC_INT64		0x0007
-#define PTP_DTC_UINT64		0x0008
-#define PTP_DTC_INT128		0x0009
-#define PTP_DTC_UINT128		0x000A
-
-#define PTP_DTC_ARRAY_MASK	0x4000
-
-#define PTP_DTC_AINT8		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT8)
-#define PTP_DTC_AUINT8		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT8)
-#define PTP_DTC_AINT16		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT16)
-#define PTP_DTC_AUINT16		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT16)
-#define PTP_DTC_AINT32		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT32)
-#define PTP_DTC_AUINT32		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT32)
-#define PTP_DTC_AINT64		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT64)
-#define PTP_DTC_AUINT64		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT64)
-#define PTP_DTC_AINT128		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT128)
-#define PTP_DTC_AUINT128	(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT128)
-
-#define PTP_DTC_STR		0xFFFF
-
-/* PTP Event Codes */
-
-#define PTP_EC_Undefined		0x4000
-#define PTP_EC_CancelTransaction	0x4001
-#define PTP_EC_ObjectAdded		0x4002
-#define PTP_EC_ObjectRemoved		0x4003
-#define PTP_EC_StoreAdded		0x4004
-#define PTP_EC_StoreRemoved		0x4005
-#define PTP_EC_DevicePropChanged	0x4006
-#define PTP_EC_ObjectInfoChanged	0x4007
-#define PTP_EC_DeviceInfoChanged	0x4008
-#define PTP_EC_RequestObjectTransfer	0x4009
-#define PTP_EC_StoreFull		0x400A
-#define PTP_EC_DeviceReset		0x400B
-#define PTP_EC_StorageInfoChanged	0x400C
-#define PTP_EC_CaptureComplete		0x400D
-#define PTP_EC_UnreportedStatus		0x400E
-
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MTP_PTP_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MTP_PTP_Exported_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_MTP_PTP_Exported_FunctionsPrototype
-  * @{
-  */ 
-USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost);
-
-USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *req);
-USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *req);
-
-USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t session);
-USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
-USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids);
-
-USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, 
-                                            uint32_t storage_id, 
-                                            PTP_StorageInfoTypedef *storage_info);
-
-USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost,
-                                           uint32_t storage_id, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           uint32_t* numobs);
-
-USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_id, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           PTP_ObjectHandlesTypedef* objecthandles);
-
-USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           PTP_ObjectInfoTypedef* objectinfo);
-
-USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost,
-                                          uint32_t handle,
-                                          uint32_t objectformatcode);
-
-USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object);
-
-USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint32_t offset,
-                                           uint32_t maxbytes, uint8_t *object,
-                                           uint32_t *len);
-
-USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
-                                                     uint16_t ofc,
-                                                     uint32_t *propnum, 
-                                                     uint16_t *props);
-
-USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t opc, 
-                                                uint16_t ofc, 
-                                                PTP_ObjectPropDescTypeDef *opd);
-
-USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost,
-                                                uint32_t handle, 
-                                                MTP_PropertiesTypedef *pprops, 
-                                                uint32_t *nrofprops);
-
-USBH_StatusTypeDef USBH_PTP_SendObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object,
-                                           uint32_t size);
-
-USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t propcode, 
-			                      PTP_DevicePropDescTypdef* devicepropertydesc);
-
-/**
-  * @}
-  */ 
-
-#endif  //__USBH_MTP_PTP_H__
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_mtp_ptp.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_mtp_ptp.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_MTP_PTP_H__
+#define __USBH_MTP_PTP_H__
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_CLASS
+  * @{
+  */
+
+/** @addtogroup USBH_MTP_PTP_CLASS
+  * @{
+  */
+  
+/** @defgroup USBH_MTP_PTP
+  * @brief This file is the Header file for usbh_mtp_ptp.c
+  * @{
+  */ 
+
+
+/* Operation Codes */
+
+/* PTP v1.0 operation codes */
+#define PTP_OC_Undefined                0x1000
+#define PTP_OC_GetDeviceInfo            0x1001
+#define PTP_OC_OpenSession              0x1002
+#define PTP_OC_CloseSession             0x1003
+#define PTP_OC_GetStorageIDs            0x1004
+#define PTP_OC_GetStorageInfo           0x1005
+#define PTP_OC_GetNumObjects            0x1006
+#define PTP_OC_GetObjectHandles         0x1007
+#define PTP_OC_GetObjectInfo            0x1008
+#define PTP_OC_GetObject                0x1009
+#define PTP_OC_GetThumb                 0x100A
+#define PTP_OC_DeleteObject             0x100B
+#define PTP_OC_SendObjectInfo           0x100C
+#define PTP_OC_SendObject               0x100D
+#define PTP_OC_InitiateCapture          0x100E
+#define PTP_OC_FormatStore              0x100F
+#define PTP_OC_ResetDevice              0x1010
+#define PTP_OC_SelfTest                 0x1011
+#define PTP_OC_SetObjectProtection      0x1012
+#define PTP_OC_PowerDown                0x1013
+#define PTP_OC_GetDevicePropDesc        0x1014
+#define PTP_OC_GetDevicePropValue       0x1015
+#define PTP_OC_SetDevicePropValue       0x1016
+#define PTP_OC_ResetDevicePropValue     0x1017
+#define PTP_OC_TerminateOpenCapture     0x1018
+#define PTP_OC_MoveObject               0x1019
+#define PTP_OC_CopyObject               0x101A
+#define PTP_OC_GetPartialObject         0x101B
+#define PTP_OC_InitiateOpenCapture      0x101C
+    
+/* PTP v1.1 operation codes */
+#define PTP_OC_StartEnumHandles		0x101D
+#define PTP_OC_EnumHandles		0x101E
+#define PTP_OC_StopEnumHandles		0x101F
+#define PTP_OC_GetVendorExtensionMaps	0x1020
+#define PTP_OC_GetVendorDeviceInfo	0x1021
+#define PTP_OC_GetResizedImageObject	0x1022
+#define PTP_OC_GetFilesystemManifest	0x1023
+#define PTP_OC_GetStreamInfo		0x1024
+#define PTP_OC_GetStream		0x1025
+
+    /* Microsoft / MTP extension codes */
+#define PTP_OC_GetObjectPropsSupported	 0x9801
+#define PTP_OC_GetObjectPropDesc	 0x9802
+#define PTP_OC_GetObjectPropValue	 0x9803
+#define PTP_OC_SetObjectPropValue	 0x9804
+#define PTP_OC_GetObjPropList		 0x9805
+#define PTP_OC_SetObjPropList		 0x9806
+#define PTP_OC_GetInterdependendPropdesc 0x9807
+#define PTP_OC_SendObjectPropList	 0x9808
+#define PTP_OC_GetObjectReferences	 0x9810
+#define PTP_OC_SetObjectReferences	 0x9811
+#define PTP_OC_UpdateDeviceFirmware	 0x9812
+#define PTP_OC_Skip			 0x9820
+
+    
+/* Response Codes */
+
+/* PTP v1.0 response codes */
+#define PTP_RC_Undefined                0x2000
+#define PTP_RC_OK                       0x2001
+#define PTP_RC_GeneralError             0x2002
+#define PTP_RC_SessionNotOpen           0x2003
+#define PTP_RC_InvalidTransactionID	0x2004
+#define PTP_RC_OperationNotSupported    0x2005
+#define PTP_RC_ParameterNotSupported    0x2006
+#define PTP_RC_IncompleteTransfer       0x2007
+#define PTP_RC_InvalidStorageId         0x2008
+#define PTP_RC_InvalidObjectHandle      0x2009
+#define PTP_RC_DevicePropNotSupported   0x200A
+#define PTP_RC_InvalidObjectFormatCode  0x200B
+#define PTP_RC_StoreFull                0x200C
+#define PTP_RC_ObjectWriteProtected     0x200D
+#define PTP_RC_StoreReadOnly            0x200E
+#define PTP_RC_AccessDenied             0x200F
+#define PTP_RC_NoThumbnailPresent       0x2010
+#define PTP_RC_SelfTestFailed           0x2011
+#define PTP_RC_PartialDeletion          0x2012
+#define PTP_RC_StoreNotAvailable        0x2013
+#define PTP_RC_SpecificationByFormatUnsupported         0x2014
+#define PTP_RC_NoValidObjectInfo        0x2015
+#define PTP_RC_InvalidCodeFormat        0x2016
+#define PTP_RC_UnknownVendorCode        0x2017
+#define PTP_RC_CaptureAlreadyTerminated 0x2018
+#define PTP_RC_DeviceBusy               0x2019
+#define PTP_RC_InvalidParentObject      0x201A
+#define PTP_RC_InvalidDevicePropFormat  0x201B
+#define PTP_RC_InvalidDevicePropValue   0x201C
+#define PTP_RC_InvalidParameter         0x201D
+#define PTP_RC_SessionAlreadyOpened     0x201E
+#define PTP_RC_TransactionCanceled      0x201F
+#define PTP_RC_SpecificationOfDestinationUnsupported       0x2020
+/* PTP v1.1 response codes */
+#define PTP_RC_InvalidEnumHandle	0x2021
+#define PTP_RC_NoStreamEnabled		0x2022
+#define PTP_RC_InvalidDataSet		0x2023
+    
+/* USB container types */
+
+#define PTP_USB_CONTAINER_UNDEFINED	 0x0000
+#define PTP_USB_CONTAINER_COMMAND	 0x0001
+#define PTP_USB_CONTAINER_DATA		 0x0002
+#define PTP_USB_CONTAINER_RESPONSE	 0x0003
+#define PTP_USB_CONTAINER_EVENT		 0x0004
+
+/* PTP/IP definitions */
+#define PTPIP_INIT_COMMAND_REQUEST	1
+#define PTPIP_INIT_COMMAND_ACK		2
+#define PTPIP_INIT_EVENT_REQUEST	3
+#define PTPIP_INIT_EVENT_ACK		4
+#define PTPIP_INIT_FAIL			5
+#define PTPIP_CMD_REQUEST		6
+#define PTPIP_CMD_RESPONSE		7
+#define PTPIP_EVENT			8
+#define PTPIP_START_DATA_PACKET		9
+#define PTPIP_DATA_PACKET		10
+#define PTPIP_CANCEL_TRANSACTION	11
+#define PTPIP_END_DATA_PACKET		12
+#define PTPIP_PING			13
+#define PTPIP_PONG			14
+
+/* Transaction data phase description */
+#define PTP_DP_NODATA		0x0000	/* no data phase */
+#define PTP_DP_SENDDATA		0x0001	/* sending data */
+#define PTP_DP_GETDATA		0x0002	/* receiving data */
+#define PTP_DP_DATA_MASK	0x00ff	/* data phase mask */
+    
+/** @defgroup USBH_MTP_PTP_Exported_Types
+  * @{
+  */ 
+
+typedef enum 
+{
+  PTP_REQ_IDLE = 0,   
+  PTP_REQ_SEND = 1,  
+  PTP_REQ_WAIT,   
+  PTP_REQ_ERROR,         
+} 
+PTP_RequestStateTypeDef;  
+
+typedef enum 
+{
+  PTP_IDLE = 0,   
+  PTP_OP_REQUEST_STATE,  
+  PTP_OP_REQUEST_WAIT_STATE,   
+  PTP_DATA_OUT_PHASE_STATE,
+  PTP_DATA_OUT_PHASE_WAIT_STATE,  
+  PTP_DATA_IN_PHASE_STATE,
+  PTP_DATA_IN_PHASE_WAIT_STATE,  
+  PTP_RESPONSE_STATE, 
+  PTP_RESPONSE_WAIT_STATE,  
+  PTP_ERROR,         
+} 
+PTP_ProcessStateTypeDef;  
+
+/* PTP request/response/event general PTP container (transport independent) */
+typedef struct 
+{
+	uint16_t Code;
+	uint32_t SessionID;
+	uint32_t Transaction_ID;
+	/* params  may be of any type of size less or equal to uint32_t */
+	uint32_t Param1;
+	uint32_t Param2;
+	uint32_t Param3;
+	/* events can only have three parameters */
+	uint32_t Param4;
+	uint32_t Param5;
+	/* the number of meaningfull parameters */
+	uint8_t	 Nparam;
+}
+PTP_ContainerTypedef; 
+
+#define PTP_USB_BULK_HS_MAX_PACKET_LEN_WRITE	1024
+#define PTP_USB_BULK_HS_MAX_PACKET_LEN_READ     1024
+#define PTP_USB_BULK_HDR_LEN		       (2*sizeof(uint32_t)+2*sizeof(uint16_t))
+#define PTP_USB_BULK_PAYLOAD_LEN_WRITE	       (PTP_USB_BULK_HS_MAX_PACKET_LEN_WRITE-PTP_USB_BULK_HDR_LEN)
+#define PTP_USB_BULK_PAYLOAD_LEN_READ	       (PTP_USB_BULK_HS_MAX_PACKET_LEN_READ-PTP_USB_BULK_HDR_LEN)
+#define PTP_USB_BULK_REQ_LEN	               (PTP_USB_BULK_HDR_LEN+5*sizeof(uint32_t))
+#define PTP_USB_BULK_REQ_RESP_MAX_LEN           63
+
+typedef struct 
+{
+  uint32_t length;
+  uint16_t type;
+  uint16_t code;
+  uint32_t trans_id;
+  uint32_t param1;
+  uint32_t param2;
+  uint32_t param3;
+  uint32_t param4;
+  uint32_t param5;
+}
+PTP_RespContainerTypedef;
+
+
+typedef struct 
+{
+  uint32_t length;
+  uint16_t type;
+  uint16_t code;
+  uint32_t trans_id;
+  uint32_t param1;
+  uint32_t param2;
+  uint32_t param3;
+  uint32_t param4;
+  uint32_t param5;
+}
+PTP_OpContainerTypedef;
+
+typedef struct 
+{
+  uint32_t length;
+  uint16_t type;
+  uint16_t code;
+  uint32_t trans_id;
+  union {
+    struct {
+      uint32_t param1;
+      uint32_t param2;
+      uint32_t param3;
+      uint32_t param4;
+      uint32_t param5;
+    } params;  
+    uint8_t  data[PTP_USB_BULK_PAYLOAD_LEN_READ];
+  }payload;
+}
+PTP_DataContainerTypedef;
+
+/* PTP USB Asynchronous Event Interrupt Data Format */
+typedef struct 
+{
+  uint32_t length;
+  uint16_t type;
+  uint16_t code;
+  uint32_t trans_id;
+  uint32_t param1;
+  uint32_t param2;
+  uint32_t param3;
+}
+PTP_EventContainerTypedef;
+
+/* Structure for PTP Transport process */
+typedef struct
+{
+  PTP_ProcessStateTypeDef      state;
+  PTP_RequestStateTypeDef      req_state;
+  PTP_OpContainerTypedef       op_container;    
+  PTP_DataContainerTypedef     data_container;  
+  PTP_RespContainerTypedef     resp_container;    
+
+  /* ptp transaction ID */
+  uint32_t	transaction_id;
+  
+  /* ptp session ID */
+  uint32_t	session_id; 
+  
+  /* device flags */
+  uint32_t	flags;  
+
+  /****** PTP transfer control *******/ 
+  
+  /* Data pointer */
+  uint8_t	*data_ptr;  
+
+  /* Data length */
+  int32_t	data_length;
+  
+  /* Data length */
+  uint32_t	data_packet;
+  
+  /* Data length */
+  uint32_t	iteration;  
+  
+  /* Packet Index */
+  uint32_t   data_packet_counter;
+  
+  /****** Object transfer control *******/
+  
+  /* object pointer */
+  uint8_t	*object_ptr;
+
+}
+PTP_HandleTypeDef;
+
+/* DeviceInfo data offset */
+#define PTP_di_StandardVersion		 0
+#define PTP_di_VendorExtensionID	 2
+#define PTP_di_VendorExtensionVersion	 6
+#define PTP_di_VendorExtensionDesc	 8
+#define PTP_di_FunctionalMode		 8
+#define PTP_di_OperationsSupported	10
+
+/* Max info items size */
+#define PTP_SUPPORTED_OPERATIONS_NBR    100
+#define PTP_SUPPORTED_EVENTS_NBR        100
+#define PTP_SUPPORTED_PROPRIETIES_NBR   100
+#define PTP_CAPTURE_FORMATS_NBR         100
+#define PTP_IMAGE_FORMATS_NBR           100
+#define PTP_MAX_STR_SIZE                255
+/* PTP device info structure */
+typedef struct
+{
+  uint16_t StandardVersion;
+  uint32_t VendorExtensionID;
+  uint16_t VendorExtensionVersion;
+  uint8_t  VendorExtensionDesc[PTP_MAX_STR_SIZE];
+  uint16_t FunctionalMode;
+  uint32_t OperationsSupported_len;
+  uint16_t OperationsSupported[PTP_SUPPORTED_OPERATIONS_NBR];
+  uint32_t EventsSupported_len;
+  uint16_t EventsSupported[PTP_SUPPORTED_EVENTS_NBR];
+  uint32_t DevicePropertiesSupported_len;
+  uint16_t DevicePropertiesSupported[PTP_SUPPORTED_PROPRIETIES_NBR];
+  uint32_t CaptureFormats_len;
+  uint16_t CaptureFormats[PTP_CAPTURE_FORMATS_NBR];
+  uint32_t ImageFormats_len;
+  uint16_t ImageFormats[PTP_IMAGE_FORMATS_NBR];
+  uint8_t  Manufacturer[PTP_MAX_STR_SIZE];
+  uint8_t  Model[PTP_MAX_STR_SIZE];
+  uint8_t  DeviceVersion[PTP_MAX_STR_SIZE];
+  uint8_t  SerialNumber[PTP_MAX_STR_SIZE];
+}
+PTP_DeviceInfoTypedef;
+
+#define PTP_MAX_STORAGE_UNITS_NBR      5
+/* PTP storageIDs structute (returned by GetStorageIDs) */
+typedef struct
+{
+  uint32_t n;
+  uint32_t Storage [PTP_MAX_STORAGE_UNITS_NBR];
+}
+PTP_StorageIDsTypedef;
+
+/* PTP StorageInfo structure (returned by GetStorageInfo) */
+
+#define PTP_si_StorageType		 0
+#define PTP_si_FilesystemType		 2
+#define PTP_si_AccessCapability		 4
+#define PTP_si_MaxCapability		 6
+#define PTP_si_FreeSpaceInBytes		14
+#define PTP_si_FreeSpaceInImages	22
+#define PTP_si_StorageDescription	26
+
+
+/* PTP Storage Types */
+
+#define PTP_ST_Undefined			0x0000
+#define PTP_ST_FixedROM				0x0001
+#define PTP_ST_RemovableROM			0x0002
+#define PTP_ST_FixedRAM				0x0003
+#define PTP_ST_RemovableRAM			0x0004
+
+/* PTP FilesystemType Values */
+
+#define PTP_FST_Undefined			0x0000
+#define PTP_FST_GenericFlat			0x0001
+#define PTP_FST_GenericHierarchical		0x0002
+#define PTP_FST_DCF				0x0003
+
+/* PTP StorageInfo AccessCapability Values */
+
+#define PTP_AC_ReadWrite			0x0000
+#define PTP_AC_ReadOnly				0x0001
+#define PTP_AC_ReadOnly_with_Object_Deletion	0x0002
+
+typedef struct
+{
+  uint16_t StorageType;
+  uint16_t FilesystemType;
+  uint16_t AccessCapability;
+  uint64_t MaxCapability;
+  uint64_t FreeSpaceInBytes;
+  uint32_t FreeSpaceInImages;
+  uint8_t  StorageDescription[PTP_MAX_STR_SIZE];
+  uint8_t  VolumeLabel[PTP_MAX_STR_SIZE];
+}
+PTP_StorageInfoTypedef;
+
+/* PTP Object Format Codes */
+
+/* ancillary formats */
+#define PTP_OFC_Undefined			0x3000
+#define PTP_OFC_Defined				0x3800
+#define PTP_OFC_Association			0x3001
+#define PTP_OFC_Script				0x3002
+#define PTP_OFC_Executable			0x3003
+#define PTP_OFC_Text				0x3004
+#define PTP_OFC_HTML				0x3005
+#define PTP_OFC_DPOF				0x3006
+#define PTP_OFC_AIFF	 			0x3007
+#define PTP_OFC_WAV				0x3008
+#define PTP_OFC_MP3				0x3009
+#define PTP_OFC_AVI				0x300A
+#define PTP_OFC_MPEG				0x300B
+#define PTP_OFC_ASF				0x300C
+#define PTP_OFC_QT				0x300D /* guessing */
+/* image formats */
+#define PTP_OFC_EXIF_JPEG			0x3801
+#define PTP_OFC_TIFF_EP				0x3802
+#define PTP_OFC_FlashPix			0x3803
+#define PTP_OFC_BMP				0x3804
+#define PTP_OFC_CIFF				0x3805
+#define PTP_OFC_Undefined_0x3806		0x3806
+#define PTP_OFC_GIF				0x3807
+#define PTP_OFC_JFIF				0x3808
+#define PTP_OFC_PCD				0x3809
+#define PTP_OFC_PICT				0x380A
+#define PTP_OFC_PNG				0x380B
+#define PTP_OFC_Undefined_0x380C		0x380C
+#define PTP_OFC_TIFF				0x380D
+#define PTP_OFC_TIFF_IT				0x380E
+#define PTP_OFC_JP2				0x380F
+#define PTP_OFC_JPX				0x3810
+/* ptp v1.1 has only DNG new */
+#define PTP_OFC_DNG				0x3811
+
+/* MTP extensions */
+#define PTP_OFC_MTP_MediaCard			0xb211
+#define PTP_OFC_MTP_MediaCardGroup		0xb212
+#define PTP_OFC_MTP_Encounter			0xb213
+#define PTP_OFC_MTP_EncounterBox		0xb214
+#define PTP_OFC_MTP_M4A				0xb215
+#define PTP_OFC_MTP_ZUNEUNDEFINED		0xb217 /* Unknown file type */
+#define PTP_OFC_MTP_Firmware			0xb802
+#define PTP_OFC_MTP_WindowsImageFormat		0xb881
+#define PTP_OFC_MTP_UndefinedAudio		0xb900
+#define PTP_OFC_MTP_WMA				0xb901
+#define PTP_OFC_MTP_OGG				0xb902
+#define PTP_OFC_MTP_AAC				0xb903
+#define PTP_OFC_MTP_AudibleCodec		0xb904
+#define PTP_OFC_MTP_FLAC			0xb906
+#define PTP_OFC_MTP_SamsungPlaylist		0xb909
+#define PTP_OFC_MTP_UndefinedVideo		0xb980
+#define PTP_OFC_MTP_WMV				0xb981
+#define PTP_OFC_MTP_MP4				0xb982
+#define PTP_OFC_MTP_MP2				0xb983
+#define PTP_OFC_MTP_3GP				0xb984
+#define PTP_OFC_MTP_UndefinedCollection		0xba00
+#define PTP_OFC_MTP_AbstractMultimediaAlbum	0xba01
+#define PTP_OFC_MTP_AbstractImageAlbum		0xba02
+#define PTP_OFC_MTP_AbstractAudioAlbum		0xba03
+#define PTP_OFC_MTP_AbstractVideoAlbum		0xba04
+#define PTP_OFC_MTP_AbstractAudioVideoPlaylist	0xba05
+#define PTP_OFC_MTP_AbstractContactGroup	0xba06
+#define PTP_OFC_MTP_AbstractMessageFolder	0xba07
+#define PTP_OFC_MTP_AbstractChapteredProduction	0xba08
+#define PTP_OFC_MTP_AbstractAudioPlaylist	0xba09
+#define PTP_OFC_MTP_AbstractVideoPlaylist	0xba0a
+#define PTP_OFC_MTP_AbstractMediacast		0xba0b
+#define PTP_OFC_MTP_WPLPlaylist			0xba10
+#define PTP_OFC_MTP_M3UPlaylist			0xba11
+#define PTP_OFC_MTP_MPLPlaylist			0xba12
+#define PTP_OFC_MTP_ASXPlaylist			0xba13
+#define PTP_OFC_MTP_PLSPlaylist			0xba14
+#define PTP_OFC_MTP_UndefinedDocument		0xba80
+#define PTP_OFC_MTP_AbstractDocument		0xba81
+#define PTP_OFC_MTP_XMLDocument			0xba82
+#define PTP_OFC_MTP_MSWordDocument		0xba83
+#define PTP_OFC_MTP_MHTCompiledHTMLDocument	0xba84
+#define PTP_OFC_MTP_MSExcelSpreadsheetXLS	0xba85
+#define PTP_OFC_MTP_MSPowerpointPresentationPPT	0xba86
+#define PTP_OFC_MTP_UndefinedMessage		0xbb00
+#define PTP_OFC_MTP_AbstractMessage		0xbb01
+#define PTP_OFC_MTP_UndefinedContact		0xbb80
+#define PTP_OFC_MTP_AbstractContact		0xbb81
+#define PTP_OFC_MTP_vCard2			0xbb82
+#define PTP_OFC_MTP_vCard3			0xbb83
+#define PTP_OFC_MTP_UndefinedCalendarItem	0xbe00
+#define PTP_OFC_MTP_AbstractCalendarItem	0xbe01
+#define PTP_OFC_MTP_vCalendar1			0xbe02
+#define PTP_OFC_MTP_vCalendar2			0xbe03
+#define PTP_OFC_MTP_UndefinedWindowsExecutable	0xbe80
+#define PTP_OFC_MTP_MediaCast			0xbe81
+#define PTP_OFC_MTP_Section			0xbe82
+
+/* MTP specific Object Properties */
+#define PTP_OPC_StorageID				0xDC01
+#define PTP_OPC_ObjectFormat				0xDC02
+#define PTP_OPC_ProtectionStatus			0xDC03
+#define PTP_OPC_ObjectSize				0xDC04
+#define PTP_OPC_AssociationType				0xDC05
+#define PTP_OPC_AssociationDesc				0xDC06
+#define PTP_OPC_ObjectFileName				0xDC07
+#define PTP_OPC_DateCreated				0xDC08
+#define PTP_OPC_DateModified				0xDC09
+#define PTP_OPC_Keywords				0xDC0A
+#define PTP_OPC_ParentObject				0xDC0B
+#define PTP_OPC_AllowedFolderContents			0xDC0C
+#define PTP_OPC_Hidden					0xDC0D
+#define PTP_OPC_SystemObject				0xDC0E
+#define PTP_OPC_PersistantUniqueObjectIdentifier	0xDC41
+#define PTP_OPC_SyncID					0xDC42
+#define PTP_OPC_PropertyBag				0xDC43
+#define PTP_OPC_Name					0xDC44
+#define PTP_OPC_CreatedBy				0xDC45
+#define PTP_OPC_Artist					0xDC46
+#define PTP_OPC_DateAuthored				0xDC47
+#define PTP_OPC_Description				0xDC48
+#define PTP_OPC_URLReference				0xDC49
+#define PTP_OPC_LanguageLocale				0xDC4A
+#define PTP_OPC_CopyrightInformation			0xDC4B
+#define PTP_OPC_Source					0xDC4C
+#define PTP_OPC_OriginLocation				0xDC4D
+#define PTP_OPC_DateAdded				0xDC4E
+#define PTP_OPC_NonConsumable				0xDC4F
+#define PTP_OPC_CorruptOrUnplayable			0xDC50
+#define PTP_OPC_ProducerSerialNumber			0xDC51
+#define PTP_OPC_RepresentativeSampleFormat		0xDC81
+#define PTP_OPC_RepresentativeSampleSize		0xDC82
+#define PTP_OPC_RepresentativeSampleHeight		0xDC83
+#define PTP_OPC_RepresentativeSampleWidth		0xDC84
+#define PTP_OPC_RepresentativeSampleDuration		0xDC85
+#define PTP_OPC_RepresentativeSampleData		0xDC86
+#define PTP_OPC_Width					0xDC87
+#define PTP_OPC_Height					0xDC88
+#define PTP_OPC_Duration				0xDC89
+#define PTP_OPC_Rating					0xDC8A
+#define PTP_OPC_Track					0xDC8B
+#define PTP_OPC_Genre					0xDC8C
+#define PTP_OPC_Credits					0xDC8D
+#define PTP_OPC_Lyrics					0xDC8E
+#define PTP_OPC_SubscriptionContentID			0xDC8F
+#define PTP_OPC_ProducedBy				0xDC90
+#define PTP_OPC_UseCount				0xDC91
+#define PTP_OPC_SkipCount				0xDC92
+#define PTP_OPC_LastAccessed				0xDC93
+#define PTP_OPC_ParentalRating				0xDC94
+#define PTP_OPC_MetaGenre				0xDC95
+#define PTP_OPC_Composer				0xDC96
+#define PTP_OPC_EffectiveRating				0xDC97
+#define PTP_OPC_Subtitle				0xDC98
+#define PTP_OPC_OriginalReleaseDate			0xDC99
+#define PTP_OPC_AlbumName				0xDC9A
+#define PTP_OPC_AlbumArtist				0xDC9B
+#define PTP_OPC_Mood					0xDC9C
+#define PTP_OPC_DRMStatus				0xDC9D
+#define PTP_OPC_SubDescription				0xDC9E
+#define PTP_OPC_IsCropped				0xDCD1
+#define PTP_OPC_IsColorCorrected			0xDCD2
+#define PTP_OPC_ImageBitDepth				0xDCD3
+#define PTP_OPC_Fnumber					0xDCD4
+#define PTP_OPC_ExposureTime				0xDCD5
+#define PTP_OPC_ExposureIndex				0xDCD6
+#define PTP_OPC_DisplayName				0xDCE0
+#define PTP_OPC_BodyText				0xDCE1
+#define PTP_OPC_Subject					0xDCE2
+#define PTP_OPC_Priority				0xDCE3
+#define PTP_OPC_GivenName				0xDD00
+#define PTP_OPC_MiddleNames				0xDD01
+#define PTP_OPC_FamilyName				0xDD02
+#define PTP_OPC_Prefix					0xDD03
+#define PTP_OPC_Suffix					0xDD04
+#define PTP_OPC_PhoneticGivenName			0xDD05
+#define PTP_OPC_PhoneticFamilyName			0xDD06
+#define PTP_OPC_EmailPrimary				0xDD07
+#define PTP_OPC_EmailPersonal1				0xDD08
+#define PTP_OPC_EmailPersonal2				0xDD09
+#define PTP_OPC_EmailBusiness1				0xDD0A
+#define PTP_OPC_EmailBusiness2				0xDD0B
+#define PTP_OPC_EmailOthers				0xDD0C
+#define PTP_OPC_PhoneNumberPrimary			0xDD0D
+#define PTP_OPC_PhoneNumberPersonal			0xDD0E
+#define PTP_OPC_PhoneNumberPersonal2			0xDD0F
+#define PTP_OPC_PhoneNumberBusiness			0xDD10
+#define PTP_OPC_PhoneNumberBusiness2			0xDD11
+#define PTP_OPC_PhoneNumberMobile			0xDD12
+#define PTP_OPC_PhoneNumberMobile2			0xDD13
+#define PTP_OPC_FaxNumberPrimary			0xDD14
+#define PTP_OPC_FaxNumberPersonal			0xDD15
+#define PTP_OPC_FaxNumberBusiness			0xDD16
+#define PTP_OPC_PagerNumber				0xDD17
+#define PTP_OPC_PhoneNumberOthers			0xDD18
+#define PTP_OPC_PrimaryWebAddress			0xDD19
+#define PTP_OPC_PersonalWebAddress			0xDD1A
+#define PTP_OPC_BusinessWebAddress			0xDD1B
+#define PTP_OPC_InstantMessengerAddress			0xDD1C
+#define PTP_OPC_InstantMessengerAddress2		0xDD1D
+#define PTP_OPC_InstantMessengerAddress3		0xDD1E
+#define PTP_OPC_PostalAddressPersonalFull		0xDD1F
+#define PTP_OPC_PostalAddressPersonalFullLine1		0xDD20
+#define PTP_OPC_PostalAddressPersonalFullLine2		0xDD21
+#define PTP_OPC_PostalAddressPersonalFullCity		0xDD22
+#define PTP_OPC_PostalAddressPersonalFullRegion		0xDD23
+#define PTP_OPC_PostalAddressPersonalFullPostalCode	0xDD24
+#define PTP_OPC_PostalAddressPersonalFullCountry	0xDD25
+#define PTP_OPC_PostalAddressBusinessFull		0xDD26
+#define PTP_OPC_PostalAddressBusinessLine1		0xDD27
+#define PTP_OPC_PostalAddressBusinessLine2		0xDD28
+#define PTP_OPC_PostalAddressBusinessCity		0xDD29
+#define PTP_OPC_PostalAddressBusinessRegion		0xDD2A
+#define PTP_OPC_PostalAddressBusinessPostalCode		0xDD2B
+#define PTP_OPC_PostalAddressBusinessCountry		0xDD2C
+#define PTP_OPC_PostalAddressOtherFull			0xDD2D
+#define PTP_OPC_PostalAddressOtherLine1			0xDD2E
+#define PTP_OPC_PostalAddressOtherLine2			0xDD2F
+#define PTP_OPC_PostalAddressOtherCity			0xDD30
+#define PTP_OPC_PostalAddressOtherRegion		0xDD31
+#define PTP_OPC_PostalAddressOtherPostalCode		0xDD32
+#define PTP_OPC_PostalAddressOtherCountry		0xDD33
+#define PTP_OPC_OrganizationName			0xDD34
+#define PTP_OPC_PhoneticOrganizationName		0xDD35
+#define PTP_OPC_Role					0xDD36
+#define PTP_OPC_Birthdate				0xDD37
+#define PTP_OPC_MessageTo				0xDD40
+#define PTP_OPC_MessageCC				0xDD41
+#define PTP_OPC_MessageBCC				0xDD42
+#define PTP_OPC_MessageRead				0xDD43
+#define PTP_OPC_MessageReceivedTime			0xDD44
+#define PTP_OPC_MessageSender				0xDD45
+#define PTP_OPC_ActivityBeginTime			0xDD50
+#define PTP_OPC_ActivityEndTime				0xDD51
+#define PTP_OPC_ActivityLocation			0xDD52
+#define PTP_OPC_ActivityRequiredAttendees		0xDD54
+#define PTP_OPC_ActivityOptionalAttendees		0xDD55
+#define PTP_OPC_ActivityResources			0xDD56
+#define PTP_OPC_ActivityAccepted			0xDD57
+#define PTP_OPC_Owner					0xDD5D
+#define PTP_OPC_Editor					0xDD5E
+#define PTP_OPC_Webmaster				0xDD5F
+#define PTP_OPC_URLSource				0xDD60
+#define PTP_OPC_URLDestination				0xDD61
+#define PTP_OPC_TimeBookmark				0xDD62
+#define PTP_OPC_ObjectBookmark				0xDD63
+#define PTP_OPC_ByteBookmark				0xDD64
+#define PTP_OPC_LastBuildDate				0xDD70
+#define PTP_OPC_TimetoLive				0xDD71
+#define PTP_OPC_MediaGUID				0xDD72
+#define PTP_OPC_TotalBitRate				0xDE91
+#define PTP_OPC_BitRateType				0xDE92
+#define PTP_OPC_SampleRate				0xDE93
+#define PTP_OPC_NumberOfChannels			0xDE94
+#define PTP_OPC_AudioBitDepth				0xDE95
+#define PTP_OPC_ScanDepth				0xDE97
+#define PTP_OPC_AudioWAVECodec				0xDE99
+#define PTP_OPC_AudioBitRate				0xDE9A
+#define PTP_OPC_VideoFourCCCodec			0xDE9B
+#define PTP_OPC_VideoBitRate				0xDE9C
+#define PTP_OPC_FramesPerThousandSeconds		0xDE9D
+#define PTP_OPC_KeyFrameDistance			0xDE9E
+#define PTP_OPC_BufferSize				0xDE9F
+#define PTP_OPC_EncodingQuality				0xDEA0
+#define PTP_OPC_EncodingProfile				0xDEA1
+#define PTP_OPC_BuyFlag					0xD901
+
+/* WiFi Provisioning MTP Extension property codes */
+#define PTP_OPC_WirelessConfigurationFile		0xB104
+
+
+/* PTP Association Types */
+#define PTP_AT_Undefined			0x0000
+#define PTP_AT_GenericFolder			0x0001
+#define PTP_AT_Album				0x0002
+#define PTP_AT_TimeSequence			0x0003
+#define PTP_AT_HorizontalPanoramic		0x0004
+#define PTP_AT_VerticalPanoramic		0x0005
+#define PTP_AT_2DPanoramic			0x0006
+#define PTP_AT_AncillaryData			0x0007
+
+#define PTP_MAX_HANDLER_NBR                      0x255
+typedef struct 
+{
+  uint32_t n;
+  uint32_t Handler[PTP_MAX_HANDLER_NBR];
+}
+PTP_ObjectHandlesTypedef;
+
+
+#define PTP_oi_StorageID		 0
+#define PTP_oi_ObjectFormat		 4
+#define PTP_oi_ProtectionStatus		 6
+#define PTP_oi_ObjectCompressedSize	 8
+#define PTP_oi_ThumbFormat		12
+#define PTP_oi_ThumbCompressedSize	14
+#define PTP_oi_ThumbPixWidth		18
+#define PTP_oi_ThumbPixHeight		22
+#define PTP_oi_ImagePixWidth		26
+#define PTP_oi_ImagePixHeight		30
+#define PTP_oi_ImageBitDepth		34
+#define PTP_oi_ParentObject		38
+#define PTP_oi_AssociationType		42
+#define PTP_oi_AssociationDesc		44
+#define PTP_oi_SequenceNumber		48
+#define PTP_oi_filenamelen		52
+#define PTP_oi_Filename			53
+
+typedef struct 
+{
+  uint32_t StorageID;
+  uint16_t ObjectFormat;
+  uint16_t ProtectionStatus;
+  /* In the regular objectinfo this is 32bit, but we keep the general object size here
+     that also arrives via other methods and so use 64bit */
+  uint64_t ObjectCompressedSize;
+  uint16_t ThumbFormat;
+  uint32_t ThumbCompressedSize;
+  uint32_t ThumbPixWidth;
+  uint32_t ThumbPixHeight;
+  uint32_t ImagePixWidth;
+  uint32_t ImagePixHeight;
+  uint32_t ImageBitDepth;
+  uint32_t ParentObject;
+  uint16_t AssociationType;
+  uint32_t AssociationDesc;
+  uint32_t SequenceNumber;
+  uint8_t  Filename[PTP_MAX_STR_SIZE];
+  uint32_t CaptureDate;
+  uint32_t ModificationDate;
+  uint8_t  Keywords[PTP_MAX_STR_SIZE];
+}
+PTP_ObjectInfoTypedef;
+
+/* Object Property Describing Dataset (DevicePropDesc) */
+
+typedef union  _PTP_PropertyValueTypedef
+{
+	char		str[PTP_MAX_STR_SIZE];
+	uint8_t		u8;
+	int8_t		i8;
+	uint16_t	u16;
+	int16_t		i16;
+	uint32_t	u32;
+	int32_t		i32;
+	uint64_t	u64;
+	int64_t		i64;
+
+	struct array {
+		uint32_t	count;
+		union _PTP_PropertyValueTypedef *v;
+	} a;
+}PTP_PropertyValueTypedef;
+
+typedef struct 
+{
+	PTP_PropertyValueTypedef 	MinimumValue;
+	PTP_PropertyValueTypedef 	MaximumValue;
+	PTP_PropertyValueTypedef 	StepSize;
+}
+PTP_PropDescRangeFormTypedef;
+
+/* Property Describing Dataset, Enum Form */
+
+typedef struct 
+{
+	uint16_t		 NumberOfValues;
+	PTP_PropertyValueTypedef SupportedValue[PTP_SUPPORTED_PROPRIETIES_NBR];
+}
+PTP_PropDescEnumFormTypedef;
+
+/* (MTP) Object Property pack/unpack */
+#define PTP_opd_ObjectPropertyCode	0
+#define PTP_opd_DataType		2
+#define PTP_opd_GetSet			4
+#define PTP_opd_FactoryDefaultValue	5
+
+typedef struct
+{
+	uint16_t		ObjectPropertyCode;
+	uint16_t		DataType;
+	uint8_t			GetSet;
+	PTP_PropertyValueTypedef FactoryDefaultValue;
+	uint32_t		GroupCode;
+	uint8_t			FormFlag;
+	union	{
+		PTP_PropDescEnumFormTypedef	Enum;
+		PTP_PropDescRangeFormTypedef	Range;
+	} FORM;
+}
+PTP_ObjectPropDescTypeDef;
+
+/* Metadata lists for MTP operations */
+typedef struct
+{
+	uint16_t 	 	property;
+	uint16_t 	 	datatype;
+	uint32_t 	 	ObjectHandle;
+	PTP_PropertyValueTypedef propval;
+}
+MTP_PropertiesTypedef;
+
+
+/* Device Property Form Flag */
+
+#define PTP_DPFF_None			0x00
+#define PTP_DPFF_Range			0x01
+#define PTP_DPFF_Enumeration		0x02
+
+/* Object Property Codes used by MTP (first 3 are same as DPFF codes) */
+#define PTP_OPFF_None			0x00
+#define PTP_OPFF_Range			0x01
+#define PTP_OPFF_Enumeration		0x02
+#define PTP_OPFF_DateTime		0x03
+#define PTP_OPFF_FixedLengthArray	0x04
+#define PTP_OPFF_RegularExpression	0x05
+#define PTP_OPFF_ByteArray		0x06
+#define PTP_OPFF_LongString		0xFF
+
+/* Device Property pack/unpack */
+
+#define PTP_dpd_DevicePropertyCode	0
+#define PTP_dpd_DataType		2
+#define PTP_dpd_GetSet			4
+#define PTP_dpd_FactoryDefaultValue	5
+
+/* Device Property Describing Dataset (DevicePropDesc) */
+
+typedef struct 
+{
+	uint16_t		DevicePropertyCode;
+	uint16_t		DataType;
+	uint8_t			GetSet;
+	PTP_PropertyValueTypedef FactoryDefaultValue;
+	PTP_PropertyValueTypedef CurrentValue;
+	uint8_t			FormFlag;
+	union	{
+		PTP_PropDescEnumFormTypedef	Enum;
+		PTP_PropDescRangeFormTypedef	Range;
+	} FORM;
+}
+PTP_DevicePropDescTypdef;
+
+/* DataType Codes */
+
+#define PTP_DTC_UNDEF		0x0000
+#define PTP_DTC_INT8		0x0001
+#define PTP_DTC_UINT8		0x0002
+#define PTP_DTC_INT16		0x0003
+#define PTP_DTC_UINT16		0x0004
+#define PTP_DTC_INT32		0x0005
+#define PTP_DTC_UINT32		0x0006
+#define PTP_DTC_INT64		0x0007
+#define PTP_DTC_UINT64		0x0008
+#define PTP_DTC_INT128		0x0009
+#define PTP_DTC_UINT128		0x000A
+
+#define PTP_DTC_ARRAY_MASK	0x4000
+
+#define PTP_DTC_AINT8		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT8)
+#define PTP_DTC_AUINT8		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT8)
+#define PTP_DTC_AINT16		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT16)
+#define PTP_DTC_AUINT16		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT16)
+#define PTP_DTC_AINT32		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT32)
+#define PTP_DTC_AUINT32		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT32)
+#define PTP_DTC_AINT64		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT64)
+#define PTP_DTC_AUINT64		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT64)
+#define PTP_DTC_AINT128		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT128)
+#define PTP_DTC_AUINT128	(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT128)
+
+#define PTP_DTC_STR		0xFFFF
+
+/* PTP Event Codes */
+
+#define PTP_EC_Undefined		0x4000
+#define PTP_EC_CancelTransaction	0x4001
+#define PTP_EC_ObjectAdded		0x4002
+#define PTP_EC_ObjectRemoved		0x4003
+#define PTP_EC_StoreAdded		0x4004
+#define PTP_EC_StoreRemoved		0x4005
+#define PTP_EC_DevicePropChanged	0x4006
+#define PTP_EC_ObjectInfoChanged	0x4007
+#define PTP_EC_DeviceInfoChanged	0x4008
+#define PTP_EC_RequestObjectTransfer	0x4009
+#define PTP_EC_StoreFull		0x400A
+#define PTP_EC_DeviceReset		0x400B
+#define PTP_EC_StorageInfoChanged	0x400C
+#define PTP_EC_CaptureComplete		0x400D
+#define PTP_EC_UnreportedStatus		0x400E
+
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MTP_PTP_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MTP_PTP_Exported_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_MTP_PTP_Exported_FunctionsPrototype
+  * @{
+  */ 
+USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost);
+
+USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *req);
+USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *req);
+
+USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t session);
+USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
+USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids);
+
+USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, 
+                                            uint32_t storage_id, 
+                                            PTP_StorageInfoTypedef *storage_info);
+
+USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost,
+                                           uint32_t storage_id, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           uint32_t* numobs);
+
+USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_id, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           PTP_ObjectHandlesTypedef* objecthandles);
+
+USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           PTP_ObjectInfoTypedef* objectinfo);
+
+USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost,
+                                          uint32_t handle,
+                                          uint32_t objectformatcode);
+
+USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object);
+
+USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint32_t offset,
+                                           uint32_t maxbytes, uint8_t *object,
+                                           uint32_t *len);
+
+USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
+                                                     uint16_t ofc,
+                                                     uint32_t *propnum, 
+                                                     uint16_t *props);
+
+USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t opc, 
+                                                uint16_t ofc, 
+                                                PTP_ObjectPropDescTypeDef *opd);
+
+USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost,
+                                                uint32_t handle, 
+                                                MTP_PropertiesTypedef *pprops, 
+                                                uint32_t *nrofprops);
+
+USBH_StatusTypeDef USBH_PTP_SendObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object,
+                                           uint32_t size);
+
+USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t propcode, 
+			                      PTP_DevicePropDescTypdef* devicepropertydesc);
+
+/**
+  * @}
+  */ 
+
+#endif  //__USBH_MTP_PTP_H__
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp.c b/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp.c
index d93aa4238c94c4f92e570676d496563b2dc6a900..1d6c1ecc89db0ed002f9b9bb086918185f5b6250 100644
--- a/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp.c
+++ b/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp.c
@@ -1,1065 +1,1065 @@
-/**
-  ******************************************************************************
-  * @file    usbh_mtp.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the MTP Layer Handlers for USB Host MTP class.
-  *
-  * @verbatim
-  *      
-  *          ===================================================================      
-  *                                MTP Class  Description
-  *          =================================================================== 
-  *           This module manages the MSC class V1.11 following the "Device Class Definition
-  *           for Human Interface Devices (MTP) Version 1.11 Jun 27, 2001".
-  *           This driver implements the following aspects of the specification:
-  *             - The Boot Interface Subclass
-  *             - The Mouse and Keyboard protocols
-  *      
-  *  @endverbatim
-  *
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_mtp.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_MTP_CLASS
-* @{
-*/
-
-/** @defgroup USBH_MTP_CORE 
-* @brief    This file includes MTP Layer Handlers for USB Host MTP class.
-* @{
-*/ 
-
-/** @defgroup USBH_MTP_CORE_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_CORE_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_CORE_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_CORE_Private_Variables
-* @{
-*/
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_CORE_Private_FunctionPrototypes
-* @{
-*/ 
-
-static USBH_StatusTypeDef USBH_MTP_InterfaceInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MTP_Process(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost);
-
-static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost);
-
-static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost);
-
-static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost);
-
-static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) ;
-
-USBH_ClassTypeDef  MTP_Class = 
-{
-  "MTP",
-  USB_MTP_CLASS,
-  USBH_MTP_InterfaceInit,
-  USBH_MTP_InterfaceDeInit,
-  USBH_MTP_ClassRequest,
-  USBH_MTP_Process,
-  USBH_MTP_SOFProcess,
-  NULL,
-};
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_CORE_Private_Functions
-* @{
-*/ 
-
-/**
-  * @brief  USBH_MTP_InterfaceInit 
-  *         The function init the MTP class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost)
-{	
-  USBH_StatusTypeDef status = USBH_OK ;
-  uint8_t interface, endpoint;
-  
-  MTP_HandleTypeDef *MTP_Handle;
-  
-  interface = USBH_FindInterface(phost, 
-                                 USB_MTP_CLASS, 
-                                 1, 
-                                 1);
-  
-  if(interface == 0xFF) /* No Valid Interface */
-  {
-    status = USBH_FAIL;  
-    USBH_DbgLog ("Cannot Find the interface for Still Image Class.");         
-  }
-  else
-  {
-    USBH_SelectInterface (phost, interface);
-    
-    endpoint = MTP_FindCtlEndpoint(phost);
-
-    phost->pActiveClass->pData = (MTP_HandleTypeDef *)USBH_malloc (sizeof(MTP_HandleTypeDef));
-    MTP_Handle =  phost->pActiveClass->pData; 
-    
-    if( MTP_Handle == NULL)
-    {
-      status = USBH_FAIL;  
-      USBH_DbgLog ("Cannot allocate RAM for MTP Handle");       
-    }
-    
-    /*Collect the control endpoint address and length*/
-    MTP_Handle->NotificationEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
-    MTP_Handle->NotificationEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
-    MTP_Handle->NotificationPipe = USBH_AllocPipe(phost, MTP_Handle->NotificationEp);
-    MTP_Handle->events.poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bInterval;
-    
-    /* Open pipe for Notification endpoint */
-    USBH_OpenPipe  (phost,
-                    MTP_Handle->NotificationPipe,
-                    MTP_Handle->NotificationEp,                            
-                    phost->device.address,
-                    phost->device.speed,
-                    USB_EP_TYPE_INTR,
-                    MTP_Handle->NotificationEpSize); 
-    
-    USBH_LL_SetToggle (phost, MTP_Handle->NotificationPipe, 0);    
-    
-    
-    endpoint = MTP_FindDataInEndpoint(phost);
-    
-    /*Collect the control endpoint address and length*/
-    MTP_Handle->DataInEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
-    MTP_Handle->DataInEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
-    MTP_Handle->DataInPipe = USBH_AllocPipe(phost, MTP_Handle->DataInEp);
-    
-    /* Open pipe for DATA IN endpoint */
-    USBH_OpenPipe  (phost,
-                    MTP_Handle->DataInPipe,
-                    MTP_Handle->DataInEp,                            
-                    phost->device.address,
-                    phost->device.speed,
-                    USB_EP_TYPE_BULK,
-                    MTP_Handle->DataInEpSize); 
-    
-    USBH_LL_SetToggle (phost, MTP_Handle->DataInPipe, 0);  
-
-    endpoint = MTP_FindDataOutEndpoint(phost);
-    
-    /*Collect the DATA OUT endpoint address and length*/
-    MTP_Handle->DataOutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
-    MTP_Handle->DataOutEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
-    MTP_Handle->DataOutPipe = USBH_AllocPipe(phost, MTP_Handle->DataOutEp);
-
-    /* Open pipe for DATA OUT endpoint */
-    USBH_OpenPipe  (phost,
-                    MTP_Handle->DataOutPipe,
-                    MTP_Handle->DataOutEp,                            
-                    phost->device.address,
-                    phost->device.speed,
-                    USB_EP_TYPE_BULK,
-                    MTP_Handle->DataOutEpSize); 
-    
-    USBH_LL_SetToggle (phost, MTP_Handle->DataOutPipe, 0); 
-    
-      
-  MTP_Handle->state = MTP_OPENSESSION;
-  MTP_Handle->is_ready = 0;
-  MTP_Handle->events.state = MTP_EVENTS_INIT;
-  return USBH_PTP_Init(phost);
-  
-  }
-  return status;
-}
-
-/**
-  * @brief  Find MTP Ctl interface
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost)
-{
-  uint8_t interface, endpoint;
-  
-  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
-  {
-    if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
-    {    
-      for (endpoint = 0;  endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
-      {
-        if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80)&&
-           (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
-             ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_INTERRUPT) == USBH_EP_INTERRUPT))
-        {
-          return endpoint;
-        }
-      }
-    }
-  }
-  
-  return 0xFF; /* Invalid Endpoint */
-}
-
-
-/**
-  * @brief  Find MTP DATA OUT interface
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost)
-{
-  uint8_t interface, endpoint;
-  
-  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
-  {
-    if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
-    {    
-      for (endpoint = 0;  endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
-      {
-
-        if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80) == 0)&&
-           (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
-             ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK))
-        {
-          return endpoint;
-        }
-      }
-    }
-  }
-  
-  return 0xFF; /* Invalid Endpoint */
-}
-
-/**
-  * @brief  Find MTP DATA IN interface
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost)
-{
-  uint8_t interface, endpoint;
-  
-  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
-  {
-    if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
-    {    
-      for (endpoint = 0;  endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
-      {
-        
-        if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80)&&
-           (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
-             ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK))
-        {
-          return endpoint;
-        }
-      }
-    }
-  }
-  
-  return 0xFF; /* Invalid Endpoint */
-}
-
-
-/**
-  * @brief  USBH_MTP_InterfaceDeInit 
-  *         The function DeInit the Pipes used for the MTP class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost)
-{
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  
-  if (MTP_Handle->DataOutPipe)
-  {
-    USBH_ClosePipe(phost, MTP_Handle->DataOutPipe);
-    USBH_FreePipe  (phost, MTP_Handle->DataOutPipe);
-    MTP_Handle->DataOutPipe = 0;     /* Reset the Channel as Free */
-  }
-  
-  if (MTP_Handle->DataInPipe)
-  {
-    USBH_ClosePipe(phost, MTP_Handle->DataInPipe);
-    USBH_FreePipe  (phost, MTP_Handle->DataInPipe);
-    MTP_Handle->DataInPipe = 0;     /* Reset the Channel as Free */
-  } 
-  
-  if (MTP_Handle->NotificationPipe)
-  {
-    USBH_ClosePipe(phost, MTP_Handle->NotificationPipe);
-    USBH_FreePipe  (phost, MTP_Handle->NotificationPipe);
-    MTP_Handle->NotificationPipe = 0;     /* Reset the Channel as Free */
-  } 
-  
-  if(phost->pActiveClass->pData)
-  {
-    USBH_free (phost->pActiveClass->pData);
-    phost->pActiveClass->pData = 0;
-  }
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_MTP_ClassRequest 
-  *         The function is responsible for handling Standard requests
-  *         for MTP class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost)
-{   
-  return USBH_OK;;
-}
-
-
-/**
-  * @brief  USBH_MTP_Process 
-  *         The function is for managing state machine for MTP data transfers 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MTP_Process (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t idx = 0;
-  
-  switch(MTP_Handle->state)
-  {
-  case  MTP_OPENSESSION:
-    
-    status = USBH_PTP_OpenSession (phost, 1); /* Session '0' is not valid */
-    
-    if(status == USBH_OK)
-    {
-      USBH_UsrLog("MTP Session #0 Opened");
-      MTP_Handle->state = MTP_GETDEVICEINFO; 
-    }
-    break;
-    
-  case MTP_GETDEVICEINFO:
-    status = USBH_PTP_GetDeviceInfo (phost, &(MTP_Handle->info.devinfo));
-    
-    if(status == USBH_OK)
-    {
-      USBH_DbgLog(">>>>> MTP Device Information");
-      USBH_DbgLog("Standard version : %x", MTP_Handle->info.devinfo.StandardVersion);
-      USBH_DbgLog("Vendor ExtID : %s", (MTP_Handle->info.devinfo.VendorExtensionID == 6)?"MTP": "NOT SUPPORTED");      
-      USBH_DbgLog("Functional mode : %s", (MTP_Handle->info.devinfo.FunctionalMode == 0) ? "Standard" : "Vendor");
-      USBH_DbgLog("Number of Supported Operation(s) : %d", MTP_Handle->info.devinfo.OperationsSupported_len);
-      USBH_DbgLog("Number of Supported Events(s) : %d", MTP_Handle->info.devinfo.EventsSupported_len);  
-      USBH_DbgLog("Number of Supported Proprieties : %d", MTP_Handle->info.devinfo.DevicePropertiesSupported_len); 
-      USBH_DbgLog("Manufacturer : %s", MTP_Handle->info.devinfo.Manufacturer);
-      USBH_DbgLog("Model : %s", MTP_Handle->info.devinfo.Model);       
-      USBH_DbgLog("Device version : %s", MTP_Handle->info.devinfo.DeviceVersion); 
-      USBH_DbgLog("Serial number : %s", MTP_Handle->info.devinfo.SerialNumber); 
-      
-      MTP_Handle->state = MTP_GETSTORAGEIDS; 
-    }
-    break;
-    
-  case MTP_GETSTORAGEIDS:
-    status = USBH_PTP_GetStorageIds (phost, &(MTP_Handle->info.storids));
-    
-    if(status == USBH_OK)
-    {
-      USBH_DbgLog("Number of storage ID items : %d", MTP_Handle->info.storids.n);
-      for (idx  = 0; idx < MTP_Handle->info.storids.n; idx ++)
-      {
-        USBH_DbgLog("storage#%d ID : %x", idx, MTP_Handle->info.storids.Storage[idx]);
-      }
-      
-      MTP_Handle->current_storage_unit = 0;
-      MTP_Handle->state = MTP_GETSTORAGEINFO; 
-    }
-    break;
-    
-  case MTP_GETSTORAGEINFO:
-    status = USBH_PTP_GetStorageInfo (phost, 
-                                      MTP_Handle->info.storids.Storage[MTP_Handle->current_storage_unit], 
-                                      &((MTP_Handle->info.storinfo)[MTP_Handle->current_storage_unit]));
-    
-    if(status == USBH_OK)
-    {
-      USBH_UsrLog("Volume#%lu: %s   [%s]", MTP_Handle->current_storage_unit,
-                  MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].StorageDescription,
-                  MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].VolumeLabel);
-      if(++MTP_Handle->current_storage_unit >= MTP_Handle->info.storids.n)
-      {
-        MTP_Handle->state = MTP_IDLE;
-        MTP_Handle->is_ready = 1;
-        MTP_Handle->current_storage_unit = 0;
-        MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[0];
-        
-        USBH_UsrLog( "MTP Class initialized.");
-        USBH_UsrLog("%s is default storage unit", MTP_Handle->info.storinfo[0].StorageDescription);
-        phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
-      }
-    }
-    break;
-  
-  case  MTP_IDLE:
-    USBH_MTP_Events(phost);
-  default:
-    status = USBH_OK;
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_SOFProcess 
-  *         The function is for managing SOF callback 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_OK;
-
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_IsReady 
-  *         Select the storage Unit to be used
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-uint8_t USBH_MTP_IsReady (USBH_HandleTypeDef *phost)
-{
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  
-  return (MTP_Handle->is_ready);
-}
-
-/**
-  * @brief  USBH_MTP_GetNumStorage 
-  *         Select the storage Unit to be used
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *storage_num)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  
-  if(MTP_Handle->is_ready > 0)
-  {
-    *storage_num = MTP_Handle->info.storids.n;
-    status  = USBH_OK;
-  }
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_SelectStorage 
-  *         Select the storage Unit to be used
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t storage_idx)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  
-  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
-  {
-      MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[storage_idx];
-      status  = USBH_OK;
-  }
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_GetStorageInfo 
-  *         Get the storage Unit info
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint8_t storage_idx, MTP_StorageInfoTypedef *info)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  
-  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
-  {
-    *info = MTP_Handle->info.storinfo[storage_idx];
-    status  = USBH_OK;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_GetStorageInfo 
-  *         Get the storage Unit info
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_idx, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           uint32_t* numobs)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
-  {
-    while ((status = USBH_PTP_GetNumObjects (phost, 
-                                             MTP_Handle->info.storids.Storage[storage_idx], 
-                                             objectformatcode, 
-                                             associationOH,
-                                             numobs)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
-
-/**
-  * @brief  USBH_MTP_GetStorageInfo 
-  *         Get the storage Unit info
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_idx, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           PTP_ObjectHandlesTypedef* objecthandles)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
-  {  
-    while ((status = USBH_PTP_GetObjectHandles (phost, 
-                                                MTP_Handle->info.storids.Storage[storage_idx], 
-                                                objectformatcode, 
-                                                associationOH,
-                                                objecthandles)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_PTP_GetObjectInfo
-  *         Gets objert info
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           PTP_ObjectInfoTypedef* objectinfo)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetObjectInfo (phost, handle, objectinfo)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-/**
-  * @brief  USBH_MTP_DeleteObject
-  *         Delete an object.
-  * @param  phost: Host handle
-  * @param  handle : Object Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost,
-                                          uint32_t handle,
-                                          uint32_t objectformatcode)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_DeleteObject (phost, handle, objectformatcode)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_GetObject
-  *         Gets object
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetObject (phost, handle, object)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_GetPartialObject
-  *         Gets object
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint32_t offset,
-                                           uint32_t maxbytes, 
-                                           uint8_t *object,
-                                           uint32_t *len)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetPartialObject(phost, 
-                                           handle, 
-                                           offset,
-                                           maxbytes, 
-                                           object,
-                                           len)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_GetObjectPropsSupported
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
-                                                     uint16_t ofc,
-                                                     uint32_t *propnum, 
-                                                     uint16_t *props)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetObjectPropsSupported (phost,
-                                                     ofc,
-                                                     propnum, 
-                                                     props)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_MTP_GetObjectPropDesc
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t opc, 
-                                                uint16_t ofc, 
-                                                PTP_ObjectPropDescTypeDef *opd)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetObjectPropDesc (phost,
-                                                opc, 
-                                                ofc, 
-                                                opd)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status; 
-}
-
-/**
-  * @brief  USBH_MTP_GetObjectPropList
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost,
-                                                uint32_t handle, 
-                                                MTP_PropertiesTypedef *pprops, 
-                                                uint32_t *nrofprops)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetObjectPropList (phost,
-                                                handle, 
-                                                pprops, 
-                                                nrofprops)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status; 
-}
-
-/**
-  * @brief  USBH_MTP_SendObject
-  *         Send an object
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object,
-                                           uint32_t size)
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_SendObject (phost, handle, object, size)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-
- /**
-  * @brief  Handle HID Control process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef status = USBH_BUSY ;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData; 
- 
-  
-  switch(MTP_Handle->events.state)
-  {
-  case MTP_EVENTS_INIT:
-    if((phost->Timer & 1) == 0)
-    {
-      MTP_Handle->events.timer = phost->Timer;
-      USBH_InterruptReceiveData(phost, 
-                                (uint8_t *)&(MTP_Handle->events.container),
-                                MTP_Handle->NotificationEpSize,
-                                MTP_Handle->NotificationPipe);
-      
-      
-     MTP_Handle->events.state = MTP_EVENTS_GETDATA ;
-    }
-    break;
-  case MTP_EVENTS_GETDATA:
-    if(USBH_LL_GetURBState(phost , MTP_Handle->NotificationPipe) == USBH_URB_DONE)
-    {
-      MTP_DecodeEvent(phost);
-    }
-    
-    if(( phost->Timer - MTP_Handle->events.timer) >= MTP_Handle->events.poll)
-    {
-     MTP_Handle->events.timer = phost->Timer;
-      
-      USBH_InterruptReceiveData(phost, 
-                                (uint8_t *)&(MTP_Handle->events.container),
-                                MTP_Handle->NotificationEpSize,
-                                MTP_Handle->NotificationPipe);     
-      
-    }
-    break;
-
-  default:  
-    break; 
-  }
-    
-  return status;  
-}
-
-/**
-  * @brief  MTP_DecodeEvent
-  *         Decode device event sent by responder
-  * @param  phost: Host handle
-  * @retval None
-  */
-static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) 
-{
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData; 
-  
-  uint16_t code;
-  uint32_t param1;
-
-  /* Process the event */
-  code = MTP_Handle->events.container.code;
-  param1 = MTP_Handle->events.container.param1;
-  
- switch(code) 
- {
-    case PTP_EC_Undefined:
-      USBH_DbgLog("EVT: PTP_EC_Undefined in session %u", MTP_Handle->ptp.session_id);
-      break;
-    case PTP_EC_CancelTransaction:
-      USBH_DbgLog("EVT: PTP_EC_CancelTransaction in session %u", MTP_Handle->ptp.session_id);
-      break;
-    case PTP_EC_ObjectAdded:
-      USBH_DbgLog("EVT: PTP_EC_ObjectAdded in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_ObjectRemoved:
-      USBH_DbgLog("EVT: PTP_EC_ObjectRemoved in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_StoreAdded:
-      USBH_DbgLog("EVT: PTP_EC_StoreAdded in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_StoreRemoved:
-      USBH_DbgLog("EVT: PTP_EC_StoreRemoved in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_DevicePropChanged:
-      USBH_DbgLog("EVT: PTP_EC_DevicePropChanged in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_ObjectInfoChanged:
-      USBH_DbgLog("EVT: PTP_EC_ObjectInfoChanged in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_DeviceInfoChanged:
-      USBH_DbgLog("EVT: PTP_EC_DeviceInfoChanged in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_RequestObjectTransfer:
-      USBH_DbgLog("EVT: PTP_EC_RequestObjectTransfer in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_StoreFull:
-      USBH_DbgLog("EVT: PTP_EC_StoreFull in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_DeviceReset:
-      USBH_DbgLog("EVT: PTP_EC_DeviceReset in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_StorageInfoChanged :
-      USBH_DbgLog( "EVT: PTP_EC_StorageInfoChanged in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_CaptureComplete :
-      USBH_DbgLog( "EVT: PTP_EC_CaptureComplete in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    case PTP_EC_UnreportedStatus :
-      USBH_DbgLog( "EVT: PTP_EC_UnreportedStatus in session %u", MTP_Handle->ptp.session_id);
-      break;
-      
-    default :
-      USBH_DbgLog( "Received unknown event in session %u", MTP_Handle->ptp.session_id);
-      break;
-  }
- 
- USBH_MTP_EventsCallback(phost, code, param1);
-}
-
-/**
-  * @brief  USBH_MTP_GetDevicePropDesc
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t propcode, 
-			                        PTP_DevicePropDescTypdef* devicepropertydesc)
-
-{
-  USBH_StatusTypeDef status = USBH_FAIL;
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  uint32_t timeout = phost->Timer + 5000;
-  
-  if(MTP_Handle->is_ready)
-  {   
-    while ((status = USBH_PTP_GetDevicePropDesc (phost, propcode, devicepropertydesc)) == USBH_BUSY)
-    {
-      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
-      {
-        return USBH_FAIL;
-      }
-    }
-  }
-  return status;
-}
-/**
-  * @brief  The function informs that host has rceived an event
-  *  @param  pdev: Selected device
-  * @retval None
-  */
-__weak void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param)
-{
-  
-}
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_mtp.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the MTP Layer Handlers for USB Host MTP class.
+  *
+  * @verbatim
+  *      
+  *          ===================================================================      
+  *                                MTP Class  Description
+  *          =================================================================== 
+  *           This module manages the MSC class V1.11 following the "Device Class Definition
+  *           for Human Interface Devices (MTP) Version 1.11 Jun 27, 2001".
+  *           This driver implements the following aspects of the specification:
+  *             - The Boot Interface Subclass
+  *             - The Mouse and Keyboard protocols
+  *      
+  *  @endverbatim
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_mtp.h"
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_MTP_CLASS
+* @{
+*/
+
+/** @defgroup USBH_MTP_CORE 
+* @brief    This file includes MTP Layer Handlers for USB Host MTP class.
+* @{
+*/ 
+
+/** @defgroup USBH_MTP_CORE_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_CORE_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_CORE_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_CORE_Private_Variables
+* @{
+*/
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_CORE_Private_FunctionPrototypes
+* @{
+*/ 
+
+static USBH_StatusTypeDef USBH_MTP_InterfaceInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MTP_Process(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost);
+
+static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost);
+
+static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost);
+
+static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost);
+
+static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) ;
+
+USBH_ClassTypeDef  MTP_Class = 
+{
+  "MTP",
+  USB_MTP_CLASS,
+  USBH_MTP_InterfaceInit,
+  USBH_MTP_InterfaceDeInit,
+  USBH_MTP_ClassRequest,
+  USBH_MTP_Process,
+  USBH_MTP_SOFProcess,
+  NULL,
+};
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_CORE_Private_Functions
+* @{
+*/ 
+
+/**
+  * @brief  USBH_MTP_InterfaceInit 
+  *         The function init the MTP class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost)
+{	
+  USBH_StatusTypeDef status = USBH_OK ;
+  uint8_t interface, endpoint;
+  
+  MTP_HandleTypeDef *MTP_Handle;
+  
+  interface = USBH_FindInterface(phost, 
+                                 USB_MTP_CLASS, 
+                                 1, 
+                                 1);
+  
+  if(interface == 0xFF) /* No Valid Interface */
+  {
+    status = USBH_FAIL;  
+    USBH_DbgLog ("Cannot Find the interface for Still Image Class.");         
+  }
+  else
+  {
+    USBH_SelectInterface (phost, interface);
+    
+    endpoint = MTP_FindCtlEndpoint(phost);
+
+    phost->pActiveClass->pData = (MTP_HandleTypeDef *)USBH_malloc (sizeof(MTP_HandleTypeDef));
+    MTP_Handle =  phost->pActiveClass->pData; 
+    
+    if( MTP_Handle == NULL)
+    {
+      status = USBH_FAIL;  
+      USBH_DbgLog ("Cannot allocate RAM for MTP Handle");       
+    }
+    
+    /*Collect the control endpoint address and length*/
+    MTP_Handle->NotificationEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
+    MTP_Handle->NotificationEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
+    MTP_Handle->NotificationPipe = USBH_AllocPipe(phost, MTP_Handle->NotificationEp);
+    MTP_Handle->events.poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bInterval;
+    
+    /* Open pipe for Notification endpoint */
+    USBH_OpenPipe  (phost,
+                    MTP_Handle->NotificationPipe,
+                    MTP_Handle->NotificationEp,                            
+                    phost->device.address,
+                    phost->device.speed,
+                    USB_EP_TYPE_INTR,
+                    MTP_Handle->NotificationEpSize); 
+    
+    USBH_LL_SetToggle (phost, MTP_Handle->NotificationPipe, 0);    
+    
+    
+    endpoint = MTP_FindDataInEndpoint(phost);
+    
+    /*Collect the control endpoint address and length*/
+    MTP_Handle->DataInEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
+    MTP_Handle->DataInEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
+    MTP_Handle->DataInPipe = USBH_AllocPipe(phost, MTP_Handle->DataInEp);
+    
+    /* Open pipe for DATA IN endpoint */
+    USBH_OpenPipe  (phost,
+                    MTP_Handle->DataInPipe,
+                    MTP_Handle->DataInEp,                            
+                    phost->device.address,
+                    phost->device.speed,
+                    USB_EP_TYPE_BULK,
+                    MTP_Handle->DataInEpSize); 
+    
+    USBH_LL_SetToggle (phost, MTP_Handle->DataInPipe, 0);  
+
+    endpoint = MTP_FindDataOutEndpoint(phost);
+    
+    /*Collect the DATA OUT endpoint address and length*/
+    MTP_Handle->DataOutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
+    MTP_Handle->DataOutEpSize  = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
+    MTP_Handle->DataOutPipe = USBH_AllocPipe(phost, MTP_Handle->DataOutEp);
+
+    /* Open pipe for DATA OUT endpoint */
+    USBH_OpenPipe  (phost,
+                    MTP_Handle->DataOutPipe,
+                    MTP_Handle->DataOutEp,                            
+                    phost->device.address,
+                    phost->device.speed,
+                    USB_EP_TYPE_BULK,
+                    MTP_Handle->DataOutEpSize); 
+    
+    USBH_LL_SetToggle (phost, MTP_Handle->DataOutPipe, 0); 
+    
+      
+  MTP_Handle->state = MTP_OPENSESSION;
+  MTP_Handle->is_ready = 0;
+  MTP_Handle->events.state = MTP_EVENTS_INIT;
+  return USBH_PTP_Init(phost);
+  
+  }
+  return status;
+}
+
+/**
+  * @brief  Find MTP Ctl interface
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost)
+{
+  uint8_t interface, endpoint;
+  
+  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
+  {
+    if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
+    {    
+      for (endpoint = 0;  endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
+      {
+        if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80)&&
+           (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
+             ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_INTERRUPT) == USBH_EP_INTERRUPT))
+        {
+          return endpoint;
+        }
+      }
+    }
+  }
+  
+  return 0xFF; /* Invalid Endpoint */
+}
+
+
+/**
+  * @brief  Find MTP DATA OUT interface
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost)
+{
+  uint8_t interface, endpoint;
+  
+  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
+  {
+    if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
+    {    
+      for (endpoint = 0;  endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
+      {
+
+        if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80) == 0)&&
+           (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
+             ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK))
+        {
+          return endpoint;
+        }
+      }
+    }
+  }
+  
+  return 0xFF; /* Invalid Endpoint */
+}
+
+/**
+  * @brief  Find MTP DATA IN interface
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost)
+{
+  uint8_t interface, endpoint;
+  
+  for (interface = 0;  interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
+  {
+    if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
+    {    
+      for (endpoint = 0;  endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
+      {
+        
+        if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80)&&
+           (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
+             ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK))
+        {
+          return endpoint;
+        }
+      }
+    }
+  }
+  
+  return 0xFF; /* Invalid Endpoint */
+}
+
+
+/**
+  * @brief  USBH_MTP_InterfaceDeInit 
+  *         The function DeInit the Pipes used for the MTP class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost)
+{
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  
+  if (MTP_Handle->DataOutPipe)
+  {
+    USBH_ClosePipe(phost, MTP_Handle->DataOutPipe);
+    USBH_FreePipe  (phost, MTP_Handle->DataOutPipe);
+    MTP_Handle->DataOutPipe = 0;     /* Reset the Channel as Free */
+  }
+  
+  if (MTP_Handle->DataInPipe)
+  {
+    USBH_ClosePipe(phost, MTP_Handle->DataInPipe);
+    USBH_FreePipe  (phost, MTP_Handle->DataInPipe);
+    MTP_Handle->DataInPipe = 0;     /* Reset the Channel as Free */
+  } 
+  
+  if (MTP_Handle->NotificationPipe)
+  {
+    USBH_ClosePipe(phost, MTP_Handle->NotificationPipe);
+    USBH_FreePipe  (phost, MTP_Handle->NotificationPipe);
+    MTP_Handle->NotificationPipe = 0;     /* Reset the Channel as Free */
+  } 
+  
+  if(phost->pActiveClass->pData)
+  {
+    USBH_free (phost->pActiveClass->pData);
+    phost->pActiveClass->pData = 0;
+  }
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_MTP_ClassRequest 
+  *         The function is responsible for handling Standard requests
+  *         for MTP class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost)
+{   
+  return USBH_OK;;
+}
+
+
+/**
+  * @brief  USBH_MTP_Process 
+  *         The function is for managing state machine for MTP data transfers 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MTP_Process (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t idx = 0;
+  
+  switch(MTP_Handle->state)
+  {
+  case  MTP_OPENSESSION:
+    
+    status = USBH_PTP_OpenSession (phost, 1); /* Session '0' is not valid */
+    
+    if(status == USBH_OK)
+    {
+      USBH_UsrLog("MTP Session #0 Opened");
+      MTP_Handle->state = MTP_GETDEVICEINFO; 
+    }
+    break;
+    
+  case MTP_GETDEVICEINFO:
+    status = USBH_PTP_GetDeviceInfo (phost, &(MTP_Handle->info.devinfo));
+    
+    if(status == USBH_OK)
+    {
+      USBH_DbgLog(">>>>> MTP Device Information");
+      USBH_DbgLog("Standard version : %x", MTP_Handle->info.devinfo.StandardVersion);
+      USBH_DbgLog("Vendor ExtID : %s", (MTP_Handle->info.devinfo.VendorExtensionID == 6)?"MTP": "NOT SUPPORTED");      
+      USBH_DbgLog("Functional mode : %s", (MTP_Handle->info.devinfo.FunctionalMode == 0) ? "Standard" : "Vendor");
+      USBH_DbgLog("Number of Supported Operation(s) : %d", MTP_Handle->info.devinfo.OperationsSupported_len);
+      USBH_DbgLog("Number of Supported Events(s) : %d", MTP_Handle->info.devinfo.EventsSupported_len);  
+      USBH_DbgLog("Number of Supported Proprieties : %d", MTP_Handle->info.devinfo.DevicePropertiesSupported_len); 
+      USBH_DbgLog("Manufacturer : %s", MTP_Handle->info.devinfo.Manufacturer);
+      USBH_DbgLog("Model : %s", MTP_Handle->info.devinfo.Model);       
+      USBH_DbgLog("Device version : %s", MTP_Handle->info.devinfo.DeviceVersion); 
+      USBH_DbgLog("Serial number : %s", MTP_Handle->info.devinfo.SerialNumber); 
+      
+      MTP_Handle->state = MTP_GETSTORAGEIDS; 
+    }
+    break;
+    
+  case MTP_GETSTORAGEIDS:
+    status = USBH_PTP_GetStorageIds (phost, &(MTP_Handle->info.storids));
+    
+    if(status == USBH_OK)
+    {
+      USBH_DbgLog("Number of storage ID items : %d", MTP_Handle->info.storids.n);
+      for (idx  = 0; idx < MTP_Handle->info.storids.n; idx ++)
+      {
+        USBH_DbgLog("storage#%d ID : %x", idx, MTP_Handle->info.storids.Storage[idx]);
+      }
+      
+      MTP_Handle->current_storage_unit = 0;
+      MTP_Handle->state = MTP_GETSTORAGEINFO; 
+    }
+    break;
+    
+  case MTP_GETSTORAGEINFO:
+    status = USBH_PTP_GetStorageInfo (phost, 
+                                      MTP_Handle->info.storids.Storage[MTP_Handle->current_storage_unit], 
+                                      &((MTP_Handle->info.storinfo)[MTP_Handle->current_storage_unit]));
+    
+    if(status == USBH_OK)
+    {
+      USBH_UsrLog("Volume#%lu: %s   [%s]", MTP_Handle->current_storage_unit,
+                  MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].StorageDescription,
+                  MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].VolumeLabel);
+      if(++MTP_Handle->current_storage_unit >= MTP_Handle->info.storids.n)
+      {
+        MTP_Handle->state = MTP_IDLE;
+        MTP_Handle->is_ready = 1;
+        MTP_Handle->current_storage_unit = 0;
+        MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[0];
+        
+        USBH_UsrLog( "MTP Class initialized.");
+        USBH_UsrLog("%s is default storage unit", MTP_Handle->info.storinfo[0].StorageDescription);
+        phost->pUser(phost, HOST_USER_CLASS_ACTIVE); 
+      }
+    }
+    break;
+  
+  case  MTP_IDLE:
+    USBH_MTP_Events(phost);
+  default:
+    status = USBH_OK;
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_SOFProcess 
+  *         The function is for managing SOF callback 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_OK;
+
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_IsReady 
+  *         Select the storage Unit to be used
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+uint8_t USBH_MTP_IsReady (USBH_HandleTypeDef *phost)
+{
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  
+  return (MTP_Handle->is_ready);
+}
+
+/**
+  * @brief  USBH_MTP_GetNumStorage 
+  *         Select the storage Unit to be used
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *storage_num)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  
+  if(MTP_Handle->is_ready > 0)
+  {
+    *storage_num = MTP_Handle->info.storids.n;
+    status  = USBH_OK;
+  }
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_SelectStorage 
+  *         Select the storage Unit to be used
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t storage_idx)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  
+  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
+  {
+      MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[storage_idx];
+      status  = USBH_OK;
+  }
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_GetStorageInfo 
+  *         Get the storage Unit info
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint8_t storage_idx, MTP_StorageInfoTypedef *info)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  
+  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
+  {
+    *info = MTP_Handle->info.storinfo[storage_idx];
+    status  = USBH_OK;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_GetStorageInfo 
+  *         Get the storage Unit info
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_idx, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           uint32_t* numobs)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
+  {
+    while ((status = USBH_PTP_GetNumObjects (phost, 
+                                             MTP_Handle->info.storids.Storage[storage_idx], 
+                                             objectformatcode, 
+                                             associationOH,
+                                             numobs)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+
+/**
+  * @brief  USBH_MTP_GetStorageInfo 
+  *         Get the storage Unit info
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_idx, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           PTP_ObjectHandlesTypedef* objecthandles)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
+  {  
+    while ((status = USBH_PTP_GetObjectHandles (phost, 
+                                                MTP_Handle->info.storids.Storage[storage_idx], 
+                                                objectformatcode, 
+                                                associationOH,
+                                                objecthandles)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_PTP_GetObjectInfo
+  *         Gets objert info
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           PTP_ObjectInfoTypedef* objectinfo)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetObjectInfo (phost, handle, objectinfo)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+/**
+  * @brief  USBH_MTP_DeleteObject
+  *         Delete an object.
+  * @param  phost: Host handle
+  * @param  handle : Object Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost,
+                                          uint32_t handle,
+                                          uint32_t objectformatcode)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_DeleteObject (phost, handle, objectformatcode)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_GetObject
+  *         Gets object
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetObject (phost, handle, object)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_GetPartialObject
+  *         Gets object
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint32_t offset,
+                                           uint32_t maxbytes, 
+                                           uint8_t *object,
+                                           uint32_t *len)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetPartialObject(phost, 
+                                           handle, 
+                                           offset,
+                                           maxbytes, 
+                                           object,
+                                           len)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_GetObjectPropsSupported
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
+                                                     uint16_t ofc,
+                                                     uint32_t *propnum, 
+                                                     uint16_t *props)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetObjectPropsSupported (phost,
+                                                     ofc,
+                                                     propnum, 
+                                                     props)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_MTP_GetObjectPropDesc
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t opc, 
+                                                uint16_t ofc, 
+                                                PTP_ObjectPropDescTypeDef *opd)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetObjectPropDesc (phost,
+                                                opc, 
+                                                ofc, 
+                                                opd)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status; 
+}
+
+/**
+  * @brief  USBH_MTP_GetObjectPropList
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost,
+                                                uint32_t handle, 
+                                                MTP_PropertiesTypedef *pprops, 
+                                                uint32_t *nrofprops)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetObjectPropList (phost,
+                                                handle, 
+                                                pprops, 
+                                                nrofprops)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status; 
+}
+
+/**
+  * @brief  USBH_MTP_SendObject
+  *         Send an object
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object,
+                                           uint32_t size)
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_SendObject (phost, handle, object, size)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+
+ /**
+  * @brief  Handle HID Control process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef status = USBH_BUSY ;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData; 
+ 
+  
+  switch(MTP_Handle->events.state)
+  {
+  case MTP_EVENTS_INIT:
+    if((phost->Timer & 1) == 0)
+    {
+      MTP_Handle->events.timer = phost->Timer;
+      USBH_InterruptReceiveData(phost, 
+                                (uint8_t *)&(MTP_Handle->events.container),
+                                MTP_Handle->NotificationEpSize,
+                                MTP_Handle->NotificationPipe);
+      
+      
+     MTP_Handle->events.state = MTP_EVENTS_GETDATA ;
+    }
+    break;
+  case MTP_EVENTS_GETDATA:
+    if(USBH_LL_GetURBState(phost , MTP_Handle->NotificationPipe) == USBH_URB_DONE)
+    {
+      MTP_DecodeEvent(phost);
+    }
+    
+    if(( phost->Timer - MTP_Handle->events.timer) >= MTP_Handle->events.poll)
+    {
+     MTP_Handle->events.timer = phost->Timer;
+      
+      USBH_InterruptReceiveData(phost, 
+                                (uint8_t *)&(MTP_Handle->events.container),
+                                MTP_Handle->NotificationEpSize,
+                                MTP_Handle->NotificationPipe);     
+      
+    }
+    break;
+
+  default:  
+    break; 
+  }
+    
+  return status;  
+}
+
+/**
+  * @brief  MTP_DecodeEvent
+  *         Decode device event sent by responder
+  * @param  phost: Host handle
+  * @retval None
+  */
+static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) 
+{
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData; 
+  
+  uint16_t code;
+  uint32_t param1;
+
+  /* Process the event */
+  code = MTP_Handle->events.container.code;
+  param1 = MTP_Handle->events.container.param1;
+  
+ switch(code) 
+ {
+    case PTP_EC_Undefined:
+      USBH_DbgLog("EVT: PTP_EC_Undefined in session %u", MTP_Handle->ptp.session_id);
+      break;
+    case PTP_EC_CancelTransaction:
+      USBH_DbgLog("EVT: PTP_EC_CancelTransaction in session %u", MTP_Handle->ptp.session_id);
+      break;
+    case PTP_EC_ObjectAdded:
+      USBH_DbgLog("EVT: PTP_EC_ObjectAdded in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_ObjectRemoved:
+      USBH_DbgLog("EVT: PTP_EC_ObjectRemoved in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_StoreAdded:
+      USBH_DbgLog("EVT: PTP_EC_StoreAdded in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_StoreRemoved:
+      USBH_DbgLog("EVT: PTP_EC_StoreRemoved in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_DevicePropChanged:
+      USBH_DbgLog("EVT: PTP_EC_DevicePropChanged in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_ObjectInfoChanged:
+      USBH_DbgLog("EVT: PTP_EC_ObjectInfoChanged in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_DeviceInfoChanged:
+      USBH_DbgLog("EVT: PTP_EC_DeviceInfoChanged in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_RequestObjectTransfer:
+      USBH_DbgLog("EVT: PTP_EC_RequestObjectTransfer in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_StoreFull:
+      USBH_DbgLog("EVT: PTP_EC_StoreFull in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_DeviceReset:
+      USBH_DbgLog("EVT: PTP_EC_DeviceReset in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_StorageInfoChanged :
+      USBH_DbgLog( "EVT: PTP_EC_StorageInfoChanged in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_CaptureComplete :
+      USBH_DbgLog( "EVT: PTP_EC_CaptureComplete in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    case PTP_EC_UnreportedStatus :
+      USBH_DbgLog( "EVT: PTP_EC_UnreportedStatus in session %u", MTP_Handle->ptp.session_id);
+      break;
+      
+    default :
+      USBH_DbgLog( "Received unknown event in session %u", MTP_Handle->ptp.session_id);
+      break;
+  }
+ 
+ USBH_MTP_EventsCallback(phost, code, param1);
+}
+
+/**
+  * @brief  USBH_MTP_GetDevicePropDesc
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t propcode, 
+			                        PTP_DevicePropDescTypdef* devicepropertydesc)
+
+{
+  USBH_StatusTypeDef status = USBH_FAIL;
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  uint32_t timeout = phost->Timer + 5000;
+  
+  if(MTP_Handle->is_ready)
+  {   
+    while ((status = USBH_PTP_GetDevicePropDesc (phost, propcode, devicepropertydesc)) == USBH_BUSY)
+    {
+      if((phost->Timer > timeout) || (phost->device.is_connected == 0)) 
+      {
+        return USBH_FAIL;
+      }
+    }
+  }
+  return status;
+}
+/**
+  * @brief  The function informs that host has rceived an event
+  *  @param  pdev: Selected device
+  * @retval None
+  */
+__weak void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param)
+{
+  
+}
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp_ptp.c b/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp_ptp.c
index dd5a293e6c829899fe5fe0c64b6d5f4c97ac70fb..512393c05a1399358de339583ebfb1769c6fe84e 100644
--- a/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp_ptp.c
+++ b/micropython/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp_ptp.c
@@ -1,1769 +1,1769 @@
-/**
-  ******************************************************************************
-  * @file    usbh_mtp_ptp.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file includes the PTP operations layer
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_mtp_ptp.h"
-#include "usbh_mtp.h"
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_MTP_CLASS
-* @{
-*/
-
-/** @defgroup USBH_MTP_PTP
-* @brief    This file includes the mass storage related functions
-* @{
-*/ 
-
-
-/** @defgroup USBH_MTP_PTP_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MTP_PTP_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_MTP_PTP_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_PTP_Private_Variables
-* @{
-*/ 
-
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_PTP_Private_FunctionPrototypes
-* @{
-*/ 
-static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
-static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids);
-static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info);
-static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen);
-static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
-static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, 
-                                   uint32_t *offset, 
-                                   uint32_t total, 
-                                   PTP_PropertyValueTypedef* value, 
-                                   uint16_t datatype);
-
-static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, 
-                                       MTP_PropertiesTypedef *props, 
-                                       uint32_t len);
-
-
-static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost);
-static void PTP_GetString(uint8_t *str, uint8_t* data, uint16_t *len);
-static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset);
-static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset);
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_PTP_Exported_Variables
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_MTP_PTP_Private_Functions
-* @{
-*/ 
-/**
-  * @brief  USBH_PTP_Init 
-  *         The function Initializes the BOT protocol.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost)
-{
-  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
-  
-  /* Set state to idle to be ready for operations */
-  MTP_Handle->ptp.state = PTP_IDLE;
-  MTP_Handle->ptp.req_state = PTP_REQ_SEND;
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_PTP_Process 
-  *         The function handle the BOT protocol.
-  * @param  phost: Host handle
-  * @param  lun: Logical Unit Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY;
-  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;  
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;  
-  uint32_t  len;
-  
-  switch (MTP_Handle->ptp.state)
-  {
-  case PTP_IDLE:
-    /*Do Nothing */
-    break;
-    
-  case PTP_OP_REQUEST_STATE:  
-    USBH_BulkSendData (phost,
-                       (uint8_t*)&(MTP_Handle->ptp.op_container),
-                       MTP_Handle->ptp.op_container.length, 
-                       MTP_Handle->DataOutPipe,
-                       1);
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_WAIT_STATE;
-    break;
-    
-  case PTP_OP_REQUEST_WAIT_STATE:
-    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe);
-    
-    if(URB_Status == USBH_URB_DONE)
-    {
-       if(MTP_Handle->ptp.flags == PTP_DP_NODATA)
-       {
-         MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
-       }
-       else  if(MTP_Handle->ptp.flags == PTP_DP_SENDDATA)
-       {
-         MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE;
-       }
-       else  if(MTP_Handle->ptp.flags == PTP_DP_GETDATA)
-       {
-         MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_STATE;
-       }
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif  
-    }
-    else if(URB_Status == USBH_URB_NOTREADY)
-    {
-      /* Re-send Request */
-      MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }     
-    else if(URB_Status == USBH_URB_STALL)
-    {
-      MTP_Handle->ptp.state  = PTP_ERROR;
-#if (USBH_USE_OS == 1)
-     osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif 
-    }
-    break;
-    
-  case PTP_DATA_OUT_PHASE_STATE:
-    
-    USBH_BulkSendData (phost,
-                       MTP_Handle->ptp.data_ptr,
-                       MTP_Handle->DataOutEpSize , 
-                       MTP_Handle->DataOutPipe,
-                       1);
-    
-    
-    MTP_Handle->ptp.state  = PTP_DATA_OUT_PHASE_WAIT_STATE;    
-    break;
-    
-  case PTP_DATA_OUT_PHASE_WAIT_STATE:
-    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe);     
-    
-    if(URB_Status == USBH_URB_DONE)
-    {
-      /* Adjudt Data pointer and data length */
-      if(MTP_Handle->ptp.data_length > MTP_Handle->DataOutEpSize)
-      {
-        MTP_Handle->ptp.data_ptr += MTP_Handle->DataOutEpSize;
-        MTP_Handle->ptp.data_length -= MTP_Handle->DataOutEpSize; 
-        MTP_Handle->ptp.data_packet += MTP_Handle->DataOutEpSize;
-        
-        if(MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ)
-        {
-          PTP_BufferFullCallback (phost);
-          MTP_Handle->ptp.data_packet = 0;
-          MTP_Handle->ptp.iteration++;            
-        }
-        
-      }
-      else
-      {
-        MTP_Handle->ptp.data_length = 0;
-      } 
-      
-      /* More Data To be Sent */
-      if(MTP_Handle->ptp.data_length > 0)
-      {
-        USBH_BulkSendData (phost,
-                           MTP_Handle->ptp.data_ptr,
-                           MTP_Handle->DataOutEpSize , 
-                           MTP_Handle->DataOutPipe,
-                           1);
-      }
-      else
-      {
-        /* If value was 0, and successful transfer, then change the state */
-        MTP_Handle->ptp.state  = PTP_RESPONSE_STATE;
-      }  
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    
-    else if(URB_Status == USBH_URB_NOTREADY)
-    {
-      /* Re-send same data */      
-      MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    
-    else if(URB_Status == USBH_URB_STALL)
-    {
-      MTP_Handle->ptp.state  = PTP_ERROR;    
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case PTP_DATA_IN_PHASE_STATE:
-    /* Send first packet */        
-    USBH_BulkReceiveData (phost,
-                          MTP_Handle->ptp.data_ptr, 
-                          MTP_Handle->DataInEpSize, 
-                          MTP_Handle->DataInPipe);
-    
-    MTP_Handle->ptp.state  = PTP_DATA_IN_PHASE_WAIT_STATE;    
-    break;
-    
-  case PTP_DATA_IN_PHASE_WAIT_STATE:
-    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe);
-    
-    if(URB_Status == USBH_URB_DONE)
-    {
-      len = USBH_LL_GetLastXferSize (phost, MTP_Handle->DataInPipe);
-      
-      if( MTP_Handle->ptp.data_packet_counter++ == 0)
-      {
-        /* This is the first packet; so retrieve exact data length from payload */ 
-        MTP_Handle->ptp.data_length = *(uint32_t*)(MTP_Handle->ptp.data_ptr);
-        MTP_Handle->ptp.iteration = 0;
-      }
-      
-      if((len >=  MTP_Handle->DataInEpSize) && (MTP_Handle->ptp.data_length > 0))
-      {
-        MTP_Handle->ptp.data_ptr += len;
-        MTP_Handle->ptp.data_length -= len;
-        MTP_Handle->ptp.data_packet += len;
-
-        if(MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ)
-        {
-          PTP_BufferFullCallback (phost);
-          MTP_Handle->ptp.data_packet = 0;
-          MTP_Handle->ptp.iteration++;            
-        }
-        
-        /* Continue receiving data*/        
-        USBH_BulkReceiveData (phost,
-                              MTP_Handle->ptp.data_ptr, 
-                              MTP_Handle->DataInEpSize, 
-                              MTP_Handle->DataInPipe);
-      }
-      else
-      {
-        MTP_Handle->ptp.data_length -= len;
-        MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif          
-      }
-    }
-    else if(URB_Status == USBH_URB_STALL)     
-    {
-      MTP_Handle->ptp.state  = PTP_ERROR;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case PTP_RESPONSE_STATE:
-    
-    USBH_BulkReceiveData (phost,
-                          (uint8_t*)&(MTP_Handle->ptp.resp_container), 
-                          PTP_USB_BULK_REQ_RESP_MAX_LEN , 
-                          MTP_Handle->DataInPipe);
-    
-    MTP_Handle->ptp.state  = PTP_RESPONSE_WAIT_STATE;
-    break;
-    
-  case PTP_RESPONSE_WAIT_STATE:
-    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe);
-    
-    if(URB_Status == USBH_URB_DONE)
-    {
-       USBH_PTP_GetResponse (phost, &ptp_container);
-       
-       if(ptp_container.Code == PTP_RC_OK)
-       {
-         status = USBH_OK;
-       }
-       else
-       {
-         status = USBH_FAIL;
-       }
-       MTP_Handle->ptp.req_state = PTP_REQ_SEND;
-    }
-    else if(URB_Status == USBH_URB_STALL)     
-    {
-      MTP_Handle->ptp.state  = PTP_ERROR;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case PTP_ERROR:
-      MTP_Handle->ptp.req_state = PTP_REQ_SEND;
-      break;
-      
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_PTP_OpenSession
-  *         Open a new session
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *req)
-{
-  USBH_StatusTypeDef            status = USBH_OK; 
-  MTP_HandleTypeDef             *MTP_Handle =  phost->pActiveClass->pData; 
-  
-  /* Clear PTP Data container*/
-  USBH_memset(&(MTP_Handle->ptp.op_container), 0, sizeof(PTP_OpContainerTypedef));
-  
-  /* build appropriate USB container */
-  MTP_Handle->ptp.op_container.length = PTP_USB_BULK_REQ_LEN- (sizeof(uint32_t)*(5-req->Nparam));
-  MTP_Handle->ptp.op_container.type = PTP_USB_CONTAINER_COMMAND;
-  MTP_Handle->ptp.op_container.code = req->Code;
-  MTP_Handle->ptp.op_container.trans_id = req->Transaction_ID;
-  MTP_Handle->ptp.op_container.param1 = req->Param1;
-  MTP_Handle->ptp.op_container.param2 = req->Param2;
-  MTP_Handle->ptp.op_container.param3 = req->Param3;
-  MTP_Handle->ptp.op_container.param4 = req->Param4;
-  MTP_Handle->ptp.op_container.param5 = req->Param5;
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_PTP_OpenSession
-  *         Open a new session
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *resp)
-{
-  USBH_StatusTypeDef            status = USBH_OK; 
-  MTP_HandleTypeDef             *MTP_Handle =  phost->pActiveClass->pData; 
-      
-  /* build an appropriate PTPContainer */
-  resp->Code = MTP_Handle->ptp.resp_container.code;
-  resp->SessionID = MTP_Handle->ptp.session_id;
-  resp->Transaction_ID = MTP_Handle->ptp.resp_container.trans_id;
-  resp->Param1 = MTP_Handle->ptp.resp_container.param1;
-  resp->Param2 = MTP_Handle->ptp.resp_container.param2;
-  resp->Param3 = MTP_Handle->ptp.resp_container.param3;
-  resp->Param4 = MTP_Handle->ptp.resp_container.param4;
-  resp->Param5 = MTP_Handle->ptp.resp_container.param5;
-  
-  return status;
-}
-
-/**
-  * @brief  The function informs user that data buffer is full
-  *  @param  phost: host handle
-  * @retval None
-  */
-void PTP_BufferFullCallback(USBH_HandleTypeDef *phost)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  
-  switch (MTP_Handle->ptp.data_container.code)
-  {
-  case PTP_OC_GetDeviceInfo:
-    PTP_DecodeDeviceInfo (phost, &(MTP_Handle->info.devinfo));
-    break;
-    
-  case PTP_OC_GetPartialObject:    
-  case PTP_OC_GetObject:
-
-    /* first packet is in the PTP data payload buffer */
-    if(MTP_Handle->ptp.iteration == 0)
-    {
-       /* copy it to object */
-       USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ);
-       
-       /* next packet should be directly copied to object */
-       MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); 
-    }
-    break;
-
-  case PTP_OC_SendObject:    
-    /* first packet is in the PTP data payload buffer */
-    if(MTP_Handle->ptp.iteration == 0)
-    {
-       /* next packet should be directly copied to object */
-       MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); 
-    }
-    break;    
-    
-  default:
-    break;
-    
-    
-  }
-}
-
-/**
-  * @brief  PTP_GetDeviceInfo
-  *         Gets device info dataset and fills deviceinfo structure.
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval None
-  */
-static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-  uint32_t totallen; 
-  uint16_t len;
-  
-  /* Max device info is PTP_USB_BULK_HS_MAX_PACKET_LEN_READ */
-  USBH_DbgLog (" MTP device info size exceeds internal buffer size.\
-               only available data are decoded.");
-                   
-  if(MTP_Handle->ptp.iteration == 0)
-  {
-    dev_info->StandardVersion = LE16(&data[PTP_di_StandardVersion]);
-    dev_info->VendorExtensionID = LE32(&data[PTP_di_VendorExtensionID]);
-    dev_info->VendorExtensionVersion = LE16(&data[PTP_di_VendorExtensionVersion]);
-    PTP_GetString(dev_info->VendorExtensionDesc, &data[PTP_di_VendorExtensionDesc], &len);
-    
-    totallen=len*2+1;
-    dev_info->FunctionalMode = LE16(&data[PTP_di_FunctionalMode+totallen]);
-    dev_info->OperationsSupported_len = PTP_GetArray16 ((uint16_t *)&dev_info->OperationsSupported, 
-                                                      data, 
-                                                      PTP_di_OperationsSupported+totallen);
-    
-    totallen=totallen+dev_info->OperationsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
-    dev_info->EventsSupported_len = PTP_GetArray16 ((uint16_t *)&dev_info->EventsSupported, 
-                                                      data, 
-                                                      PTP_di_OperationsSupported+totallen);
-    
-    totallen=totallen+dev_info->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
-    dev_info->DevicePropertiesSupported_len = PTP_GetArray16 ((uint16_t *)&dev_info->DevicePropertiesSupported, 
-                                                      data, 
-                                                      PTP_di_OperationsSupported+totallen);
-      
-    totallen=totallen+dev_info->DevicePropertiesSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
-      
-    dev_info->CaptureFormats_len = PTP_GetArray16 ((uint16_t *)&dev_info->CaptureFormats, 
-                                                      data, 
-                                                      PTP_di_OperationsSupported+totallen);
-      
-    totallen=totallen+dev_info->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_t);
-    dev_info->ImageFormats_len =  PTP_GetArray16 ((uint16_t *)&dev_info->ImageFormats, 
-                                                      data, 
-                                                      PTP_di_OperationsSupported+totallen);
-      
-    totallen=totallen+dev_info->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t); 
-    PTP_GetString(dev_info->Manufacturer, &data[PTP_di_OperationsSupported+totallen], &len);
-
-    totallen+=len*2+1;
-    PTP_GetString(dev_info->Model, &data[PTP_di_OperationsSupported+totallen], &len);
-    
-    totallen+=len*2+1;
-    PTP_GetString(dev_info->DeviceVersion, &data[PTP_di_OperationsSupported+totallen], &len);
-
-    totallen+=len*2+1;
-    PTP_GetString(dev_info->SerialNumber, &data[PTP_di_OperationsSupported+totallen], &len);
-  }
-}
-                 
-/**
-  * @brief  PTP_GetStorageIDs
-  *         Gets Storage Ids and fills stor_ids structure.
-  * @param  phost: Host handle
-  * @param  stor_ids: Storage IDsstructure
-  * @retval None
-  */
-static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-
-  stor_ids->n = PTP_GetArray32 (stor_ids->Storage, data, 0); 
-}
-
-                                  
-/**
-  * @brief  PTP_GetStorageInfo
-  *         Gets Storage Info and fills stor_info structure.
-  * @param  phost: Host handle
-  * @param  stor_ids: Storage IDsstructure
-  * @retval None
-  */
-static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-
-  uint16_t len;
-  
-  stor_info->StorageType=LE16(&data[PTP_si_StorageType]);
-  stor_info->FilesystemType=LE16(&data[PTP_si_FilesystemType]);
-  stor_info->AccessCapability=LE16(&data[PTP_si_AccessCapability]);
-  stor_info->MaxCapability=LE64(&data[PTP_si_MaxCapability]);
-  stor_info->FreeSpaceInBytes=LE64(&data[PTP_si_FreeSpaceInBytes]);
-  stor_info->FreeSpaceInImages=LE32(&data[PTP_si_FreeSpaceInImages]);
-  
-  PTP_GetString(stor_info->StorageDescription, &data[PTP_si_StorageDescription], &len);
-  PTP_GetString(stor_info->VolumeLabel, &data[PTP_si_StorageDescription+len*2+1], &len);   
-}
-
-/**
-  * @brief  PTP_GetObjectInfo
-  *         Gets objectInfo and fills object_info structure.
-  * @param  phost: Host handle
-  * @param  object_info: object info structure
-  * @retval None
-  */
-static void PTP_GetObjectInfo (USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-  uint16_t filenamelen;
-  
-  object_info->StorageID=LE32(&data[PTP_oi_StorageID]);
-  object_info->ObjectFormat=LE16(&data[PTP_oi_ObjectFormat]);
-  object_info->ProtectionStatus=LE16(&data[PTP_oi_ProtectionStatus]);
-  object_info->ObjectCompressedSize=LE32(&data[PTP_oi_ObjectCompressedSize]);
-  
-  /* For Samsung Galaxy */
-  if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)) 
-  {
-    data += 4;
-  }
-  object_info->ThumbFormat=LE16(&data[PTP_oi_ThumbFormat]);
-  object_info->ThumbCompressedSize=LE32(&data[PTP_oi_ThumbCompressedSize]);
-  object_info->ThumbPixWidth=LE32(&data[PTP_oi_ThumbPixWidth]);
-  object_info->ThumbPixHeight=LE32(&data[PTP_oi_ThumbPixHeight]);
-  object_info->ImagePixWidth=LE32(&data[PTP_oi_ImagePixWidth]);
-  object_info->ImagePixHeight=LE32(&data[PTP_oi_ImagePixHeight]);
-  object_info->ImageBitDepth=LE32(&data[PTP_oi_ImageBitDepth]);
-  object_info->ParentObject=LE32(&data[PTP_oi_ParentObject]);
-  object_info->AssociationType=LE16(&data[PTP_oi_AssociationType]);
-  object_info->AssociationDesc=LE32(&data[PTP_oi_AssociationDesc]);
-  object_info->SequenceNumber=LE32(&data[PTP_oi_SequenceNumber]);
-  PTP_GetString(object_info->Filename, &data[PTP_oi_filenamelen], &filenamelen);
-}
-
-                 
-/**
-  * @brief  PTP_GetObjectPropDesc
-  *         Gets objectInfo and fills object_info structure.
-  * @param  phost: Host handle
-  * @param  opd: object prop descriptor structure
-  * @retval None
-  */
-static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-  uint32_t offset = 0, i;
-  
-  opd->ObjectPropertyCode=LE16(&data[PTP_opd_ObjectPropertyCode]);
-  opd->DataType=LE16(&data[PTP_opd_DataType]);
-  opd->GetSet=*(uint8_t *)(&data[PTP_opd_GetSet]);
-  
-  offset = PTP_opd_FactoryDefaultValue;
-  PTP_GetDevicePropValue (phost, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType);
-  
-  opd->GroupCode=LE32(&data[offset]);
-  offset+=sizeof(uint32_t);
-  
-  opd->FormFlag=*(uint8_t *)(&data[offset]);
-  offset+=sizeof(uint8_t);
-  
-  switch (opd->FormFlag) 
-  {
-  case PTP_OPFF_Range:
-    PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType);
-    PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType);
-    PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType);
-    break;
-    
-  case PTP_OPFF_Enumeration:
-    
-    opd->FORM.Enum.NumberOfValues = LE16(&data[offset]);
-    offset+=sizeof(uint16_t);
-    
-    for (i=0 ; i < opd->FORM.Enum.NumberOfValues ; i++) 
-    {
-      PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType);
-    }
-    break;
-  default:
-    break;
-  }
-}
-                 
-/**
-  * @brief  PTP_GetDevicePropValue
-  *         Gets objectInfo and fills object_info structure.
-  * @param  phost: Host handle
-  * @param  opd: object prop descriptor structure
-  * @retval None
-  */             
-static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, 
-                                   uint32_t *offset, 
-                                   uint32_t total, 
-                                   PTP_PropertyValueTypedef* value, 
-                                   uint16_t datatype)
-{
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-  uint16_t len;
-  switch (datatype) 
-  {
-  case PTP_DTC_INT8:
-    value->i8 = *(uint8_t *)&(data[*offset]);
-    *offset += 1;
-    break;
-  case PTP_DTC_UINT8:
-    value->u8 = *(uint8_t *)&(data[*offset]);
-    *offset += 1;                
-    break;
-  case PTP_DTC_INT16:
-    
-    value->i16 = LE16(&(data[*offset]));
-    *offset += 2;                
-    break;
-  case PTP_DTC_UINT16:
-    value->u16 = LE16(&(data[*offset]));                
-    *offset += 2;                
-    break;
-  case PTP_DTC_INT32:
-    value->i32 = LE32(&(data[*offset]));              
-    *offset += 4;                
-    break;
-  case PTP_DTC_UINT32:
-    value->u32 = LE32(&(data[*offset]));             
-    *offset += 4;                
-    break;
-  case PTP_DTC_INT64:
-    value->i64 = LE64(&(data[*offset]));            
-    *offset += 8;                
-    break;
-  case PTP_DTC_UINT64:
-    value->u64 = LE64(&(data[*offset]));              
-    *offset += 8;                
-    break;
-    
-  case PTP_DTC_UINT128:
-    *offset += 16;
-    break;
-  case PTP_DTC_INT128:
-    *offset += 16;
-    break;
- 
-  case PTP_DTC_STR:
-    
-    PTP_GetString((uint8_t *)value->str, (uint8_t *)&(data[*offset]), &len);
-    *offset += len*2+1;
-    break;
-  default:
-    break;
-  }
-}
-
-                 
-/**
-  * @brief  PTP_GetDevicePropValue
-  *         Gets objectInfo and fills object_info structure.
-  * @param  phost: Host handle
-  * @param  opd: object prop descriptor structure
-  * @retval None
-  */             
-static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, 
-                                   MTP_PropertiesTypedef *props, 
-                                   uint32_t len)
-{ 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
-  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
-  uint32_t prop_count;
-  uint32_t offset = 0, i;
-  
- prop_count = LE32(data);
-
- 
- if (prop_count == 0) 
- {
-   return 0;
- }
-
- data += sizeof(uint32_t);
- len -= sizeof(uint32_t);
- 
- for (i = 0; i < prop_count; i++) 
- {
-   if (len <= 0) 
-   {
-     return 0;
-   }
-   
-   props[i].ObjectHandle = LE32(data);
-   data += sizeof(uint32_t);
-   len -= sizeof(uint32_t);
-   
-   props[i].property = LE16(data);
-   data += sizeof(uint16_t);
-   len -= sizeof(uint16_t);
-   
-   props[i].datatype = LE16(data);
-   data += sizeof(uint16_t);
-   len -= sizeof(uint16_t);
-   
-   offset = 0;
-   
-   PTP_GetDevicePropValue(phost, &offset, len, &props[i].propval, props[i].datatype);
-   
-   data += offset;
-   len -= offset;
- }
- 
- return prop_count;
-}
-                 
-/**
-  * @brief  PTP_GetString
-  *         Gets SCII String from.
-  * @param  str: ascii string
-  * @param  data: Device info structure
-  * @retval None
-  */
-static void PTP_GetString (uint8_t *str, uint8_t* data, uint16_t *len)
-{
-  uint16_t strlength;
-  uint16_t idx;
-  
-  *len = data[0];
-  strlength = 2 * data[0]; 
-  data ++; /* Adjust the offset ignoring the String Len */
-  
-  for (idx = 0; idx < strlength; idx+=2 )
-  {
-    /* Copy Only the string and ignore the UNICODE ID, hence add the src */
-    *str =  data[idx];
-    str++;
-  }  
-  *str = 0; /* mark end of string */  
-}
-  
-/**
-  * @brief  PTP_GetString
-  *         Gets SCII String from.
-  * @param  str: ascii string
-  * @param  data: Device info structure
-  * @retval None
-  */              
-
-static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset)
-{
-  uint32_t size, idx = 0;
-  
-  size=LE32(&data[offset]);
-  while (size > idx) 
-  {
-    array[idx] = LE16(&data[offset+(sizeof(uint16_t)*(idx+2))]);
-    idx++;
-  }
-  return size;
-}
-
-/**
-  * @brief  PTP_GetString
-  *         Gets SCII String from.
-  * @param  str: ascii string
-  * @param  data: Device info structure
-  * @retval None
-  */              
-
-static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset)
-{
-  uint32_t size, idx = 0;
-  
-  size=LE32(&data[offset]);
-  while (size > idx) 
-  {
-    array[idx] = LE32(&data[offset+(sizeof(uint32_t)*(idx+1))]);
-    idx++;
-  }
-  return size;
-}
-
-/*******************************************************************************
-                             
-                          PTP Requests
-
-*******************************************************************************/
-/**
-  * @brief  USBH_PTP_OpenSession
-  *         Open a new session
-  * @param  phost: Host handle
-  * @param  session: Session ID (MUST BE > 0)
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t session)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Init session params */
-    MTP_Handle->ptp.transaction_id = 0x00000000;
-    MTP_Handle->ptp.session_id = session;
-    MTP_Handle->ptp.flags = PTP_DP_NODATA;
-    
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_OpenSession;
-    ptp_container.SessionID = session;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = session;
-    ptp_container.Nparam = 1;
-    
-    /* convert request packet inti USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_PTP_GetDevicePropDesc
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t propcode, 
-			PTP_DevicePropDescTypdef* devicepropertydesc)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  uint8_t               *data = MTP_Handle->ptp.data_container.payload.data;
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetDevicePropDesc;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = propcode;     
-    ptp_container.Nparam = 1;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-	devicepropertydesc->DevicePropertyCode = LE16(&data[PTP_dpd_DevicePropertyCode]);
-	devicepropertydesc->DataType = LE16(&data[PTP_dpd_DataType]);
-	devicepropertydesc->GetSet = *(uint8_t *)(&data[PTP_dpd_GetSet]);
-	devicepropertydesc->FormFlag =  PTP_DPFF_None;
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-/**
-  * @brief  USBH_PTP_GetDeviceInfo
-  *         Gets device info dataset and fills deviceinfo structure.
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetDeviceInfo;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Nparam = 0;
-    
-    /* convert request packet inti USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-       PTP_DecodeDeviceInfo (phost, dev_info);
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_PTP_GetStorageIds
-  *         Gets device info dataset and fills deviceinfo structure.
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetStorageIDs;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Nparam = 0;
-    
-    /* convert request packet inti USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      PTP_GetStorageIDs (phost, storage_ids);
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetDeviceInfo
-  *         Gets device info dataset and fills deviceinfo structure.
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *storage_info)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetStorageInfo;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = storage_id;    
-    ptp_container.Nparam = 1;
-    
-    /* convert request packet inti USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      PTP_GetStorageInfo (phost, storage_id, storage_info);
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetNumObjects
-  *         Gets device info dataset and fills deviceinfo structure.
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_id, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           uint32_t* numobs)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_NODATA;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetNumObjects;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = storage_id;  
-    ptp_container.Param2 = objectformatcode;
-    ptp_container.Param3 = associationOH;    
-    ptp_container.Nparam = 3;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      *numobs = MTP_Handle->ptp.resp_container.param1;
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_PTP_GetObjectHandles
-  *         Gets device info dataset and fills deviceinfo structure.
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
-                                           uint32_t storage_id, 
-                                           uint32_t objectformatcode, 
-                                           uint32_t associationOH,
-                                           PTP_ObjectHandlesTypedef* objecthandles)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetObjectHandles;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = storage_id;  
-    ptp_container.Param2 = objectformatcode;
-    ptp_container.Param3 = associationOH;    
-    ptp_container.Nparam = 3;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-       objecthandles->n = PTP_GetArray32 (objecthandles->Handler, 
-                                          MTP_Handle->ptp.data_container.payload.data, 
-                                          0); 
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetObjectInfo
-  *         Gets objert info
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           PTP_ObjectInfoTypedef* object_info)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetObjectInfo;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = handle;  
-    ptp_container.Nparam = 1;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-       PTP_GetObjectInfo (phost, object_info);
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_DeleteObject
-  *         Delete an object.
-  * @param  phost: Host handle
-  * @param  handle : Object Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost,
-                                          uint32_t handle,
-                                          uint32_t objectformatcode)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_NODATA;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_DeleteObject;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = handle;  
-    ptp_container.Param2 = objectformatcode;
-    ptp_container.Nparam = 2;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetObject
-  *         Gets object
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-    
-    /* set object control params */
-    MTP_Handle->ptp.object_ptr = object;
-    
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetObject;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = handle;  
-    ptp_container.Nparam = 1;
-
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      /* first packet is in the PTP data payload buffer */
-      if(MTP_Handle->ptp.iteration == 0)
-      {
-        /* copy it to object */
-        USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ);
-      }
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetPartialObject
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint32_t offset,
-                                           uint32_t maxbytes, 
-                                           uint8_t *object,
-                                           uint32_t *len)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-
-    /* set object control params */
-    MTP_Handle->ptp.object_ptr = object;
-    
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetPartialObject;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = handle;  
-    ptp_container.Param2 = offset;
-    ptp_container.Param3 = maxbytes;   
-    ptp_container.Nparam = 3;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      *len = MTP_Handle->ptp.resp_container.param1;
-      /* first packet is in the PTP data payload buffer */
-      if(MTP_Handle->ptp.iteration == 0)
-      {
-        /* copy it to object */
-        USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, *len);
-      }      
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetObjectPropsSupported
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
-                                                     uint16_t ofc,
-                                                     uint32_t *propnum, 
-                                                     uint16_t *props)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetObjectPropsSupported;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = ofc;  
-    ptp_container.Nparam = 1;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      *propnum = PTP_GetArray16 (props, MTP_Handle->ptp.data_container.payload.data, 0);      
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetObjectPropDesc
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
-                                                uint16_t opc, 
-                                                uint16_t ofc, 
-                                                PTP_ObjectPropDescTypeDef *opd)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetObjectPropDesc;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = opc;  
-    ptp_container.Param2 = ofc;      
-    ptp_container.Nparam = 2;
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-     PTP_GetObjectPropDesc(phost, opd, MTP_Handle->ptp.data_length);
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-                 
-/**
-  * @brief  USBH_PTP_GetObjectPropList
-  *         Gets object partially
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost,
-                                                uint32_t handle, 
-                                                MTP_PropertiesTypedef *pprops, 
-                                                uint32_t *nrofprops)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_length = 0;
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-   
-    /* copy first packet of the object into data container */
-    USBH_memcpy(MTP_Handle->ptp.data_container.payload.data, MTP_Handle->ptp.object_ptr, PTP_USB_BULK_PAYLOAD_LEN_READ);
-       
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_GetObjPropList;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Param1 = handle;  
-    ptp_container.Param2 = 0x00000000U;  /* 0x00000000U should be "all formats" */
-    ptp_container.Param3 = 0xFFFFFFFFU;  /* 0xFFFFFFFFU should be "all properties" */
-    ptp_container.Param4 = 0x00000000U;
-    ptp_container.Param5 = 0xFFFFFFFFU;  /* Return full tree below the Param1 handle */
-    ptp_container.Nparam = 5;  
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    
-    if(status == USBH_OK)
-    {
-      PTP_GetObjectPropList (phost, pprops,  MTP_Handle->ptp.data_length);
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-               
-/**
-  * @brief  USBH_PTP_SendObject
-  *         Send an object
-  * @param  phost: Host handle
-  * @param  dev_info: Device info structure
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_PTP_SendObject (USBH_HandleTypeDef *phost, 
-                                           uint32_t handle, 
-                                           uint8_t *object,
-                                           uint32_t size)
-{
-  USBH_StatusTypeDef   status = USBH_BUSY; 
-  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
-  PTP_ContainerTypedef  ptp_container;
-  
-  switch(MTP_Handle->ptp.req_state)
-  {
-  case PTP_REQ_SEND:
-
-    /* Set operation request type */
-    MTP_Handle->ptp.flags = PTP_DP_SENDDATA;
-    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
-    MTP_Handle->ptp.data_packet_counter = 0;
-    MTP_Handle->ptp.data_packet = 0;
-    MTP_Handle->ptp.iteration = 0;
-    
-    /* set object control params */
-    MTP_Handle->ptp.object_ptr = object;
-    MTP_Handle->ptp.data_length = size;    
-    
-    /* Fill operation request params */      
-    ptp_container.Code = PTP_OC_SendObject;
-    ptp_container.SessionID = MTP_Handle->ptp.session_id;
-    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
-    ptp_container.Nparam = 0;
-
-    
-    /* convert request packet into USB raw packet*/
-    USBH_PTP_SendRequest (phost, &ptp_container); 
-        
-    /* Setup State machine and start transfer */
-    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
-    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
-    status = USBH_BUSY; 
-    break;
-    
-  case PTP_REQ_WAIT:
-    status = USBH_PTP_Process(phost);
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}               
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_mtp_ptp.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file includes the PTP operations layer
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_mtp_ptp.h"
+#include "usbh_mtp.h"
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_MTP_CLASS
+* @{
+*/
+
+/** @defgroup USBH_MTP_PTP
+* @brief    This file includes the mass storage related functions
+* @{
+*/ 
+
+
+/** @defgroup USBH_MTP_PTP_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MTP_PTP_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_MTP_PTP_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_PTP_Private_Variables
+* @{
+*/ 
+
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_PTP_Private_FunctionPrototypes
+* @{
+*/ 
+static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
+static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids);
+static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info);
+static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen);
+static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
+static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, 
+                                   uint32_t *offset, 
+                                   uint32_t total, 
+                                   PTP_PropertyValueTypedef* value, 
+                                   uint16_t datatype);
+
+static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, 
+                                       MTP_PropertiesTypedef *props, 
+                                       uint32_t len);
+
+
+static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost);
+static void PTP_GetString(uint8_t *str, uint8_t* data, uint16_t *len);
+static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset);
+static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset);
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_PTP_Exported_Variables
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_MTP_PTP_Private_Functions
+* @{
+*/ 
+/**
+  * @brief  USBH_PTP_Init 
+  *         The function Initializes the BOT protocol.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost)
+{
+  MTP_HandleTypeDef *MTP_Handle =  phost->pActiveClass->pData;
+  
+  /* Set state to idle to be ready for operations */
+  MTP_Handle->ptp.state = PTP_IDLE;
+  MTP_Handle->ptp.req_state = PTP_REQ_SEND;
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_PTP_Process 
+  *         The function handle the BOT protocol.
+  * @param  phost: Host handle
+  * @param  lun: Logical Unit Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY;
+  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;  
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;  
+  uint32_t  len;
+  
+  switch (MTP_Handle->ptp.state)
+  {
+  case PTP_IDLE:
+    /*Do Nothing */
+    break;
+    
+  case PTP_OP_REQUEST_STATE:  
+    USBH_BulkSendData (phost,
+                       (uint8_t*)&(MTP_Handle->ptp.op_container),
+                       MTP_Handle->ptp.op_container.length, 
+                       MTP_Handle->DataOutPipe,
+                       1);
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_WAIT_STATE;
+    break;
+    
+  case PTP_OP_REQUEST_WAIT_STATE:
+    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe);
+    
+    if(URB_Status == USBH_URB_DONE)
+    {
+       if(MTP_Handle->ptp.flags == PTP_DP_NODATA)
+       {
+         MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
+       }
+       else  if(MTP_Handle->ptp.flags == PTP_DP_SENDDATA)
+       {
+         MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE;
+       }
+       else  if(MTP_Handle->ptp.flags == PTP_DP_GETDATA)
+       {
+         MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_STATE;
+       }
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif  
+    }
+    else if(URB_Status == USBH_URB_NOTREADY)
+    {
+      /* Re-send Request */
+      MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }     
+    else if(URB_Status == USBH_URB_STALL)
+    {
+      MTP_Handle->ptp.state  = PTP_ERROR;
+#if (USBH_USE_OS == 1)
+     osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif 
+    }
+    break;
+    
+  case PTP_DATA_OUT_PHASE_STATE:
+    
+    USBH_BulkSendData (phost,
+                       MTP_Handle->ptp.data_ptr,
+                       MTP_Handle->DataOutEpSize , 
+                       MTP_Handle->DataOutPipe,
+                       1);
+    
+    
+    MTP_Handle->ptp.state  = PTP_DATA_OUT_PHASE_WAIT_STATE;    
+    break;
+    
+  case PTP_DATA_OUT_PHASE_WAIT_STATE:
+    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe);     
+    
+    if(URB_Status == USBH_URB_DONE)
+    {
+      /* Adjudt Data pointer and data length */
+      if(MTP_Handle->ptp.data_length > MTP_Handle->DataOutEpSize)
+      {
+        MTP_Handle->ptp.data_ptr += MTP_Handle->DataOutEpSize;
+        MTP_Handle->ptp.data_length -= MTP_Handle->DataOutEpSize; 
+        MTP_Handle->ptp.data_packet += MTP_Handle->DataOutEpSize;
+        
+        if(MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ)
+        {
+          PTP_BufferFullCallback (phost);
+          MTP_Handle->ptp.data_packet = 0;
+          MTP_Handle->ptp.iteration++;            
+        }
+        
+      }
+      else
+      {
+        MTP_Handle->ptp.data_length = 0;
+      } 
+      
+      /* More Data To be Sent */
+      if(MTP_Handle->ptp.data_length > 0)
+      {
+        USBH_BulkSendData (phost,
+                           MTP_Handle->ptp.data_ptr,
+                           MTP_Handle->DataOutEpSize , 
+                           MTP_Handle->DataOutPipe,
+                           1);
+      }
+      else
+      {
+        /* If value was 0, and successful transfer, then change the state */
+        MTP_Handle->ptp.state  = PTP_RESPONSE_STATE;
+      }  
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    
+    else if(URB_Status == USBH_URB_NOTREADY)
+    {
+      /* Re-send same data */      
+      MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    
+    else if(URB_Status == USBH_URB_STALL)
+    {
+      MTP_Handle->ptp.state  = PTP_ERROR;    
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case PTP_DATA_IN_PHASE_STATE:
+    /* Send first packet */        
+    USBH_BulkReceiveData (phost,
+                          MTP_Handle->ptp.data_ptr, 
+                          MTP_Handle->DataInEpSize, 
+                          MTP_Handle->DataInPipe);
+    
+    MTP_Handle->ptp.state  = PTP_DATA_IN_PHASE_WAIT_STATE;    
+    break;
+    
+  case PTP_DATA_IN_PHASE_WAIT_STATE:
+    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe);
+    
+    if(URB_Status == USBH_URB_DONE)
+    {
+      len = USBH_LL_GetLastXferSize (phost, MTP_Handle->DataInPipe);
+      
+      if( MTP_Handle->ptp.data_packet_counter++ == 0)
+      {
+        /* This is the first packet; so retrieve exact data length from payload */ 
+        MTP_Handle->ptp.data_length = *(uint32_t*)(MTP_Handle->ptp.data_ptr);
+        MTP_Handle->ptp.iteration = 0;
+      }
+      
+      if((len >=  MTP_Handle->DataInEpSize) && (MTP_Handle->ptp.data_length > 0))
+      {
+        MTP_Handle->ptp.data_ptr += len;
+        MTP_Handle->ptp.data_length -= len;
+        MTP_Handle->ptp.data_packet += len;
+
+        if(MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ)
+        {
+          PTP_BufferFullCallback (phost);
+          MTP_Handle->ptp.data_packet = 0;
+          MTP_Handle->ptp.iteration++;            
+        }
+        
+        /* Continue receiving data*/        
+        USBH_BulkReceiveData (phost,
+                              MTP_Handle->ptp.data_ptr, 
+                              MTP_Handle->DataInEpSize, 
+                              MTP_Handle->DataInPipe);
+      }
+      else
+      {
+        MTP_Handle->ptp.data_length -= len;
+        MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif          
+      }
+    }
+    else if(URB_Status == USBH_URB_STALL)     
+    {
+      MTP_Handle->ptp.state  = PTP_ERROR;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case PTP_RESPONSE_STATE:
+    
+    USBH_BulkReceiveData (phost,
+                          (uint8_t*)&(MTP_Handle->ptp.resp_container), 
+                          PTP_USB_BULK_REQ_RESP_MAX_LEN , 
+                          MTP_Handle->DataInPipe);
+    
+    MTP_Handle->ptp.state  = PTP_RESPONSE_WAIT_STATE;
+    break;
+    
+  case PTP_RESPONSE_WAIT_STATE:
+    URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe);
+    
+    if(URB_Status == USBH_URB_DONE)
+    {
+       USBH_PTP_GetResponse (phost, &ptp_container);
+       
+       if(ptp_container.Code == PTP_RC_OK)
+       {
+         status = USBH_OK;
+       }
+       else
+       {
+         status = USBH_FAIL;
+       }
+       MTP_Handle->ptp.req_state = PTP_REQ_SEND;
+    }
+    else if(URB_Status == USBH_URB_STALL)     
+    {
+      MTP_Handle->ptp.state  = PTP_ERROR;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case PTP_ERROR:
+      MTP_Handle->ptp.req_state = PTP_REQ_SEND;
+      break;
+      
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_PTP_OpenSession
+  *         Open a new session
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *req)
+{
+  USBH_StatusTypeDef            status = USBH_OK; 
+  MTP_HandleTypeDef             *MTP_Handle =  phost->pActiveClass->pData; 
+  
+  /* Clear PTP Data container*/
+  USBH_memset(&(MTP_Handle->ptp.op_container), 0, sizeof(PTP_OpContainerTypedef));
+  
+  /* build appropriate USB container */
+  MTP_Handle->ptp.op_container.length = PTP_USB_BULK_REQ_LEN- (sizeof(uint32_t)*(5-req->Nparam));
+  MTP_Handle->ptp.op_container.type = PTP_USB_CONTAINER_COMMAND;
+  MTP_Handle->ptp.op_container.code = req->Code;
+  MTP_Handle->ptp.op_container.trans_id = req->Transaction_ID;
+  MTP_Handle->ptp.op_container.param1 = req->Param1;
+  MTP_Handle->ptp.op_container.param2 = req->Param2;
+  MTP_Handle->ptp.op_container.param3 = req->Param3;
+  MTP_Handle->ptp.op_container.param4 = req->Param4;
+  MTP_Handle->ptp.op_container.param5 = req->Param5;
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_PTP_OpenSession
+  *         Open a new session
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_ContainerTypedef  *resp)
+{
+  USBH_StatusTypeDef            status = USBH_OK; 
+  MTP_HandleTypeDef             *MTP_Handle =  phost->pActiveClass->pData; 
+      
+  /* build an appropriate PTPContainer */
+  resp->Code = MTP_Handle->ptp.resp_container.code;
+  resp->SessionID = MTP_Handle->ptp.session_id;
+  resp->Transaction_ID = MTP_Handle->ptp.resp_container.trans_id;
+  resp->Param1 = MTP_Handle->ptp.resp_container.param1;
+  resp->Param2 = MTP_Handle->ptp.resp_container.param2;
+  resp->Param3 = MTP_Handle->ptp.resp_container.param3;
+  resp->Param4 = MTP_Handle->ptp.resp_container.param4;
+  resp->Param5 = MTP_Handle->ptp.resp_container.param5;
+  
+  return status;
+}
+
+/**
+  * @brief  The function informs user that data buffer is full
+  *  @param  phost: host handle
+  * @retval None
+  */
+void PTP_BufferFullCallback(USBH_HandleTypeDef *phost)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  
+  switch (MTP_Handle->ptp.data_container.code)
+  {
+  case PTP_OC_GetDeviceInfo:
+    PTP_DecodeDeviceInfo (phost, &(MTP_Handle->info.devinfo));
+    break;
+    
+  case PTP_OC_GetPartialObject:    
+  case PTP_OC_GetObject:
+
+    /* first packet is in the PTP data payload buffer */
+    if(MTP_Handle->ptp.iteration == 0)
+    {
+       /* copy it to object */
+       USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ);
+       
+       /* next packet should be directly copied to object */
+       MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); 
+    }
+    break;
+
+  case PTP_OC_SendObject:    
+    /* first packet is in the PTP data payload buffer */
+    if(MTP_Handle->ptp.iteration == 0)
+    {
+       /* next packet should be directly copied to object */
+       MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); 
+    }
+    break;    
+    
+  default:
+    break;
+    
+    
+  }
+}
+
+/**
+  * @brief  PTP_GetDeviceInfo
+  *         Gets device info dataset and fills deviceinfo structure.
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval None
+  */
+static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+  uint32_t totallen; 
+  uint16_t len;
+  
+  /* Max device info is PTP_USB_BULK_HS_MAX_PACKET_LEN_READ */
+  USBH_DbgLog (" MTP device info size exceeds internal buffer size.\
+               only available data are decoded.");
+                   
+  if(MTP_Handle->ptp.iteration == 0)
+  {
+    dev_info->StandardVersion = LE16(&data[PTP_di_StandardVersion]);
+    dev_info->VendorExtensionID = LE32(&data[PTP_di_VendorExtensionID]);
+    dev_info->VendorExtensionVersion = LE16(&data[PTP_di_VendorExtensionVersion]);
+    PTP_GetString(dev_info->VendorExtensionDesc, &data[PTP_di_VendorExtensionDesc], &len);
+    
+    totallen=len*2+1;
+    dev_info->FunctionalMode = LE16(&data[PTP_di_FunctionalMode+totallen]);
+    dev_info->OperationsSupported_len = PTP_GetArray16 ((uint16_t *)&dev_info->OperationsSupported, 
+                                                      data, 
+                                                      PTP_di_OperationsSupported+totallen);
+    
+    totallen=totallen+dev_info->OperationsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
+    dev_info->EventsSupported_len = PTP_GetArray16 ((uint16_t *)&dev_info->EventsSupported, 
+                                                      data, 
+                                                      PTP_di_OperationsSupported+totallen);
+    
+    totallen=totallen+dev_info->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
+    dev_info->DevicePropertiesSupported_len = PTP_GetArray16 ((uint16_t *)&dev_info->DevicePropertiesSupported, 
+                                                      data, 
+                                                      PTP_di_OperationsSupported+totallen);
+      
+    totallen=totallen+dev_info->DevicePropertiesSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
+      
+    dev_info->CaptureFormats_len = PTP_GetArray16 ((uint16_t *)&dev_info->CaptureFormats, 
+                                                      data, 
+                                                      PTP_di_OperationsSupported+totallen);
+      
+    totallen=totallen+dev_info->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_t);
+    dev_info->ImageFormats_len =  PTP_GetArray16 ((uint16_t *)&dev_info->ImageFormats, 
+                                                      data, 
+                                                      PTP_di_OperationsSupported+totallen);
+      
+    totallen=totallen+dev_info->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t); 
+    PTP_GetString(dev_info->Manufacturer, &data[PTP_di_OperationsSupported+totallen], &len);
+
+    totallen+=len*2+1;
+    PTP_GetString(dev_info->Model, &data[PTP_di_OperationsSupported+totallen], &len);
+    
+    totallen+=len*2+1;
+    PTP_GetString(dev_info->DeviceVersion, &data[PTP_di_OperationsSupported+totallen], &len);
+
+    totallen+=len*2+1;
+    PTP_GetString(dev_info->SerialNumber, &data[PTP_di_OperationsSupported+totallen], &len);
+  }
+}
+                 
+/**
+  * @brief  PTP_GetStorageIDs
+  *         Gets Storage Ids and fills stor_ids structure.
+  * @param  phost: Host handle
+  * @param  stor_ids: Storage IDsstructure
+  * @retval None
+  */
+static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+
+  stor_ids->n = PTP_GetArray32 (stor_ids->Storage, data, 0); 
+}
+
+                                  
+/**
+  * @brief  PTP_GetStorageInfo
+  *         Gets Storage Info and fills stor_info structure.
+  * @param  phost: Host handle
+  * @param  stor_ids: Storage IDsstructure
+  * @retval None
+  */
+static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+
+  uint16_t len;
+  
+  stor_info->StorageType=LE16(&data[PTP_si_StorageType]);
+  stor_info->FilesystemType=LE16(&data[PTP_si_FilesystemType]);
+  stor_info->AccessCapability=LE16(&data[PTP_si_AccessCapability]);
+  stor_info->MaxCapability=LE64(&data[PTP_si_MaxCapability]);
+  stor_info->FreeSpaceInBytes=LE64(&data[PTP_si_FreeSpaceInBytes]);
+  stor_info->FreeSpaceInImages=LE32(&data[PTP_si_FreeSpaceInImages]);
+  
+  PTP_GetString(stor_info->StorageDescription, &data[PTP_si_StorageDescription], &len);
+  PTP_GetString(stor_info->VolumeLabel, &data[PTP_si_StorageDescription+len*2+1], &len);   
+}
+
+/**
+  * @brief  PTP_GetObjectInfo
+  *         Gets objectInfo and fills object_info structure.
+  * @param  phost: Host handle
+  * @param  object_info: object info structure
+  * @retval None
+  */
+static void PTP_GetObjectInfo (USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+  uint16_t filenamelen;
+  
+  object_info->StorageID=LE32(&data[PTP_oi_StorageID]);
+  object_info->ObjectFormat=LE16(&data[PTP_oi_ObjectFormat]);
+  object_info->ProtectionStatus=LE16(&data[PTP_oi_ProtectionStatus]);
+  object_info->ObjectCompressedSize=LE32(&data[PTP_oi_ObjectCompressedSize]);
+  
+  /* For Samsung Galaxy */
+  if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)) 
+  {
+    data += 4;
+  }
+  object_info->ThumbFormat=LE16(&data[PTP_oi_ThumbFormat]);
+  object_info->ThumbCompressedSize=LE32(&data[PTP_oi_ThumbCompressedSize]);
+  object_info->ThumbPixWidth=LE32(&data[PTP_oi_ThumbPixWidth]);
+  object_info->ThumbPixHeight=LE32(&data[PTP_oi_ThumbPixHeight]);
+  object_info->ImagePixWidth=LE32(&data[PTP_oi_ImagePixWidth]);
+  object_info->ImagePixHeight=LE32(&data[PTP_oi_ImagePixHeight]);
+  object_info->ImageBitDepth=LE32(&data[PTP_oi_ImageBitDepth]);
+  object_info->ParentObject=LE32(&data[PTP_oi_ParentObject]);
+  object_info->AssociationType=LE16(&data[PTP_oi_AssociationType]);
+  object_info->AssociationDesc=LE32(&data[PTP_oi_AssociationDesc]);
+  object_info->SequenceNumber=LE32(&data[PTP_oi_SequenceNumber]);
+  PTP_GetString(object_info->Filename, &data[PTP_oi_filenamelen], &filenamelen);
+}
+
+                 
+/**
+  * @brief  PTP_GetObjectPropDesc
+  *         Gets objectInfo and fills object_info structure.
+  * @param  phost: Host handle
+  * @param  opd: object prop descriptor structure
+  * @retval None
+  */
+static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+  uint32_t offset = 0, i;
+  
+  opd->ObjectPropertyCode=LE16(&data[PTP_opd_ObjectPropertyCode]);
+  opd->DataType=LE16(&data[PTP_opd_DataType]);
+  opd->GetSet=*(uint8_t *)(&data[PTP_opd_GetSet]);
+  
+  offset = PTP_opd_FactoryDefaultValue;
+  PTP_GetDevicePropValue (phost, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType);
+  
+  opd->GroupCode=LE32(&data[offset]);
+  offset+=sizeof(uint32_t);
+  
+  opd->FormFlag=*(uint8_t *)(&data[offset]);
+  offset+=sizeof(uint8_t);
+  
+  switch (opd->FormFlag) 
+  {
+  case PTP_OPFF_Range:
+    PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType);
+    PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType);
+    PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType);
+    break;
+    
+  case PTP_OPFF_Enumeration:
+    
+    opd->FORM.Enum.NumberOfValues = LE16(&data[offset]);
+    offset+=sizeof(uint16_t);
+    
+    for (i=0 ; i < opd->FORM.Enum.NumberOfValues ; i++) 
+    {
+      PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType);
+    }
+    break;
+  default:
+    break;
+  }
+}
+                 
+/**
+  * @brief  PTP_GetDevicePropValue
+  *         Gets objectInfo and fills object_info structure.
+  * @param  phost: Host handle
+  * @param  opd: object prop descriptor structure
+  * @retval None
+  */             
+static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, 
+                                   uint32_t *offset, 
+                                   uint32_t total, 
+                                   PTP_PropertyValueTypedef* value, 
+                                   uint16_t datatype)
+{
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+  uint16_t len;
+  switch (datatype) 
+  {
+  case PTP_DTC_INT8:
+    value->i8 = *(uint8_t *)&(data[*offset]);
+    *offset += 1;
+    break;
+  case PTP_DTC_UINT8:
+    value->u8 = *(uint8_t *)&(data[*offset]);
+    *offset += 1;                
+    break;
+  case PTP_DTC_INT16:
+    
+    value->i16 = LE16(&(data[*offset]));
+    *offset += 2;                
+    break;
+  case PTP_DTC_UINT16:
+    value->u16 = LE16(&(data[*offset]));                
+    *offset += 2;                
+    break;
+  case PTP_DTC_INT32:
+    value->i32 = LE32(&(data[*offset]));              
+    *offset += 4;                
+    break;
+  case PTP_DTC_UINT32:
+    value->u32 = LE32(&(data[*offset]));             
+    *offset += 4;                
+    break;
+  case PTP_DTC_INT64:
+    value->i64 = LE64(&(data[*offset]));            
+    *offset += 8;                
+    break;
+  case PTP_DTC_UINT64:
+    value->u64 = LE64(&(data[*offset]));              
+    *offset += 8;                
+    break;
+    
+  case PTP_DTC_UINT128:
+    *offset += 16;
+    break;
+  case PTP_DTC_INT128:
+    *offset += 16;
+    break;
+ 
+  case PTP_DTC_STR:
+    
+    PTP_GetString((uint8_t *)value->str, (uint8_t *)&(data[*offset]), &len);
+    *offset += len*2+1;
+    break;
+  default:
+    break;
+  }
+}
+
+                 
+/**
+  * @brief  PTP_GetDevicePropValue
+  *         Gets objectInfo and fills object_info structure.
+  * @param  phost: Host handle
+  * @param  opd: object prop descriptor structure
+  * @retval None
+  */             
+static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, 
+                                   MTP_PropertiesTypedef *props, 
+                                   uint32_t len)
+{ 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData;   
+  uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
+  uint32_t prop_count;
+  uint32_t offset = 0, i;
+  
+ prop_count = LE32(data);
+
+ 
+ if (prop_count == 0) 
+ {
+   return 0;
+ }
+
+ data += sizeof(uint32_t);
+ len -= sizeof(uint32_t);
+ 
+ for (i = 0; i < prop_count; i++) 
+ {
+   if (len <= 0) 
+   {
+     return 0;
+   }
+   
+   props[i].ObjectHandle = LE32(data);
+   data += sizeof(uint32_t);
+   len -= sizeof(uint32_t);
+   
+   props[i].property = LE16(data);
+   data += sizeof(uint16_t);
+   len -= sizeof(uint16_t);
+   
+   props[i].datatype = LE16(data);
+   data += sizeof(uint16_t);
+   len -= sizeof(uint16_t);
+   
+   offset = 0;
+   
+   PTP_GetDevicePropValue(phost, &offset, len, &props[i].propval, props[i].datatype);
+   
+   data += offset;
+   len -= offset;
+ }
+ 
+ return prop_count;
+}
+                 
+/**
+  * @brief  PTP_GetString
+  *         Gets SCII String from.
+  * @param  str: ascii string
+  * @param  data: Device info structure
+  * @retval None
+  */
+static void PTP_GetString (uint8_t *str, uint8_t* data, uint16_t *len)
+{
+  uint16_t strlength;
+  uint16_t idx;
+  
+  *len = data[0];
+  strlength = 2 * data[0]; 
+  data ++; /* Adjust the offset ignoring the String Len */
+  
+  for (idx = 0; idx < strlength; idx+=2 )
+  {
+    /* Copy Only the string and ignore the UNICODE ID, hence add the src */
+    *str =  data[idx];
+    str++;
+  }  
+  *str = 0; /* mark end of string */  
+}
+  
+/**
+  * @brief  PTP_GetString
+  *         Gets SCII String from.
+  * @param  str: ascii string
+  * @param  data: Device info structure
+  * @retval None
+  */              
+
+static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset)
+{
+  uint32_t size, idx = 0;
+  
+  size=LE32(&data[offset]);
+  while (size > idx) 
+  {
+    array[idx] = LE16(&data[offset+(sizeof(uint16_t)*(idx+2))]);
+    idx++;
+  }
+  return size;
+}
+
+/**
+  * @brief  PTP_GetString
+  *         Gets SCII String from.
+  * @param  str: ascii string
+  * @param  data: Device info structure
+  * @retval None
+  */              
+
+static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset)
+{
+  uint32_t size, idx = 0;
+  
+  size=LE32(&data[offset]);
+  while (size > idx) 
+  {
+    array[idx] = LE32(&data[offset+(sizeof(uint32_t)*(idx+1))]);
+    idx++;
+  }
+  return size;
+}
+
+/*******************************************************************************
+                             
+                          PTP Requests
+
+*******************************************************************************/
+/**
+  * @brief  USBH_PTP_OpenSession
+  *         Open a new session
+  * @param  phost: Host handle
+  * @param  session: Session ID (MUST BE > 0)
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t session)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Init session params */
+    MTP_Handle->ptp.transaction_id = 0x00000000;
+    MTP_Handle->ptp.session_id = session;
+    MTP_Handle->ptp.flags = PTP_DP_NODATA;
+    
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_OpenSession;
+    ptp_container.SessionID = session;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = session;
+    ptp_container.Nparam = 1;
+    
+    /* convert request packet inti USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_PTP_GetDevicePropDesc
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t propcode, 
+			PTP_DevicePropDescTypdef* devicepropertydesc)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  uint8_t               *data = MTP_Handle->ptp.data_container.payload.data;
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetDevicePropDesc;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = propcode;     
+    ptp_container.Nparam = 1;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+	devicepropertydesc->DevicePropertyCode = LE16(&data[PTP_dpd_DevicePropertyCode]);
+	devicepropertydesc->DataType = LE16(&data[PTP_dpd_DataType]);
+	devicepropertydesc->GetSet = *(uint8_t *)(&data[PTP_dpd_GetSet]);
+	devicepropertydesc->FormFlag =  PTP_DPFF_None;
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+/**
+  * @brief  USBH_PTP_GetDeviceInfo
+  *         Gets device info dataset and fills deviceinfo structure.
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetDeviceInfo;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Nparam = 0;
+    
+    /* convert request packet inti USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+       PTP_DecodeDeviceInfo (phost, dev_info);
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_PTP_GetStorageIds
+  *         Gets device info dataset and fills deviceinfo structure.
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetStorageIDs;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Nparam = 0;
+    
+    /* convert request packet inti USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      PTP_GetStorageIDs (phost, storage_ids);
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetDeviceInfo
+  *         Gets device info dataset and fills deviceinfo structure.
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *storage_info)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetStorageInfo;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = storage_id;    
+    ptp_container.Nparam = 1;
+    
+    /* convert request packet inti USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      PTP_GetStorageInfo (phost, storage_id, storage_info);
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetNumObjects
+  *         Gets device info dataset and fills deviceinfo structure.
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_id, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           uint32_t* numobs)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_NODATA;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetNumObjects;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = storage_id;  
+    ptp_container.Param2 = objectformatcode;
+    ptp_container.Param3 = associationOH;    
+    ptp_container.Nparam = 3;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      *numobs = MTP_Handle->ptp.resp_container.param1;
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_PTP_GetObjectHandles
+  *         Gets device info dataset and fills deviceinfo structure.
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, 
+                                           uint32_t storage_id, 
+                                           uint32_t objectformatcode, 
+                                           uint32_t associationOH,
+                                           PTP_ObjectHandlesTypedef* objecthandles)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetObjectHandles;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = storage_id;  
+    ptp_container.Param2 = objectformatcode;
+    ptp_container.Param3 = associationOH;    
+    ptp_container.Nparam = 3;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+       objecthandles->n = PTP_GetArray32 (objecthandles->Handler, 
+                                          MTP_Handle->ptp.data_container.payload.data, 
+                                          0); 
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetObjectInfo
+  *         Gets objert info
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           PTP_ObjectInfoTypedef* object_info)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetObjectInfo;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = handle;  
+    ptp_container.Nparam = 1;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+       PTP_GetObjectInfo (phost, object_info);
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_DeleteObject
+  *         Delete an object.
+  * @param  phost: Host handle
+  * @param  handle : Object Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost,
+                                          uint32_t handle,
+                                          uint32_t objectformatcode)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_NODATA;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_DeleteObject;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = handle;  
+    ptp_container.Param2 = objectformatcode;
+    ptp_container.Nparam = 2;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetObject
+  *         Gets object
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+    
+    /* set object control params */
+    MTP_Handle->ptp.object_ptr = object;
+    
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetObject;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = handle;  
+    ptp_container.Nparam = 1;
+
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      /* first packet is in the PTP data payload buffer */
+      if(MTP_Handle->ptp.iteration == 0)
+      {
+        /* copy it to object */
+        USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ);
+      }
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetPartialObject
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint32_t offset,
+                                           uint32_t maxbytes, 
+                                           uint8_t *object,
+                                           uint32_t *len)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+
+    /* set object control params */
+    MTP_Handle->ptp.object_ptr = object;
+    
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetPartialObject;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = handle;  
+    ptp_container.Param2 = offset;
+    ptp_container.Param3 = maxbytes;   
+    ptp_container.Nparam = 3;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      *len = MTP_Handle->ptp.resp_container.param1;
+      /* first packet is in the PTP data payload buffer */
+      if(MTP_Handle->ptp.iteration == 0)
+      {
+        /* copy it to object */
+        USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, *len);
+      }      
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetObjectPropsSupported
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost,
+                                                     uint16_t ofc,
+                                                     uint32_t *propnum, 
+                                                     uint16_t *props)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetObjectPropsSupported;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = ofc;  
+    ptp_container.Nparam = 1;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      *propnum = PTP_GetArray16 (props, MTP_Handle->ptp.data_container.payload.data, 0);      
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetObjectPropDesc
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost,
+                                                uint16_t opc, 
+                                                uint16_t ofc, 
+                                                PTP_ObjectPropDescTypeDef *opd)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetObjectPropDesc;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = opc;  
+    ptp_container.Param2 = ofc;      
+    ptp_container.Nparam = 2;
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+     PTP_GetObjectPropDesc(phost, opd, MTP_Handle->ptp.data_length);
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+                 
+/**
+  * @brief  USBH_PTP_GetObjectPropList
+  *         Gets object partially
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost,
+                                                uint32_t handle, 
+                                                MTP_PropertiesTypedef *pprops, 
+                                                uint32_t *nrofprops)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_GETDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_length = 0;
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+   
+    /* copy first packet of the object into data container */
+    USBH_memcpy(MTP_Handle->ptp.data_container.payload.data, MTP_Handle->ptp.object_ptr, PTP_USB_BULK_PAYLOAD_LEN_READ);
+       
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_GetObjPropList;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Param1 = handle;  
+    ptp_container.Param2 = 0x00000000U;  /* 0x00000000U should be "all formats" */
+    ptp_container.Param3 = 0xFFFFFFFFU;  /* 0xFFFFFFFFU should be "all properties" */
+    ptp_container.Param4 = 0x00000000U;
+    ptp_container.Param5 = 0xFFFFFFFFU;  /* Return full tree below the Param1 handle */
+    ptp_container.Nparam = 5;  
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    
+    if(status == USBH_OK)
+    {
+      PTP_GetObjectPropList (phost, pprops,  MTP_Handle->ptp.data_length);
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+               
+/**
+  * @brief  USBH_PTP_SendObject
+  *         Send an object
+  * @param  phost: Host handle
+  * @param  dev_info: Device info structure
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_PTP_SendObject (USBH_HandleTypeDef *phost, 
+                                           uint32_t handle, 
+                                           uint8_t *object,
+                                           uint32_t size)
+{
+  USBH_StatusTypeDef   status = USBH_BUSY; 
+  MTP_HandleTypeDef    *MTP_Handle =  phost->pActiveClass->pData; 
+  PTP_ContainerTypedef  ptp_container;
+  
+  switch(MTP_Handle->ptp.req_state)
+  {
+  case PTP_REQ_SEND:
+
+    /* Set operation request type */
+    MTP_Handle->ptp.flags = PTP_DP_SENDDATA;
+    MTP_Handle->ptp.data_ptr = (uint8_t *)&(MTP_Handle->ptp.data_container);
+    MTP_Handle->ptp.data_packet_counter = 0;
+    MTP_Handle->ptp.data_packet = 0;
+    MTP_Handle->ptp.iteration = 0;
+    
+    /* set object control params */
+    MTP_Handle->ptp.object_ptr = object;
+    MTP_Handle->ptp.data_length = size;    
+    
+    /* Fill operation request params */      
+    ptp_container.Code = PTP_OC_SendObject;
+    ptp_container.SessionID = MTP_Handle->ptp.session_id;
+    ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
+    ptp_container.Nparam = 0;
+
+    
+    /* convert request packet into USB raw packet*/
+    USBH_PTP_SendRequest (phost, &ptp_container); 
+        
+    /* Setup State machine and start transfer */
+    MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
+    MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
+    status = USBH_BUSY; 
+    break;
+    
+  case PTP_REQ_WAIT:
+    status = USBH_PTP_Process(phost);
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}               
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Class/Template/Inc/usbh_template.h b/micropython/ports/stm32/usbhost/Class/Template/Inc/usbh_template.h
index 728a36c86bdf636483ee25bdcad0725429faac43..8d48fb6cfbdfef43eb2517c32670d2f0d140798a 100644
--- a/micropython/ports/stm32/usbhost/Class/Template/Inc/usbh_template.h
+++ b/micropython/ports/stm32/usbhost/Class/Template/Inc/usbh_template.h
@@ -1,122 +1,122 @@
-/**
-  ******************************************************************************
-  * @file    usbh_mtp.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file contains all the prototypes for the usbh_template.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_TEMPLATE_CORE_H
-#define __USBH_TEMPLATE_CORE_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_TEMPLATE_CLASS
-* @{
-*/
-
-/** @defgroup USBH_TEMPLATE_CORE
-* @brief This file is the Header file for USBH_TEMPLATE_CORE.c
-* @{
-*/ 
-
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_TEMPLATE_CORE_Exported_Types
-* @{
-*/ 
-
-/* States for TEMPLATE State Machine */
-
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_TEMPLATE_CORE_Exported_Defines
-* @{
-*/ 
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_TEMPLATE_CORE_Exported_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_TEMPLATE_CORE_Exported_Variables
-* @{
-*/ 
-extern USBH_ClassTypeDef  TEMPLATE_Class;
-#define USBH_TEMPLATE_CLASS    &TEMPLATE_Class
-
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_TEMPLATE_CORE_Exported_FunctionsPrototype
-* @{
-*/ 
-USBH_StatusTypeDef USBH_TEMPLATE_IOProcess (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost);
-/**
-* @}
-*/ 
-
-
-#endif /* __USBH_TEMPLATE_CORE_H */
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_mtp.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file contains all the prototypes for the usbh_template.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_TEMPLATE_CORE_H
+#define __USBH_TEMPLATE_CORE_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_TEMPLATE_CLASS
+* @{
+*/
+
+/** @defgroup USBH_TEMPLATE_CORE
+* @brief This file is the Header file for USBH_TEMPLATE_CORE.c
+* @{
+*/ 
+
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_TEMPLATE_CORE_Exported_Types
+* @{
+*/ 
+
+/* States for TEMPLATE State Machine */
+
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_TEMPLATE_CORE_Exported_Defines
+* @{
+*/ 
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_TEMPLATE_CORE_Exported_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_TEMPLATE_CORE_Exported_Variables
+* @{
+*/ 
+extern USBH_ClassTypeDef  TEMPLATE_Class;
+#define USBH_TEMPLATE_CLASS    &TEMPLATE_Class
+
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_TEMPLATE_CORE_Exported_FunctionsPrototype
+* @{
+*/ 
+USBH_StatusTypeDef USBH_TEMPLATE_IOProcess (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost);
+/**
+* @}
+*/ 
+
+
+#endif /* __USBH_TEMPLATE_CORE_H */
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Class/Template/Src/usbh_template.c b/micropython/ports/stm32/usbhost/Class/Template/Src/usbh_template.c
index 2ea14a89e2c90cd0bebb69b155894bbec8bae155..7899e43609980b5b30ce5e88466be73a0035ba8e 100644
--- a/micropython/ports/stm32/usbhost/Class/Template/Src/usbh_template.c
+++ b/micropython/ports/stm32/usbhost/Class/Template/Src/usbh_template.c
@@ -1,240 +1,240 @@
-/**
-  ******************************************************************************
-  * @file    usbh_mtp.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file is the MTP Layer Handlers for USB Host MTP class.
-  *
-  *
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_template.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_TEMPLATE_CLASS
-* @{
-*/
-
-/** @defgroup USBH_TEMPLATE_CORE 
-* @brief    This file includes TEMPLATE Layer Handlers for USB Host TEMPLATE class.
-* @{
-*/ 
-
-/** @defgroup USBH_TEMPLATE_CORE_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_TEMPLATE_CORE_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_TEMPLATE_CORE_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_TEMPLATE_CORE_Private_Variables
-* @{
-*/
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_TEMPLATE_CORE_Private_FunctionPrototypes
-* @{
-*/ 
-
-static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit  (USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_TEMPLATE_Process(USBH_HandleTypeDef *phost);
-
-static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost);
-
-
-USBH_ClassTypeDef  TEMPLATE_Class = 
-{
-  "TEMPLATE",
-  USB_TEMPLATE_CLASS,
-  USBH_TEMPLATE_InterfaceInit,
-  USBH_TEMPLATE_InterfaceDeInit,
-  USBH_TEMPLATE_ClassRequest,
-  USBH_TEMPLATE_Process
-};
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_TEMPLATE_CORE_Private_Functions
-* @{
-*/ 
-
-/**
-  * @brief  USBH_TEMPLATE_InterfaceInit 
-  *         The function init the TEMPLATE class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit (USBH_HandleTypeDef *phost)
-{	
-
-  return USBH_OK;
-}
-
-
-
-/**
-  * @brief  USBH_TEMPLATE_InterfaceDeInit 
-  *         The function DeInit the Pipes used for the TEMPLATE class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit (USBH_HandleTypeDef *phost)
-{
-
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_TEMPLATE_ClassRequest 
-  *         The function is responsible for handling Standard requests
-  *         for TEMPLATE class.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost)
-{   
-
-  return USBH_OK; 
-}
-
-
-/**
-  * @brief  USBH_TEMPLATE_Process 
-  *         The function is for managing state machine for TEMPLATE data transfers 
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_TEMPLATE_Process (USBH_HandleTypeDef *phost)
-{
- 
-  return USBH_OK;
-}
-
-
-/**
-  * @brief  USBH_TEMPLATE_Init 
-  *         The function Initialize the TEMPLATE function
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef Status = USBH_BUSY;
-#if (USBH_USE_OS == 1)
-  osEvent event;
-  
-  event = osMessageGet( phost->class_ready_event, osWaitForever );
-  
-  if( event.status == osEventMessage )      
-  {
-    if(event.value.v == USBH_CLASS_EVENT)
-    {
-#else 
-      
-  while ((Status == USBH_BUSY) || (Status == USBH_FAIL))
-  {
-    /* Host background process */
-    USBH_Process(phost);
-    if(phost->gState == HOST_CLASS)
-    {
-#endif        
-      Status = USBH_OK;
-    }
-  }
-  return Status;   
-}
-
-/**
-  * @brief  USBH_TEMPLATE_IOProcess 
-  *         TEMPLATE TEMPLATE process
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_TEMPLATE_IOProcess (USBH_HandleTypeDef *phost)
-{
-  if (phost->device.is_connected == 1)
-  {
-    if(phost->gState == HOST_CLASS)
-    {
-      USBH_TEMPLATE_Process(phost);
-    }
-  }
-  
-  return USBH_OK;
-}
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_mtp.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file is the MTP Layer Handlers for USB Host MTP class.
+  *
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_template.h"
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_CLASS
+* @{
+*/
+
+/** @addtogroup USBH_TEMPLATE_CLASS
+* @{
+*/
+
+/** @defgroup USBH_TEMPLATE_CORE 
+* @brief    This file includes TEMPLATE Layer Handlers for USB Host TEMPLATE class.
+* @{
+*/ 
+
+/** @defgroup USBH_TEMPLATE_CORE_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_TEMPLATE_CORE_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_TEMPLATE_CORE_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_TEMPLATE_CORE_Private_Variables
+* @{
+*/
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_TEMPLATE_CORE_Private_FunctionPrototypes
+* @{
+*/ 
+
+static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit  (USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_TEMPLATE_Process(USBH_HandleTypeDef *phost);
+
+static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost);
+
+
+USBH_ClassTypeDef  TEMPLATE_Class = 
+{
+  "TEMPLATE",
+  USB_TEMPLATE_CLASS,
+  USBH_TEMPLATE_InterfaceInit,
+  USBH_TEMPLATE_InterfaceDeInit,
+  USBH_TEMPLATE_ClassRequest,
+  USBH_TEMPLATE_Process
+};
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_TEMPLATE_CORE_Private_Functions
+* @{
+*/ 
+
+/**
+  * @brief  USBH_TEMPLATE_InterfaceInit 
+  *         The function init the TEMPLATE class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit (USBH_HandleTypeDef *phost)
+{	
+
+  return USBH_OK;
+}
+
+
+
+/**
+  * @brief  USBH_TEMPLATE_InterfaceDeInit 
+  *         The function DeInit the Pipes used for the TEMPLATE class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit (USBH_HandleTypeDef *phost)
+{
+
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_TEMPLATE_ClassRequest 
+  *         The function is responsible for handling Standard requests
+  *         for TEMPLATE class.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost)
+{   
+
+  return USBH_OK; 
+}
+
+
+/**
+  * @brief  USBH_TEMPLATE_Process 
+  *         The function is for managing state machine for TEMPLATE data transfers 
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_TEMPLATE_Process (USBH_HandleTypeDef *phost)
+{
+ 
+  return USBH_OK;
+}
+
+
+/**
+  * @brief  USBH_TEMPLATE_Init 
+  *         The function Initialize the TEMPLATE function
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef Status = USBH_BUSY;
+#if (USBH_USE_OS == 1)
+  osEvent event;
+  
+  event = osMessageGet( phost->class_ready_event, osWaitForever );
+  
+  if( event.status == osEventMessage )      
+  {
+    if(event.value.v == USBH_CLASS_EVENT)
+    {
+#else 
+      
+  while ((Status == USBH_BUSY) || (Status == USBH_FAIL))
+  {
+    /* Host background process */
+    USBH_Process(phost);
+    if(phost->gState == HOST_CLASS)
+    {
+#endif        
+      Status = USBH_OK;
+    }
+  }
+  return Status;   
+}
+
+/**
+  * @brief  USBH_TEMPLATE_IOProcess 
+  *         TEMPLATE TEMPLATE process
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_TEMPLATE_IOProcess (USBH_HandleTypeDef *phost)
+{
+  if (phost->device.is_connected == 1)
+  {
+    if(phost->gState == HOST_CLASS)
+    {
+      USBH_TEMPLATE_Process(phost);
+    }
+  }
+  
+  return USBH_OK;
+}
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Core/Inc/usbh_conf_template.h b/micropython/ports/stm32/usbhost/Core/Inc/usbh_conf_template.h
index 8f85e13604e2540b619114fed1d633ade48510f4..b37f432f6cc12317cf655840f5f4b5e3d91470aa 100644
--- a/micropython/ports/stm32/usbhost/Core/Inc/usbh_conf_template.h
+++ b/micropython/ports/stm32/usbhost/Core/Inc/usbh_conf_template.h
@@ -1,151 +1,151 @@
-/**
-  ******************************************************************************
-  * @file    USBH_conf.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   General low level driver configuration
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USBH_CONF__H__
-#define __USBH_CONF__H__
-
-#include "stm32f4xx.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-/* Includes ------------------------------------------------------------------*/
-
-/** @addtogroup USBH_OTG_DRIVER
-  * @{
-  */
-  
-/** @defgroup USBH_CONF
-  * @brief usb otg low level driver configuration file
-  * @{
-  */ 
-
-/** @defgroup USBH_CONF_Exported_Defines
-  * @{
-  */ 
-
-#define USBH_MAX_NUM_ENDPOINTS                2
-#define USBH_MAX_NUM_INTERFACES               2
-#define USBH_MAX_NUM_CONFIGURATION            1
-#define USBH_KEEP_CFG_DESCRIPTOR              1
-#define USBH_MAX_NUM_SUPPORTED_CLASS          1
-#define USBH_MAX_SIZE_CONFIGURATION           0x200
-#define USBH_MAX_DATA_BUFFER                  0x200
-#define USBH_DEBUG_LEVEL                      2
-#define USBH_USE_OS                           1
-    
-/** @defgroup USBH_Exported_Macros
-  * @{
-  */ 
-
- /* Memory management macros */   
-#define USBH_malloc               malloc
-#define USBH_free                 free
-#define USBH_memset               memset
-#define USBH_memcpy               memcpy
-    
- /* DEBUG macros */  
-
-  
-#if (USBH_DEBUG_LEVEL > 0)
-#define  USBH_UsrLog(...)   printf(__VA_ARGS__);\
-                            printf("\n");
-#else
-#define USBH_UsrLog(...)   
-#endif 
-                            
-                            
-#if (USBH_DEBUG_LEVEL > 1)
-
-#define  USBH_ErrLog(...)   printf("ERROR: ") ;\
-                            printf(__VA_ARGS__);\
-                            printf("\n");
-#else
-#define USBH_ErrLog(...)   
-#endif 
-                            
-                            
-#if (USBH_DEBUG_LEVEL > 2)                         
-#define  USBH_DbgLog(...)   printf("DEBUG : ") ;\
-                            printf(__VA_ARGS__);\
-                            printf("\n");
-#else
-#define USBH_DbgLog(...)                         
-#endif
-                            
-/**
-  * @}
-  */ 
-   
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_CONF_Exported_Types
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_CONF_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CONF_Exported_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CONF_Exported_FunctionsPrototype
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-#endif //__USBH_CONF__H__
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    USBH_conf.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   General low level driver configuration
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBH_CONF__H__
+#define __USBH_CONF__H__
+
+#include "stm32f4xx.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Includes ------------------------------------------------------------------*/
+
+/** @addtogroup USBH_OTG_DRIVER
+  * @{
+  */
+  
+/** @defgroup USBH_CONF
+  * @brief usb otg low level driver configuration file
+  * @{
+  */ 
+
+/** @defgroup USBH_CONF_Exported_Defines
+  * @{
+  */ 
+
+#define USBH_MAX_NUM_ENDPOINTS                2
+#define USBH_MAX_NUM_INTERFACES               2
+#define USBH_MAX_NUM_CONFIGURATION            1
+#define USBH_KEEP_CFG_DESCRIPTOR              1
+#define USBH_MAX_NUM_SUPPORTED_CLASS          1
+#define USBH_MAX_SIZE_CONFIGURATION           0x200
+#define USBH_MAX_DATA_BUFFER                  0x200
+#define USBH_DEBUG_LEVEL                      2
+#define USBH_USE_OS                           1
+    
+/** @defgroup USBH_Exported_Macros
+  * @{
+  */ 
+
+ /* Memory management macros */   
+#define USBH_malloc               malloc
+#define USBH_free                 free
+#define USBH_memset               memset
+#define USBH_memcpy               memcpy
+    
+ /* DEBUG macros */  
+
+  
+#if (USBH_DEBUG_LEVEL > 0)
+#define  USBH_UsrLog(...)   printf(__VA_ARGS__);\
+                            printf("\n");
+#else
+#define USBH_UsrLog(...)   
+#endif 
+                            
+                            
+#if (USBH_DEBUG_LEVEL > 1)
+
+#define  USBH_ErrLog(...)   printf("ERROR: ") ;\
+                            printf(__VA_ARGS__);\
+                            printf("\n");
+#else
+#define USBH_ErrLog(...)   
+#endif 
+                            
+                            
+#if (USBH_DEBUG_LEVEL > 2)                         
+#define  USBH_DbgLog(...)   printf("DEBUG : ") ;\
+                            printf(__VA_ARGS__);\
+                            printf("\n");
+#else
+#define USBH_DbgLog(...)                         
+#endif
+                            
+/**
+  * @}
+  */ 
+   
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_CONF_Exported_Types
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_CONF_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CONF_Exported_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CONF_Exported_FunctionsPrototype
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+#endif //__USBH_CONF__H__
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Core/Inc/usbh_core.h b/micropython/ports/stm32/usbhost/Core/Inc/usbh_core.h
index bc3da6d1fe906fd9f821e3efe09e1e3f8d6602b7..ad0301fc6f8845eca2ad0f19716415b97272eda8 100644
--- a/micropython/ports/stm32/usbhost/Core/Inc/usbh_core.h
+++ b/micropython/ports/stm32/usbhost/Core/Inc/usbh_core.h
@@ -1,161 +1,161 @@
-/**
-  ******************************************************************************
-  * @file    usbh_core.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_core.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_CORE_H
-#define __USBH_CORE_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_conf.h"
-#include "usbh_def.h"
-#include "usbh_ioreq.h"
-#include "usbh_pipes.h"
-#include "usbh_ctlreq.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_CORE
-  * @brief This file is the Header file for usbh_core.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_CORE_Exported_Defines
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-#define HOST_USER_SELECT_CONFIGURATION          1
-#define HOST_USER_CLASS_ACTIVE                  2
-#define HOST_USER_CLASS_SELECTED                3
-#define HOST_USER_CONNECTION                    4
-#define HOST_USER_DISCONNECTION                 5
-
-
-
-/**
-  * @}
-  */ 
-
-
-
-/** @defgroup USBH_CORE_Exported_Macros
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CORE_Exported_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CORE_Exported_FunctionsPrototype
-  * @{
-  */ 
-
-  
-USBH_StatusTypeDef  USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t ), uint8_t id);
-USBH_StatusTypeDef  USBH_DeInit(USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef  USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass);
-USBH_StatusTypeDef  USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface);
-uint8_t             USBH_FindInterface(USBH_HandleTypeDef *phost, 
-                                            uint8_t Class, 
-                                            uint8_t SubClass, 
-                                            uint8_t Protocol);
-uint8_t             USBH_GetActiveClass(USBH_HandleTypeDef *phost);
-
-uint8_t             USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, 
-                                            uint8_t interface_number, 
-                                            uint8_t alt_settings);
-
-USBH_StatusTypeDef  USBH_Start            (USBH_HandleTypeDef *phost); 
-USBH_StatusTypeDef  USBH_Stop             (USBH_HandleTypeDef *phost); 
-USBH_StatusTypeDef  USBH_Process          (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef  USBH_ReEnumerate      (USBH_HandleTypeDef *phost);
-
-/* USBH Low Level Driver */
-USBH_StatusTypeDef   USBH_LL_Init         (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef   USBH_LL_DeInit       (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef   USBH_LL_Start        (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef   USBH_LL_Stop         (USBH_HandleTypeDef *phost);
-
-USBH_StatusTypeDef   USBH_LL_Connect      (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef   USBH_LL_Disconnect   (USBH_HandleTypeDef *phost);
-USBH_SpeedTypeDef    USBH_LL_GetSpeed     (USBH_HandleTypeDef *phost);
-USBH_StatusTypeDef   USBH_LL_ResetPort    (USBH_HandleTypeDef *phost);
-uint32_t             USBH_LL_GetLastXferSize   (USBH_HandleTypeDef *phost, uint8_t ); 
-USBH_StatusTypeDef   USBH_LL_DriverVBUS   (USBH_HandleTypeDef *phost, uint8_t );
-
-USBH_StatusTypeDef   USBH_LL_OpenPipe     (USBH_HandleTypeDef *phost, uint8_t, uint8_t, uint8_t, uint8_t , uint8_t, uint16_t ); 
-USBH_StatusTypeDef   USBH_LL_ClosePipe    (USBH_HandleTypeDef *phost, uint8_t );   
-USBH_StatusTypeDef   USBH_LL_SubmitURB    (USBH_HandleTypeDef *phost, uint8_t, uint8_t,uint8_t,  uint8_t, uint8_t*, uint16_t, uint8_t ); 
-USBH_URBStateTypeDef USBH_LL_GetURBState  (USBH_HandleTypeDef *phost, uint8_t ); 
-#if (USBH_USE_OS == 1)
-USBH_StatusTypeDef  USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost);
-#endif
-USBH_StatusTypeDef   USBH_LL_SetToggle    (USBH_HandleTypeDef *phost, uint8_t , uint8_t );
-uint8_t              USBH_LL_GetToggle    (USBH_HandleTypeDef *phost, uint8_t );
-
-/* USBH Time base */
-void                 USBH_Delay (uint32_t Delay);
-void                 USBH_LL_SetTimer     (USBH_HandleTypeDef *phost, uint32_t );  
-void                 USBH_LL_IncTimer     (USBH_HandleTypeDef *phost);  
-/**
-  * @}
-  */ 
-
-#endif /* __CORE_H */
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_core.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_core.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_CORE_H
+#define __USBH_CORE_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_conf.h"
+#include "usbh_def.h"
+#include "usbh_ioreq.h"
+#include "usbh_pipes.h"
+#include "usbh_ctlreq.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_CORE
+  * @brief This file is the Header file for usbh_core.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_CORE_Exported_Defines
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+#define HOST_USER_SELECT_CONFIGURATION          1
+#define HOST_USER_CLASS_ACTIVE                  2
+#define HOST_USER_CLASS_SELECTED                3
+#define HOST_USER_CONNECTION                    4
+#define HOST_USER_DISCONNECTION                 5
+
+
+
+/**
+  * @}
+  */ 
+
+
+
+/** @defgroup USBH_CORE_Exported_Macros
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CORE_Exported_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CORE_Exported_FunctionsPrototype
+  * @{
+  */ 
+
+  
+USBH_StatusTypeDef  USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t ), uint8_t id);
+USBH_StatusTypeDef  USBH_DeInit(USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef  USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass);
+USBH_StatusTypeDef  USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface);
+uint8_t             USBH_FindInterface(USBH_HandleTypeDef *phost, 
+                                            uint8_t Class, 
+                                            uint8_t SubClass, 
+                                            uint8_t Protocol);
+uint8_t             USBH_GetActiveClass(USBH_HandleTypeDef *phost);
+
+uint8_t             USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, 
+                                            uint8_t interface_number, 
+                                            uint8_t alt_settings);
+
+USBH_StatusTypeDef  USBH_Start            (USBH_HandleTypeDef *phost); 
+USBH_StatusTypeDef  USBH_Stop             (USBH_HandleTypeDef *phost); 
+USBH_StatusTypeDef  USBH_Process          (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef  USBH_ReEnumerate      (USBH_HandleTypeDef *phost);
+
+/* USBH Low Level Driver */
+USBH_StatusTypeDef   USBH_LL_Init         (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef   USBH_LL_DeInit       (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef   USBH_LL_Start        (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef   USBH_LL_Stop         (USBH_HandleTypeDef *phost);
+
+USBH_StatusTypeDef   USBH_LL_Connect      (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef   USBH_LL_Disconnect   (USBH_HandleTypeDef *phost);
+USBH_SpeedTypeDef    USBH_LL_GetSpeed     (USBH_HandleTypeDef *phost);
+USBH_StatusTypeDef   USBH_LL_ResetPort    (USBH_HandleTypeDef *phost);
+uint32_t             USBH_LL_GetLastXferSize   (USBH_HandleTypeDef *phost, uint8_t ); 
+USBH_StatusTypeDef   USBH_LL_DriverVBUS   (USBH_HandleTypeDef *phost, uint8_t );
+
+USBH_StatusTypeDef   USBH_LL_OpenPipe     (USBH_HandleTypeDef *phost, uint8_t, uint8_t, uint8_t, uint8_t , uint8_t, uint16_t ); 
+USBH_StatusTypeDef   USBH_LL_ClosePipe    (USBH_HandleTypeDef *phost, uint8_t );   
+USBH_StatusTypeDef   USBH_LL_SubmitURB    (USBH_HandleTypeDef *phost, uint8_t, uint8_t,uint8_t,  uint8_t, uint8_t*, uint16_t, uint8_t ); 
+USBH_URBStateTypeDef USBH_LL_GetURBState  (USBH_HandleTypeDef *phost, uint8_t ); 
+#if (USBH_USE_OS == 1)
+USBH_StatusTypeDef  USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost);
+#endif
+USBH_StatusTypeDef   USBH_LL_SetToggle    (USBH_HandleTypeDef *phost, uint8_t , uint8_t );
+uint8_t              USBH_LL_GetToggle    (USBH_HandleTypeDef *phost, uint8_t );
+
+/* USBH Time base */
+void                 USBH_Delay (uint32_t Delay);
+void                 USBH_LL_SetTimer     (USBH_HandleTypeDef *phost, uint32_t );  
+void                 USBH_LL_IncTimer     (USBH_HandleTypeDef *phost);  
+/**
+  * @}
+  */ 
+
+#endif /* __CORE_H */
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Core/Inc/usbh_ctlreq.h b/micropython/ports/stm32/usbhost/Core/Inc/usbh_ctlreq.h
index cd61755e3ed3925cdfa110cde57ea729e5b68a98..498c037407faeaf28ed2f8f46eb72763dacc13e4 100644
--- a/micropython/ports/stm32/usbhost/Core/Inc/usbh_ctlreq.h
+++ b/micropython/ports/stm32/usbhost/Core/Inc/usbh_ctlreq.h
@@ -1,147 +1,147 @@
-/**
-  ******************************************************************************
-  * @file    usbh_ctlreq.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_ctlreq.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_CTLREQ_H
-#define __USBH_CTLREQ_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_CTLREQ
-  * @brief This file is the 
-  * @{
-  */ 
-
-
-/** @defgroup USBH_CTLREQ_Exported_Defines
-  * @{
-  */
-/*Standard Feature Selector for clear feature command*/
-#define FEATURE_SELECTOR_ENDPOINT         0X00
-#define FEATURE_SELECTOR_DEVICE           0X01
-
-
-#define INTERFACE_DESC_TYPE               0x04
-#define ENDPOINT_DESC_TYPE                0x05
-#define INTERFACE_DESC_SIZE               0x09
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_CTLREQ_Exported_Types
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_CTLREQ_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CTLREQ_Exported_Variables
-  * @{
-  */ 
-extern uint8_t USBH_CfgDesc[512];
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CTLREQ_Exported_FunctionsPrototype
-  * @{
-  */
-USBH_StatusTypeDef USBH_CtlReq     (USBH_HandleTypeDef *phost, 
-                             uint8_t             *buff,
-                             uint16_t            length);
-
-USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,                                
-                               uint8_t  req_type,
-                               uint16_t value_idx, 
-                               uint8_t* buff, 
-                               uint16_t length );
-
-USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost,
-                             uint8_t length);
-
-USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,                              
-                                uint8_t string_index, 
-                                uint8_t *buff, 
-                                uint16_t length);
-
-USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, 
-                        uint16_t configuration_value);
-
-USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,                              
-                             uint16_t length);
-
-USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost,                          
-                            uint8_t DeviceAddress);
-
-USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, 
-                        uint8_t ep_num, uint8_t altSetting);
-
-USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, 
-                                   uint8_t ep_num);
-
-USBH_DescHeader_t      *USBH_GetNextDesc (uint8_t   *pbuf, 
-                                                  uint16_t  *ptr);
-/**
-  * @}
-  */ 
-
-#endif /* __USBH_CTLREQ_H */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_ctlreq.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_ctlreq.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_CTLREQ_H
+#define __USBH_CTLREQ_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_CTLREQ
+  * @brief This file is the 
+  * @{
+  */ 
+
+
+/** @defgroup USBH_CTLREQ_Exported_Defines
+  * @{
+  */
+/*Standard Feature Selector for clear feature command*/
+#define FEATURE_SELECTOR_ENDPOINT         0X00
+#define FEATURE_SELECTOR_DEVICE           0X01
+
+
+#define INTERFACE_DESC_TYPE               0x04
+#define ENDPOINT_DESC_TYPE                0x05
+#define INTERFACE_DESC_SIZE               0x09
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_CTLREQ_Exported_Types
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_CTLREQ_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CTLREQ_Exported_Variables
+  * @{
+  */ 
+extern uint8_t USBH_CfgDesc[512];
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CTLREQ_Exported_FunctionsPrototype
+  * @{
+  */
+USBH_StatusTypeDef USBH_CtlReq     (USBH_HandleTypeDef *phost, 
+                             uint8_t             *buff,
+                             uint16_t            length);
+
+USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,                                
+                               uint8_t  req_type,
+                               uint16_t value_idx, 
+                               uint8_t* buff, 
+                               uint16_t length );
+
+USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost,
+                             uint8_t length);
+
+USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,                              
+                                uint8_t string_index, 
+                                uint8_t *buff, 
+                                uint16_t length);
+
+USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, 
+                        uint16_t configuration_value);
+
+USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,                              
+                             uint16_t length);
+
+USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost,                          
+                            uint8_t DeviceAddress);
+
+USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, 
+                        uint8_t ep_num, uint8_t altSetting);
+
+USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, 
+                                   uint8_t ep_num);
+
+USBH_DescHeader_t      *USBH_GetNextDesc (uint8_t   *pbuf, 
+                                                  uint16_t  *ptr);
+/**
+  * @}
+  */ 
+
+#endif /* __USBH_CTLREQ_H */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/micropython/ports/stm32/usbhost/Core/Inc/usbh_def.h b/micropython/ports/stm32/usbhost/Core/Inc/usbh_def.h
index cf24d69f3702cfa224f2d52aac80a08a7dac9656..d6ba6a6976a8b95320587807308d2f7c5cd6c1af 100644
--- a/micropython/ports/stm32/usbhost/Core/Inc/usbh_def.h
+++ b/micropython/ports/stm32/usbhost/Core/Inc/usbh_def.h
@@ -1,480 +1,480 @@
-/**
-  ******************************************************************************
-  * @file    usbh_def.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Definitions used in the USB host library
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_DEF
-  * @brief This file is includes USB descriptors
-  * @{
-  */ 
-
-#ifndef  USBH_DEF_H
-#define  USBH_DEF_H
-
-#include "usbh_conf.h"
-
-#ifndef NULL
-#define NULL ((void *)0)
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-
-#define ValBit(VAR,POS)                               (VAR & (1 << POS))
-#define SetBit(VAR,POS)                               (VAR |= (1 << POS))
-#define ClrBit(VAR,POS)                               (VAR &= ((1 << POS)^255))
-
-#define  LE16(addr)             (((uint16_t)(*((uint8_t *)(addr))))\
-                                + (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
-
-#define  LE16S(addr)              (uint16_t)(LE16((addr)))
-
-#define  LE32(addr)              ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
-                                              (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
-                                              (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16) + \
-                                              (((uint32_t)(*(((uint8_t *)(addr)) + 3))) << 24)))
-
-#define  LE64(addr)              ((((uint64_t)(*(((uint8_t *)(addr)) + 0))) + \
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 1))) <<  8) +\
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 2))) << 16) +\
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 3))) << 24) +\
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 4))) << 32) +\
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 5))) << 40) +\
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 6))) << 48) +\
-                                              (((uint64_t)(*(((uint8_t *)(addr)) + 7))) << 56)))
-
-
-#define  LE24(addr)              ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
-                                              (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
-                                              (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16)))
-
-
-#define  LE32S(addr)              (int32_t)(LE32((addr)))
-
-
-
-#define  USB_LEN_DESC_HDR                               0x02
-#define  USB_LEN_DEV_DESC                               0x12
-#define  USB_LEN_CFG_DESC                               0x09
-#define  USB_LEN_IF_DESC                                0x09
-#define  USB_LEN_EP_DESC                                0x07
-#define  USB_LEN_OTG_DESC                               0x03
-#define  USB_LEN_SETUP_PKT                              0x08
-
-/* bmRequestType :D7 Data Phase Transfer Direction  */
-#define  USB_REQ_DIR_MASK                               0x80
-#define  USB_H2D                                        0x00
-#define  USB_D2H                                        0x80
-
-/* bmRequestType D6..5 Type */
-#define  USB_REQ_TYPE_STANDARD                          0x00
-#define  USB_REQ_TYPE_CLASS                             0x20
-#define  USB_REQ_TYPE_VENDOR                            0x40
-#define  USB_REQ_TYPE_RESERVED                          0x60
-
-/* bmRequestType D4..0 Recipient */
-#define  USB_REQ_RECIPIENT_DEVICE                       0x00
-#define  USB_REQ_RECIPIENT_INTERFACE                    0x01
-#define  USB_REQ_RECIPIENT_ENDPOINT                     0x02
-#define  USB_REQ_RECIPIENT_OTHER                        0x03
-
-/* Table 9-4. Standard Request Codes  */
-/* bRequest , Value */
-#define  USB_REQ_GET_STATUS                             0x00
-#define  USB_REQ_CLEAR_FEATURE                          0x01
-#define  USB_REQ_SET_FEATURE                            0x03
-#define  USB_REQ_SET_ADDRESS                            0x05
-#define  USB_REQ_GET_DESCRIPTOR                         0x06
-#define  USB_REQ_SET_DESCRIPTOR                         0x07
-#define  USB_REQ_GET_CONFIGURATION                      0x08
-#define  USB_REQ_SET_CONFIGURATION                      0x09
-#define  USB_REQ_GET_INTERFACE                          0x0A
-#define  USB_REQ_SET_INTERFACE                          0x0B
-#define  USB_REQ_SYNCH_FRAME                            0x0C
-
-/* Table 9-5. Descriptor Types of USB Specifications */
-#define  USB_DESC_TYPE_DEVICE                              1
-#define  USB_DESC_TYPE_CONFIGURATION                       2
-#define  USB_DESC_TYPE_STRING                              3
-#define  USB_DESC_TYPE_INTERFACE                           4
-#define  USB_DESC_TYPE_ENDPOINT                            5
-#define  USB_DESC_TYPE_DEVICE_QUALIFIER                    6
-#define  USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION           7
-#define  USB_DESC_TYPE_INTERFACE_POWER                     8
-#define  USB_DESC_TYPE_HID                                 0x21
-#define  USB_DESC_TYPE_HID_REPORT                          0x22
-
-
-#define USB_DEVICE_DESC_SIZE                               18
-#define USB_CONFIGURATION_DESC_SIZE                        9
-#define USB_HID_DESC_SIZE                                  9
-#define USB_INTERFACE_DESC_SIZE                            9
-#define USB_ENDPOINT_DESC_SIZE                             7
-
-/* Descriptor Type and Descriptor Index  */
-/* Use the following values when calling the function USBH_GetDescriptor  */
-#define  USB_DESC_DEVICE                    ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
-#define  USB_DESC_CONFIGURATION             ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
-#define  USB_DESC_STRING                    ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
-#define  USB_DESC_INTERFACE                 ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
-#define  USB_DESC_ENDPOINT                  ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
-#define  USB_DESC_DEVICE_QUALIFIER          ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
-#define  USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
-#define  USB_DESC_INTERFACE_POWER           ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
-#define  USB_DESC_HID_REPORT                ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
-#define  USB_DESC_HID                       ((USB_DESC_TYPE_HID << 8) & 0xFF00)
-
-
-#define  USB_EP_TYPE_CTRL                               0x00
-#define  USB_EP_TYPE_ISOC                               0x01
-#define  USB_EP_TYPE_BULK                               0x02
-#define  USB_EP_TYPE_INTR                               0x03
-
-#define  USB_EP_DIR_OUT                                 0x00
-#define  USB_EP_DIR_IN                                  0x80
-#define  USB_EP_DIR_MSK                                 0x80  
-
-#define USBH_MAX_PIPES_NBR                              15                                                
-
-
-
-#define USBH_DEVICE_ADDRESS_DEFAULT                     0
-#define USBH_MAX_ERROR_COUNT                            2
-#define USBH_DEVICE_ADDRESS                             1
-
-
-/**
-  * @}
-  */ 
-
-
-#define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
-                                           + USB_INTERFACE_DESC_SIZE\
-                                           + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
-
-
-#define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
-                                          ConfigurationDescriptor.wTotalLength)
-
-
-typedef union
-{
-  uint16_t w;
-  struct BW
-  {
-    uint8_t msb;
-    uint8_t lsb;
-  }
-  bw;
-}
-uint16_t_uint8_t;
-
-
-typedef union _USB_Setup
-{
-  uint32_t d8[2];
-  
-  struct _SetupPkt_Struc
-  {
-    uint8_t           bmRequestType;
-    uint8_t           bRequest;
-    uint16_t_uint8_t  wValue;
-    uint16_t_uint8_t  wIndex;
-    uint16_t_uint8_t  wLength;
-  } b;
-} 
-USB_Setup_TypeDef;  
-
-typedef  struct  _DescHeader 
-{
-    uint8_t  bLength;       
-    uint8_t  bDescriptorType;
-} 
-USBH_DescHeader_t;
-
-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;
-  /* If equal to Zero, each interface specifies its own class
-  code if equal to 0xFF, the class code is vendor specified.
-  Otherwise field is valid Class Code.*/
-  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_DevDescTypeDef;
-
-typedef struct _EndpointDescriptor
-{
-  uint8_t   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_EpDescTypeDef;
-
-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_EpDescTypeDef               Ep_Desc[USBH_MAX_NUM_ENDPOINTS];   
-}
-USBH_InterfaceDescTypeDef;
-
-
-typedef struct _ConfigurationDescriptor
-{
-  uint8_t   bLength;
-  uint8_t   bDescriptorType;
-  uint16_t  wTotalLength;        /* Total Length of Data Returned */
-  uint8_t   bNumInterfaces;       /* Number of Interfaces */
-  uint8_t   bConfigurationValue;  /* Value to use as an argument to select this configuration*/
-  uint8_t   iConfiguration;       /*Index of String Descriptor Describing this configuration */
-  uint8_t   bmAttributes;         /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
-  uint8_t   bMaxPower;            /*Maximum Power Consumption */
-  USBH_InterfaceDescTypeDef        Itf_Desc[USBH_MAX_NUM_INTERFACES];
-}
-USBH_CfgDescTypeDef;
-
-
-/* Following USB Host status */
-typedef enum 
-{
-  USBH_OK   = 0,
-  USBH_BUSY,
-  USBH_FAIL,
-  USBH_NOT_SUPPORTED,
-  USBH_UNRECOVERED_ERROR,
-  USBH_ERROR_SPEED_UNKNOWN,
-}USBH_StatusTypeDef;
-
-
-/** @defgroup USBH_CORE_Exported_Types
-  * @{
-  */
-
-typedef enum 
-{
-  USBH_SPEED_HIGH  = 0,
-  USBH_SPEED_FULL  = 1,
-  USBH_SPEED_LOW   = 2,  
-    
-}USBH_SpeedTypeDef;
-
-/* Following states are used for gState */
-typedef enum 
-{
-  HOST_IDLE =0,
-  HOST_DEV_WAIT_FOR_ATTACHMENT,  
-  HOST_DEV_ATTACHED,
-  HOST_DEV_DISCONNECTED,  
-  HOST_DETECT_DEVICE_SPEED,
-  HOST_ENUMERATION,
-  HOST_CLASS_REQUEST,  
-  HOST_INPUT,
-  HOST_SET_CONFIGURATION,
-  HOST_CHECK_CLASS,
-  HOST_CLASS,
-  HOST_SUSPENDED,
-  HOST_ABORT_STATE,  
-}HOST_StateTypeDef;  
-
-/* Following states are used for EnumerationState */
-typedef enum 
-{
-  ENUM_IDLE = 0,
-  ENUM_GET_FULL_DEV_DESC,
-  ENUM_SET_ADDR,
-  ENUM_GET_CFG_DESC,
-  ENUM_GET_FULL_CFG_DESC,
-  ENUM_GET_MFC_STRING_DESC,
-  ENUM_GET_PRODUCT_STRING_DESC,
-  ENUM_GET_SERIALNUM_STRING_DESC,
-} ENUM_StateTypeDef;  
-
-/* Following states are used for CtrlXferStateMachine */
-typedef enum 
-{
-  CTRL_IDLE =0,
-  CTRL_SETUP,
-  CTRL_SETUP_WAIT,
-  CTRL_DATA_IN,
-  CTRL_DATA_IN_WAIT,
-  CTRL_DATA_OUT,
-  CTRL_DATA_OUT_WAIT,
-  CTRL_STATUS_IN,
-  CTRL_STATUS_IN_WAIT,
-  CTRL_STATUS_OUT,
-  CTRL_STATUS_OUT_WAIT,
-  CTRL_ERROR,
-  CTRL_STALLED,
-  CTRL_COMPLETE    
-}CTRL_StateTypeDef;  
-
-
-/* Following states are used for RequestState */
-typedef enum 
-{
-  CMD_IDLE =0,
-  CMD_SEND,
-  CMD_WAIT
-} CMD_StateTypeDef;  
-
-typedef enum {
-  USBH_URB_IDLE = 0,
-  USBH_URB_DONE,
-  USBH_URB_NOTREADY,
-  USBH_URB_NYET,  
-  USBH_URB_ERROR,
-  USBH_URB_STALL
-}USBH_URBStateTypeDef;
-
-typedef enum
-{
-  USBH_PORT_EVENT = 1,  
-  USBH_URB_EVENT,
-  USBH_CONTROL_EVENT,    
-  USBH_CLASS_EVENT,     
-  USBH_STATE_CHANGED_EVENT,   
-}
-USBH_OSEventTypeDef;
-
-/* Control request structure */
-typedef struct 
-{
-  uint8_t               pipe_in; 
-  uint8_t               pipe_out; 
-  uint8_t               pipe_size;  
-  uint8_t               *buff;
-  uint16_t              length;
-  uint16_t              timer;  
-  USB_Setup_TypeDef     setup;
-  CTRL_StateTypeDef     state;  
-  uint8_t               errorcount;  
-
-} USBH_CtrlTypeDef;
-
-/* Attached device structure */
-typedef struct
-{
-#if (USBH_KEEP_CFG_DESCRIPTOR == 1)  
-  uint8_t                           CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION];
-#endif  
-  uint8_t                           Data[USBH_MAX_DATA_BUFFER];
-  uint8_t                           address;
-  uint8_t                           speed;
-  __IO uint8_t                      is_connected;    
-  uint8_t                           current_interface;   
-  USBH_DevDescTypeDef               DevDesc;
-  USBH_CfgDescTypeDef               CfgDesc; 
-  
-}USBH_DeviceTypeDef;
-
-struct _USBH_HandleTypeDef;
-
-/* USB Host Class structure */
-typedef struct 
-{
-  const char          *Name;
-  uint8_t              ClassCode;  
-  USBH_StatusTypeDef  (*Init)        (struct _USBH_HandleTypeDef *phost);
-  USBH_StatusTypeDef  (*DeInit)      (struct _USBH_HandleTypeDef *phost);
-  USBH_StatusTypeDef  (*Requests)    (struct _USBH_HandleTypeDef *phost);  
-  USBH_StatusTypeDef  (*BgndProcess) (struct _USBH_HandleTypeDef *phost);
-  USBH_StatusTypeDef  (*SOFProcess) (struct _USBH_HandleTypeDef *phost);  
-  void*                pData;
-} USBH_ClassTypeDef;
-
-/* USB Host handle structure */
-typedef struct _USBH_HandleTypeDef
-{
-  __IO HOST_StateTypeDef     gState;       /*  Host State Machine Value */
-  ENUM_StateTypeDef     EnumState;    /* Enumeration state Machine */
-  CMD_StateTypeDef      RequestState;       
-  USBH_CtrlTypeDef      Control;
-  USBH_DeviceTypeDef    device;
-  USBH_ClassTypeDef*    pClass[USBH_MAX_NUM_SUPPORTED_CLASS];
-  USBH_ClassTypeDef*    pActiveClass;
-  uint32_t              ClassNumber;
-  uint32_t              Pipes[15];
-  __IO uint32_t         Timer;
-  uint8_t               id;  
-  void*                 pData;                  
-  void                 (* pUser )(struct _USBH_HandleTypeDef *pHandle, uint8_t id);
-  
-#if (USBH_USE_OS == 1)
-  osMessageQId          os_event;   
-  osThreadId            thread; 
-#endif  
-  
-} USBH_HandleTypeDef;
-
-
-#if  defined ( __GNUC__ )
-  #ifndef __weak
-    #define __weak   __attribute__((weak))
-  #endif /* __weak */
-  #ifndef __packed
-    #define __packed __attribute__((__packed__))
-  #endif /* __packed */
-#endif /* __GNUC__ */
-
-#endif
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
+/**
+  ******************************************************************************
+  * @file    usbh_def.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Definitions used in the USB host library
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_DEF
+  * @brief This file is includes USB descriptors
+  * @{
+  */ 
+
+#ifndef  USBH_DEF_H
+#define  USBH_DEF_H
+
+#include "usbh_conf.h"
+
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+
+#define ValBit(VAR,POS)                               (VAR & (1 << POS))
+#define SetBit(VAR,POS)                               (VAR |= (1 << POS))
+#define ClrBit(VAR,POS)                               (VAR &= ((1 << POS)^255))
+
+#define  LE16(addr)             (((uint16_t)(*((uint8_t *)(addr))))\
+                                + (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
+
+#define  LE16S(addr)              (uint16_t)(LE16((addr)))
+
+#define  LE32(addr)              ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
+                                              (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
+                                              (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16) + \
+                                              (((uint32_t)(*(((uint8_t *)(addr)) + 3))) << 24)))
+
+#define  LE64(addr)              ((((uint64_t)(*(((uint8_t *)(addr)) + 0))) + \
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 1))) <<  8) +\
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 2))) << 16) +\
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 3))) << 24) +\
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 4))) << 32) +\
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 5))) << 40) +\
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 6))) << 48) +\
+                                              (((uint64_t)(*(((uint8_t *)(addr)) + 7))) << 56)))
+
+
+#define  LE24(addr)              ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
+                                              (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
+                                              (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16)))
+
+
+#define  LE32S(addr)              (int32_t)(LE32((addr)))
+
+
+
+#define  USB_LEN_DESC_HDR                               0x02
+#define  USB_LEN_DEV_DESC                               0x12
+#define  USB_LEN_CFG_DESC                               0x09
+#define  USB_LEN_IF_DESC                                0x09
+#define  USB_LEN_EP_DESC                                0x07
+#define  USB_LEN_OTG_DESC                               0x03
+#define  USB_LEN_SETUP_PKT                              0x08
+
+/* bmRequestType :D7 Data Phase Transfer Direction  */
+#define  USB_REQ_DIR_MASK                               0x80
+#define  USB_H2D                                        0x00
+#define  USB_D2H                                        0x80
+
+/* bmRequestType D6..5 Type */
+#define  USB_REQ_TYPE_STANDARD                          0x00
+#define  USB_REQ_TYPE_CLASS                             0x20
+#define  USB_REQ_TYPE_VENDOR                            0x40
+#define  USB_REQ_TYPE_RESERVED                          0x60
+
+/* bmRequestType D4..0 Recipient */
+#define  USB_REQ_RECIPIENT_DEVICE                       0x00
+#define  USB_REQ_RECIPIENT_INTERFACE                    0x01
+#define  USB_REQ_RECIPIENT_ENDPOINT                     0x02
+#define  USB_REQ_RECIPIENT_OTHER                        0x03
+
+/* Table 9-4. Standard Request Codes  */
+/* bRequest , Value */
+#define  USB_REQ_GET_STATUS                             0x00
+#define  USB_REQ_CLEAR_FEATURE                          0x01
+#define  USB_REQ_SET_FEATURE                            0x03
+#define  USB_REQ_SET_ADDRESS                            0x05
+#define  USB_REQ_GET_DESCRIPTOR                         0x06
+#define  USB_REQ_SET_DESCRIPTOR                         0x07
+#define  USB_REQ_GET_CONFIGURATION                      0x08
+#define  USB_REQ_SET_CONFIGURATION                      0x09
+#define  USB_REQ_GET_INTERFACE                          0x0A
+#define  USB_REQ_SET_INTERFACE                          0x0B
+#define  USB_REQ_SYNCH_FRAME                            0x0C
+
+/* Table 9-5. Descriptor Types of USB Specifications */
+#define  USB_DESC_TYPE_DEVICE                              1
+#define  USB_DESC_TYPE_CONFIGURATION                       2
+#define  USB_DESC_TYPE_STRING                              3
+#define  USB_DESC_TYPE_INTERFACE                           4
+#define  USB_DESC_TYPE_ENDPOINT                            5
+#define  USB_DESC_TYPE_DEVICE_QUALIFIER                    6
+#define  USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION           7
+#define  USB_DESC_TYPE_INTERFACE_POWER                     8
+#define  USB_DESC_TYPE_HID                                 0x21
+#define  USB_DESC_TYPE_HID_REPORT                          0x22
+
+
+#define USB_DEVICE_DESC_SIZE                               18
+#define USB_CONFIGURATION_DESC_SIZE                        9
+#define USB_HID_DESC_SIZE                                  9
+#define USB_INTERFACE_DESC_SIZE                            9
+#define USB_ENDPOINT_DESC_SIZE                             7
+
+/* Descriptor Type and Descriptor Index  */
+/* Use the following values when calling the function USBH_GetDescriptor  */
+#define  USB_DESC_DEVICE                    ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
+#define  USB_DESC_CONFIGURATION             ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
+#define  USB_DESC_STRING                    ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
+#define  USB_DESC_INTERFACE                 ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
+#define  USB_DESC_ENDPOINT                  ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
+#define  USB_DESC_DEVICE_QUALIFIER          ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
+#define  USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
+#define  USB_DESC_INTERFACE_POWER           ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
+#define  USB_DESC_HID_REPORT                ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
+#define  USB_DESC_HID                       ((USB_DESC_TYPE_HID << 8) & 0xFF00)
+
+
+#define  USB_EP_TYPE_CTRL                               0x00
+#define  USB_EP_TYPE_ISOC                               0x01
+#define  USB_EP_TYPE_BULK                               0x02
+#define  USB_EP_TYPE_INTR                               0x03
+
+#define  USB_EP_DIR_OUT                                 0x00
+#define  USB_EP_DIR_IN                                  0x80
+#define  USB_EP_DIR_MSK                                 0x80  
+
+#define USBH_MAX_PIPES_NBR                              15                                                
+
+
+
+#define USBH_DEVICE_ADDRESS_DEFAULT                     0
+#define USBH_MAX_ERROR_COUNT                            2
+#define USBH_DEVICE_ADDRESS                             1
+
+
+/**
+  * @}
+  */ 
+
+
+#define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
+                                           + USB_INTERFACE_DESC_SIZE\
+                                           + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
+
+
+#define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
+                                          ConfigurationDescriptor.wTotalLength)
+
+
+typedef union
+{
+  uint16_t w;
+  struct BW
+  {
+    uint8_t msb;
+    uint8_t lsb;
+  }
+  bw;
+}
+uint16_t_uint8_t;
+
+
+typedef union _USB_Setup
+{
+  uint32_t d8[2];
+  
+  struct _SetupPkt_Struc
+  {
+    uint8_t           bmRequestType;
+    uint8_t           bRequest;
+    uint16_t_uint8_t  wValue;
+    uint16_t_uint8_t  wIndex;
+    uint16_t_uint8_t  wLength;
+  } b;
+} 
+USB_Setup_TypeDef;  
+
+typedef  struct  _DescHeader 
+{
+    uint8_t  bLength;       
+    uint8_t  bDescriptorType;
+} 
+USBH_DescHeader_t;
+
+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;
+  /* If equal to Zero, each interface specifies its own class
+  code if equal to 0xFF, the class code is vendor specified.
+  Otherwise field is valid Class Code.*/
+  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_DevDescTypeDef;
+
+typedef struct _EndpointDescriptor
+{
+  uint8_t   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_EpDescTypeDef;
+
+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_EpDescTypeDef               Ep_Desc[USBH_MAX_NUM_ENDPOINTS];   
+}
+USBH_InterfaceDescTypeDef;
+
+
+typedef struct _ConfigurationDescriptor
+{
+  uint8_t   bLength;
+  uint8_t   bDescriptorType;
+  uint16_t  wTotalLength;        /* Total Length of Data Returned */
+  uint8_t   bNumInterfaces;       /* Number of Interfaces */
+  uint8_t   bConfigurationValue;  /* Value to use as an argument to select this configuration*/
+  uint8_t   iConfiguration;       /*Index of String Descriptor Describing this configuration */
+  uint8_t   bmAttributes;         /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
+  uint8_t   bMaxPower;            /*Maximum Power Consumption */
+  USBH_InterfaceDescTypeDef        Itf_Desc[USBH_MAX_NUM_INTERFACES];
+}
+USBH_CfgDescTypeDef;
+
+
+/* Following USB Host status */
+typedef enum 
+{
+  USBH_OK   = 0,
+  USBH_BUSY,
+  USBH_FAIL,
+  USBH_NOT_SUPPORTED,
+  USBH_UNRECOVERED_ERROR,
+  USBH_ERROR_SPEED_UNKNOWN,
+}USBH_StatusTypeDef;
+
+
+/** @defgroup USBH_CORE_Exported_Types
+  * @{
+  */
+
+typedef enum 
+{
+  USBH_SPEED_HIGH  = 0,
+  USBH_SPEED_FULL  = 1,
+  USBH_SPEED_LOW   = 2,  
+    
+}USBH_SpeedTypeDef;
+
+/* Following states are used for gState */
+typedef enum 
+{
+  HOST_IDLE =0,
+  HOST_DEV_WAIT_FOR_ATTACHMENT,  
+  HOST_DEV_ATTACHED,
+  HOST_DEV_DISCONNECTED,  
+  HOST_DETECT_DEVICE_SPEED,
+  HOST_ENUMERATION,
+  HOST_CLASS_REQUEST,  
+  HOST_INPUT,
+  HOST_SET_CONFIGURATION,
+  HOST_CHECK_CLASS,
+  HOST_CLASS,
+  HOST_SUSPENDED,
+  HOST_ABORT_STATE,  
+}HOST_StateTypeDef;  
+
+/* Following states are used for EnumerationState */
+typedef enum 
+{
+  ENUM_IDLE = 0,
+  ENUM_GET_FULL_DEV_DESC,
+  ENUM_SET_ADDR,
+  ENUM_GET_CFG_DESC,
+  ENUM_GET_FULL_CFG_DESC,
+  ENUM_GET_MFC_STRING_DESC,
+  ENUM_GET_PRODUCT_STRING_DESC,
+  ENUM_GET_SERIALNUM_STRING_DESC,
+} ENUM_StateTypeDef;  
+
+/* Following states are used for CtrlXferStateMachine */
+typedef enum 
+{
+  CTRL_IDLE =0,
+  CTRL_SETUP,
+  CTRL_SETUP_WAIT,
+  CTRL_DATA_IN,
+  CTRL_DATA_IN_WAIT,
+  CTRL_DATA_OUT,
+  CTRL_DATA_OUT_WAIT,
+  CTRL_STATUS_IN,
+  CTRL_STATUS_IN_WAIT,
+  CTRL_STATUS_OUT,
+  CTRL_STATUS_OUT_WAIT,
+  CTRL_ERROR,
+  CTRL_STALLED,
+  CTRL_COMPLETE    
+}CTRL_StateTypeDef;  
+
+
+/* Following states are used for RequestState */
+typedef enum 
+{
+  CMD_IDLE =0,
+  CMD_SEND,
+  CMD_WAIT
+} CMD_StateTypeDef;  
+
+typedef enum {
+  USBH_URB_IDLE = 0,
+  USBH_URB_DONE,
+  USBH_URB_NOTREADY,
+  USBH_URB_NYET,  
+  USBH_URB_ERROR,
+  USBH_URB_STALL
+}USBH_URBStateTypeDef;
+
+typedef enum
+{
+  USBH_PORT_EVENT = 1,  
+  USBH_URB_EVENT,
+  USBH_CONTROL_EVENT,    
+  USBH_CLASS_EVENT,     
+  USBH_STATE_CHANGED_EVENT,   
+}
+USBH_OSEventTypeDef;
+
+/* Control request structure */
+typedef struct 
+{
+  uint8_t               pipe_in; 
+  uint8_t               pipe_out; 
+  uint8_t               pipe_size;  
+  uint8_t               *buff;
+  uint16_t              length;
+  uint16_t              timer;  
+  USB_Setup_TypeDef     setup;
+  CTRL_StateTypeDef     state;  
+  uint8_t               errorcount;  
+
+} USBH_CtrlTypeDef;
+
+/* Attached device structure */
+typedef struct
+{
+#if (USBH_KEEP_CFG_DESCRIPTOR == 1)  
+  uint8_t                           CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION];
+#endif  
+  uint8_t                           Data[USBH_MAX_DATA_BUFFER];
+  uint8_t                           address;
+  uint8_t                           speed;
+  __IO uint8_t                      is_connected;    
+  uint8_t                           current_interface;   
+  USBH_DevDescTypeDef               DevDesc;
+  USBH_CfgDescTypeDef               CfgDesc; 
+  
+}USBH_DeviceTypeDef;
+
+struct _USBH_HandleTypeDef;
+
+/* USB Host Class structure */
+typedef struct 
+{
+  const char          *Name;
+  uint8_t              ClassCode;  
+  USBH_StatusTypeDef  (*Init)        (struct _USBH_HandleTypeDef *phost);
+  USBH_StatusTypeDef  (*DeInit)      (struct _USBH_HandleTypeDef *phost);
+  USBH_StatusTypeDef  (*Requests)    (struct _USBH_HandleTypeDef *phost);  
+  USBH_StatusTypeDef  (*BgndProcess) (struct _USBH_HandleTypeDef *phost);
+  USBH_StatusTypeDef  (*SOFProcess) (struct _USBH_HandleTypeDef *phost);  
+  void*                pData;
+} USBH_ClassTypeDef;
+
+/* USB Host handle structure */
+typedef struct _USBH_HandleTypeDef
+{
+  __IO HOST_StateTypeDef     gState;       /*  Host State Machine Value */
+  ENUM_StateTypeDef     EnumState;    /* Enumeration state Machine */
+  CMD_StateTypeDef      RequestState;       
+  USBH_CtrlTypeDef      Control;
+  USBH_DeviceTypeDef    device;
+  USBH_ClassTypeDef*    pClass[USBH_MAX_NUM_SUPPORTED_CLASS];
+  USBH_ClassTypeDef*    pActiveClass;
+  uint32_t              ClassNumber;
+  uint32_t              Pipes[15];
+  __IO uint32_t         Timer;
+  uint8_t               id;  
+  void*                 pData;                  
+  void                 (* pUser )(struct _USBH_HandleTypeDef *pHandle, uint8_t id);
+  
+#if (USBH_USE_OS == 1)
+  osMessageQId          os_event;   
+  osThreadId            thread; 
+#endif  
+  
+} USBH_HandleTypeDef;
+
+
+#if  defined ( __GNUC__ )
+  #ifndef __weak
+    #define __weak   __attribute__((weak))
+  #endif /* __weak */
+  #ifndef __packed
+    #define __packed __attribute__((__packed__))
+  #endif /* __packed */
+#endif /* __GNUC__ */
+
+#endif
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/micropython/ports/stm32/usbhost/Core/Inc/usbh_ioreq.h b/micropython/ports/stm32/usbhost/Core/Inc/usbh_ioreq.h
index 463d4ea37b21bc8dcd483514ad6b6412b3999e54..1b5055efe94473cc5ed83881db06b1fbec2c037b 100644
--- a/micropython/ports/stm32/usbhost/Core/Inc/usbh_ioreq.h
+++ b/micropython/ports/stm32/usbhost/Core/Inc/usbh_ioreq.h
@@ -1,159 +1,159 @@
-/**
-  ******************************************************************************
-  * @file    usbh_ioreq.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_ioreq.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_IOREQ_H
-#define __USBH_IOREQ_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_conf.h"
-#include "usbh_core.h"
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_IOREQ
-  * @brief This file is the header file for usbh_ioreq.c
-  * @{
-  */ 
-
-
-/** @defgroup USBH_IOREQ_Exported_Defines
-  * @{
-  */
-    
-#define USBH_PID_SETUP                            0
-#define USBH_PID_DATA                             1
-
-#define USBH_EP_CONTROL                           0
-#define USBH_EP_ISO                               1
-#define USBH_EP_BULK                              2
-#define USBH_EP_INTERRUPT                         3
-
-#define USBH_SETUP_PKT_SIZE                       8
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_IOREQ_Exported_Types
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_IOREQ_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_IOREQ_Exported_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_IOREQ_Exported_FunctionsPrototype
-  * @{
-  */
-USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint8_t hc_num);
-
-USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t hc_num,
-                                uint8_t do_ping );
-
-USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t hc_num);
-
-USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t hc_num);
-
-USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t hc_num,
-                                uint8_t do_ping );
-
-USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, 
-                                       uint8_t             *buff, 
-                                       uint8_t             length,
-                                       uint8_t             hc_num);
-
-USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, 
-                                    uint8_t *buff, 
-                                    uint8_t length,
-                                    uint8_t hc_num);
-
-
-USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint32_t length,
-                                uint8_t hc_num);
-
-
-USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint32_t length,
-                                uint8_t hc_num);
-/**
-  * @}
-  */ 
-
-#endif /* __USBH_IOREQ_H */
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_ioreq.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_ioreq.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_IOREQ_H
+#define __USBH_IOREQ_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_conf.h"
+#include "usbh_core.h"
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_IOREQ
+  * @brief This file is the header file for usbh_ioreq.c
+  * @{
+  */ 
+
+
+/** @defgroup USBH_IOREQ_Exported_Defines
+  * @{
+  */
+    
+#define USBH_PID_SETUP                            0
+#define USBH_PID_DATA                             1
+
+#define USBH_EP_CONTROL                           0
+#define USBH_EP_ISO                               1
+#define USBH_EP_BULK                              2
+#define USBH_EP_INTERRUPT                         3
+
+#define USBH_SETUP_PKT_SIZE                       8
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_IOREQ_Exported_Types
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_IOREQ_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_IOREQ_Exported_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_IOREQ_Exported_FunctionsPrototype
+  * @{
+  */
+USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint8_t hc_num);
+
+USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t hc_num,
+                                uint8_t do_ping );
+
+USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t hc_num);
+
+USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t hc_num);
+
+USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t hc_num,
+                                uint8_t do_ping );
+
+USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, 
+                                       uint8_t             *buff, 
+                                       uint8_t             length,
+                                       uint8_t             hc_num);
+
+USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, 
+                                    uint8_t *buff, 
+                                    uint8_t length,
+                                    uint8_t hc_num);
+
+
+USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint32_t length,
+                                uint8_t hc_num);
+
+
+USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint32_t length,
+                                uint8_t hc_num);
+/**
+  * @}
+  */ 
+
+#endif /* __USBH_IOREQ_H */
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/micropython/ports/stm32/usbhost/Core/Inc/usbh_pipes.h b/micropython/ports/stm32/usbhost/Core/Inc/usbh_pipes.h
index d72cd53870d22a7d5540b6655d6c51a1b26a1945..fe6581c765a7db48f3ed672d47590ae2d9fa207e 100644
--- a/micropython/ports/stm32/usbhost/Core/Inc/usbh_pipes.h
+++ b/micropython/ports/stm32/usbhost/Core/Inc/usbh_pipes.h
@@ -1,124 +1,124 @@
-/**
-  ******************************************************************************
-  * @file    usbh_PIPES.h
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   Header file for usbh_pipes.c
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __USBH_PIPES_H
-#define __USBH_PIPES_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_PIPES
-  * @brief This file is the header file for usbh_PIPES.c
-  * @{
-  */ 
-
-/** @defgroup USBH_PIPES_Exported_Defines
-  * @{
-  */
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_PIPES_Exported_Types
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_PIPES_Exported_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_PIPES_Exported_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_PIPES_Exported_FunctionsPrototype
-  * @{
-  */
-
-USBH_StatusTypeDef USBH_OpenPipe  (USBH_HandleTypeDef *phost,
-                            uint8_t ch_num,
-                            uint8_t epnum,                            
-                            uint8_t dev_address,
-                            uint8_t speed,
-                            uint8_t ep_type,
-                            uint16_t mps);
-
-USBH_StatusTypeDef USBH_ClosePipe  (USBH_HandleTypeDef *phost,
-                            uint8_t pipe_num);
-
-uint8_t USBH_AllocPipe  (USBH_HandleTypeDef *phost, 
-                         uint8_t ep_addr);
-
-USBH_StatusTypeDef USBH_FreePipe  (USBH_HandleTypeDef *phost, 
-                                   uint8_t idx);
-
-
-
-
-/**
-  * @}
-  */ 
-
-
-
-#endif /* __USBH_PIPES_H */
-
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_PIPES.h
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   Header file for usbh_pipes.c
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive  ----------------------------------------------*/
+#ifndef __USBH_PIPES_H
+#define __USBH_PIPES_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_PIPES
+  * @brief This file is the header file for usbh_PIPES.c
+  * @{
+  */ 
+
+/** @defgroup USBH_PIPES_Exported_Defines
+  * @{
+  */
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_PIPES_Exported_Types
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_PIPES_Exported_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_PIPES_Exported_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_PIPES_Exported_FunctionsPrototype
+  * @{
+  */
+
+USBH_StatusTypeDef USBH_OpenPipe  (USBH_HandleTypeDef *phost,
+                            uint8_t ch_num,
+                            uint8_t epnum,                            
+                            uint8_t dev_address,
+                            uint8_t speed,
+                            uint8_t ep_type,
+                            uint16_t mps);
+
+USBH_StatusTypeDef USBH_ClosePipe  (USBH_HandleTypeDef *phost,
+                            uint8_t pipe_num);
+
+uint8_t USBH_AllocPipe  (USBH_HandleTypeDef *phost, 
+                         uint8_t ep_addr);
+
+USBH_StatusTypeDef USBH_FreePipe  (USBH_HandleTypeDef *phost, 
+                                   uint8_t idx);
+
+
+
+
+/**
+  * @}
+  */ 
+
+
+
+#endif /* __USBH_PIPES_H */
+
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/micropython/ports/stm32/usbhost/Core/Src/usbh_conf_template.c b/micropython/ports/stm32/usbhost/Core/Src/usbh_conf_template.c
index 1c25f7b2e7324c8a94837417b234a3ccb1017404..de689ec0a119a5a94caf6ef8bf4b6f75807cff70 100644
--- a/micropython/ports/stm32/usbhost/Core/Src/usbh_conf_template.c
+++ b/micropython/ports/stm32/usbhost/Core/Src/usbh_conf_template.c
@@ -1,270 +1,270 @@
-/**
-  ******************************************************************************
-  * @file    usb_bsp.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file implements the board support package for the USB host library
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_core.h"
-
-/**
-  * @brief  USBH_LL_Init 
-  *         Initialize the Low Level portion of the Host driver.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_LL_Init (USBH_HandleTypeDef *phost)
-{
-
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_LL_DeInit 
-  *         De-Initialize the Low Level portion of the Host driver.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_LL_DeInit (USBH_HandleTypeDef *phost)
-{
-
-  return USBH_OK; 
-}
-
-/**
-  * @brief  USBH_LL_Start 
-  *         Start the Low Level portion of the Host driver.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_LL_Start(USBH_HandleTypeDef *phost)
-{
-
-  return USBH_OK; 
-}
-
-/**
-  * @brief  USBH_LL_Stop 
-  *         Stop the Low Level portion of the Host driver.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_LL_Stop (USBH_HandleTypeDef *phost)
-{
-
-  return USBH_OK; 
-}
-
-/**
-  * @brief  USBH_LL_GetSpeed 
-  *         Return the USB Host Speed from the Low Level Driver.
-  * @param  phost: Host handle
-  * @retval USBH Speeds
-  */
-USBH_SpeedTypeDef USBH_LL_GetSpeed  (USBH_HandleTypeDef *phost)
-{
-  USBH_SpeedTypeDef speed = 0;
-    
-
-  return  speed;
-}
-
-/**
-  * @brief  USBH_LL_ResetPort 
-  *         Reset the Host Port of the Low Level Driver.
-  * @param  phost: Host handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost) 
-{
-
-  return USBH_OK; 
-}
-
-/**
-  * @brief  USBH_LL_GetLastXferSize 
-  *         Return the last transfered packet size.
-  * @param  phost: Host handle
-  * @param  pipe: Pipe index   
-  * @retval Packet Size
-  */
-uint32_t USBH_LL_GetLastXferSize  (USBH_HandleTypeDef *phost, uint8_t pipe)  
-{
-
-}
-
-/**
-  * @brief  USBH_LL_OpenPipe 
-  *         Open a pipe of the Low Level Driver.
-  * @param  phost: Host handle
-  * @param  pipe_num: Pipe index
-  * @param  epnum: Endpoint Number
-  * @param  dev_address: Device USB address
-  * @param  speed: Device Speed 
-  * @param  ep_type: Endpoint Type
-  * @param  mps: Endpoint Max Packet Size                 
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef   USBH_LL_OpenPipe (USBH_HandleTypeDef *phost, 
-                                      uint8_t pipe_num,
-                                      uint8_t epnum,                                      
-                                      uint8_t dev_address,
-                                      uint8_t speed,
-                                      uint8_t ep_type,
-                                      uint16_t mps)
-{
- 
-  return USBH_OK; 
-}
-
-/**
-  * @brief  USBH_LL_ClosePipe 
-  *         Close a pipe of the Low Level Driver.
-  * @param  phost: Host handle
-  * @param  pipe_num: Pipe index               
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef   USBH_LL_ClosePipe   (USBH_HandleTypeDef *phost, uint8_t pipe)   
-{
-
-}
-/**
-  * @brief  USBH_LL_SubmitURB 
-  *         Submit a new URB to the low level driver.
-  * @param  phost: Host handle
-  * @param  pipe: Pipe index    
-  *         This parameter can be a value from 1 to 15
-  * @param  direction : Channel number
-  *          This parameter can be one of the these values:
-  *           0 : Output 
-  *           1 : Input
-  * @param  ep_type : Endpoint Type
-  *          This parameter can be one of the these values:
-  *            @arg EP_TYPE_CTRL: Control type
-  *            @arg EP_TYPE_ISOC: Isochrounous type
-  *            @arg EP_TYPE_BULK: Bulk type
-  *            @arg EP_TYPE_INTR: Interrupt type
-  * @param  token : Endpoint Type
-  *          This parameter can be one of the these values:
-  *            @arg 0: PID_SETUP
-  *            @arg 1: PID_DATA
-  * @param  pbuff : pointer to URB data
-  * @param  length : Length of URB data
-  * @param  do_ping : activate do ping protocol (for high speed only)
-  *          This parameter can be one of the these values:
-  *           0 : do ping inactive 
-  *           1 : do ping active 
-  * @retval Status
-  */
-
-USBH_StatusTypeDef   USBH_LL_SubmitURB  (USBH_HandleTypeDef *phost, 
-                                            uint8_t pipe, 
-                                            uint8_t direction ,
-                                            uint8_t ep_type,  
-                                            uint8_t token, 
-                                            uint8_t* pbuff, 
-                                            uint16_t length,
-                                            uint8_t do_ping ) 
-{
-
-  return USBH_OK;   
-}
-
-/**
-  * @brief  USBH_LL_GetURBState 
-  *         Get a URB state from the low level driver.
-  * @param  phost: Host handle
-  * @param  pipe: Pipe index
-  *         This parameter can be a value from 1 to 15
-  * @retval URB state
-  *          This parameter can be one of the these values:
-  *            @arg URB_IDLE
-  *            @arg URB_DONE
-  *            @arg URB_NOTREADY
-  *            @arg URB_NYET 
-  *            @arg URB_ERROR  
-  *            @arg URB_STALL      
-  */
-USBH_URBStateTypeDef  USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t pipe) 
-{
-
-}
-
-/**
-  * @brief  USBH_LL_DriverVBUS 
-  *         Drive VBUS.
-  * @param  phost: Host handle
-  * @param  state : VBUS state
-  *          This parameter can be one of the these values:
-  *           0 : VBUS Active 
-  *           1 : VBUS Inactive
-  * @retval Status
-  */
-
-USBH_StatusTypeDef  USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t state)
-{
-
-  return USBH_OK;  
-}
-
-/**
-  * @brief  USBH_LL_SetToggle 
-  *         Set toggle for a pipe.
-  * @param  phost: Host handle
-  * @param  pipe: Pipe index
-  * @param  pipe_num: Pipe index     
-  * @param  toggle: toggle (0/1)
-  * @retval Status
-  */
-USBH_StatusTypeDef   USBH_LL_SetToggle   (USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle)   
-{
-
-  return USBH_OK; 
-}
-
-/**
-  * @brief  USBH_LL_GetToggle 
-  *         Return the current toggle of a pipe.
-  * @param  phost: Host handle
-  * @param  pipe: Pipe index
-  * @retval toggle (0/1)
-  */
-uint8_t  USBH_LL_GetToggle   (USBH_HandleTypeDef *phost, uint8_t pipe)   
-{
-  uint8_t toggle = 0;
-  
-
-  return toggle; 
-}
-/**
-  * @brief  USBH_Delay 
-  *         Delay routine for the USB Host Library
-  * @param  Delay: Delay in ms
-  * @retval None
-  */
-void  USBH_Delay (uint32_t Delay)
-{
-
-}
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usb_bsp.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file implements the board support package for the USB host library
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+/**
+  * @brief  USBH_LL_Init 
+  *         Initialize the Low Level portion of the Host driver.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_LL_Init (USBH_HandleTypeDef *phost)
+{
+
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_LL_DeInit 
+  *         De-Initialize the Low Level portion of the Host driver.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_LL_DeInit (USBH_HandleTypeDef *phost)
+{
+
+  return USBH_OK; 
+}
+
+/**
+  * @brief  USBH_LL_Start 
+  *         Start the Low Level portion of the Host driver.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_LL_Start(USBH_HandleTypeDef *phost)
+{
+
+  return USBH_OK; 
+}
+
+/**
+  * @brief  USBH_LL_Stop 
+  *         Stop the Low Level portion of the Host driver.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_LL_Stop (USBH_HandleTypeDef *phost)
+{
+
+  return USBH_OK; 
+}
+
+/**
+  * @brief  USBH_LL_GetSpeed 
+  *         Return the USB Host Speed from the Low Level Driver.
+  * @param  phost: Host handle
+  * @retval USBH Speeds
+  */
+USBH_SpeedTypeDef USBH_LL_GetSpeed  (USBH_HandleTypeDef *phost)
+{
+  USBH_SpeedTypeDef speed = 0;
+    
+
+  return  speed;
+}
+
+/**
+  * @brief  USBH_LL_ResetPort 
+  *         Reset the Host Port of the Low Level Driver.
+  * @param  phost: Host handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost) 
+{
+
+  return USBH_OK; 
+}
+
+/**
+  * @brief  USBH_LL_GetLastXferSize 
+  *         Return the last transfered packet size.
+  * @param  phost: Host handle
+  * @param  pipe: Pipe index   
+  * @retval Packet Size
+  */
+uint32_t USBH_LL_GetLastXferSize  (USBH_HandleTypeDef *phost, uint8_t pipe)  
+{
+
+}
+
+/**
+  * @brief  USBH_LL_OpenPipe 
+  *         Open a pipe of the Low Level Driver.
+  * @param  phost: Host handle
+  * @param  pipe_num: Pipe index
+  * @param  epnum: Endpoint Number
+  * @param  dev_address: Device USB address
+  * @param  speed: Device Speed 
+  * @param  ep_type: Endpoint Type
+  * @param  mps: Endpoint Max Packet Size                 
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef   USBH_LL_OpenPipe (USBH_HandleTypeDef *phost, 
+                                      uint8_t pipe_num,
+                                      uint8_t epnum,                                      
+                                      uint8_t dev_address,
+                                      uint8_t speed,
+                                      uint8_t ep_type,
+                                      uint16_t mps)
+{
+ 
+  return USBH_OK; 
+}
+
+/**
+  * @brief  USBH_LL_ClosePipe 
+  *         Close a pipe of the Low Level Driver.
+  * @param  phost: Host handle
+  * @param  pipe_num: Pipe index               
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef   USBH_LL_ClosePipe   (USBH_HandleTypeDef *phost, uint8_t pipe)   
+{
+
+}
+/**
+  * @brief  USBH_LL_SubmitURB 
+  *         Submit a new URB to the low level driver.
+  * @param  phost: Host handle
+  * @param  pipe: Pipe index    
+  *         This parameter can be a value from 1 to 15
+  * @param  direction : Channel number
+  *          This parameter can be one of the these values:
+  *           0 : Output 
+  *           1 : Input
+  * @param  ep_type : Endpoint Type
+  *          This parameter can be one of the these values:
+  *            @arg EP_TYPE_CTRL: Control type
+  *            @arg EP_TYPE_ISOC: Isochrounous type
+  *            @arg EP_TYPE_BULK: Bulk type
+  *            @arg EP_TYPE_INTR: Interrupt type
+  * @param  token : Endpoint Type
+  *          This parameter can be one of the these values:
+  *            @arg 0: PID_SETUP
+  *            @arg 1: PID_DATA
+  * @param  pbuff : pointer to URB data
+  * @param  length : Length of URB data
+  * @param  do_ping : activate do ping protocol (for high speed only)
+  *          This parameter can be one of the these values:
+  *           0 : do ping inactive 
+  *           1 : do ping active 
+  * @retval Status
+  */
+
+USBH_StatusTypeDef   USBH_LL_SubmitURB  (USBH_HandleTypeDef *phost, 
+                                            uint8_t pipe, 
+                                            uint8_t direction ,
+                                            uint8_t ep_type,  
+                                            uint8_t token, 
+                                            uint8_t* pbuff, 
+                                            uint16_t length,
+                                            uint8_t do_ping ) 
+{
+
+  return USBH_OK;   
+}
+
+/**
+  * @brief  USBH_LL_GetURBState 
+  *         Get a URB state from the low level driver.
+  * @param  phost: Host handle
+  * @param  pipe: Pipe index
+  *         This parameter can be a value from 1 to 15
+  * @retval URB state
+  *          This parameter can be one of the these values:
+  *            @arg URB_IDLE
+  *            @arg URB_DONE
+  *            @arg URB_NOTREADY
+  *            @arg URB_NYET 
+  *            @arg URB_ERROR  
+  *            @arg URB_STALL      
+  */
+USBH_URBStateTypeDef  USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t pipe) 
+{
+
+}
+
+/**
+  * @brief  USBH_LL_DriverVBUS 
+  *         Drive VBUS.
+  * @param  phost: Host handle
+  * @param  state : VBUS state
+  *          This parameter can be one of the these values:
+  *           0 : VBUS Active 
+  *           1 : VBUS Inactive
+  * @retval Status
+  */
+
+USBH_StatusTypeDef  USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t state)
+{
+
+  return USBH_OK;  
+}
+
+/**
+  * @brief  USBH_LL_SetToggle 
+  *         Set toggle for a pipe.
+  * @param  phost: Host handle
+  * @param  pipe: Pipe index
+  * @param  pipe_num: Pipe index     
+  * @param  toggle: toggle (0/1)
+  * @retval Status
+  */
+USBH_StatusTypeDef   USBH_LL_SetToggle   (USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle)   
+{
+
+  return USBH_OK; 
+}
+
+/**
+  * @brief  USBH_LL_GetToggle 
+  *         Return the current toggle of a pipe.
+  * @param  phost: Host handle
+  * @param  pipe: Pipe index
+  * @retval toggle (0/1)
+  */
+uint8_t  USBH_LL_GetToggle   (USBH_HandleTypeDef *phost, uint8_t pipe)   
+{
+  uint8_t toggle = 0;
+  
+
+  return toggle; 
+}
+/**
+  * @brief  USBH_Delay 
+  *         Delay routine for the USB Host Library
+  * @param  Delay: Delay in ms
+  * @retval None
+  */
+void  USBH_Delay (uint32_t Delay)
+{
+
+}
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Core/Src/usbh_core.c b/micropython/ports/stm32/usbhost/Core/Src/usbh_core.c
index 9d2727a89f92ace6f3c3651b302ab184b15a678b..a363f968fbed4931a612ff18b731398a1837321b 100644
--- a/micropython/ports/stm32/usbhost/Core/Src/usbh_core.c
+++ b/micropython/ports/stm32/usbhost/Core/Src/usbh_core.c
@@ -1,936 +1,936 @@
-/**
-  ******************************************************************************
-  * @file    usbh_core.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file implements the functions for the core state machine process
-  *          the enumeration and the control transfer process
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-/* Includes ------------------------------------------------------------------*/
-
-#include "usbh_core.h"
-
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-  * @{
-  */
-
-/** @defgroup USBH_CORE 
-  * @brief TThis file handles the basic enumaration when a device is connected 
-  *          to the host.
-  * @{
-  */ 
-
-
-/** @defgroup USBH_CORE_Private_Defines
-  * @{
-  */ 
-#define USBH_ADDRESS_DEFAULT                     0
-#define USBH_ADDRESS_ASSIGNED                    1      
-#define USBH_MPS_DEFAULT                         0x40
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_CORE_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_CORE_Private_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
- 
-
-/** @defgroup USBH_CORE_Private_Functions
-  * @{
-  */ 
-static USBH_StatusTypeDef  USBH_HandleEnum    (USBH_HandleTypeDef *phost);
-static void                USBH_HandleSof     (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef  DeInitStateMachine(USBH_HandleTypeDef *phost);
-
-#if (USBH_USE_OS == 1)  
-static void USBH_Process_OS(void const * argument);
-#endif
-
-/**
-  * @brief  HCD_Init 
-  *         Initialize the HOST Core.
-  * @param  phost: Host Handle
-  * @param  pUsrFunc: User Callback
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t ), uint8_t id)
-{
-  /* Check whether the USB Host handle is valid */
-  if(phost == NULL)
-  {
-    USBH_ErrLog("Invalid Host handle");
-    return USBH_FAIL; 
-  }
-  
-  /* Set DRiver ID */
-  phost->id = id;
-  
-  /* Unlink class*/
-  phost->pActiveClass = NULL;
-  phost->ClassNumber = 0;
-  
-  /* Restore default states and prepare EP0 */ 
-  DeInitStateMachine(phost);
-  
-  /* Assign User process */
-  if(pUsrFunc != NULL)
-  {
-    phost->pUser = pUsrFunc;
-  }
-  
-#if (USBH_USE_OS == 1) 
-  
-  /* Create USB Host Queue */
-  osMessageQDef(USBH_Queue, 10, uint16_t);
-  phost->os_event = osMessageCreate (osMessageQ(USBH_Queue), NULL); 
-  
-  /*Create USB Host Task */
-  osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0, 8 * configMINIMAL_STACK_SIZE);
-  phost->thread = osThreadCreate (osThread(USBH_Thread), phost);
-#endif  
-  
-  /* Initialize low level driver */
-  USBH_LL_Init(phost);
-  return USBH_OK;
-}
-
-/**
-  * @brief  HCD_Init 
-  *         De-Initialize the Host portion of the driver.
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_DeInit(USBH_HandleTypeDef *phost)
-{
-  DeInitStateMachine(phost);
-  
-  if(phost->pData != NULL)
-  {
-    phost->pActiveClass->pData = NULL;
-    USBH_LL_Stop(phost);
-  }
-
-  return USBH_OK;
-}
-
-/**
-  * @brief  DeInitStateMachine 
-  *         De-Initialize the Host state machine.
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef  DeInitStateMachine(USBH_HandleTypeDef *phost)
-{
-  uint32_t i = 0;
-
-  /* Clear Pipes flags*/
-  for ( ; i < USBH_MAX_PIPES_NBR; i++)
-  {
-    phost->Pipes[i] = 0;
-  }
-  
-  for(i = 0; i< USBH_MAX_DATA_BUFFER; i++)
-  {
-    phost->device.Data[i] = 0;
-  }
-  
-  phost->gState = HOST_IDLE;
-  phost->EnumState = ENUM_IDLE;
-  phost->RequestState = CMD_SEND;
-  phost->Timer = 0;  
-  
-  phost->Control.state = CTRL_SETUP;
-  phost->Control.pipe_size = USBH_MPS_DEFAULT;  
-  phost->Control.errorcount = 0;
-  
-  phost->device.address = USBH_ADDRESS_DEFAULT;
-  phost->device.speed   = USBH_SPEED_FULL;
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_RegisterClass 
-  *         Link class driver to Host Core.
-  * @param  phost : Host Handle
-  * @param  pclass: Class handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass)
-{
-  USBH_StatusTypeDef   status = USBH_OK;
-  
-  if(pclass != 0)
-  {
-    if(phost->ClassNumber < USBH_MAX_NUM_SUPPORTED_CLASS)
-    {
-      /* link the class tgo the USB Host handle */
-      phost->pClass[phost->ClassNumber++] = pclass;
-      status = USBH_OK;
-    }
-    else
-    {
-      USBH_ErrLog("Max Class Number reached");
-      status = USBH_FAIL; 
-    }
-  }
-  else
-  {
-    USBH_ErrLog("Invalid Class handle");
-    status = USBH_FAIL; 
-  }
-  
-  return status;
-}
-
-/**
-  * @brief  USBH_SelectInterface 
-  *         Select current interface.
-  * @param  phost: Host Handle
-  * @param  interface: Interface number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface)
-{
-  USBH_StatusTypeDef   status = USBH_OK;
-  
-  if(interface < phost->device.CfgDesc.bNumInterfaces)
-  {
-    phost->device.current_interface = interface;
-    USBH_UsrLog ("Switching to Interface (#%d)", interface);
-    USBH_UsrLog ("Class    : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass );
-    USBH_UsrLog ("SubClass : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass );
-    USBH_UsrLog ("Protocol : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol );                 
-  }
-  else
-  {
-    USBH_ErrLog ("Cannot Select This Interface.");
-    status = USBH_FAIL; 
-  }
-  return status;  
-}
-
-/**
-  * @brief  USBH_GetActiveClass 
-  *         Return Device Class.
-  * @param  phost: Host Handle
-  * @param  interface: Interface index
-  * @retval Class Code
-  */
-uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost)
-{
-   return (phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass);            
-}
-/**
-  * @brief  USBH_FindInterface 
-  *         Find the interface index for a specific class.
-  * @param  phost: Host Handle
-  * @param  Class: Class code
-  * @param  SubClass: SubClass code
-  * @param  Protocol: Protocol code
-  * @retval interface index in the configuration structure
-  * @note : (1)interface index 0xFF means interface index not found
-  */
-uint8_t  USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
-{
-  USBH_InterfaceDescTypeDef    *pif ;
-  USBH_CfgDescTypeDef          *pcfg ;
-  int8_t                        if_ix = 0;
-  
-  pif = (USBH_InterfaceDescTypeDef *)0;
-  pcfg = &phost->device.CfgDesc;  
-  
-  if((pif->bInterfaceClass == 0xFF) &&(pif->bInterfaceSubClass == 0xFF) && (pif->bInterfaceProtocol == 0xFF))
-  {
-    return 0xFF;
-  }
-  
-  while (if_ix < USBH_MAX_NUM_INTERFACES)
-  {
-    pif = &pcfg->Itf_Desc[if_ix];
-    if(((pif->bInterfaceClass == Class) || (Class == 0xFF))&&
-       ((pif->bInterfaceSubClass == SubClass) || (SubClass == 0xFF))&&
-         ((pif->bInterfaceProtocol == Protocol) || (Protocol == 0xFF)))
-    {
-      return  if_ix;
-    }
-    if_ix++;
-  }
-  return 0xFF;
-}
-
-/**
-  * @brief  USBH_FindInterfaceIndex 
-  *         Find the interface index for a specific class interface and alternate setting number.
-  * @param  phost: Host Handle
-  * @param  interface_number: interface number
-  * @param  alt_settings    : alaternate setting number
-  * @retval interface index in the configuration structure
-  * @note : (1)interface index 0xFF means interface index not found
-  */
-uint8_t  USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_number, uint8_t alt_settings)
-{
-  USBH_InterfaceDescTypeDef    *pif ;
-  USBH_CfgDescTypeDef          *pcfg ;
-  int8_t                        if_ix = 0;
-  
-  pif = (USBH_InterfaceDescTypeDef *)0;
-  pcfg = &phost->device.CfgDesc;  
-  
-  while (if_ix < USBH_MAX_NUM_INTERFACES)
-  {
-    pif = &pcfg->Itf_Desc[if_ix];
-    if((pif->bInterfaceNumber == interface_number) && (pif->bAlternateSetting == alt_settings))
-    {
-      return  if_ix;
-    }
-    if_ix++;
-  }
-  return 0xFF;
-}
-
-/**
-  * @brief  USBH_Start 
-  *         Start the USB Host Core.
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_Start  (USBH_HandleTypeDef *phost)
-{
-  /* Start the low level driver  */
-  USBH_LL_Start(phost);
-  
-  /* Activate VBUS on the port */ 
-  USBH_LL_DriverVBUS (phost, TRUE);
-  
-  return USBH_OK;  
-}
-
-/**
-  * @brief  USBH_Stop 
-  *         Stop the USB Host Core.
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_Stop   (USBH_HandleTypeDef *phost)
-{
-  /* Stop and cleanup the low level driver  */
-  USBH_LL_Stop(phost);  
-  
-  /* DeActivate VBUS on the port */ 
-  USBH_LL_DriverVBUS (phost, FALSE);
-  
-  /* FRee Control Pipes */
-  USBH_FreePipe  (phost, phost->Control.pipe_in);
-  USBH_FreePipe  (phost, phost->Control.pipe_out);  
-  
-  return USBH_OK;  
-}
-
-/**
-  * @brief  HCD_ReEnumerate 
-  *         Perform a new Enumeration phase.
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_ReEnumerate   (USBH_HandleTypeDef *phost)
-{
-  /*Stop Host */ 
-  USBH_Stop(phost);
-
-  /*Device has disconnected, so wait for 200 ms */  
-  USBH_Delay(200);
-  
-  /* Set State machines in default state */
-  DeInitStateMachine(phost);
-   
-  /* Start again the host */
-  USBH_Start(phost);
-      
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
-#endif  
-  return USBH_OK;  
-}
-
-/**
-  * @brief  USBH_Process 
-  *         Background process of the USB Core.
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef  USBH_Process(USBH_HandleTypeDef *phost)
-{
-  __IO USBH_StatusTypeDef status = USBH_FAIL;
-  uint8_t idx = 0;
-  
-  switch (phost->gState)
-  {
-  case HOST_IDLE :
-    
-    if (phost->device.is_connected)  
-    {
-      /* Wait for 200 ms after connection */
-      phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT; 
-      USBH_Delay(200); 
-      USBH_LL_ResetPort(phost);
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
-#endif
-    }
-    break;
-    
-  case HOST_DEV_WAIT_FOR_ATTACHMENT:
-    break;    
-    
-  case HOST_DEV_ATTACHED :
-    
-    USBH_UsrLog("USB Device Attached");  
-      
-    /* Wait for 100 ms after Reset */
-    USBH_Delay(100); 
-          
-    phost->device.speed = USBH_LL_GetSpeed(phost);
-    
-    phost->gState = HOST_ENUMERATION;
-    
-    phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00);
-    phost->Control.pipe_in  = USBH_AllocPipe (phost, 0x80);    
-    
-    
-    /* Open Control pipes */
-    USBH_OpenPipe (phost,
-                   phost->Control.pipe_in,
-                   0x80,
-                   phost->device.address,
-                   phost->device.speed,
-                   USBH_EP_CONTROL,
-                   phost->Control.pipe_size); 
-    
-    /* Open Control pipes */
-    USBH_OpenPipe (phost,
-                   phost->Control.pipe_out,
-                   0x00,
-                   phost->device.address,
-                   phost->device.speed,
-                   USBH_EP_CONTROL,
-                   phost->Control.pipe_size);
-    
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
-#endif    
-    
-    break;
-    
-  case HOST_ENUMERATION:     
-    /* Check for enumeration status */  
-    if ( USBH_HandleEnum(phost) == USBH_OK)
-    { 
-      /* The function shall return USBH_OK when full enumeration is complete */
-      USBH_UsrLog ("Enumeration done.");
-      phost->device.current_interface = 0;
-      if(phost->device.DevDesc.bNumConfigurations == 1)
-      {
-        USBH_UsrLog ("This device has only 1 configuration.");
-        phost->gState  = HOST_SET_CONFIGURATION;        
-        
-      }
-      else
-      {
-        phost->gState  = HOST_INPUT; 
-      }
-          
-    }
-    break;
-    
-  case HOST_INPUT:
-    {
-      /* user callback for end of device basic enumeration */
-      if(phost->pUser != NULL)
-      {
-        phost->pUser(phost, HOST_USER_SELECT_CONFIGURATION);
-        phost->gState = HOST_SET_CONFIGURATION;
-        
-#if (USBH_USE_OS == 1)
-        osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif         
-      }
-    }
-    break;
-    
-  case HOST_SET_CONFIGURATION:
-    /* set configuration */
-    if (USBH_SetCfg(phost, phost->device.CfgDesc.bConfigurationValue) == USBH_OK)
-    {
-      phost->gState  = HOST_CHECK_CLASS;
-      USBH_UsrLog ("Default configuration set.");
-      
-    }      
-    
-    break;
-    
-  case HOST_CHECK_CLASS:
-    
-    if(phost->ClassNumber == 0)
-    {
-      USBH_UsrLog ("No Class has been registered.");
-    }
-    else
-    {
-      phost->pActiveClass = NULL;
-      
-      for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS ; idx ++)
-      {
-        if(phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass)
-        {
-          phost->pActiveClass = phost->pClass[idx];
-        }
-      }
-      
-      if(phost->pActiveClass != NULL)
-      {
-        if(phost->pActiveClass->Init(phost)== USBH_OK)
-        {
-          phost->gState  = HOST_CLASS_REQUEST; 
-          USBH_UsrLog ("%s class started.", phost->pActiveClass->Name);
-          
-          /* Inform user that a class has been activated */
-          phost->pUser(phost, HOST_USER_CLASS_SELECTED);   
-        }
-        else
-        {
-          phost->gState  = HOST_ABORT_STATE;
-          USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name);
-        }
-      }
-      else
-      {
-        phost->gState  = HOST_ABORT_STATE;
-        USBH_UsrLog ("No registered class for this device.");
-      }
-    }
-    
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif 
-    break;    
-    
-  case HOST_CLASS_REQUEST:  
-    /* process class standard contol requests state machine */ 
-    
-    if(phost->pActiveClass != NULL)
-    {
-      status = phost->pActiveClass->Requests(phost);
-      
-      if(status == USBH_OK)
-      {
-        phost->gState  = HOST_CLASS;        
-      }  
-    }
-    else
-    {
-      phost->gState  = HOST_ABORT_STATE;
-      USBH_ErrLog ("Invalid Class Driver.");
-    
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif       
-    }
-    
-    break;    
-  case HOST_CLASS:   
-    /* process class state machine */
-    if(phost->pActiveClass != NULL)
-    { 
-      phost->pActiveClass->BgndProcess(phost);
-    }
-    break;       
-
-  case HOST_DEV_DISCONNECTED :
-    
-    DeInitStateMachine(phost);  
-    
-    /* Re-Initilaize Host for new Enumeration */
-    if(phost->pActiveClass != NULL)
-    {
-      phost->pActiveClass->DeInit(phost); 
-      phost->pActiveClass = NULL;
-    }     
-    break;
-    
-  case HOST_ABORT_STATE:
-  default :
-    break;
-  }
- return USBH_OK;  
-}
-
-
-/**
-  * @brief  USBH_HandleEnum 
-  *         This function includes the complete enumeration process
-  * @param  phost: Host Handle
-  * @retval USBH_Status
-  */
-static USBH_StatusTypeDef USBH_HandleEnum (USBH_HandleTypeDef *phost)
-{
-  USBH_StatusTypeDef Status = USBH_BUSY;  
-  
-  switch (phost->EnumState)
-  {
-  case ENUM_IDLE:  
-    /* Get Device Desc for only 1st 8 bytes : To get EP0 MaxPacketSize */
-    if ( USBH_Get_DevDesc(phost, 8) == USBH_OK)
-    {
-      phost->Control.pipe_size = phost->device.DevDesc.bMaxPacketSize;
-
-      phost->EnumState = ENUM_GET_FULL_DEV_DESC;
-      
-      /* modify control channels configuration for MaxPacket size */
-      USBH_OpenPipe (phost,
-                           phost->Control.pipe_in,
-                           0x80,
-                           phost->device.address,
-                           phost->device.speed,
-                           USBH_EP_CONTROL,
-                           phost->Control.pipe_size); 
-      
-      /* Open Control pipes */
-      USBH_OpenPipe (phost,
-                           phost->Control.pipe_out,
-                           0x00,
-                           phost->device.address,
-                           phost->device.speed,
-                           USBH_EP_CONTROL,
-                           phost->Control.pipe_size);           
-      
-    }
-    break;
-    
-  case ENUM_GET_FULL_DEV_DESC:  
-    /* Get FULL Device Desc  */
-    if ( USBH_Get_DevDesc(phost, USB_DEVICE_DESC_SIZE)== USBH_OK)
-    {
-      USBH_UsrLog("PID: %xh", phost->device.DevDesc.idProduct );  
-      USBH_UsrLog("VID: %xh", phost->device.DevDesc.idVendor );  
-      
-      phost->EnumState = ENUM_SET_ADDR;
-       
-    }
-    break;
-   
-  case ENUM_SET_ADDR: 
-    /* set address */
-    if ( USBH_SetAddress(phost, USBH_DEVICE_ADDRESS) == USBH_OK)
-    {
-      USBH_Delay(2);
-      phost->device.address = USBH_DEVICE_ADDRESS;
-      
-      /* user callback for device address assigned */
-      USBH_UsrLog("Address (#%d) assigned.", phost->device.address);
-      phost->EnumState = ENUM_GET_CFG_DESC;
-      
-      /* modify control channels to update device address */
-      USBH_OpenPipe (phost,
-                           phost->Control.pipe_in,
-                           0x80,
-                           phost->device.address,
-                           phost->device.speed,
-                           USBH_EP_CONTROL,
-                           phost->Control.pipe_size); 
-      
-      /* Open Control pipes */
-      USBH_OpenPipe (phost,
-                           phost->Control.pipe_out,
-                           0x00,
-                           phost->device.address,
-                           phost->device.speed,
-                           USBH_EP_CONTROL,
-                           phost->Control.pipe_size);        
-    }
-    break;
-    
-  case ENUM_GET_CFG_DESC:  
-    /* get standard configuration descriptor */
-    if ( USBH_Get_CfgDesc(phost, 
-                          USB_CONFIGURATION_DESC_SIZE) == USBH_OK)
-    {
-      phost->EnumState = ENUM_GET_FULL_CFG_DESC;        
-    }
-    break;
-    
-  case ENUM_GET_FULL_CFG_DESC:  
-    /* get FULL config descriptor (config, interface, endpoints) */
-    if (USBH_Get_CfgDesc(phost, 
-                         phost->device.CfgDesc.wTotalLength) == USBH_OK)
-    {
-      phost->EnumState = ENUM_GET_MFC_STRING_DESC;       
-    }
-    break;
-    
-  case ENUM_GET_MFC_STRING_DESC:  
-    if (phost->device.DevDesc.iManufacturer != 0)
-    { /* Check that Manufacturer String is available */
-      
-      if ( USBH_Get_StringDesc(phost,
-                               phost->device.DevDesc.iManufacturer, 
-                                phost->device.Data , 
-                               0xff) == USBH_OK)
-      {
-        /* User callback for Manufacturing string */
-        USBH_UsrLog("Manufacturer : %s",  (char *)phost->device.Data);
-        phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC;
-        
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif          
-      }
-    }
-    else
-    {
-     USBH_UsrLog("Manufacturer : N/A");      
-     phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; 
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif       
-    }
-    break;
-    
-  case ENUM_GET_PRODUCT_STRING_DESC:   
-    if (phost->device.DevDesc.iProduct != 0)
-    { /* Check that Product string is available */
-      if ( USBH_Get_StringDesc(phost,
-                               phost->device.DevDesc.iProduct, 
-                               phost->device.Data, 
-                               0xff) == USBH_OK)
-      {
-        /* User callback for Product string */
-        USBH_UsrLog("Product : %s",  (char *)phost->device.Data);
-        phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC;        
-      }
-    }
-    else
-    {
-      USBH_UsrLog("Product : N/A");
-      phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; 
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif        
-    } 
-    break;
-    
-  case ENUM_GET_SERIALNUM_STRING_DESC:   
-    if (phost->device.DevDesc.iSerialNumber != 0)
-    { /* Check that Serial number string is available */    
-      if ( USBH_Get_StringDesc(phost,
-                               phost->device.DevDesc.iSerialNumber, 
-                               phost->device.Data, 
-                               0xff) == USBH_OK)
-      {
-        /* User callback for Serial number string */
-         USBH_UsrLog("Serial Number : %s",  (char *)phost->device.Data);
-        Status = USBH_OK;
-      }
-    }
-    else
-    {
-      USBH_UsrLog("Serial Number : N/A"); 
-      Status = USBH_OK;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
-#endif        
-    }  
-    break;
-    
-  default:
-    break;
-  }  
-  return Status;
-}
-
-/**
-  * @brief  USBH_LL_SetTimer 
-  *         Set the initial Host Timer tick
-  * @param  phost: Host Handle
-  * @retval None
-  */
-void  USBH_LL_SetTimer  (USBH_HandleTypeDef *phost, uint32_t time)
-{
-  phost->Timer = time;
-}
-/**
-  * @brief  USBH_LL_IncTimer 
-  *         Increment Host Timer tick
-  * @param  phost: Host Handle
-  * @retval None
-  */
-void  USBH_LL_IncTimer  (USBH_HandleTypeDef *phost)
-{
-  phost->Timer ++;
-  USBH_HandleSof(phost);
-}
-
-/**
-  * @brief  USBH_HandleSof 
-  *         Call SOF process
-  * @param  phost: Host Handle
-  * @retval None
-  */
-void  USBH_HandleSof  (USBH_HandleTypeDef *phost)
-{
-  if((phost->gState == HOST_CLASS)&&(phost->pActiveClass != NULL))
-  {
-    phost->pActiveClass->SOFProcess(phost);
-  }
-}
-/**
-  * @brief  USBH_LL_Connect 
-  *         Handle USB Host connexion event
-  * @param  phost: Host Handle
-  * @retval USBH_Status
-  */
-USBH_StatusTypeDef  USBH_LL_Connect  (USBH_HandleTypeDef *phost)
-{
-  if(phost->gState == HOST_IDLE )
-  {
-    phost->device.is_connected = 1;
-    phost->gState = HOST_IDLE ;
-    
-    if(phost->pUser != NULL)
-    {    
-      phost->pUser(phost, HOST_USER_CONNECTION);
-    }
-  } 
-  else if(phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT )
-  {
-    phost->gState = HOST_DEV_ATTACHED ;
-  }
-#if (USBH_USE_OS == 1)
-  osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
-#endif 
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_LL_Disconnect 
-  *         Handle USB Host disconnexion event
-  * @param  phost: Host Handle
-  * @retval USBH_Status
-  */
-USBH_StatusTypeDef  USBH_LL_Disconnect  (USBH_HandleTypeDef *phost)
-{
-  /*Stop Host */ 
-  USBH_LL_Stop(phost);  
-  
-  /* FRee Control Pipes */
-  USBH_FreePipe  (phost, phost->Control.pipe_in);
-  USBH_FreePipe  (phost, phost->Control.pipe_out);  
-   
-  phost->device.is_connected = 0; 
-   
-  if(phost->pUser != NULL)
-  {    
-    phost->pUser(phost, HOST_USER_DISCONNECTION);
-  }
-  USBH_UsrLog("USB Device disconnected"); 
-  
-  /* Start the low level driver  */
-  USBH_LL_Start(phost);
-  
-  phost->gState = HOST_DEV_DISCONNECTED;
-  
-#if (USBH_USE_OS == 1)
-  osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
-#endif 
-  
-  return USBH_OK;
-}
-
-
-#if (USBH_USE_OS == 1)  
-/**
-  * @brief  USB Host Thread task
-  * @param  pvParameters not used
-  * @retval None
-  */
-static void USBH_Process_OS(void const * argument)
-{
-  osEvent event;
-  
-  for(;;)
-  {
-    event = osMessageGet(((USBH_HandleTypeDef *)argument)->os_event, osWaitForever );
-    
-    if( event.status == osEventMessage )
-    {
-      USBH_Process((USBH_HandleTypeDef *)argument);
-    }
-   }
-}
-
-/**
-* @brief  USBH_LL_NotifyURBChange 
-*         Notify URB state Change
-* @param  phost: Host handle
-* @retval USBH Status
-*/
-USBH_StatusTypeDef  USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost)
-{
-  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-  return USBH_OK;
-}
-#endif  
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */ 
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+  ******************************************************************************
+  * @file    usbh_core.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file implements the functions for the core state machine process
+  *          the enumeration and the control transfer process
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+/* Includes ------------------------------------------------------------------*/
+
+#include "usbh_core.h"
+
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+  * @{
+  */
+
+/** @defgroup USBH_CORE 
+  * @brief TThis file handles the basic enumaration when a device is connected 
+  *          to the host.
+  * @{
+  */ 
+
+
+/** @defgroup USBH_CORE_Private_Defines
+  * @{
+  */ 
+#define USBH_ADDRESS_DEFAULT                     0
+#define USBH_ADDRESS_ASSIGNED                    1      
+#define USBH_MPS_DEFAULT                         0x40
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_CORE_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_CORE_Private_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+ 
+
+/** @defgroup USBH_CORE_Private_Functions
+  * @{
+  */ 
+static USBH_StatusTypeDef  USBH_HandleEnum    (USBH_HandleTypeDef *phost);
+static void                USBH_HandleSof     (USBH_HandleTypeDef *phost);
+static USBH_StatusTypeDef  DeInitStateMachine(USBH_HandleTypeDef *phost);
+
+#if (USBH_USE_OS == 1)  
+static void USBH_Process_OS(void const * argument);
+#endif
+
+/**
+  * @brief  HCD_Init 
+  *         Initialize the HOST Core.
+  * @param  phost: Host Handle
+  * @param  pUsrFunc: User Callback
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t ), uint8_t id)
+{
+  /* Check whether the USB Host handle is valid */
+  if(phost == NULL)
+  {
+    USBH_ErrLog("Invalid Host handle");
+    return USBH_FAIL; 
+  }
+  
+  /* Set DRiver ID */
+  phost->id = id;
+  
+  /* Unlink class*/
+  phost->pActiveClass = NULL;
+  phost->ClassNumber = 0;
+  
+  /* Restore default states and prepare EP0 */ 
+  DeInitStateMachine(phost);
+  
+  /* Assign User process */
+  if(pUsrFunc != NULL)
+  {
+    phost->pUser = pUsrFunc;
+  }
+  
+#if (USBH_USE_OS == 1) 
+  
+  /* Create USB Host Queue */
+  osMessageQDef(USBH_Queue, 10, uint16_t);
+  phost->os_event = osMessageCreate (osMessageQ(USBH_Queue), NULL); 
+  
+  /*Create USB Host Task */
+  osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0, 8 * configMINIMAL_STACK_SIZE);
+  phost->thread = osThreadCreate (osThread(USBH_Thread), phost);
+#endif  
+  
+  /* Initialize low level driver */
+  USBH_LL_Init(phost);
+  return USBH_OK;
+}
+
+/**
+  * @brief  HCD_Init 
+  *         De-Initialize the Host portion of the driver.
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_DeInit(USBH_HandleTypeDef *phost)
+{
+  DeInitStateMachine(phost);
+  
+  if(phost->pData != NULL)
+  {
+    phost->pActiveClass->pData = NULL;
+    USBH_LL_Stop(phost);
+  }
+
+  return USBH_OK;
+}
+
+/**
+  * @brief  DeInitStateMachine 
+  *         De-Initialize the Host state machine.
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef  DeInitStateMachine(USBH_HandleTypeDef *phost)
+{
+  uint32_t i = 0;
+
+  /* Clear Pipes flags*/
+  for ( ; i < USBH_MAX_PIPES_NBR; i++)
+  {
+    phost->Pipes[i] = 0;
+  }
+  
+  for(i = 0; i< USBH_MAX_DATA_BUFFER; i++)
+  {
+    phost->device.Data[i] = 0;
+  }
+  
+  phost->gState = HOST_IDLE;
+  phost->EnumState = ENUM_IDLE;
+  phost->RequestState = CMD_SEND;
+  phost->Timer = 0;  
+  
+  phost->Control.state = CTRL_SETUP;
+  phost->Control.pipe_size = USBH_MPS_DEFAULT;  
+  phost->Control.errorcount = 0;
+  
+  phost->device.address = USBH_ADDRESS_DEFAULT;
+  phost->device.speed   = USBH_SPEED_FULL;
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_RegisterClass 
+  *         Link class driver to Host Core.
+  * @param  phost : Host Handle
+  * @param  pclass: Class handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass)
+{
+  USBH_StatusTypeDef   status = USBH_OK;
+  
+  if(pclass != 0)
+  {
+    if(phost->ClassNumber < USBH_MAX_NUM_SUPPORTED_CLASS)
+    {
+      /* link the class tgo the USB Host handle */
+      phost->pClass[phost->ClassNumber++] = pclass;
+      status = USBH_OK;
+    }
+    else
+    {
+      USBH_ErrLog("Max Class Number reached");
+      status = USBH_FAIL; 
+    }
+  }
+  else
+  {
+    USBH_ErrLog("Invalid Class handle");
+    status = USBH_FAIL; 
+  }
+  
+  return status;
+}
+
+/**
+  * @brief  USBH_SelectInterface 
+  *         Select current interface.
+  * @param  phost: Host Handle
+  * @param  interface: Interface number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface)
+{
+  USBH_StatusTypeDef   status = USBH_OK;
+  
+  if(interface < phost->device.CfgDesc.bNumInterfaces)
+  {
+    phost->device.current_interface = interface;
+    USBH_UsrLog ("Switching to Interface (#%d)", interface);
+    USBH_UsrLog ("Class    : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass );
+    USBH_UsrLog ("SubClass : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass );
+    USBH_UsrLog ("Protocol : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol );                 
+  }
+  else
+  {
+    USBH_ErrLog ("Cannot Select This Interface.");
+    status = USBH_FAIL; 
+  }
+  return status;  
+}
+
+/**
+  * @brief  USBH_GetActiveClass 
+  *         Return Device Class.
+  * @param  phost: Host Handle
+  * @param  interface: Interface index
+  * @retval Class Code
+  */
+uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost)
+{
+   return (phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass);            
+}
+/**
+  * @brief  USBH_FindInterface 
+  *         Find the interface index for a specific class.
+  * @param  phost: Host Handle
+  * @param  Class: Class code
+  * @param  SubClass: SubClass code
+  * @param  Protocol: Protocol code
+  * @retval interface index in the configuration structure
+  * @note : (1)interface index 0xFF means interface index not found
+  */
+uint8_t  USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
+{
+  USBH_InterfaceDescTypeDef    *pif ;
+  USBH_CfgDescTypeDef          *pcfg ;
+  int8_t                        if_ix = 0;
+  
+  pif = (USBH_InterfaceDescTypeDef *)0;
+  pcfg = &phost->device.CfgDesc;  
+  
+  if((pif->bInterfaceClass == 0xFF) &&(pif->bInterfaceSubClass == 0xFF) && (pif->bInterfaceProtocol == 0xFF))
+  {
+    return 0xFF;
+  }
+  
+  while (if_ix < USBH_MAX_NUM_INTERFACES)
+  {
+    pif = &pcfg->Itf_Desc[if_ix];
+    if(((pif->bInterfaceClass == Class) || (Class == 0xFF))&&
+       ((pif->bInterfaceSubClass == SubClass) || (SubClass == 0xFF))&&
+         ((pif->bInterfaceProtocol == Protocol) || (Protocol == 0xFF)))
+    {
+      return  if_ix;
+    }
+    if_ix++;
+  }
+  return 0xFF;
+}
+
+/**
+  * @brief  USBH_FindInterfaceIndex 
+  *         Find the interface index for a specific class interface and alternate setting number.
+  * @param  phost: Host Handle
+  * @param  interface_number: interface number
+  * @param  alt_settings    : alaternate setting number
+  * @retval interface index in the configuration structure
+  * @note : (1)interface index 0xFF means interface index not found
+  */
+uint8_t  USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_number, uint8_t alt_settings)
+{
+  USBH_InterfaceDescTypeDef    *pif ;
+  USBH_CfgDescTypeDef          *pcfg ;
+  int8_t                        if_ix = 0;
+  
+  pif = (USBH_InterfaceDescTypeDef *)0;
+  pcfg = &phost->device.CfgDesc;  
+  
+  while (if_ix < USBH_MAX_NUM_INTERFACES)
+  {
+    pif = &pcfg->Itf_Desc[if_ix];
+    if((pif->bInterfaceNumber == interface_number) && (pif->bAlternateSetting == alt_settings))
+    {
+      return  if_ix;
+    }
+    if_ix++;
+  }
+  return 0xFF;
+}
+
+/**
+  * @brief  USBH_Start 
+  *         Start the USB Host Core.
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_Start  (USBH_HandleTypeDef *phost)
+{
+  /* Start the low level driver  */
+  USBH_LL_Start(phost);
+  
+  /* Activate VBUS on the port */ 
+  USBH_LL_DriverVBUS (phost, TRUE);
+  
+  return USBH_OK;  
+}
+
+/**
+  * @brief  USBH_Stop 
+  *         Stop the USB Host Core.
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_Stop   (USBH_HandleTypeDef *phost)
+{
+  /* Stop and cleanup the low level driver  */
+  USBH_LL_Stop(phost);  
+  
+  /* DeActivate VBUS on the port */ 
+  USBH_LL_DriverVBUS (phost, FALSE);
+  
+  /* FRee Control Pipes */
+  USBH_FreePipe  (phost, phost->Control.pipe_in);
+  USBH_FreePipe  (phost, phost->Control.pipe_out);  
+  
+  return USBH_OK;  
+}
+
+/**
+  * @brief  HCD_ReEnumerate 
+  *         Perform a new Enumeration phase.
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_ReEnumerate   (USBH_HandleTypeDef *phost)
+{
+  /*Stop Host */ 
+  USBH_Stop(phost);
+
+  /*Device has disconnected, so wait for 200 ms */  
+  USBH_Delay(200);
+  
+  /* Set State machines in default state */
+  DeInitStateMachine(phost);
+   
+  /* Start again the host */
+  USBH_Start(phost);
+      
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
+#endif  
+  return USBH_OK;  
+}
+
+/**
+  * @brief  USBH_Process 
+  *         Background process of the USB Core.
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef  USBH_Process(USBH_HandleTypeDef *phost)
+{
+  __IO USBH_StatusTypeDef status = USBH_FAIL;
+  uint8_t idx = 0;
+  
+  switch (phost->gState)
+  {
+  case HOST_IDLE :
+    
+    if (phost->device.is_connected)  
+    {
+      /* Wait for 200 ms after connection */
+      phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT; 
+      USBH_Delay(200); 
+      USBH_LL_ResetPort(phost);
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
+#endif
+    }
+    break;
+    
+  case HOST_DEV_WAIT_FOR_ATTACHMENT:
+    break;    
+    
+  case HOST_DEV_ATTACHED :
+    
+    USBH_UsrLog("USB Device Attached");  
+      
+    /* Wait for 100 ms after Reset */
+    USBH_Delay(100); 
+          
+    phost->device.speed = USBH_LL_GetSpeed(phost);
+    
+    phost->gState = HOST_ENUMERATION;
+    
+    phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00);
+    phost->Control.pipe_in  = USBH_AllocPipe (phost, 0x80);    
+    
+    
+    /* Open Control pipes */
+    USBH_OpenPipe (phost,
+                   phost->Control.pipe_in,
+                   0x80,
+                   phost->device.address,
+                   phost->device.speed,
+                   USBH_EP_CONTROL,
+                   phost->Control.pipe_size); 
+    
+    /* Open Control pipes */
+    USBH_OpenPipe (phost,
+                   phost->Control.pipe_out,
+                   0x00,
+                   phost->device.address,
+                   phost->device.speed,
+                   USBH_EP_CONTROL,
+                   phost->Control.pipe_size);
+    
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
+#endif    
+    
+    break;
+    
+  case HOST_ENUMERATION:     
+    /* Check for enumeration status */  
+    if ( USBH_HandleEnum(phost) == USBH_OK)
+    { 
+      /* The function shall return USBH_OK when full enumeration is complete */
+      USBH_UsrLog ("Enumeration done.");
+      phost->device.current_interface = 0;
+      if(phost->device.DevDesc.bNumConfigurations == 1)
+      {
+        USBH_UsrLog ("This device has only 1 configuration.");
+        phost->gState  = HOST_SET_CONFIGURATION;        
+        
+      }
+      else
+      {
+        phost->gState  = HOST_INPUT; 
+      }
+          
+    }
+    break;
+    
+  case HOST_INPUT:
+    {
+      /* user callback for end of device basic enumeration */
+      if(phost->pUser != NULL)
+      {
+        phost->pUser(phost, HOST_USER_SELECT_CONFIGURATION);
+        phost->gState = HOST_SET_CONFIGURATION;
+        
+#if (USBH_USE_OS == 1)
+        osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif         
+      }
+    }
+    break;
+    
+  case HOST_SET_CONFIGURATION:
+    /* set configuration */
+    if (USBH_SetCfg(phost, phost->device.CfgDesc.bConfigurationValue) == USBH_OK)
+    {
+      phost->gState  = HOST_CHECK_CLASS;
+      USBH_UsrLog ("Default configuration set.");
+      
+    }      
+    
+    break;
+    
+  case HOST_CHECK_CLASS:
+    
+    if(phost->ClassNumber == 0)
+    {
+      USBH_UsrLog ("No Class has been registered.");
+    }
+    else
+    {
+      phost->pActiveClass = NULL;
+      
+      for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS ; idx ++)
+      {
+        if(phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass)
+        {
+          phost->pActiveClass = phost->pClass[idx];
+        }
+      }
+      
+      if(phost->pActiveClass != NULL)
+      {
+        if(phost->pActiveClass->Init(phost)== USBH_OK)
+        {
+          phost->gState  = HOST_CLASS_REQUEST; 
+          USBH_UsrLog ("%s class started.", phost->pActiveClass->Name);
+          
+          /* Inform user that a class has been activated */
+          phost->pUser(phost, HOST_USER_CLASS_SELECTED);   
+        }
+        else
+        {
+          phost->gState  = HOST_ABORT_STATE;
+          USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name);
+        }
+      }
+      else
+      {
+        phost->gState  = HOST_ABORT_STATE;
+        USBH_UsrLog ("No registered class for this device.");
+      }
+    }
+    
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif 
+    break;    
+    
+  case HOST_CLASS_REQUEST:  
+    /* process class standard contol requests state machine */ 
+    
+    if(phost->pActiveClass != NULL)
+    {
+      status = phost->pActiveClass->Requests(phost);
+      
+      if(status == USBH_OK)
+      {
+        phost->gState  = HOST_CLASS;        
+      }  
+    }
+    else
+    {
+      phost->gState  = HOST_ABORT_STATE;
+      USBH_ErrLog ("Invalid Class Driver.");
+    
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif       
+    }
+    
+    break;    
+  case HOST_CLASS:   
+    /* process class state machine */
+    if(phost->pActiveClass != NULL)
+    { 
+      phost->pActiveClass->BgndProcess(phost);
+    }
+    break;       
+
+  case HOST_DEV_DISCONNECTED :
+    
+    DeInitStateMachine(phost);  
+    
+    /* Re-Initilaize Host for new Enumeration */
+    if(phost->pActiveClass != NULL)
+    {
+      phost->pActiveClass->DeInit(phost); 
+      phost->pActiveClass = NULL;
+    }     
+    break;
+    
+  case HOST_ABORT_STATE:
+  default :
+    break;
+  }
+ return USBH_OK;  
+}
+
+
+/**
+  * @brief  USBH_HandleEnum 
+  *         This function includes the complete enumeration process
+  * @param  phost: Host Handle
+  * @retval USBH_Status
+  */
+static USBH_StatusTypeDef USBH_HandleEnum (USBH_HandleTypeDef *phost)
+{
+  USBH_StatusTypeDef Status = USBH_BUSY;  
+  
+  switch (phost->EnumState)
+  {
+  case ENUM_IDLE:  
+    /* Get Device Desc for only 1st 8 bytes : To get EP0 MaxPacketSize */
+    if ( USBH_Get_DevDesc(phost, 8) == USBH_OK)
+    {
+      phost->Control.pipe_size = phost->device.DevDesc.bMaxPacketSize;
+
+      phost->EnumState = ENUM_GET_FULL_DEV_DESC;
+      
+      /* modify control channels configuration for MaxPacket size */
+      USBH_OpenPipe (phost,
+                           phost->Control.pipe_in,
+                           0x80,
+                           phost->device.address,
+                           phost->device.speed,
+                           USBH_EP_CONTROL,
+                           phost->Control.pipe_size); 
+      
+      /* Open Control pipes */
+      USBH_OpenPipe (phost,
+                           phost->Control.pipe_out,
+                           0x00,
+                           phost->device.address,
+                           phost->device.speed,
+                           USBH_EP_CONTROL,
+                           phost->Control.pipe_size);           
+      
+    }
+    break;
+    
+  case ENUM_GET_FULL_DEV_DESC:  
+    /* Get FULL Device Desc  */
+    if ( USBH_Get_DevDesc(phost, USB_DEVICE_DESC_SIZE)== USBH_OK)
+    {
+      USBH_UsrLog("PID: %xh", phost->device.DevDesc.idProduct );  
+      USBH_UsrLog("VID: %xh", phost->device.DevDesc.idVendor );  
+      
+      phost->EnumState = ENUM_SET_ADDR;
+       
+    }
+    break;
+   
+  case ENUM_SET_ADDR: 
+    /* set address */
+    if ( USBH_SetAddress(phost, USBH_DEVICE_ADDRESS) == USBH_OK)
+    {
+      USBH_Delay(2);
+      phost->device.address = USBH_DEVICE_ADDRESS;
+      
+      /* user callback for device address assigned */
+      USBH_UsrLog("Address (#%d) assigned.", phost->device.address);
+      phost->EnumState = ENUM_GET_CFG_DESC;
+      
+      /* modify control channels to update device address */
+      USBH_OpenPipe (phost,
+                           phost->Control.pipe_in,
+                           0x80,
+                           phost->device.address,
+                           phost->device.speed,
+                           USBH_EP_CONTROL,
+                           phost->Control.pipe_size); 
+      
+      /* Open Control pipes */
+      USBH_OpenPipe (phost,
+                           phost->Control.pipe_out,
+                           0x00,
+                           phost->device.address,
+                           phost->device.speed,
+                           USBH_EP_CONTROL,
+                           phost->Control.pipe_size);        
+    }
+    break;
+    
+  case ENUM_GET_CFG_DESC:  
+    /* get standard configuration descriptor */
+    if ( USBH_Get_CfgDesc(phost, 
+                          USB_CONFIGURATION_DESC_SIZE) == USBH_OK)
+    {
+      phost->EnumState = ENUM_GET_FULL_CFG_DESC;        
+    }
+    break;
+    
+  case ENUM_GET_FULL_CFG_DESC:  
+    /* get FULL config descriptor (config, interface, endpoints) */
+    if (USBH_Get_CfgDesc(phost, 
+                         phost->device.CfgDesc.wTotalLength) == USBH_OK)
+    {
+      phost->EnumState = ENUM_GET_MFC_STRING_DESC;       
+    }
+    break;
+    
+  case ENUM_GET_MFC_STRING_DESC:  
+    if (phost->device.DevDesc.iManufacturer != 0)
+    { /* Check that Manufacturer String is available */
+      
+      if ( USBH_Get_StringDesc(phost,
+                               phost->device.DevDesc.iManufacturer, 
+                                phost->device.Data , 
+                               0xff) == USBH_OK)
+      {
+        /* User callback for Manufacturing string */
+        USBH_UsrLog("Manufacturer : %s",  (char *)phost->device.Data);
+        phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC;
+        
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif          
+      }
+    }
+    else
+    {
+     USBH_UsrLog("Manufacturer : N/A");      
+     phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; 
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif       
+    }
+    break;
+    
+  case ENUM_GET_PRODUCT_STRING_DESC:   
+    if (phost->device.DevDesc.iProduct != 0)
+    { /* Check that Product string is available */
+      if ( USBH_Get_StringDesc(phost,
+                               phost->device.DevDesc.iProduct, 
+                               phost->device.Data, 
+                               0xff) == USBH_OK)
+      {
+        /* User callback for Product string */
+        USBH_UsrLog("Product : %s",  (char *)phost->device.Data);
+        phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC;        
+      }
+    }
+    else
+    {
+      USBH_UsrLog("Product : N/A");
+      phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; 
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif        
+    } 
+    break;
+    
+  case ENUM_GET_SERIALNUM_STRING_DESC:   
+    if (phost->device.DevDesc.iSerialNumber != 0)
+    { /* Check that Serial number string is available */    
+      if ( USBH_Get_StringDesc(phost,
+                               phost->device.DevDesc.iSerialNumber, 
+                               phost->device.Data, 
+                               0xff) == USBH_OK)
+      {
+        /* User callback for Serial number string */
+         USBH_UsrLog("Serial Number : %s",  (char *)phost->device.Data);
+        Status = USBH_OK;
+      }
+    }
+    else
+    {
+      USBH_UsrLog("Serial Number : N/A"); 
+      Status = USBH_OK;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
+#endif        
+    }  
+    break;
+    
+  default:
+    break;
+  }  
+  return Status;
+}
+
+/**
+  * @brief  USBH_LL_SetTimer 
+  *         Set the initial Host Timer tick
+  * @param  phost: Host Handle
+  * @retval None
+  */
+void  USBH_LL_SetTimer  (USBH_HandleTypeDef *phost, uint32_t time)
+{
+  phost->Timer = time;
+}
+/**
+  * @brief  USBH_LL_IncTimer 
+  *         Increment Host Timer tick
+  * @param  phost: Host Handle
+  * @retval None
+  */
+void  USBH_LL_IncTimer  (USBH_HandleTypeDef *phost)
+{
+  phost->Timer ++;
+  USBH_HandleSof(phost);
+}
+
+/**
+  * @brief  USBH_HandleSof 
+  *         Call SOF process
+  * @param  phost: Host Handle
+  * @retval None
+  */
+void  USBH_HandleSof  (USBH_HandleTypeDef *phost)
+{
+  if((phost->gState == HOST_CLASS)&&(phost->pActiveClass != NULL))
+  {
+    phost->pActiveClass->SOFProcess(phost);
+  }
+}
+/**
+  * @brief  USBH_LL_Connect 
+  *         Handle USB Host connexion event
+  * @param  phost: Host Handle
+  * @retval USBH_Status
+  */
+USBH_StatusTypeDef  USBH_LL_Connect  (USBH_HandleTypeDef *phost)
+{
+  if(phost->gState == HOST_IDLE )
+  {
+    phost->device.is_connected = 1;
+    phost->gState = HOST_IDLE ;
+    
+    if(phost->pUser != NULL)
+    {    
+      phost->pUser(phost, HOST_USER_CONNECTION);
+    }
+  } 
+  else if(phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT )
+  {
+    phost->gState = HOST_DEV_ATTACHED ;
+  }
+#if (USBH_USE_OS == 1)
+  osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
+#endif 
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_LL_Disconnect 
+  *         Handle USB Host disconnexion event
+  * @param  phost: Host Handle
+  * @retval USBH_Status
+  */
+USBH_StatusTypeDef  USBH_LL_Disconnect  (USBH_HandleTypeDef *phost)
+{
+  /*Stop Host */ 
+  USBH_LL_Stop(phost);  
+  
+  /* FRee Control Pipes */
+  USBH_FreePipe  (phost, phost->Control.pipe_in);
+  USBH_FreePipe  (phost, phost->Control.pipe_out);  
+   
+  phost->device.is_connected = 0; 
+   
+  if(phost->pUser != NULL)
+  {    
+    phost->pUser(phost, HOST_USER_DISCONNECTION);
+  }
+  USBH_UsrLog("USB Device disconnected"); 
+  
+  /* Start the low level driver  */
+  USBH_LL_Start(phost);
+  
+  phost->gState = HOST_DEV_DISCONNECTED;
+  
+#if (USBH_USE_OS == 1)
+  osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
+#endif 
+  
+  return USBH_OK;
+}
+
+
+#if (USBH_USE_OS == 1)  
+/**
+  * @brief  USB Host Thread task
+  * @param  pvParameters not used
+  * @retval None
+  */
+static void USBH_Process_OS(void const * argument)
+{
+  osEvent event;
+  
+  for(;;)
+  {
+    event = osMessageGet(((USBH_HandleTypeDef *)argument)->os_event, osWaitForever );
+    
+    if( event.status == osEventMessage )
+    {
+      USBH_Process((USBH_HandleTypeDef *)argument);
+    }
+   }
+}
+
+/**
+* @brief  USBH_LL_NotifyURBChange 
+*         Notify URB state Change
+* @param  phost: Host handle
+* @retval USBH Status
+*/
+USBH_StatusTypeDef  USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost)
+{
+  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
+  return USBH_OK;
+}
+#endif  
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */ 
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/micropython/ports/stm32/usbhost/Core/Src/usbh_ctlreq.c b/micropython/ports/stm32/usbhost/Core/Src/usbh_ctlreq.c
index 58bc34d6435036d9ac95fcd773503b9c498373f2..90dca7ffef1201b391e889242080fbf902958d94 100644
--- a/micropython/ports/stm32/usbhost/Core/Src/usbh_ctlreq.c
+++ b/micropython/ports/stm32/usbhost/Core/Src/usbh_ctlreq.c
@@ -1,881 +1,881 @@
-/**
-  ******************************************************************************
-  * @file    usbh_ctlreq.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file implements the control requests for device enumeration
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-/* Includes ------------------------------------------------------------------*/
-
-#include "usbh_ctlreq.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-
-/** @defgroup USBH_CTLREQ 
-* @brief This file implements the standard requests for device enumeration
-* @{
-*/
-
-
-/** @defgroup USBH_CTLREQ_Private_Defines
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CTLREQ_Private_TypesDefinitions
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-
-/** @defgroup USBH_CTLREQ_Private_Macros
-* @{
-*/ 
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CTLREQ_Private_Variables
-* @{
-*/
-/**
-* @}
-*/ 
-
-/** @defgroup USBH_CTLREQ_Private_FunctionPrototypes
-* @{
-*/
-static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost);
-
-static void USBH_ParseDevDesc (USBH_DevDescTypeDef* , uint8_t *buf, uint16_t length);
-
-static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc,
-                               uint8_t *buf, 
-                               uint16_t length);
-
-
-static void USBH_ParseEPDesc (USBH_EpDescTypeDef  *ep_descriptor, uint8_t *buf);
-static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length);
-static void USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef  *if_descriptor, uint8_t *buf);
-
-
-/**
-* @}
-*/ 
-
-
-/** @defgroup USBH_CTLREQ_Private_Functions
-* @{
-*/ 
-
-
-/**
-  * @brief  USBH_Get_DevDesc
-  *         Issue Get Device Descriptor command to the device. Once the response 
-  *         received, it parses the device descriptor and updates the status.
-  * @param  phost: Host Handle
-  * @param  length: Length of the descriptor
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint8_t length)
-{
-  USBH_StatusTypeDef status;
-  
-  if((status = USBH_GetDescriptor(phost,
-                                  USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,                          
-                                  USB_DESC_DEVICE, 
-                                  phost->device.Data,
-                                  length)) == USBH_OK)
-  {
-    /* Commands successfully sent and Response Received */       
-    USBH_ParseDevDesc(&phost->device.DevDesc, phost->device.Data, length);
-  }
-  return status;      
-}
-
-/**
-  * @brief  USBH_Get_CfgDesc
-  *         Issues Configuration Descriptor to the device. Once the response 
-  *         received, it parses the configuartion descriptor and updates the 
-  *         status.
-  * @param  phost: Host Handle
-  * @param  length: Length of the descriptor
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,                      
-                             uint16_t length)
-
-{
-  USBH_StatusTypeDef status;
-  uint8_t *pData;
-#if (USBH_KEEP_CFG_DESCRIPTOR == 1)  
-  pData = phost->device.CfgDesc_Raw;
-#else
-  pData = phost->device.Data;
-#endif  
-  if((status = USBH_GetDescriptor(phost,
-                                  USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,                          
-                                  USB_DESC_CONFIGURATION, 
-                                  pData,
-                                  length)) == USBH_OK)
-  {
-    
-    /* Commands successfully sent and Response Received  */       
-    USBH_ParseCfgDesc (&phost->device.CfgDesc,
-                       pData,
-                       length); 
-    
-  }
-  return status;
-}
-
-
-/**
-  * @brief  USBH_Get_StringDesc
-  *         Issues string Descriptor command to the device. Once the response 
-  *         received, it parses the string descriptor and updates the status.
-  * @param  phost: Host Handle
-  * @param  string_index: String index for the descriptor
-  * @param  buff: Buffer address for the descriptor
-  * @param  length: Length of the descriptor
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,
-                                uint8_t string_index, 
-                                uint8_t *buff, 
-                                uint16_t length)
-{
-  USBH_StatusTypeDef status;
-  if((status = USBH_GetDescriptor(phost,
-                                  USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,                                    
-                                  USB_DESC_STRING | string_index, 
-                                  phost->device.Data,
-                                  length)) == USBH_OK)
-  {
-    /* Commands successfully sent and Response Received  */       
-    USBH_ParseStringDesc(phost->device.Data,buff, length);    
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_GetDescriptor
-  *         Issues Descriptor command to the device. Once the response received,
-  *         it parses the descriptor and updates the status.
-  * @param  phost: Host Handle
-  * @param  req_type: Descriptor type
-  * @param  value_idx: wValue for the GetDescriptr request
-  * @param  buff: Buffer to store the descriptor
-  * @param  length: Length of the descriptor
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,                          
-                               uint8_t  req_type,
-                               uint16_t value_idx, 
-                               uint8_t* buff, 
-                               uint16_t length )
-{ 
-  if(phost->RequestState == CMD_SEND)
-  {
-    phost->Control.setup.b.bmRequestType = USB_D2H | req_type;
-    phost->Control.setup.b.bRequest = USB_REQ_GET_DESCRIPTOR;
-    phost->Control.setup.b.wValue.w = value_idx;
-    
-    if ((value_idx & 0xff00) == USB_DESC_STRING)
-    {
-      phost->Control.setup.b.wIndex.w = 0x0409;
-    }
-    else
-    {
-      phost->Control.setup.b.wIndex.w = 0;
-    }
-    phost->Control.setup.b.wLength.w = length; 
-  }
-  return USBH_CtlReq(phost, buff , length );     
-}
-
-/**
-  * @brief  USBH_SetAddress
-  *         This command sets the address to the connected device
-  * @param  phost: Host Handle
-  * @param  DeviceAddress: Device address to assign
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost, 
-                                   uint8_t DeviceAddress)
-{
-  if(phost->RequestState == CMD_SEND)
-  {
-    phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE | \
-      USB_REQ_TYPE_STANDARD;
-    
-    phost->Control.setup.b.bRequest = USB_REQ_SET_ADDRESS;
-    
-    phost->Control.setup.b.wValue.w = (uint16_t)DeviceAddress;
-    phost->Control.setup.b.wIndex.w = 0;
-    phost->Control.setup.b.wLength.w = 0;
-  }
-  return USBH_CtlReq(phost, 0 , 0 );
-}
-
-/**
-  * @brief  USBH_SetCfg
-  *         The command sets the configuration value to the connected device
-  * @param  phost: Host Handle
-  * @param  cfg_idx: Configuration value
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, 
-                               uint16_t cfg_idx)
-{
-  if(phost->RequestState == CMD_SEND)
-  {
-    phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE |\
-      USB_REQ_TYPE_STANDARD;
-    phost->Control.setup.b.bRequest = USB_REQ_SET_CONFIGURATION;
-    phost->Control.setup.b.wValue.w = cfg_idx;
-    phost->Control.setup.b.wIndex.w = 0;
-    phost->Control.setup.b.wLength.w = 0; 
-  }
-  
-  return USBH_CtlReq(phost, 0 , 0 );      
-}
-
-/**
-  * @brief  USBH_SetInterface
-  *         The command sets the Interface value to the connected device
-  * @param  phost: Host Handle
-  * @param  altSetting: Interface value
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, 
-                        uint8_t ep_num, uint8_t altSetting)
-{
-  
-  if(phost->RequestState == CMD_SEND)
-  {
-    phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \
-      USB_REQ_TYPE_STANDARD;
-    
-    phost->Control.setup.b.bRequest = USB_REQ_SET_INTERFACE;
-    phost->Control.setup.b.wValue.w = altSetting;
-    phost->Control.setup.b.wIndex.w = ep_num;
-    phost->Control.setup.b.wLength.w = 0;           
-  }
-  return USBH_CtlReq(phost, 0 , 0 );     
-}
-
-/**
-  * @brief  USBH_ClrFeature
-  *         This request is used to clear or disable a specific feature.
-  * @param  phost: Host Handle
-  * @param  ep_num: endpoint number 
-  * @param  hc_num: Host channel number 
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost,
-                                   uint8_t ep_num) 
-{
-  if(phost->RequestState == CMD_SEND)
-  {
-    phost->Control.setup.b.bmRequestType = USB_H2D | 
-      USB_REQ_RECIPIENT_ENDPOINT |
-        USB_REQ_TYPE_STANDARD;
-    
-    phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE;
-    phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT;
-    phost->Control.setup.b.wIndex.w = ep_num;
-    phost->Control.setup.b.wLength.w = 0;           
-  }
-  return USBH_CtlReq(phost, 0 , 0 );   
-}
-
-/**
-  * @brief  USBH_ParseDevDesc 
-  *         This function Parses the device descriptor
-  * @param  dev_desc: device_descriptor destinaton address 
-  * @param  buf: Buffer where the source descriptor is available
-  * @param  length: Length of the descriptor
-  * @retval None
-  */
-static void  USBH_ParseDevDesc (USBH_DevDescTypeDef* dev_desc,
-                                uint8_t *buf, 
-                                uint16_t length)
-{
-  dev_desc->bLength            = *(uint8_t  *) (buf +  0);
-  dev_desc->bDescriptorType    = *(uint8_t  *) (buf +  1);
-  dev_desc->bcdUSB             = LE16 (buf +  2);
-  dev_desc->bDeviceClass       = *(uint8_t  *) (buf +  4);
-  dev_desc->bDeviceSubClass    = *(uint8_t  *) (buf +  5);
-  dev_desc->bDeviceProtocol    = *(uint8_t  *) (buf +  6);
-  dev_desc->bMaxPacketSize     = *(uint8_t  *) (buf +  7);
-  
-  if (length > 8)
-  { /* For 1st time after device connection, Host may issue only 8 bytes for 
-    Device Descriptor Length  */
-    dev_desc->idVendor           = LE16 (buf +  8);
-    dev_desc->idProduct          = LE16 (buf + 10);
-    dev_desc->bcdDevice          = LE16 (buf + 12);
-    dev_desc->iManufacturer      = *(uint8_t  *) (buf + 14);
-    dev_desc->iProduct           = *(uint8_t  *) (buf + 15);
-    dev_desc->iSerialNumber      = *(uint8_t  *) (buf + 16);
-    dev_desc->bNumConfigurations = *(uint8_t  *) (buf + 17);
-  }
-}
-
-/**
-  * @brief  USBH_ParseCfgDesc 
-  *         This function Parses the configuration descriptor
-  * @param  cfg_desc: Configuration Descriptor address
-  * @param  buf: Buffer where the source descriptor is available
-  * @param  length: Length of the descriptor
-  * @retval None
-  */
-static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc,
-                               uint8_t *buf, 
-                               uint16_t length)
-{  
-  USBH_InterfaceDescTypeDef    *pif ;
-  USBH_EpDescTypeDef           *pep;  
-  USBH_DescHeader_t             *pdesc = (USBH_DescHeader_t *)buf;
-  uint16_t                      ptr;
-  int8_t                        if_ix = 0;
-  int8_t                        ep_ix = 0;  
-  
-  pdesc   = (USBH_DescHeader_t *)buf;
-  
-  /* Parse configuration descriptor */
-  cfg_desc->bLength             = *(uint8_t  *) (buf + 0);
-  cfg_desc->bDescriptorType     = *(uint8_t  *) (buf + 1);
-  cfg_desc->wTotalLength        = LE16 (buf + 2);
-  cfg_desc->bNumInterfaces      = *(uint8_t  *) (buf + 4);
-  cfg_desc->bConfigurationValue = *(uint8_t  *) (buf + 5);
-  cfg_desc->iConfiguration      = *(uint8_t  *) (buf + 6);
-  cfg_desc->bmAttributes        = *(uint8_t  *) (buf + 7);
-  cfg_desc->bMaxPower           = *(uint8_t  *) (buf + 8);    
-  
-  
-  if (length > USB_CONFIGURATION_DESC_SIZE)
-  {
-    ptr = USB_LEN_CFG_DESC;
-    pif = (USBH_InterfaceDescTypeDef *)0;
-    
-    
-    while ((if_ix < USBH_MAX_NUM_INTERFACES ) && (ptr < cfg_desc->wTotalLength))
-    {
-      pdesc = USBH_GetNextDesc((uint8_t *)pdesc, &ptr);
-      if (pdesc->bDescriptorType   == USB_DESC_TYPE_INTERFACE) 
-      {
-        pif = &cfg_desc->Itf_Desc[if_ix];
-        USBH_ParseInterfaceDesc (pif, (uint8_t *)pdesc);            
-        
-        ep_ix = 0;
-        pep = (USBH_EpDescTypeDef *)0;        
-        while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength))
-        {
-          pdesc = USBH_GetNextDesc((void* )pdesc, &ptr);
-          if (pdesc->bDescriptorType   == USB_DESC_TYPE_ENDPOINT) 
-          {  
-            pep = &cfg_desc->Itf_Desc[if_ix].Ep_Desc[ep_ix];
-            USBH_ParseEPDesc (pep, (uint8_t *)pdesc);
-            ep_ix++;
-          }
-        }
-        if_ix++;
-      }
-    }
-  }  
-}
-
-
-
-/**
-  * @brief  USBH_ParseInterfaceDesc 
-  *         This function Parses the interface descriptor
-  * @param  if_descriptor : Interface descriptor destination
-  * @param  buf: Buffer where the descriptor data is available
-  * @retval None
-  */
-static void  USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef *if_descriptor, 
-                                      uint8_t *buf)
-{
-  if_descriptor->bLength            = *(uint8_t  *) (buf + 0);
-  if_descriptor->bDescriptorType    = *(uint8_t  *) (buf + 1);
-  if_descriptor->bInterfaceNumber   = *(uint8_t  *) (buf + 2);
-  if_descriptor->bAlternateSetting  = *(uint8_t  *) (buf + 3);
-  if_descriptor->bNumEndpoints      = *(uint8_t  *) (buf + 4);
-  if_descriptor->bInterfaceClass    = *(uint8_t  *) (buf + 5);
-  if_descriptor->bInterfaceSubClass = *(uint8_t  *) (buf + 6);
-  if_descriptor->bInterfaceProtocol = *(uint8_t  *) (buf + 7);
-  if_descriptor->iInterface         = *(uint8_t  *) (buf + 8);
-}
-
-/**
-  * @brief  USBH_ParseEPDesc 
-  *         This function Parses the endpoint descriptor
-  * @param  ep_descriptor: Endpoint descriptor destination address
-  * @param  buf: Buffer where the parsed descriptor stored
-  * @retval None
-  */
-static void  USBH_ParseEPDesc (USBH_EpDescTypeDef  *ep_descriptor, 
-                               uint8_t *buf)
-{
-  
-  ep_descriptor->bLength          = *(uint8_t  *) (buf + 0);
-  ep_descriptor->bDescriptorType  = *(uint8_t  *) (buf + 1);
-  ep_descriptor->bEndpointAddress = *(uint8_t  *) (buf + 2);
-  ep_descriptor->bmAttributes     = *(uint8_t  *) (buf + 3);
-  ep_descriptor->wMaxPacketSize   = LE16 (buf + 4);
-  ep_descriptor->bInterval        = *(uint8_t  *) (buf + 6);
-}
-
-/**
-  * @brief  USBH_ParseStringDesc 
-  *         This function Parses the string descriptor
-  * @param  psrc: Source pointer containing the descriptor data
-  * @param  pdest: Destination address pointer
-  * @param  length: Length of the descriptor
-  * @retval None
-  */
-static void USBH_ParseStringDesc (uint8_t* psrc, 
-                                  uint8_t* pdest, 
-                                  uint16_t length)
-{
-  uint16_t strlength;
-  uint16_t idx;
-  
-  /* The UNICODE string descriptor is not NULL-terminated. The string length is
-  computed by substracting two from the value of the first byte of the descriptor.
-  */
-  
-  /* Check which is lower size, the Size of string or the length of bytes read 
-  from the device */
-  
-  if ( psrc[1] == USB_DESC_TYPE_STRING)
-  { /* Make sure the Descriptor is String Type */
-    
-    /* psrc[0] contains Size of Descriptor, subtract 2 to get the length of string */      
-    strlength = ( ( (psrc[0]-2) <= length) ? (psrc[0]-2) :length); 
-    psrc += 2; /* Adjust the offset ignoring the String Len and Descriptor type */
-    
-    for (idx = 0; idx < strlength; idx+=2 )
-    {/* Copy Only the string and ignore the UNICODE ID, hence add the src */
-      *pdest =  psrc[idx];
-      pdest++;
-    }  
-    *pdest = 0; /* mark end of string */  
-  }
-}
-
-/**
-  * @brief  USBH_GetNextDesc 
-  *         This function return the next descriptor header
-  * @param  buf: Buffer where the cfg descriptor is available
-  * @param  ptr: data popinter inside the cfg descriptor
-  * @retval next header
-  */
-USBH_DescHeader_t  *USBH_GetNextDesc (uint8_t   *pbuf, uint16_t  *ptr)
-{
-  USBH_DescHeader_t  *pnext;
- 
-  *ptr += ((USBH_DescHeader_t *)pbuf)->bLength;  
-  pnext = (USBH_DescHeader_t *)((uint8_t *)pbuf + \
-         ((USBH_DescHeader_t *)pbuf)->bLength);
- 
-  return(pnext);
-}
-
-
-/**
-  * @brief  USBH_CtlReq
-  *         USBH_CtlReq sends a control request and provide the status after 
-  *            completion of the request
-  * @param  phost: Host Handle
-  * @param  req: Setup Request Structure
-  * @param  buff: data buffer address to store the response
-  * @param  length: length of the response
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_CtlReq     (USBH_HandleTypeDef *phost, 
-                             uint8_t             *buff,
-                             uint16_t            length)
-{
-  USBH_StatusTypeDef status;
-  status = USBH_BUSY;
-  
-  switch (phost->RequestState)
-  {
-  case CMD_SEND:
-    /* Start a SETUP transfer */
-    phost->Control.buff = buff; 
-    phost->Control.length = length;
-    phost->Control.state = CTRL_SETUP;  
-    phost->RequestState = CMD_WAIT;
-    status = USBH_BUSY;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    break;
-    
-  case CMD_WAIT:
-    status = USBH_HandleControl(phost);
-     if (status == USBH_OK) 
-    {
-      /* Commands successfully sent and Response Received  */       
-      phost->RequestState = CMD_SEND;
-      phost->Control.state =CTRL_IDLE;  
-      status = USBH_OK;      
-    }
-    else if  (status == USBH_FAIL)
-    {
-      /* Failure Mode */
-      phost->RequestState = CMD_SEND;
-      status = USBH_FAIL;
-    }   
-    break;
-    
-  default:
-    break; 
-  }
-  return status;
-}
-
-/**
-  * @brief  USBH_HandleControl
-  *         Handles the USB control transfer state machine
-  * @param  phost: Host Handle
-  * @retval USBH Status
-  */
-static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost)
-{
-  uint8_t direction;  
-  USBH_StatusTypeDef status = USBH_BUSY;
-  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
-  
-  switch (phost->Control.state)
-  {
-  case CTRL_SETUP:
-    /* send a SETUP packet */
-    USBH_CtlSendSetup     (phost, 
-	                   (uint8_t *)phost->Control.setup.d8 , 
-	                   phost->Control.pipe_out); 
-    
-    phost->Control.state = CTRL_SETUP_WAIT; 
-    break; 
-    
-  case CTRL_SETUP_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out); 
-    /* case SETUP packet sent successfully */
-    if(URB_Status == USBH_URB_DONE)
-    { 
-      direction = (phost->Control.setup.b.bmRequestType & USB_REQ_DIR_MASK);
-      
-      /* check if there is a data stage */
-      if (phost->Control.setup.b.wLength.w != 0 )
-      {        
-        if (direction == USB_D2H)
-        {
-          /* Data Direction is IN */
-          phost->Control.state = CTRL_DATA_IN;
-        }
-        else
-        {
-          /* Data Direction is OUT */
-          phost->Control.state = CTRL_DATA_OUT;
-        } 
-      }
-      /* No DATA stage */
-      else
-      {
-        /* If there is No Data Transfer Stage */
-        if (direction == USB_D2H)
-        {
-          /* Data Direction is IN */
-          phost->Control.state = CTRL_STATUS_OUT;
-        }
-        else
-        {
-          /* Data Direction is OUT */
-          phost->Control.state = CTRL_STATUS_IN;
-        } 
-      }          
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif
-    }
-    else if(URB_Status == USBH_URB_ERROR)
-    {
-      phost->Control.state = CTRL_ERROR;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }    
-    break;
-    
-  case CTRL_DATA_IN:  
-    /* Issue an IN token */ 
-     phost->Control.timer = phost->Timer;
-    USBH_CtlReceiveData(phost,
-                        phost->Control.buff, 
-                        phost->Control.length,
-                        phost->Control.pipe_in);
- 
-    phost->Control.state = CTRL_DATA_IN_WAIT;
-    break;    
-    
-  case CTRL_DATA_IN_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in); 
-    
-    /* check is DATA packet transfered successfully */
-    if  (URB_Status == USBH_URB_DONE)
-    { 
-      phost->Control.state = CTRL_STATUS_OUT;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-   
-    /* manage error cases*/
-    if  (URB_Status == USBH_URB_STALL) 
-    { 
-      /* In stall case, return to previous machine state*/
-      status = USBH_NOT_SUPPORTED;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }   
-    else if (URB_Status == USBH_URB_ERROR)
-    {
-      /* Device error */
-      phost->Control.state = CTRL_ERROR;  
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-    break;
-    
-  case CTRL_DATA_OUT:
-    
-    USBH_CtlSendData (phost,
-                      phost->Control.buff, 
-                      phost->Control.length , 
-                      phost->Control.pipe_out,
-                      1);
-     phost->Control.timer = phost->Timer;
-    phost->Control.state = CTRL_DATA_OUT_WAIT;
-    break;
-    
-  case CTRL_DATA_OUT_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out);     
-    
-    if  (URB_Status == USBH_URB_DONE)
-    { /* If the Setup Pkt is sent successful, then change the state */
-      phost->Control.state = CTRL_STATUS_IN;
-#if (USBH_USE_OS == 1)
-      osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-    
-    /* handle error cases */
-    else if  (URB_Status == USBH_URB_STALL) 
-    { 
-      /* In stall case, return to previous machine state*/
-      phost->Control.state = CTRL_STALLED; 
-      status = USBH_NOT_SUPPORTED;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    } 
-    else if  (URB_Status == USBH_URB_NOTREADY)
-    { 
-      /* Nack received from device */
-      phost->Control.state = CTRL_DATA_OUT;
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }    
-    else if (URB_Status == USBH_URB_ERROR)
-    {
-      /* device error */
-      phost->Control.state = CTRL_ERROR;  
-      status = USBH_FAIL;    
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    } 
-    break;
-    
-    
-  case CTRL_STATUS_IN:
-    /* Send 0 bytes out packet */
-    USBH_CtlReceiveData (phost,
-                         0,
-                         0,
-                         phost->Control.pipe_in);
-    phost->Control.timer = phost->Timer;
-    phost->Control.state = CTRL_STATUS_IN_WAIT;
-    
-    break;
-    
-  case CTRL_STATUS_IN_WAIT:
-    
-    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in); 
-    
-    if  ( URB_Status == USBH_URB_DONE)
-    { /* Control transfers completed, Exit the State Machine */
-      phost->Control.state = CTRL_COMPLETE;
-      status = USBH_OK;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-    
-    else if (URB_Status == USBH_URB_ERROR)
-    {
-      phost->Control.state = CTRL_ERROR;
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-     else if(URB_Status == USBH_URB_STALL)
-    {
-      /* Control transfers completed, Exit the State Machine */
-      status = USBH_NOT_SUPPORTED;
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-    break;
-    
-  case CTRL_STATUS_OUT:
-    USBH_CtlSendData (phost,
-                      0,
-                      0,
-                      phost->Control.pipe_out,
-                      1);
-     phost->Control.timer = phost->Timer;
-    phost->Control.state = CTRL_STATUS_OUT_WAIT;
-    break;
-    
-  case CTRL_STATUS_OUT_WAIT: 
-    
-    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out);  
-    if  (URB_Status == USBH_URB_DONE)
-    { 
-      status = USBH_OK;      
-      phost->Control.state = CTRL_COMPLETE; 
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-    else if  (URB_Status == USBH_URB_NOTREADY)
-    { 
-      phost->Control.state = CTRL_STATUS_OUT;
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }      
-    else if (URB_Status == USBH_URB_ERROR)
-    {
-      phost->Control.state = CTRL_ERROR; 
-      
-#if (USBH_USE_OS == 1)
-    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
-#endif      
-    }
-    break;
-    
-  case CTRL_ERROR:
-    /* 
-    After a halt condition is encountered or an error is detected by the 
-    host, a control endpoint is allowed to recover by accepting the next Setup 
-    PID; i.e., recovery actions via some other pipe are not required for control
-    endpoints. For the Default Control Pipe, a device reset will ultimately be 
-    required to clear the halt or error condition if the next Setup PID is not 
-    accepted.
-    */
-    if (++ phost->Control.errorcount <= USBH_MAX_ERROR_COUNT)
-    {
-      /* try to recover control */
-      USBH_LL_Stop(phost);
-         
-      /* Do the transmission again, starting from SETUP Packet */
-      phost->Control.state = CTRL_SETUP; 
-      phost->RequestState = CMD_SEND;
-    }
-    else
-    {
-      phost->Control.errorcount = 0;
-      USBH_ErrLog("Control error");
-      status = USBH_FAIL;
-      
-    }
-    break;
-    
-  default:
-    break;
-  }
-  return status;
-}
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_ctlreq.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file implements the control requests for device enumeration
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+/* Includes ------------------------------------------------------------------*/
+
+#include "usbh_ctlreq.h"
+
+/** @addtogroup USBH_LIB
+* @{
+*/
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+
+/** @defgroup USBH_CTLREQ 
+* @brief This file implements the standard requests for device enumeration
+* @{
+*/
+
+
+/** @defgroup USBH_CTLREQ_Private_Defines
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CTLREQ_Private_TypesDefinitions
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+
+/** @defgroup USBH_CTLREQ_Private_Macros
+* @{
+*/ 
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CTLREQ_Private_Variables
+* @{
+*/
+/**
+* @}
+*/ 
+
+/** @defgroup USBH_CTLREQ_Private_FunctionPrototypes
+* @{
+*/
+static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost);
+
+static void USBH_ParseDevDesc (USBH_DevDescTypeDef* , uint8_t *buf, uint16_t length);
+
+static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc,
+                               uint8_t *buf, 
+                               uint16_t length);
+
+
+static void USBH_ParseEPDesc (USBH_EpDescTypeDef  *ep_descriptor, uint8_t *buf);
+static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length);
+static void USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef  *if_descriptor, uint8_t *buf);
+
+
+/**
+* @}
+*/ 
+
+
+/** @defgroup USBH_CTLREQ_Private_Functions
+* @{
+*/ 
+
+
+/**
+  * @brief  USBH_Get_DevDesc
+  *         Issue Get Device Descriptor command to the device. Once the response 
+  *         received, it parses the device descriptor and updates the status.
+  * @param  phost: Host Handle
+  * @param  length: Length of the descriptor
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint8_t length)
+{
+  USBH_StatusTypeDef status;
+  
+  if((status = USBH_GetDescriptor(phost,
+                                  USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,                          
+                                  USB_DESC_DEVICE, 
+                                  phost->device.Data,
+                                  length)) == USBH_OK)
+  {
+    /* Commands successfully sent and Response Received */       
+    USBH_ParseDevDesc(&phost->device.DevDesc, phost->device.Data, length);
+  }
+  return status;      
+}
+
+/**
+  * @brief  USBH_Get_CfgDesc
+  *         Issues Configuration Descriptor to the device. Once the response 
+  *         received, it parses the configuartion descriptor and updates the 
+  *         status.
+  * @param  phost: Host Handle
+  * @param  length: Length of the descriptor
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,                      
+                             uint16_t length)
+
+{
+  USBH_StatusTypeDef status;
+  uint8_t *pData;
+#if (USBH_KEEP_CFG_DESCRIPTOR == 1)  
+  pData = phost->device.CfgDesc_Raw;
+#else
+  pData = phost->device.Data;
+#endif  
+  if((status = USBH_GetDescriptor(phost,
+                                  USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,                          
+                                  USB_DESC_CONFIGURATION, 
+                                  pData,
+                                  length)) == USBH_OK)
+  {
+    
+    /* Commands successfully sent and Response Received  */       
+    USBH_ParseCfgDesc (&phost->device.CfgDesc,
+                       pData,
+                       length); 
+    
+  }
+  return status;
+}
+
+
+/**
+  * @brief  USBH_Get_StringDesc
+  *         Issues string Descriptor command to the device. Once the response 
+  *         received, it parses the string descriptor and updates the status.
+  * @param  phost: Host Handle
+  * @param  string_index: String index for the descriptor
+  * @param  buff: Buffer address for the descriptor
+  * @param  length: Length of the descriptor
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,
+                                uint8_t string_index, 
+                                uint8_t *buff, 
+                                uint16_t length)
+{
+  USBH_StatusTypeDef status;
+  if((status = USBH_GetDescriptor(phost,
+                                  USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,                                    
+                                  USB_DESC_STRING | string_index, 
+                                  phost->device.Data,
+                                  length)) == USBH_OK)
+  {
+    /* Commands successfully sent and Response Received  */       
+    USBH_ParseStringDesc(phost->device.Data,buff, length);    
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_GetDescriptor
+  *         Issues Descriptor command to the device. Once the response received,
+  *         it parses the descriptor and updates the status.
+  * @param  phost: Host Handle
+  * @param  req_type: Descriptor type
+  * @param  value_idx: wValue for the GetDescriptr request
+  * @param  buff: Buffer to store the descriptor
+  * @param  length: Length of the descriptor
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,                          
+                               uint8_t  req_type,
+                               uint16_t value_idx, 
+                               uint8_t* buff, 
+                               uint16_t length )
+{ 
+  if(phost->RequestState == CMD_SEND)
+  {
+    phost->Control.setup.b.bmRequestType = USB_D2H | req_type;
+    phost->Control.setup.b.bRequest = USB_REQ_GET_DESCRIPTOR;
+    phost->Control.setup.b.wValue.w = value_idx;
+    
+    if ((value_idx & 0xff00) == USB_DESC_STRING)
+    {
+      phost->Control.setup.b.wIndex.w = 0x0409;
+    }
+    else
+    {
+      phost->Control.setup.b.wIndex.w = 0;
+    }
+    phost->Control.setup.b.wLength.w = length; 
+  }
+  return USBH_CtlReq(phost, buff , length );     
+}
+
+/**
+  * @brief  USBH_SetAddress
+  *         This command sets the address to the connected device
+  * @param  phost: Host Handle
+  * @param  DeviceAddress: Device address to assign
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost, 
+                                   uint8_t DeviceAddress)
+{
+  if(phost->RequestState == CMD_SEND)
+  {
+    phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE | \
+      USB_REQ_TYPE_STANDARD;
+    
+    phost->Control.setup.b.bRequest = USB_REQ_SET_ADDRESS;
+    
+    phost->Control.setup.b.wValue.w = (uint16_t)DeviceAddress;
+    phost->Control.setup.b.wIndex.w = 0;
+    phost->Control.setup.b.wLength.w = 0;
+  }
+  return USBH_CtlReq(phost, 0 , 0 );
+}
+
+/**
+  * @brief  USBH_SetCfg
+  *         The command sets the configuration value to the connected device
+  * @param  phost: Host Handle
+  * @param  cfg_idx: Configuration value
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, 
+                               uint16_t cfg_idx)
+{
+  if(phost->RequestState == CMD_SEND)
+  {
+    phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE |\
+      USB_REQ_TYPE_STANDARD;
+    phost->Control.setup.b.bRequest = USB_REQ_SET_CONFIGURATION;
+    phost->Control.setup.b.wValue.w = cfg_idx;
+    phost->Control.setup.b.wIndex.w = 0;
+    phost->Control.setup.b.wLength.w = 0; 
+  }
+  
+  return USBH_CtlReq(phost, 0 , 0 );      
+}
+
+/**
+  * @brief  USBH_SetInterface
+  *         The command sets the Interface value to the connected device
+  * @param  phost: Host Handle
+  * @param  altSetting: Interface value
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, 
+                        uint8_t ep_num, uint8_t altSetting)
+{
+  
+  if(phost->RequestState == CMD_SEND)
+  {
+    phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \
+      USB_REQ_TYPE_STANDARD;
+    
+    phost->Control.setup.b.bRequest = USB_REQ_SET_INTERFACE;
+    phost->Control.setup.b.wValue.w = altSetting;
+    phost->Control.setup.b.wIndex.w = ep_num;
+    phost->Control.setup.b.wLength.w = 0;           
+  }
+  return USBH_CtlReq(phost, 0 , 0 );     
+}
+
+/**
+  * @brief  USBH_ClrFeature
+  *         This request is used to clear or disable a specific feature.
+  * @param  phost: Host Handle
+  * @param  ep_num: endpoint number 
+  * @param  hc_num: Host channel number 
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost,
+                                   uint8_t ep_num) 
+{
+  if(phost->RequestState == CMD_SEND)
+  {
+    phost->Control.setup.b.bmRequestType = USB_H2D | 
+      USB_REQ_RECIPIENT_ENDPOINT |
+        USB_REQ_TYPE_STANDARD;
+    
+    phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE;
+    phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT;
+    phost->Control.setup.b.wIndex.w = ep_num;
+    phost->Control.setup.b.wLength.w = 0;           
+  }
+  return USBH_CtlReq(phost, 0 , 0 );   
+}
+
+/**
+  * @brief  USBH_ParseDevDesc 
+  *         This function Parses the device descriptor
+  * @param  dev_desc: device_descriptor destinaton address 
+  * @param  buf: Buffer where the source descriptor is available
+  * @param  length: Length of the descriptor
+  * @retval None
+  */
+static void  USBH_ParseDevDesc (USBH_DevDescTypeDef* dev_desc,
+                                uint8_t *buf, 
+                                uint16_t length)
+{
+  dev_desc->bLength            = *(uint8_t  *) (buf +  0);
+  dev_desc->bDescriptorType    = *(uint8_t  *) (buf +  1);
+  dev_desc->bcdUSB             = LE16 (buf +  2);
+  dev_desc->bDeviceClass       = *(uint8_t  *) (buf +  4);
+  dev_desc->bDeviceSubClass    = *(uint8_t  *) (buf +  5);
+  dev_desc->bDeviceProtocol    = *(uint8_t  *) (buf +  6);
+  dev_desc->bMaxPacketSize     = *(uint8_t  *) (buf +  7);
+  
+  if (length > 8)
+  { /* For 1st time after device connection, Host may issue only 8 bytes for 
+    Device Descriptor Length  */
+    dev_desc->idVendor           = LE16 (buf +  8);
+    dev_desc->idProduct          = LE16 (buf + 10);
+    dev_desc->bcdDevice          = LE16 (buf + 12);
+    dev_desc->iManufacturer      = *(uint8_t  *) (buf + 14);
+    dev_desc->iProduct           = *(uint8_t  *) (buf + 15);
+    dev_desc->iSerialNumber      = *(uint8_t  *) (buf + 16);
+    dev_desc->bNumConfigurations = *(uint8_t  *) (buf + 17);
+  }
+}
+
+/**
+  * @brief  USBH_ParseCfgDesc 
+  *         This function Parses the configuration descriptor
+  * @param  cfg_desc: Configuration Descriptor address
+  * @param  buf: Buffer where the source descriptor is available
+  * @param  length: Length of the descriptor
+  * @retval None
+  */
+static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc,
+                               uint8_t *buf, 
+                               uint16_t length)
+{  
+  USBH_InterfaceDescTypeDef    *pif ;
+  USBH_EpDescTypeDef           *pep;  
+  USBH_DescHeader_t             *pdesc = (USBH_DescHeader_t *)buf;
+  uint16_t                      ptr;
+  int8_t                        if_ix = 0;
+  int8_t                        ep_ix = 0;  
+  
+  pdesc   = (USBH_DescHeader_t *)buf;
+  
+  /* Parse configuration descriptor */
+  cfg_desc->bLength             = *(uint8_t  *) (buf + 0);
+  cfg_desc->bDescriptorType     = *(uint8_t  *) (buf + 1);
+  cfg_desc->wTotalLength        = LE16 (buf + 2);
+  cfg_desc->bNumInterfaces      = *(uint8_t  *) (buf + 4);
+  cfg_desc->bConfigurationValue = *(uint8_t  *) (buf + 5);
+  cfg_desc->iConfiguration      = *(uint8_t  *) (buf + 6);
+  cfg_desc->bmAttributes        = *(uint8_t  *) (buf + 7);
+  cfg_desc->bMaxPower           = *(uint8_t  *) (buf + 8);    
+  
+  
+  if (length > USB_CONFIGURATION_DESC_SIZE)
+  {
+    ptr = USB_LEN_CFG_DESC;
+    pif = (USBH_InterfaceDescTypeDef *)0;
+    
+    
+    while ((if_ix < USBH_MAX_NUM_INTERFACES ) && (ptr < cfg_desc->wTotalLength))
+    {
+      pdesc = USBH_GetNextDesc((uint8_t *)pdesc, &ptr);
+      if (pdesc->bDescriptorType   == USB_DESC_TYPE_INTERFACE) 
+      {
+        pif = &cfg_desc->Itf_Desc[if_ix];
+        USBH_ParseInterfaceDesc (pif, (uint8_t *)pdesc);            
+        
+        ep_ix = 0;
+        pep = (USBH_EpDescTypeDef *)0;        
+        while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength))
+        {
+          pdesc = USBH_GetNextDesc((void* )pdesc, &ptr);
+          if (pdesc->bDescriptorType   == USB_DESC_TYPE_ENDPOINT) 
+          {  
+            pep = &cfg_desc->Itf_Desc[if_ix].Ep_Desc[ep_ix];
+            USBH_ParseEPDesc (pep, (uint8_t *)pdesc);
+            ep_ix++;
+          }
+        }
+        if_ix++;
+      }
+    }
+  }  
+}
+
+
+
+/**
+  * @brief  USBH_ParseInterfaceDesc 
+  *         This function Parses the interface descriptor
+  * @param  if_descriptor : Interface descriptor destination
+  * @param  buf: Buffer where the descriptor data is available
+  * @retval None
+  */
+static void  USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef *if_descriptor, 
+                                      uint8_t *buf)
+{
+  if_descriptor->bLength            = *(uint8_t  *) (buf + 0);
+  if_descriptor->bDescriptorType    = *(uint8_t  *) (buf + 1);
+  if_descriptor->bInterfaceNumber   = *(uint8_t  *) (buf + 2);
+  if_descriptor->bAlternateSetting  = *(uint8_t  *) (buf + 3);
+  if_descriptor->bNumEndpoints      = *(uint8_t  *) (buf + 4);
+  if_descriptor->bInterfaceClass    = *(uint8_t  *) (buf + 5);
+  if_descriptor->bInterfaceSubClass = *(uint8_t  *) (buf + 6);
+  if_descriptor->bInterfaceProtocol = *(uint8_t  *) (buf + 7);
+  if_descriptor->iInterface         = *(uint8_t  *) (buf + 8);
+}
+
+/**
+  * @brief  USBH_ParseEPDesc 
+  *         This function Parses the endpoint descriptor
+  * @param  ep_descriptor: Endpoint descriptor destination address
+  * @param  buf: Buffer where the parsed descriptor stored
+  * @retval None
+  */
+static void  USBH_ParseEPDesc (USBH_EpDescTypeDef  *ep_descriptor, 
+                               uint8_t *buf)
+{
+  
+  ep_descriptor->bLength          = *(uint8_t  *) (buf + 0);
+  ep_descriptor->bDescriptorType  = *(uint8_t  *) (buf + 1);
+  ep_descriptor->bEndpointAddress = *(uint8_t  *) (buf + 2);
+  ep_descriptor->bmAttributes     = *(uint8_t  *) (buf + 3);
+  ep_descriptor->wMaxPacketSize   = LE16 (buf + 4);
+  ep_descriptor->bInterval        = *(uint8_t  *) (buf + 6);
+}
+
+/**
+  * @brief  USBH_ParseStringDesc 
+  *         This function Parses the string descriptor
+  * @param  psrc: Source pointer containing the descriptor data
+  * @param  pdest: Destination address pointer
+  * @param  length: Length of the descriptor
+  * @retval None
+  */
+static void USBH_ParseStringDesc (uint8_t* psrc, 
+                                  uint8_t* pdest, 
+                                  uint16_t length)
+{
+  uint16_t strlength;
+  uint16_t idx;
+  
+  /* The UNICODE string descriptor is not NULL-terminated. The string length is
+  computed by substracting two from the value of the first byte of the descriptor.
+  */
+  
+  /* Check which is lower size, the Size of string or the length of bytes read 
+  from the device */
+  
+  if ( psrc[1] == USB_DESC_TYPE_STRING)
+  { /* Make sure the Descriptor is String Type */
+    
+    /* psrc[0] contains Size of Descriptor, subtract 2 to get the length of string */      
+    strlength = ( ( (psrc[0]-2) <= length) ? (psrc[0]-2) :length); 
+    psrc += 2; /* Adjust the offset ignoring the String Len and Descriptor type */
+    
+    for (idx = 0; idx < strlength; idx+=2 )
+    {/* Copy Only the string and ignore the UNICODE ID, hence add the src */
+      *pdest =  psrc[idx];
+      pdest++;
+    }  
+    *pdest = 0; /* mark end of string */  
+  }
+}
+
+/**
+  * @brief  USBH_GetNextDesc 
+  *         This function return the next descriptor header
+  * @param  buf: Buffer where the cfg descriptor is available
+  * @param  ptr: data popinter inside the cfg descriptor
+  * @retval next header
+  */
+USBH_DescHeader_t  *USBH_GetNextDesc (uint8_t   *pbuf, uint16_t  *ptr)
+{
+  USBH_DescHeader_t  *pnext;
+ 
+  *ptr += ((USBH_DescHeader_t *)pbuf)->bLength;  
+  pnext = (USBH_DescHeader_t *)((uint8_t *)pbuf + \
+         ((USBH_DescHeader_t *)pbuf)->bLength);
+ 
+  return(pnext);
+}
+
+
+/**
+  * @brief  USBH_CtlReq
+  *         USBH_CtlReq sends a control request and provide the status after 
+  *            completion of the request
+  * @param  phost: Host Handle
+  * @param  req: Setup Request Structure
+  * @param  buff: data buffer address to store the response
+  * @param  length: length of the response
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_CtlReq     (USBH_HandleTypeDef *phost, 
+                             uint8_t             *buff,
+                             uint16_t            length)
+{
+  USBH_StatusTypeDef status;
+  status = USBH_BUSY;
+  
+  switch (phost->RequestState)
+  {
+  case CMD_SEND:
+    /* Start a SETUP transfer */
+    phost->Control.buff = buff; 
+    phost->Control.length = length;
+    phost->Control.state = CTRL_SETUP;  
+    phost->RequestState = CMD_WAIT;
+    status = USBH_BUSY;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    break;
+    
+  case CMD_WAIT:
+    status = USBH_HandleControl(phost);
+     if (status == USBH_OK) 
+    {
+      /* Commands successfully sent and Response Received  */       
+      phost->RequestState = CMD_SEND;
+      phost->Control.state =CTRL_IDLE;  
+      status = USBH_OK;      
+    }
+    else if  (status == USBH_FAIL)
+    {
+      /* Failure Mode */
+      phost->RequestState = CMD_SEND;
+      status = USBH_FAIL;
+    }   
+    break;
+    
+  default:
+    break; 
+  }
+  return status;
+}
+
+/**
+  * @brief  USBH_HandleControl
+  *         Handles the USB control transfer state machine
+  * @param  phost: Host Handle
+  * @retval USBH Status
+  */
+static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost)
+{
+  uint8_t direction;  
+  USBH_StatusTypeDef status = USBH_BUSY;
+  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
+  
+  switch (phost->Control.state)
+  {
+  case CTRL_SETUP:
+    /* send a SETUP packet */
+    USBH_CtlSendSetup     (phost, 
+	                   (uint8_t *)phost->Control.setup.d8 , 
+	                   phost->Control.pipe_out); 
+    
+    phost->Control.state = CTRL_SETUP_WAIT; 
+    break; 
+    
+  case CTRL_SETUP_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out); 
+    /* case SETUP packet sent successfully */
+    if(URB_Status == USBH_URB_DONE)
+    { 
+      direction = (phost->Control.setup.b.bmRequestType & USB_REQ_DIR_MASK);
+      
+      /* check if there is a data stage */
+      if (phost->Control.setup.b.wLength.w != 0 )
+      {        
+        if (direction == USB_D2H)
+        {
+          /* Data Direction is IN */
+          phost->Control.state = CTRL_DATA_IN;
+        }
+        else
+        {
+          /* Data Direction is OUT */
+          phost->Control.state = CTRL_DATA_OUT;
+        } 
+      }
+      /* No DATA stage */
+      else
+      {
+        /* If there is No Data Transfer Stage */
+        if (direction == USB_D2H)
+        {
+          /* Data Direction is IN */
+          phost->Control.state = CTRL_STATUS_OUT;
+        }
+        else
+        {
+          /* Data Direction is OUT */
+          phost->Control.state = CTRL_STATUS_IN;
+        } 
+      }          
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif
+    }
+    else if(URB_Status == USBH_URB_ERROR)
+    {
+      phost->Control.state = CTRL_ERROR;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }    
+    break;
+    
+  case CTRL_DATA_IN:  
+    /* Issue an IN token */ 
+     phost->Control.timer = phost->Timer;
+    USBH_CtlReceiveData(phost,
+                        phost->Control.buff, 
+                        phost->Control.length,
+                        phost->Control.pipe_in);
+ 
+    phost->Control.state = CTRL_DATA_IN_WAIT;
+    break;    
+    
+  case CTRL_DATA_IN_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in); 
+    
+    /* check is DATA packet transfered successfully */
+    if  (URB_Status == USBH_URB_DONE)
+    { 
+      phost->Control.state = CTRL_STATUS_OUT;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+   
+    /* manage error cases*/
+    if  (URB_Status == USBH_URB_STALL) 
+    { 
+      /* In stall case, return to previous machine state*/
+      status = USBH_NOT_SUPPORTED;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }   
+    else if (URB_Status == USBH_URB_ERROR)
+    {
+      /* Device error */
+      phost->Control.state = CTRL_ERROR;  
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+    break;
+    
+  case CTRL_DATA_OUT:
+    
+    USBH_CtlSendData (phost,
+                      phost->Control.buff, 
+                      phost->Control.length , 
+                      phost->Control.pipe_out,
+                      1);
+     phost->Control.timer = phost->Timer;
+    phost->Control.state = CTRL_DATA_OUT_WAIT;
+    break;
+    
+  case CTRL_DATA_OUT_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out);     
+    
+    if  (URB_Status == USBH_URB_DONE)
+    { /* If the Setup Pkt is sent successful, then change the state */
+      phost->Control.state = CTRL_STATUS_IN;
+#if (USBH_USE_OS == 1)
+      osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+    
+    /* handle error cases */
+    else if  (URB_Status == USBH_URB_STALL) 
+    { 
+      /* In stall case, return to previous machine state*/
+      phost->Control.state = CTRL_STALLED; 
+      status = USBH_NOT_SUPPORTED;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    } 
+    else if  (URB_Status == USBH_URB_NOTREADY)
+    { 
+      /* Nack received from device */
+      phost->Control.state = CTRL_DATA_OUT;
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }    
+    else if (URB_Status == USBH_URB_ERROR)
+    {
+      /* device error */
+      phost->Control.state = CTRL_ERROR;  
+      status = USBH_FAIL;    
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    } 
+    break;
+    
+    
+  case CTRL_STATUS_IN:
+    /* Send 0 bytes out packet */
+    USBH_CtlReceiveData (phost,
+                         0,
+                         0,
+                         phost->Control.pipe_in);
+    phost->Control.timer = phost->Timer;
+    phost->Control.state = CTRL_STATUS_IN_WAIT;
+    
+    break;
+    
+  case CTRL_STATUS_IN_WAIT:
+    
+    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in); 
+    
+    if  ( URB_Status == USBH_URB_DONE)
+    { /* Control transfers completed, Exit the State Machine */
+      phost->Control.state = CTRL_COMPLETE;
+      status = USBH_OK;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+    
+    else if (URB_Status == USBH_URB_ERROR)
+    {
+      phost->Control.state = CTRL_ERROR;
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+     else if(URB_Status == USBH_URB_STALL)
+    {
+      /* Control transfers completed, Exit the State Machine */
+      status = USBH_NOT_SUPPORTED;
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+    break;
+    
+  case CTRL_STATUS_OUT:
+    USBH_CtlSendData (phost,
+                      0,
+                      0,
+                      phost->Control.pipe_out,
+                      1);
+     phost->Control.timer = phost->Timer;
+    phost->Control.state = CTRL_STATUS_OUT_WAIT;
+    break;
+    
+  case CTRL_STATUS_OUT_WAIT: 
+    
+    URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out);  
+    if  (URB_Status == USBH_URB_DONE)
+    { 
+      status = USBH_OK;      
+      phost->Control.state = CTRL_COMPLETE; 
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+    else if  (URB_Status == USBH_URB_NOTREADY)
+    { 
+      phost->Control.state = CTRL_STATUS_OUT;
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }      
+    else if (URB_Status == USBH_URB_ERROR)
+    {
+      phost->Control.state = CTRL_ERROR; 
+      
+#if (USBH_USE_OS == 1)
+    osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
+#endif      
+    }
+    break;
+    
+  case CTRL_ERROR:
+    /* 
+    After a halt condition is encountered or an error is detected by the 
+    host, a control endpoint is allowed to recover by accepting the next Setup 
+    PID; i.e., recovery actions via some other pipe are not required for control
+    endpoints. For the Default Control Pipe, a device reset will ultimately be 
+    required to clear the halt or error condition if the next Setup PID is not 
+    accepted.
+    */
+    if (++ phost->Control.errorcount <= USBH_MAX_ERROR_COUNT)
+    {
+      /* try to recover control */
+      USBH_LL_Stop(phost);
+         
+      /* Do the transmission again, starting from SETUP Packet */
+      phost->Control.state = CTRL_SETUP; 
+      phost->RequestState = CMD_SEND;
+    }
+    else
+    {
+      phost->Control.errorcount = 0;
+      USBH_ErrLog("Control error");
+      status = USBH_FAIL;
+      
+    }
+    break;
+    
+  default:
+    break;
+  }
+  return status;
+}
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Core/Src/usbh_ioreq.c b/micropython/ports/stm32/usbhost/Core/Src/usbh_ioreq.c
index 280020355d44635a9d12379d47f733f265519604..8c869eadb6a1a9ec3c1aa52c954deeca85085809 100644
--- a/micropython/ports/stm32/usbhost/Core/Src/usbh_ioreq.c
+++ b/micropython/ports/stm32/usbhost/Core/Src/usbh_ioreq.c
@@ -1,358 +1,358 @@
-/** 
-  ******************************************************************************
-  * @file    usbh_ioreq.c 
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file handles the issuing of the USB transactions
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-/* Includes ------------------------------------------------------------------*/
-
-#include "usbh_ioreq.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_IOREQ 
-  * @brief This file handles the standard protocol processing (USB v2.0)
-  * @{
-  */
-
-
-/** @defgroup USBH_IOREQ_Private_Defines
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
- 
-
-/** @defgroup USBH_IOREQ_Private_TypesDefinitions
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-
-/** @defgroup USBH_IOREQ_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_IOREQ_Private_Variables
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-/** @defgroup USBH_IOREQ_Private_FunctionPrototypes
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_IOREQ_Private_Functions
-  * @{
-  */ 
-
-
-
-/**
-  * @brief  USBH_CtlSendSetup
-  *         Sends the Setup Packet to the Device
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer from which the Data will be send to Device
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint8_t pipe_num)
-{
-
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          0,                    /* Direction : OUT  */
-                          USBH_EP_CONTROL,      /* EP type          */
-                          USBH_PID_SETUP,       /* Type setup       */
-                          buff,                 /* data buffer      */
-                          USBH_SETUP_PKT_SIZE,  /* data length      */ 
-                          0);
-  return USBH_OK;  
-}
-
-
-/**
-  * @brief  USBH_CtlSendData
-  *         Sends a data Packet to the Device
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer from which the Data will be sent to Device
-  * @param  length: Length of the data to be sent
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t pipe_num,
-                                uint8_t do_ping )
-{
-  if(phost->device.speed != USBH_SPEED_HIGH)
-  {
-    do_ping = 0;
-  }
-  
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          0,                    /* Direction : OUT  */
-                          USBH_EP_CONTROL,      /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */ 
-                          do_ping);             /* do ping (HS Only)*/
-  
-  return USBH_OK;
-}
-
-
-/**
-  * @brief  USBH_CtlReceiveData
-  *         Receives the Device Response to the Setup Packet
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer in which the response needs to be copied
-  * @param  length: Length of the data to be received
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status. 
-  */
-USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t* buff, 
-                                uint16_t length,
-                                uint8_t pipe_num)
-{
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          1,                    /* Direction : IN   */
-                          USBH_EP_CONTROL,      /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */ 
-                          0);
-  return USBH_OK;
-  
-}
-
-
-/**
-  * @brief  USBH_BulkSendData
-  *         Sends the Bulk Packet to the device
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer from which the Data will be sent to Device
-  * @param  length: Length of the data to be sent
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t pipe_num,
-                                uint8_t do_ping )
-{ 
-  if(phost->device.speed != USBH_SPEED_HIGH)
-  {
-    do_ping = 0;
-  }
-  
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          0,                    /* Direction : IN   */
-                          USBH_EP_BULK,         /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */  
-                          do_ping);             /* do ping (HS Only)*/
-  return USBH_OK;
-}
-
-
-/**
-  * @brief  USBH_BulkReceiveData
-  *         Receives IN bulk packet from device
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer in which the received data packet to be copied
-  * @param  length: Length of the data to be received
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status. 
-  */
-USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint16_t length,
-                                uint8_t pipe_num)
-{
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          1,                    /* Direction : IN   */
-                          USBH_EP_BULK,         /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */  
-                          0);
-  return USBH_OK;
-}
-
-
-/**
-  * @brief  USBH_InterruptReceiveData
-  *         Receives the Device Response to the Interrupt IN token
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer in which the response needs to be copied
-  * @param  length: Length of the data to be received
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status. 
-  */
-USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint8_t length,
-                                uint8_t pipe_num)
-{
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          1,                    /* Direction : IN   */
-                          USBH_EP_INTERRUPT,    /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */  
-                          0); 
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_InterruptSendData
-  *         Sends the data on Interrupt OUT Endpoint
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer from where the data needs to be copied
-  * @param  length: Length of the data to be sent
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status. 
-  */
-USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint8_t length,
-                                uint8_t pipe_num)
-{
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          0,                    /* Direction : OUT   */
-                          USBH_EP_INTERRUPT,    /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */  
-                          0);  
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_IsocReceiveData
-  *         Receives the Device Response to the Isochronous IN token
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer in which the response needs to be copied
-  * @param  length: Length of the data to be received
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status. 
-  */
-USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint32_t length,
-                                uint8_t pipe_num)
-{    
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          1,                    /* Direction : IN   */
-                          USBH_EP_ISO,          /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */
-                          0);
-
-  
-  return USBH_OK;
-}
-
-/**
-  * @brief  USBH_IsocSendData
-  *         Sends the data on Isochronous OUT Endpoint
-  * @param  phost: Host Handle
-  * @param  buff: Buffer pointer from where the data needs to be copied
-  * @param  length: Length of the data to be sent
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status. 
-  */
-USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, 
-                                uint8_t *buff, 
-                                uint32_t length,
-                                uint8_t pipe_num)
-{
-  USBH_LL_SubmitURB (phost,         /* Driver handle    */
-                          pipe_num,             /* Pipe index       */
-                          0,                    /* Direction : OUT   */
-                          USBH_EP_ISO,          /* EP type          */                          
-                          USBH_PID_DATA,        /* Type Data        */
-                          buff,                 /* data buffer      */
-                          length,               /* data length      */ 
-                          0);
-  
-  return USBH_OK;
-}
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
+/** 
+  ******************************************************************************
+  * @file    usbh_ioreq.c 
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file handles the issuing of the USB transactions
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+/* Includes ------------------------------------------------------------------*/
+
+#include "usbh_ioreq.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_IOREQ 
+  * @brief This file handles the standard protocol processing (USB v2.0)
+  * @{
+  */
+
+
+/** @defgroup USBH_IOREQ_Private_Defines
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+ 
+
+/** @defgroup USBH_IOREQ_Private_TypesDefinitions
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+
+/** @defgroup USBH_IOREQ_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_IOREQ_Private_Variables
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+/** @defgroup USBH_IOREQ_Private_FunctionPrototypes
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_IOREQ_Private_Functions
+  * @{
+  */ 
+
+
+
+/**
+  * @brief  USBH_CtlSendSetup
+  *         Sends the Setup Packet to the Device
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer from which the Data will be send to Device
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint8_t pipe_num)
+{
+
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          0,                    /* Direction : OUT  */
+                          USBH_EP_CONTROL,      /* EP type          */
+                          USBH_PID_SETUP,       /* Type setup       */
+                          buff,                 /* data buffer      */
+                          USBH_SETUP_PKT_SIZE,  /* data length      */ 
+                          0);
+  return USBH_OK;  
+}
+
+
+/**
+  * @brief  USBH_CtlSendData
+  *         Sends a data Packet to the Device
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer from which the Data will be sent to Device
+  * @param  length: Length of the data to be sent
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t pipe_num,
+                                uint8_t do_ping )
+{
+  if(phost->device.speed != USBH_SPEED_HIGH)
+  {
+    do_ping = 0;
+  }
+  
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          0,                    /* Direction : OUT  */
+                          USBH_EP_CONTROL,      /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */ 
+                          do_ping);             /* do ping (HS Only)*/
+  
+  return USBH_OK;
+}
+
+
+/**
+  * @brief  USBH_CtlReceiveData
+  *         Receives the Device Response to the Setup Packet
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer in which the response needs to be copied
+  * @param  length: Length of the data to be received
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status. 
+  */
+USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t* buff, 
+                                uint16_t length,
+                                uint8_t pipe_num)
+{
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          1,                    /* Direction : IN   */
+                          USBH_EP_CONTROL,      /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */ 
+                          0);
+  return USBH_OK;
+  
+}
+
+
+/**
+  * @brief  USBH_BulkSendData
+  *         Sends the Bulk Packet to the device
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer from which the Data will be sent to Device
+  * @param  length: Length of the data to be sent
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t pipe_num,
+                                uint8_t do_ping )
+{ 
+  if(phost->device.speed != USBH_SPEED_HIGH)
+  {
+    do_ping = 0;
+  }
+  
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          0,                    /* Direction : IN   */
+                          USBH_EP_BULK,         /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */  
+                          do_ping);             /* do ping (HS Only)*/
+  return USBH_OK;
+}
+
+
+/**
+  * @brief  USBH_BulkReceiveData
+  *         Receives IN bulk packet from device
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer in which the received data packet to be copied
+  * @param  length: Length of the data to be received
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status. 
+  */
+USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint16_t length,
+                                uint8_t pipe_num)
+{
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          1,                    /* Direction : IN   */
+                          USBH_EP_BULK,         /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */  
+                          0);
+  return USBH_OK;
+}
+
+
+/**
+  * @brief  USBH_InterruptReceiveData
+  *         Receives the Device Response to the Interrupt IN token
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer in which the response needs to be copied
+  * @param  length: Length of the data to be received
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status. 
+  */
+USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint8_t length,
+                                uint8_t pipe_num)
+{
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          1,                    /* Direction : IN   */
+                          USBH_EP_INTERRUPT,    /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */  
+                          0); 
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_InterruptSendData
+  *         Sends the data on Interrupt OUT Endpoint
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer from where the data needs to be copied
+  * @param  length: Length of the data to be sent
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status. 
+  */
+USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint8_t length,
+                                uint8_t pipe_num)
+{
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          0,                    /* Direction : OUT   */
+                          USBH_EP_INTERRUPT,    /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */  
+                          0);  
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_IsocReceiveData
+  *         Receives the Device Response to the Isochronous IN token
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer in which the response needs to be copied
+  * @param  length: Length of the data to be received
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status. 
+  */
+USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint32_t length,
+                                uint8_t pipe_num)
+{    
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          1,                    /* Direction : IN   */
+                          USBH_EP_ISO,          /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */
+                          0);
+
+  
+  return USBH_OK;
+}
+
+/**
+  * @brief  USBH_IsocSendData
+  *         Sends the data on Isochronous OUT Endpoint
+  * @param  phost: Host Handle
+  * @param  buff: Buffer pointer from where the data needs to be copied
+  * @param  length: Length of the data to be sent
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status. 
+  */
+USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, 
+                                uint8_t *buff, 
+                                uint32_t length,
+                                uint8_t pipe_num)
+{
+  USBH_LL_SubmitURB (phost,         /* Driver handle    */
+                          pipe_num,             /* Pipe index       */
+                          0,                    /* Direction : OUT   */
+                          USBH_EP_ISO,          /* EP type          */                          
+                          USBH_PID_DATA,        /* Type Data        */
+                          buff,                 /* data buffer      */
+                          length,               /* data length      */ 
+                          0);
+  
+  return USBH_OK;
+}
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
diff --git a/micropython/ports/stm32/usbhost/Core/Src/usbh_pipes.c b/micropython/ports/stm32/usbhost/Core/Src/usbh_pipes.c
index 9dcc4c517b0f2d6740305888c074fa31a6dbd99d..de20a0b3fd821cd54830997de6f822e386265f13 100644
--- a/micropython/ports/stm32/usbhost/Core/Src/usbh_pipes.c
+++ b/micropython/ports/stm32/usbhost/Core/Src/usbh_pipes.c
@@ -1,204 +1,204 @@
-/**
-  ******************************************************************************
-  * @file    usbh_pipes.c
-  * @author  MCD Application Team
-  * @version V3.0.0
-  * @date    18-February-2014
-  * @brief   This file implements functions for opening and closing Pipes
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_pipes.h"
-
-/** @addtogroup USBH_LIB
-  * @{
-  */
-
-/** @addtogroup USBH_LIB_CORE
-* @{
-*/
-  
-/** @defgroup USBH_PIPES
-  * @brief This file includes opening and closing Pipes
-  * @{
-  */ 
-
-/** @defgroup USBH_PIPES_Private_Defines
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-/** @defgroup USBH_PIPES_Private_TypesDefinitions
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_PIPES_Private_Macros
-  * @{
-  */ 
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_PIPES_Private_Variables
-  * @{
-  */ 
-
-/**
-  * @}
-  */ 
-
-
-/** @defgroup USBH_PIPES_Private_Functions
-  * @{
-  */ 
-static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost);
-
-
-/**
-  * @brief  USBH_Open_Pipe
-  *         Open a  pipe
-  * @param  phost: Host Handle
-  * @param  pipe_num: Pipe Number
-  * @param  dev_address: USB Device address allocated to attached device
-  * @param  speed : USB device speed (Full/Low)
-  * @param  ep_type: end point type (Bulk/int/ctl)
-  * @param  mps: max pkt size
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_OpenPipe  (USBH_HandleTypeDef *phost,
-                            uint8_t pipe_num,
-                            uint8_t epnum,
-                            uint8_t dev_address,
-                            uint8_t speed,
-                            uint8_t ep_type,
-                            uint16_t mps)
-{
-
-  USBH_LL_OpenPipe(phost,
-                        pipe_num,
-                        epnum,
-                        dev_address,
-                        speed,
-                        ep_type,
-                        mps);
-  
-  return USBH_OK; 
-
-}
-
-/**
-  * @brief  USBH_ClosePipe
-  *         Close a  pipe
-  * @param  phost: Host Handle
-  * @param  pipe_num: Pipe Number
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_ClosePipe  (USBH_HandleTypeDef *phost,
-                            uint8_t pipe_num)
-{
-
-  USBH_LL_ClosePipe(phost, pipe_num);
-  
-  return USBH_OK; 
-
-}
-
-/**
-  * @brief  USBH_Alloc_Pipe
-  *         Allocate a new Pipe
-  * @param  phost: Host Handle
-  * @param  ep_addr: End point for which the Pipe to be allocated
-  * @retval Pipe number
-  */
-uint8_t USBH_AllocPipe  (USBH_HandleTypeDef *phost, uint8_t ep_addr)
-{
-  uint16_t pipe;
-  
-  pipe =  USBH_GetFreePipe(phost);
-
-  if (pipe != 0xFFFF)
-  {
-	phost->Pipes[pipe] = 0x8000 | ep_addr;
-  }
-  return pipe;
-}
-
-/**
-  * @brief  USBH_Free_Pipe
-  *         Free the USB Pipe
-  * @param  phost: Host Handle
-  * @param  idx: Pipe number to be freed 
-  * @retval USBH Status
-  */
-USBH_StatusTypeDef USBH_FreePipe  (USBH_HandleTypeDef *phost, uint8_t idx)
-{
-   if(idx < 11)
-   {
-	 phost->Pipes[idx] &= 0x7FFF;
-   }
-   return USBH_OK;
-}
-
-/**
-  * @brief  USBH_GetFreePipe
-  * @param  phost: Host Handle
-  *         Get a free Pipe number for allocation to a device endpoint
-  * @retval idx: Free Pipe number
-  */
-static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost)
-{
-  uint8_t idx = 0;
-  
-  for (idx = 0 ; idx < 11 ; idx++)
-  {
-	if ((phost->Pipes[idx] & 0x8000) == 0)
-	{
-	   return idx;
-	} 
-  }
-  return 0xFFFF;
-}
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/ 
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/ 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
+/**
+  ******************************************************************************
+  * @file    usbh_pipes.c
+  * @author  MCD Application Team
+  * @version V3.0.0
+  * @date    18-February-2014
+  * @brief   This file implements functions for opening and closing Pipes
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software 
+  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */ 
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbh_pipes.h"
+
+/** @addtogroup USBH_LIB
+  * @{
+  */
+
+/** @addtogroup USBH_LIB_CORE
+* @{
+*/
+  
+/** @defgroup USBH_PIPES
+  * @brief This file includes opening and closing Pipes
+  * @{
+  */ 
+
+/** @defgroup USBH_PIPES_Private_Defines
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+/** @defgroup USBH_PIPES_Private_TypesDefinitions
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_PIPES_Private_Macros
+  * @{
+  */ 
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_PIPES_Private_Variables
+  * @{
+  */ 
+
+/**
+  * @}
+  */ 
+
+
+/** @defgroup USBH_PIPES_Private_Functions
+  * @{
+  */ 
+static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost);
+
+
+/**
+  * @brief  USBH_Open_Pipe
+  *         Open a  pipe
+  * @param  phost: Host Handle
+  * @param  pipe_num: Pipe Number
+  * @param  dev_address: USB Device address allocated to attached device
+  * @param  speed : USB device speed (Full/Low)
+  * @param  ep_type: end point type (Bulk/int/ctl)
+  * @param  mps: max pkt size
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_OpenPipe  (USBH_HandleTypeDef *phost,
+                            uint8_t pipe_num,
+                            uint8_t epnum,
+                            uint8_t dev_address,
+                            uint8_t speed,
+                            uint8_t ep_type,
+                            uint16_t mps)
+{
+
+  USBH_LL_OpenPipe(phost,
+                        pipe_num,
+                        epnum,
+                        dev_address,
+                        speed,
+                        ep_type,
+                        mps);
+  
+  return USBH_OK; 
+
+}
+
+/**
+  * @brief  USBH_ClosePipe
+  *         Close a  pipe
+  * @param  phost: Host Handle
+  * @param  pipe_num: Pipe Number
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_ClosePipe  (USBH_HandleTypeDef *phost,
+                            uint8_t pipe_num)
+{
+
+  USBH_LL_ClosePipe(phost, pipe_num);
+  
+  return USBH_OK; 
+
+}
+
+/**
+  * @brief  USBH_Alloc_Pipe
+  *         Allocate a new Pipe
+  * @param  phost: Host Handle
+  * @param  ep_addr: End point for which the Pipe to be allocated
+  * @retval Pipe number
+  */
+uint8_t USBH_AllocPipe  (USBH_HandleTypeDef *phost, uint8_t ep_addr)
+{
+  uint16_t pipe;
+  
+  pipe =  USBH_GetFreePipe(phost);
+
+  if (pipe != 0xFFFF)
+  {
+	phost->Pipes[pipe] = 0x8000 | ep_addr;
+  }
+  return pipe;
+}
+
+/**
+  * @brief  USBH_Free_Pipe
+  *         Free the USB Pipe
+  * @param  phost: Host Handle
+  * @param  idx: Pipe number to be freed 
+  * @retval USBH Status
+  */
+USBH_StatusTypeDef USBH_FreePipe  (USBH_HandleTypeDef *phost, uint8_t idx)
+{
+   if(idx < 11)
+   {
+	 phost->Pipes[idx] &= 0x7FFF;
+   }
+   return USBH_OK;
+}
+
+/**
+  * @brief  USBH_GetFreePipe
+  * @param  phost: Host Handle
+  *         Get a free Pipe number for allocation to a device endpoint
+  * @retval idx: Free Pipe number
+  */
+static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost)
+{
+  uint8_t idx = 0;
+  
+  for (idx = 0 ; idx < 11 ; idx++)
+  {
+	if ((phost->Pipes[idx] & 0x8000) == 0)
+	{
+	   return idx;
+	} 
+  }
+  return 0xFFFF;
+}
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/ 
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/micropython/tests/basics/string_crlf_conversion.py b/micropython/tests/basics/string_crlf_conversion.py
index f91121099211276b9649ccf601f7dc20aa82b0ce..f97b6a4f37328005713b233267ea54eb0f2ef45f 100644
--- a/micropython/tests/basics/string_crlf_conversion.py
+++ b/micropython/tests/basics/string_crlf_conversion.py
@@ -1,4 +1,4 @@
-# this file has CRLF line endings to test lexer's conversion of them to LF
-# in triple quoted strings
-print(repr("""abc
-def"""))
+# this file has CRLF line endings to test lexer's conversion of them to LF
+# in triple quoted strings
+print(repr("""abc
+def"""))