This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp 430 usb problem

Other Parts Discussed in Thread: MSP430F5638

Hi ,

I am trying to implement USB for MSP430f5638 . I got the code from TI, but while running this code I am facing some problems.

1.values in  tInputEndPointDescriptorBlock  not updating .after running the USB_reset function its values shows as all 0.

2. if I run the code I can see unknown device in my system for a moment, then its disappearing .then I can see that the register values in USBCNF become 0.

how can i solve this problems..?????

Thank you.

  • I'm using MSP430USBDevelopersPackage_4_20_00 and SD card reader example in mass storage class.
  • Hello Tinu,

    I am assuming that you are running the M2_SDCardReader example that came with version 4_20_00 of the USB Developers Package.

    Are you running the exact example that came with the USB Developers Package without any code changes or descriptor.c/h, UsbIsr.c file changes?  If you have changed the original code, can you paste it here?  If you changed the descriptor files, did you use the Descriptor Tool that came with the 4_20_00 Developers Package?

     

    Regards,

    Arthi Bhat

  • Hi Arthi,

    Thanks for the reply. I'm using the exact code mentioned above. But i made some changes to the assignment of port pins according to my requirement (ie.pins for SPI and SD card). i used the descriptor tool and hereby i attach the descriptor files.

    // USBISR 

    #include <device.h>
    // Basic Type declarations
    #include <defMSP430USB.h>
    #include "descriptors.h"
    #include <usb.h> //USB-specific Data Structures
    #include <UsbIsr.h>
    #include <string.h>
    #include <UsbMscStateMachine.h>
    #include <UsbMscScsi.h>
    #include <UsbMsc.h>

    /*----------------------------------------------------------------------------+
    | External Variables |
    +----------------------------------------------------------------------------*/
    extern uint8_t bFunctionSuspended;
    extern __no_init tEDB0 __data16 tEndPoint0DescriptorBlock;
    extern __no_init tEDB __data16 tInputEndPointDescriptorBlock[];
    extern __no_init tEDB __data16 tOutputEndPointDescriptorBlock[];
    extern volatile uint8_t bHostAsksUSBData;
    extern volatile uint8_t bTransferInProgress;
    extern volatile uint8_t bSecondUartTxDataCounter[];
    extern volatile uint8_t* pbSecondUartTxData;
    extern uint8_t bStatusAction;
    extern uint16_t wUsbEventMask;
    int16_t CdcToHostFromBuffer(uint8_t);
    int16_t CdcToBufferFromHost(uint8_t);
    int16_t CdcIsReceiveInProgress(uint8_t);
    int16_t HidToHostFromBuffer(uint8_t);
    int16_t HidToBufferFromHost(uint8_t);
    int16_t HidIsReceiveInProgress(uint8_t);
    extern uint16_t wUsbHidEventMask;
    int16_t PHDCToHostFromBuffer(uint8_t);
    int16_t PHDCToBufferFromHost(uint8_t);
    int16_t PHDCIsReceiveInProgress(uint8_t);
    uint16_t USB_determineFreq(void);
    /*----------------------------------------------------------------------------+
    | General Subroutines |
    +----------------------------------------------------------------------------*/
    #if defined(__TI_COMPILER_VERSION__) || (__IAR_SYSTEMS_ICC__)
    //#pragma vector=USB_UBM_VECTOR
    __interrupt void iUsbInterruptHandler(void)
    #elif defined(__GNUC__) && (__MSP430__)
    void __attribute__ ((interrupt(USB_UBM_VECTOR))) iUsbInterruptHandler(void)
    #endif
    {
    uint8_t bWakeUp = FALSE;
    //Check if the setup interrupt is pending.
    //We need to check it before other interrupts,
    //to work around that the Setup Int has lower priority then Input Endpoint 0
    if (USBIFG & SETUPIFG)
    {
    bWakeUp = SetupPacketInterruptHandler();
    #ifdef USB10_WORKAROUND
    tEndPoint0DescriptorBlock.bIEPCNFG &= ~EPCNF_UBME; // Clear ME to gate off SETUPIFG clear event
    tEndPoint0DescriptorBlock.bOEPCNFG &= ~EPCNF_UBME; // Clear ME to gate off SETUPIFG clear event
    #endif
    USBIFG &= ~SETUPIFG; // clear the interrupt bit
    #ifdef USB10_WORKAROUND
    tEndPoint0DescriptorBlock.bIEPCNFG |= EPCNF_UBME; // Set ME to continue with normal operation
    tEndPoint0DescriptorBlock.bOEPCNFG |= EPCNF_UBME; // Set ME to continue with normal operation
    #endif
    }
    switch (__even_in_range(USBVECINT & 0x3f, USBVECINT_OUTPUT_ENDPOINT7))
    {
    case USBVECINT_NONE:
    break;
    case USBVECINT_PWR_DROP:
    __no_operation();
    break;
    case USBVECINT_PLL_LOCK:
    break;
    case USBVECINT_PLL_SIGNAL:
    break;
    case USBVECINT_PLL_RANGE:
    if (wUsbEventMask & kUSB_clockFaultEvent)
    {
    bWakeUp = USB_handleClockEvent();
    }
    break;
    case USBVECINT_PWR_VBUSOn:
    PWRVBUSonHandler();
    if (wUsbEventMask & kUSB_VbusOnEvent)
    {
    bWakeUp = USB_handleVbusOnEvent();
    }
    break;
    case USBVECINT_PWR_VBUSOff:
    PWRVBUSoffHandler();
    if (wUsbEventMask & kUSB_VbusOffEvent)
    {
    bWakeUp = USB_handleVbusOffEvent();
    }
    break;
    case USBVECINT_USB_TIMESTAMP:
    break;
    case USBVECINT_INPUT_ENDPOINT0:
    IEP0InterruptHandler();
    break;
    case USBVECINT_OUTPUT_ENDPOINT0:
    OEP0InterruptHandler();
    break;
    case USBVECINT_RSTR:
    USB_reset();
    if (wUsbEventMask & kUSB_UsbResetEvent)
    {
    bWakeUp = USB_handleResetEvent();
    }
    break;
    case USBVECINT_SUSR:
    USB_suspend();
    if (wUsbEventMask & kUSB_UsbSuspendEvent)
    {
    bWakeUp = USB_handleSuspendEvent();
    }
    break;
    case USBVECINT_RESR:
    USB_resume();
    if (wUsbEventMask & kUSB_UsbResumeEvent)
    {
    bWakeUp = USB_handleResumeEvent();
    }
    //-- after resume we will wake up! Independ what event handler says.
    bWakeUp = TRUE;
    break;
    case USBVECINT_SETUP_PACKET_RECEIVED:
    // NAK both IEP and OEP enpoints
    tEndPoint0DescriptorBlock.bIEPBCNT = EPBCNT_NAK;
    tEndPoint0DescriptorBlock.bOEPBCNT = EPBCNT_NAK;
    SetupPacketInterruptHandler();
    break;
    case USBVECINT_STPOW_PACKET_RECEIVED:
    break;
    case USBVECINT_INPUT_ENDPOINT1:
    bWakeUp = MSCToHostFromBuffer();
    break;
    case USBVECINT_INPUT_ENDPOINT2:
    break;
    case USBVECINT_INPUT_ENDPOINT3:
    break;
    case USBVECINT_INPUT_ENDPOINT4:
    break;
    case USBVECINT_INPUT_ENDPOINT5:
    break;
    case USBVECINT_INPUT_ENDPOINT6:
    break;
    case USBVECINT_INPUT_ENDPOINT7:
    break;
    case USBVECINT_OUTPUT_ENDPOINT1:
    bWakeUp = MSCFromHostToBuffer();
    break;
    case USBVECINT_OUTPUT_ENDPOINT2:
    break;
    case USBVECINT_OUTPUT_ENDPOINT3:
    break;
    case USBVECINT_OUTPUT_ENDPOINT4:
    break;
    case USBVECINT_OUTPUT_ENDPOINT5:
    break;
    case USBVECINT_OUTPUT_ENDPOINT6:
    break;
    case USBVECINT_OUTPUT_ENDPOINT7:
    break;
    default:
    break;
    }
    if (bWakeUp)
    {
    __bic_SR_register_on_exit(LPM3_bits); // Exit LPM0-3
    __no_operation(); // Required for debugger
    }
    }

    /*----------------------------------------------------------------------------+
    | Interrupt Sub-routines |
    +----------------------------------------------------------------------------*/
    uint8_t SetupPacketInterruptHandler(void)
    {
    uint8_t bTemp;
    uint8_t bWakeUp = FALSE;
    USBCTL |= FRSTE; // Function Reset Connection Enable - set enable after first setup packet was received
    usbProcessNewSetupPacket:
    // copy the MSB of bmRequestType to DIR bit of USBCTL
    if((tSetupPacket.bmRequestType & USB_REQ_TYPE_INPUT) == USB_REQ_TYPE_INPUT)
    {
    USBCTL |= DIR;
    }
    else
    {
    USBCTL &= ~DIR;
    }
    bStatusAction = STATUS_ACTION_NOTHING;
    // clear out return data buffer
    for(bTemp=0; bTemp<USB_RETURN_DATA_LENGTH; bTemp++)
    {
    abUsbRequestReturnData[bTemp] = 0x00;
    }
    // decode and process the request
    bWakeUp = usbDecodeAndProcessUsbRequest();
    // check if there is another setup packet pending
    // if it is, abandon current one by NAKing both data endpoint 0
    if((USBIFG & STPOWIFG) != 0x00)
    {
    USBIFG &= ~(STPOWIFG | SETUPIFG);
    goto usbProcessNewSetupPacket;
    }
    return bWakeUp;
    }

    //----------------------------------------------------------------------------
    void PWRVBUSoffHandler(void)
    {
    uint16_t MCLKFreq = USB_determineFreq();
    uint16_t DelayConstant_250us = ((MCLKFreq >> 6) + (MCLKFreq >> 7) + (MCLKFreq >> 9));
    volatile uint16_t i, j;

    //wait 1 ms till enable USB
    for(j = 0; j < 4; j++)
    {
    for (i = 0; i < (DelayConstant_250us); i++){
    _NOP();
    }
    }
    if (!(USBPWRCTL & USBBGVBV))
    {
    USBKEYPID = 0x9628; // set KEY and PID to 0x9628 -> access to configuration registers enabled
    bEnumerationStatus = 0x00; // device is not enumerated
    bFunctionSuspended = FALSE; // device is not suspended
    USBCNF = 0; // disable USB module
    USBPLLCTL &= ~UPLLEN; // disable PLL
    USBPWRCTL &= ~(VBOFFIE + VBOFFIFG + SLDOEN); // disable interrupt VBUSoff
    USBKEYPID = 0x9600; // access to configuration registers disabled
    }
    }

    //----------------------------------------------------------------------------
    void PWRVBUSonHandler(void)
    {
    uint16_t MCLKFreq = USB_determineFreq();
    uint16_t DelayConstant_250us = ((MCLKFreq >> 6) + (MCLKFreq >> 7) + (MCLKFreq >> 9));
    volatile uint16_t i, j;

    //wait 1 ms till enable USB
    for(j = 0; j < 4; j++)
    {
    for (i = 0; i < (DelayConstant_250us); i++){
    _NOP();
    }
    }
    if (USBPWRCTL & USBBGVBV) //Checking for USB Bandgap and VBUS valid before modifying USBPWRCTL
    {
    USBKEYPID = 0x9628; // set KEY and PID to 0x9628 -> access to configuration registers enabled
    USBPWRCTL |= VBOFFIE; // enable interrupt VBUSoff
    USBPWRCTL &= ~ (VBONIFG + VBOFFIFG); // clean int flag (bouncing)
    USBKEYPID = 0x9600; // access to configuration registers disabled
    }
    }

    //----------------------------------------------------------------------------
    void IEP0InterruptHandler(void)
    {
    USBCTL |= FRSTE; // Function Reset Connection Enable
    tEndPoint0DescriptorBlock.bOEPBCNT = 0x00;
    if(bStatusAction == STATUS_ACTION_DATA_IN)
    {
    usbSendNextPacketOnIEP0();
    }
    else
    {
    tEndPoint0DescriptorBlock.bIEPCNFG |= EPCNF_STALL; // no more data
    }
    }

    //----------------------------------------------------------------------------
    uint8_t OEP0InterruptHandler(void)
    {
    uint8_t bWakeUp = FALSE;
    USBCTL |= FRSTE; // Function Reset Connection Enable
    tEndPoint0DescriptorBlock.bIEPBCNT = 0x00;
    if(bStatusAction == STATUS_ACTION_DATA_OUT)
    {
    usbReceiveNextPacketOnOEP0();
    if(bStatusAction == STATUS_ACTION_NOTHING)
    {
    # ifdef _CDC_
    if(tSetupPacket.bRequest == USB_CDC_SET_LINE_CODING)
    {
    bWakeUp = Handler_SetLineCoding();
    }
    # endif
    #ifdef _HID_
    if (tSetupPacket.bRequest == USB_REQ_SET_REPORT) {
    bWakeUp = USBHID_handleEP0SetReportDataAvailable(tSetupPacket.wIndex);
    }
    #endif
    }
    }
    else
    {
    tEndPoint0DescriptorBlock.bOEPCNFG |= EPCNF_STALL; // no more data
    }
    return (bWakeUp);
    }

    /*----------------------------------------------------------------------------+
    | End of source file

    // DESCRIPTOR.C

    /*-----------------------------------------------------------------------------+
    | Include files |
    |-----------------------------------------------------------------------------*/
    #include <device.h>
    #include <defMSP430USB.h>
    #include <usb.h> // USB-specific Data Structures
    #include "descriptors.h"
    #include <UsbMscReq.h>
    #include <UsbMscScsi.h>

    /*-----------------------------------------------------------------------------+
    | Device Descriptor |
    |-----------------------------------------------------------------------------*/
    uint8_t const abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR] = {
    SIZEOF_DEVICE_DESCRIPTOR, // Length of this descriptor
    DESC_TYPE_DEVICE, // Type code of this descriptor
    0x00, 0x02, // Release of USB spec
    0x00, // Device's base class code
    0x00, // Device's sub class code
    0x00, // Device's protocol type code
    EP0_PACKET_SIZE, // End point 0's packet size
    USB_VID&0xFF, USB_VID>>8, // Vendor ID for device, TI=0x0451
    // You can order your own VID at www.usb.org
    USB_PID&0xFF, USB_PID>>8, // Product ID for device,
    // this ID is to only with this example
    VER_FW_L, VER_FW_H, // Revision level of device
    1, // Index of manufacturer name string desc
    2, // Index of product name string desc
    USB_STR_INDEX_SERNUM, // Index of serial number string desc
    1 // Number of configurations supported
    };

    /*-----------------------------------------------------------------------------+
    | Configuration Descriptor |
    |-----------------------------------------------------------------------------*/
    const struct abromConfigurationDescriptorGroup abromConfigurationDescriptorGroup=
    {
    /* Generic part */
    {
    // CONFIGURATION DESCRIPTOR (9 bytes)
    SIZEOF_CONFIG_DESCRIPTOR, // bLength
    DESC_TYPE_CONFIG, // bDescriptorType
    DESCRIPTOR_TOTAL_LENGTH, 0x00, // wTotalLength
    USB_NUM_INTERFACES, // bNumInterfaces
    USB_CONFIG_VALUE, // bConfigurationvalue
    CONFIG_STRING_INDEX, // iConfiguration Description offset
    USB_SUPPORT_SELF_POWERED | USB_SUPPORT_REM_WAKE, // bmAttributes, bus power, remote wakeup
    USB_MAX_POWER // Max. Power Consumption
    },

    /******************************************************* start of MSC*************************************/
    {
    /*start MSC[0] Here */
    {
    //-------- Descriptor for MSC class device -------------------------------------
    // INTERFACE DESCRIPTOR (9 bytes)
    SIZEOF_INTERFACE_DESCRIPTOR, // bLength
    DESC_TYPE_INTERFACE, // bDescriptorType: 4
    MSC0_DATA_INTERFACE, // bInterfaceNumber
    0x00, // bAlternateSetting
    0x02, // bNumEndpoints
    0x08, // bInterfaceClass: 3 = MSC Device
    0x06, // bInterfaceSubClass:
    0x50, // bInterfaceProtocol:
    INTF_STRING_INDEX + 0, // iInterface:1

    SIZEOF_ENDPOINT_DESCRIPTOR, // bLength
    DESC_TYPE_ENDPOINT, // bDescriptorType
    MSC0_INEP_ADDR, // bEndpointAddress; bit7=1 for IN, bits 3-0=1 for ep1
    EP_DESC_ATTR_TYPE_BULK, // bmAttributes, interrupt transfers
    0x40, 0x00, // wMaxPacketSize, 64 bytes
    0X01, // bInterval, ms

    SIZEOF_ENDPOINT_DESCRIPTOR, // bLength
    DESC_TYPE_ENDPOINT, // bDescriptorType
    MSC0_OUTEP_ADDR, // bEndpointAddress; bit7=1 for IN, bits 3-0=1 for ep1
    EP_DESC_ATTR_TYPE_BULK, // bmAttributes, interrupt transfers
    0x40, 0x00, // wMaxPacketSize, 64 bytes
    0x01, // bInterval, ms
    /* end of MSC[0]*/
    }
    }
    /******************************************************* end of MSC**************************************/
    };
    /*-----------------------------------------------------------------------------+
    | String Descriptor |
    |-----------------------------------------------------------------------------*/
    uint8_t const abromStringDescriptor[] = {

    // String index0, language support
    4, // Length of language descriptor ID
    3, // LANGID tag
    0x09, 0x04, // 0x0409 for English

    // String index1, Manufacturer
    34, // Length of this string descriptor
    3, // bDescriptorType
    'S',0x00,'S',0x00,'S',0x00,'S',0x00,'S',0x00,'S',0x00,
    'S',0x00,' ',0x00,'S',0x00,'S',0x00,'S',0x00,'S',0x00,
    'S',0x00,'S',0x00,'S',0x00,'S',0x00,

    // String index2, Product
    38, // Length of this string descriptor
    3, // bDescriptorType
    'M',0x00,'S',0x00,'P',0x00,'4',0x00,'3',0x00,'0',0x00,
    '-',0x00,'U',0x00,'S',0x00,'B',0x00,' ',0x00,'E',0x00,
    'x',0x00,'a',0x00,'m',0x00,'p',0x00,'l',0x00,'e',0x00,

    // String index3, Serial Number
    4, // Length of this string descriptor
    3, // bDescriptorType
    '0',0x00,

    // String index4, Configuration String
    22, // Length of this string descriptor
    3, // bDescriptorType
    'M',0x00,'S',0x00,'P',0x00,'4',0x00,'3',0x00,'0',0x00,
    ' ',0x00,'U',0x00,'S',0x00,'B',0x00,

    // String index5, Interface String
    28, // Length of this string descriptor
    3, // bDescriptorType
    'M',0x00,'S',0x00,'C',0x00,' ',0x00,'I',0x00,'n',0x00,
    't',0x00,'e',0x00,'r',0x00,'f',0x00,'a',0x00,'c',0x00,
    'e',0x00
    };

    /**** Populating the endpoint information handle here ****/

    const struct tUsbHandle stUsbHandle[]=
    {
    {
    MSC0_INEP_ADDR,
    MSC0_OUTEP_ADDR,
    0,
    MSC_CLASS,
    0,
    0,
    OEP1_X_BUFFER_ADDRESS,
    OEP1_Y_BUFFER_ADDRESS,
    IEP1_X_BUFFER_ADDRESS,
    IEP1_Y_BUFFER_ADDRESS
    }
    };
    //-------------DEVICE REQUEST LIST---------------------------------------------

    const tDEVICE_REQUEST_COMPARE tUsbRequestList[] =
    {

    {
    //---- MSC Class Requests -----//
    // Reset MSC
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
    USB_MSC_RESET_BULK,
    0x00,0x00, // always zero
    MSC0_DATA_INTERFACE,0x00, // MSC interface is 0
    0x00,0x00, // Size of Structure (data length)
    0xff,&USBMSC_reset,
    },
    {
    // Get Max Lun
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
    USB_MSC_GET_MAX_LUN,
    0x00,0x00, // always zero
    MSC0_DATA_INTERFACE,0x00, // MSC interface is 0
    0x01,0x00, // Size of Structure (data length)
    0xff,&Get_MaxLUN,
    },
    {
    //---- USB Standard Requests -----//
    // clear device feature
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_CLEAR_FEATURE,
    FEATURE_REMOTE_WAKEUP,0x00, // feature selector
    0x00,0x00,
    0x00,0x00,
    0xff,&usbClearDeviceFeature,
    },
    {

    // clear endpoint feature
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_ENDPOINT,
    USB_REQ_CLEAR_FEATURE,
    FEATURE_ENDPOINT_STALL,0x00,
    0xff,0x00,
    0x00,0x00,
    0xf7,&usbClearEndpointFeature,
    },
    {
    // get configuration
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_GET_CONFIGURATION,
    0x00,0x00,
    0x00,0x00,
    0x01,0x00,
    0xff,&usbGetConfiguration,
    },
    {
    // get device descriptor
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_GET_DESCRIPTOR,
    0xff,DESC_TYPE_DEVICE, // bValueL is index and bValueH is type
    0xff,0xff,
    0xff,0xff,
    0xd0,&usbGetDeviceDescriptor,
    },
    {
    // get configuration descriptor
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_GET_DESCRIPTOR,
    0xff,DESC_TYPE_CONFIG, // bValueL is index and bValueH is type
    0xff,0xff,
    0xff,0xff,
    0xd0,&usbGetConfigurationDescriptor,
    },
    {
    // get string descriptor
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_GET_DESCRIPTOR,
    0xff,DESC_TYPE_STRING, // bValueL is index and bValueH is type
    0xff,0xff,
    0xff,0xff,
    0xd0,&usbGetStringDescriptor,
    },
    {
    // get interface
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
    USB_REQ_GET_INTERFACE,
    0x00,0x00,
    0xff,0xff,
    0x01,0x00,
    0xf3,&usbGetInterface,
    },
    {
    // get device status
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_GET_STATUS,
    0x00,0x00,
    0x00,0x00,
    0x02,0x00,
    0xff,&usbGetDeviceStatus,
    },
    {
    // get interface status
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
    USB_REQ_GET_STATUS,
    0x00,0x00,
    0xff,0x00,
    0x02,0x00,
    0xf7,&usbGetInterfaceStatus,
    },
    {
    // get endpoint status
    USB_REQ_TYPE_INPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_ENDPOINT,
    USB_REQ_GET_STATUS,
    0x00,0x00,
    0xff,0x00,
    0x02,0x00,
    0xf7,&usbGetEndpointStatus,
    },
    {
    // set address
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_SET_ADDRESS,
    0xff,0x00,
    0x00,0x00,
    0x00,0x00,
    0xdf,&usbSetAddress,
    },
    {
    // set configuration
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_SET_CONFIGURATION,
    0xff,0x00,
    0x00,0x00,
    0x00,0x00,
    0xdf,&usbSetConfiguration,
    },
    {
    // set device feature
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE,
    USB_REQ_SET_FEATURE,
    0xff,0x00, // feature selector
    0x00,0x00,
    0x00,0x00,
    0xdf,&usbSetDeviceFeature,
    },
    {
    // set endpoint feature
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_ENDPOINT,
    USB_REQ_SET_FEATURE,
    0xff,0x00, // feature selector
    0xff,0x00, // endpoint number <= 127
    0x00,0x00,
    0xd7,&usbSetEndpointFeature,
    },
    {
    // set interface
    USB_REQ_TYPE_OUTPUT | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
    USB_REQ_SET_INTERFACE,
    0xff,0x00, // feature selector
    0xff,0x00, // interface number
    0x00,0x00,
    0xd7,&usbSetInterface,
    },
    {

    // end of usb descriptor -- this one will be matched to any USB request
    // since bCompareMask is 0x00.
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
    0x00,&usbInvalidRequest // end of list
    }
    };

    /*
    * Every application using this MSC API must define an instance of this
    * structure. It establishes compile-time information about the storage media.
    */
    struct config_struct USBMSC_config = {
    {
    { // LUN0
    0x0, // The number of this LUN.
    0x00, // PDT (Peripheral Device Type).
    0x00, // 0x00 = media not removable, 0x80 = media removable
    "TI MSC", // Vendor ID. Has no impact on most OSes.
    "LUN0", // Product ID. Has no impact on most OSes.
    "0", // Revision string. Has no impact on most OSes.
    },
    }
    };
    /*-----------------------------------------------------------------------------+
    | END OF Descriptor.c FILE |
    |-----------------------------------------------------------------------------*/

    //DESCRIPTOR.H

    #include <stdint.h>
    #include "usb.h"

    #ifndef _DESCRIPTORS_H_
    #define _DESCRIPTORS_H_

    #ifdef __cplusplus
    extern "C"
    {
    #endif

    /*-----------------------------------------------------------------------------+
    | Include files |
    |-----------------------------------------------------------------------------*/

    //***********************************************************************************************
    // CDC or HID - Define both for composite support
    //***********************************************************************************************
    #define _MSC_ // Needed for MSCinterface
    //***********************************************************************************************
    // CONFIGURATION CONSTANTS
    //***********************************************************************************************
    // These constants configure the API stack and help define the USB descriptors.
    // Refer to Sec. 6 of the MSP430 USB CDC API Programmer's Guide for descriptions of these constants.

    // Configuration Constants that can change
    // #define that relates to Device Descriptor
    #define USB_VID 0x2047 // Vendor ID (VID)
    #define USB_PID 0x03df // Product ID (PID)
    /*----------------------------------------------------------------------------+
    | Firmware Version |
    | How to detect version number of the FW running on MSP430? |
    | on Windows Open ControlPanel->Systems->Hardware->DeviceManager->Ports-> |
    | Msp430->ApplicationUART->Details |
    +----------------------------------------------------------------------------*/
    #define VER_FW_H 0x02 // Device release number, in binary-coded decimal
    #define VER_FW_L 0x00 // Device release number, in binary-coded decimal
    // If a serial number is to be reported, set this to the index within the string descriptor
    //of the dummy serial number string. It will then be automatically handled by the API.
    // If no serial number is to be reported, set this to 0.
    #define USB_STR_INDEX_SERNUM 3
    #define PHDC_ENDPOINTS_NUMBER 2 // bulk in, bulk out


    #define DESCRIPTOR_TOTAL_LENGTH 32 // wTotalLength, This is the sum of configuration descriptor length + CDC descriptor length + HID descriptor length
    #define USB_NUM_INTERFACES 1 // Number of implemented interfaces.

    #define MSC0_DATA_INTERFACE 0 // Data interface number of MSC0
    #define MSC0_OUTEP_ADDR 0x01 // Output Endpoint number of MSC0
    #define MSC0_INEP_ADDR 0x81 // Input Endpoint number of MSC0

    #define CDC_NUM_INTERFACES 0 // Total Number of CDCs implemented. should set to 0 if there are no CDCs implemented.
    #define HID_NUM_INTERFACES 0 // Total Number of HIDs implemented. should set to 0 if there are no HIDs implemented.
    #define MSC_NUM_INTERFACES 1 // Total Number of MSCs implemented. should set to 0 if there are no MSCs implemented.
    #define PHDC_NUM_INTERFACES 0 // Total Number of PHDCs implemented. should set to 0 if there are no PHDCs implemented.
    // Interface numbers for the implemented CDSs and HIDs, This is to use in the Application(main.c) and in the interupt file(UsbIsr.c).
    #define MSC0_INTFNUM 0
    #define MSC_MAX_LUN_NUMBER 1 // Maximum number of LUNs supported

    #define PUTWORD(x) ((x)&0xFF),((x)>>8)

    #define USB_OUTEP_INT_EN BIT0 | BIT1
    #define USB_INEP_INT_EN BIT0 | BIT1

    #define USB_USE_INTERNAL_3V3LDO TRUE

    #define USB_XT2_BYPASS_MODE FALSE
    // MCLK frequency of MCU, in Hz
    // For running higher frequencies the Vcore voltage adjustment may required.
    // Please refer to Data Sheet of the MSP430 device you use
    #define USB_PLL_XT 2 // Defines which XT is used by the PLL (1=XT1, 2=XT2)
    #define USB_XT_FREQ_VALUE 12.0 // Indicates the freq of the crystal on the oscillator indicated by USB_PLL_XT
    #define USB_XT_FREQ USBPLL_SETCLK_12_0 // Indicates the freq of the crystal on the oscillator indicated by USB_PLL_XT
    #define USB_DISABLE_XT_SUSPEND 0 // If non-zero, then USB_suspend() will disable the oscillator
    // that is designated by USB_PLL_XT; if zero, USB_suspend won't
    // affect the oscillator
    #define USB_DMA_CHAN DMA_CHANNEL_1 // Set to 0xFF if no DMA channel will be used 0..7 for selected DMA channel

    // Controls whether the remote wakeup feature is supported by this device.
    // A value of 0x20 indicates that is it supported (this value is the mask for
    // the bmAttributes field in the configuration descriptor).
    // A value of zero indicates remote wakeup is not supported.
    // Other values are undefined, as they will interfere with bmAttributes.
    #define USB_SUPPORT_REM_WAKE 0x00

    // Controls whether the application is self-powered to any degree. Should be
    // set to 0x40, unless the USB device is fully supplied by the bus.
    #define USB_SUPPORT_SELF_POWERED 0x80

    // Controls what the device reports to the host regarding how much power it will
    // consume from VBUS. Expressed in 2mA units; that is, the number of mA
    // communicated is twice the value of this field.
    #define USB_MAX_POWER 0x32
    //Configuration constants that can not change ( Fixed Values)
    #define CDC_CLASS 2
    #define HID_CLASS 3
    #define MSC_CLASS 4
    #define PHDC_CLASS 5

    #define MAX_PACKET_SIZE 0x40 // Max size of the USB packets.

    //***********************************************************************************************
    // DESCRIPTOR CONSTANTS
    //***********************************************************************************************
    #define SIZEOF_DEVICE_DESCRIPTOR 0x12
    #define MAX_STRING_DESCRIPTOR_INDEX 5
    //#define SIZEOF_REPORT_DESCRIPTOR 36
    //#define USBHID_REPORT_LENGTH 64 // length of whole HID report (including Report ID)
    #define CONFIG_STRING_INDEX 4
    #define INTF_STRING_INDEX 5
    #define USB_CONFIG_VALUE 0x01
    //***********************************************************************************************
    // OUTWARD DECLARATIONS
    //***********************************************************************************************

    //Calculates the endpoint descriptor block number from given address
    #define EDB(addr) ((addr&0x07)-1)

    /* Structure for generic part of configuration descriptor */
    struct abromConfigurationDescriptorGenric
    {
    uint8_t sizeof_config_descriptor; // bLength
    uint8_t desc_type_config; // bDescriptorType: 2
    uint8_t sizeof_configuration_descriptor1; // wTotalLength
    uint8_t sizeof_configuration_descriptor2;
    uint8_t usb_num_configurations; // bNumInterfaces
    uint8_t bconfigurationvalue; // bConfigurationValue
    uint8_t config_string_index; // iConfiguration Description offset
    uint8_t mattributes; // bmAttributes, bus power, remote wakeup
    uint8_t usb_max_power; // Max. Power Consumption at 2mA unit
    };

    /************************************************CDC Descriptor**************************/
    struct abromConfigurationDescriptorCdc
    {
    // interface descriptor (9 bytes)
    uint8_t blength_intf; // blength: interface descriptor size
    uint8_t desc_type_interface; // bdescriptortype: interface
    uint8_t interface_number_cdc; // binterfacenumber
    uint8_t balternatesetting; // balternatesetting: alternate setting
    uint8_t bnumendpoints; // bnumendpoints: three endpoints used
    uint8_t binterfaceclass; // binterfaceclass: communication interface class
    uint8_t binterfacesubclass; // binterfacesubclass: abstract control model
    uint8_t binterfaceprotocol; // binterfaceprotocol: common at commands
    uint8_t intf_string_index; // interface:
    //header functional descriptor
    uint8_t blength_header; // blength: endpoint descriptor size
    uint8_t bdescriptortype_header; // bdescriptortype: cs_interface
    uint8_t bdescriptorsubtype_header; // bdescriptorsubtype: header func desc
    uint8_t bcdcdc1;
    uint8_t bcdcdc2; // bcdcdc: spec release number

    //call managment functional descriptor
    uint8_t bfunctionlength; // bfunctionlength
    uint8_t bdescriptortype_c; // bdescriptortype: cs_interface
    uint8_t bdescriptorsubtype_c; // bdescriptorsubtype: call management func desc
    uint8_t bmcapabilities; // bmcapabilities: d0+d1
    uint8_t intf_number_cdc; // bdatainterface: 0

    //acm functional descriptor
    uint8_t bfunctionlength_acm; // bfunctionlength
    uint8_t bdescriptortype_acm; // bdescriptortype: cs_interface
    uint8_t bdescriptorsubtype_acm; // bdescriptorsubtype: abstract control management desc
    uint8_t bmcapabilities_acm; // bmcapabilities

    // Union Functional Descriptor
    uint8_t bLength_ufd; // Size, in bytes
    uint8_t bdescriptortype_ufd; // bDescriptorType: CS_INTERFACE
    uint8_t bdescriptorsubtype_ufd; // bDescriptorSubtype: Union Functional Desc
    uint8_t bmasterinterface_ufd; // bMasterInterface -- the controlling intf for the union
    uint8_t bslaveinterface_ufd; // bSlaveInterface -- the controlled intf for the union

    //Interrupt end point related fields
    uint8_t sizeof_epintep_descriptor; // blength: endpoint descriptor size
    uint8_t desc_type_epintep; // bdescriptortype: endpoint
    uint8_t cdc_intep_addr; // bendpointaddress: (in2)
    uint8_t epintep_desc_attr_type_int; // bmattributes: interrupt
    uint8_t epintep_wmaxpacketsize1;
    uint8_t epintep_wmaxpacketsize; // wmaxpacketsize, 64 bytes
    uint8_t epintep_binterval; // binterval

    // Data interface descriptor (9 bytes)
    uint8_t blength_slaveintf; // blength: interface descriptor size
    uint8_t desc_type_slaveinterface; // bdescriptortype: interface
    uint8_t interface_number_slavecdc; // binterfacenumber
    uint8_t balternatesetting_slave; // balternatesetting: alternate setting
    uint8_t bnumendpoints_slave; // bnumendpoints: three endpoints used
    uint8_t binterfaceclass_slave; // binterfaceclass: data interface class
    uint8_t binterfacesubclass_slave; // binterfacesubclass: abstract control model
    uint8_t binterfaceprotocol_slave; // binterfaceprotocol: common at commands
    uint8_t intf_string_index_slave; // interface:

    // Bulk out end point related fields
    uint8_t sizeof_outep_descriptor; // blength: endpoint descriptor size
    uint8_t desc_type_outep; // bdescriptortype: endpoint
    uint8_t cdc_outep_addr; // bendpointaddress: (out3)
    uint8_t outep_desc_attr_type_bulk; // bmattributes: bulk
    uint8_t outep_wmaxpacketsize1;
    uint8_t outep_wmaxpacketsize2; // wmaxpacketsize, 64 bytes
    uint8_t outep_binterval; // binterval: ignored for bulk transfer

    // Bulk in related fields
    uint8_t sizeof_inep_descriptor; // blength: endpoint descriptor size
    uint8_t desc_type_inep; // bdescriptortype: endpoint
    uint8_t cdc_inep_addr; // bendpointaddress: (in3)
    uint8_t inep_desc_attr_type_bulk; // bmattributes: bulk
    uint8_t inep_wmaxpacketsize1;
    uint8_t inep_wmaxpacketsize2; // wmaxpacketsize, 64 bytes
    uint8_t inep_binterval; // binterval: ignored for bulk transfer
    } ;

    /**************************************HID descriptor structure *************************/
    struct abromConfigurationDescriptorHid
    {
    //INTERFACE DESCRIPTOR (9 bytes)
    uint8_t sizeof_interface_descriptor; // Desc Length
    uint8_t desc_type_interface; // DescriptorType
    uint8_t interface_number_hid; // Interface number
    uint8_t balternatesetting; // Any alternate settings if supported
    uint8_t bnumendpoints; // Number of end points required
    uint8_t binterfaceclass; // Class ID
    uint8_t binterfacesubclass; // Sub class ID
    uint8_t binterfaceprotocol; // Protocol
    uint8_t intf_string_index; // String Index

    //hid descriptor (9 bytes)
    uint8_t blength_hid_descriptor; // HID Desc length
    uint8_t hid_descriptor_type; // HID Desc Type
    uint8_t hidrevno1; // Rev no
    uint8_t hidrevno2; // Rev no - 2nd part
    uint8_t tcountry; // Country code
    uint8_t numhidclasses; // Number of HID classes to follow
    uint8_t report_descriptor_type; // Report desc type
    uint8_t tlength; // Total length of report descriptor
    uint8_t size_rep_desc;

    //input end point descriptor (7 bytes)
    uint8_t size_inp_endpoint_descriptor; // End point desc size
    uint8_t desc_type_inp_endpoint; // Desc type
    uint8_t hid_inep_addr; // Input end point address
    uint8_t ep_desc_attr_type_inp_int; // Type of end point
    uint8_t inp_wmaxpacketsize1; // Max packet size
    uint8_t inp_wmaxpacketsize2;
    uint8_t inp_binterval; // bInterval in ms

    // Output end point descriptor; (7 bytes)
    uint8_t size_out_endpoint_descriptor; // Output endpoint desc size
    uint8_t desc_type_out_endpoint; // Desc type
    uint8_t hid_outep_addr; // Output end point address
    uint8_t ep_desc_attr_type_out_int; // End point type
    uint8_t out_wmaxpacketsize1; // Max packet size
    uint8_t out_wmaxpacketsize2;
    uint8_t out_binterval; // bInterval in ms
    };

    /**************************************MSC descriptor structure *************************/
    struct abromConfigurationDescriptorMsc
    {
    // INTERFACE DESCRIPTOR (9 bytes)
    uint8_t sizeof_interface_descriptor; // Desc Length
    uint8_t desc_type_interface; // DescriptorType
    uint8_t interface_number_hid; // Interface number
    uint8_t balternatesetting; // Any alternate settings if supported
    uint8_t bnumendpoints; // Number of end points required
    uint8_t binterfaceclass; // Class ID
    uint8_t binterfacesubclass; // Sub class ID
    uint8_t binterfaceprotocol; // Protocol
    uint8_t intf_string_index; // String Index

    // input end point descriptor (7 bytes)
    uint8_t size_inp_endpoint_descriptor; // End point desc size
    uint8_t desc_type_inp_endpoint; // Desc type
    uint8_t hid_inep_addr; // Input end point address
    uint8_t ep_desc_attr_type_inp_int; // Type of end point
    uint8_t inp_wmaxpacketsize1; // Max packet size
    uint8_t inp_wmaxpacketsize2;
    uint8_t inp_binterval; // bInterval in ms

    // Output end point descriptor; (7 bytes)
    uint8_t size_out_endpoint_descriptor; // Output endpoint desc size
    uint8_t desc_type_out_endpoint; // Desc type
    uint8_t hid_outep_addr; // Output end point address
    uint8_t ep_desc_attr_type_out_int; // End point type
    uint8_t out_wmaxpacketsize1; // Max packet size
    uint8_t out_wmaxpacketsize2;
    uint8_t out_binterval; // bInterval in ms
    };

    /* Global structure having Generic,CDC,HID, MSC structures */
    struct abromConfigurationDescriptorGroup
    {
    /* Generic part of config descriptor */
    const struct abromConfigurationDescriptorGenric abromConfigurationDescriptorGenric;
    #ifdef _MSC_
    /* MSC descriptor structure */
    const struct abromConfigurationDescriptorMsc stMsc[MSC_NUM_INTERFACES];
    #endif
    #ifdef _CDC_
    /* CDC descriptor structure */
    const struct abromConfigurationDescriptorCdc stCdc[CDC_NUM_INTERFACES];
    #endif
    #ifdef _HID_
    /* HID descriptor structure */
    const struct abromConfigurationDescriptorHid stHid[HID_NUM_INTERFACES];
    #endif
    #ifdef _PHDC_
    /* PDC descriptor structure */
    const struct abromConfigurationDescriptorPhdc stPhdc[PHDC_NUM_INTERFACES];
    #endif
    };

    extern const struct abromConfigurationDescriptorGroup abromConfigurationDescriptorGroup;
    extern uint8_t const abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR];
    extern uint8_t const abromStringDescriptor[];
    //extern uint8_t const abromReportDescriptor[SIZEOF_REPORT_DESCRIPTOR];

    /* Handle Structure - Will be populated in descriptors.c based on number of CDC,HID interfaces */
    struct tUsbHandle
    {
    uint8_t ep_In_Addr; // Input EP Addr
    uint8_t ep_Out_Addr; // Output EP Addr
    uint8_t edb_Index; // The EDB index
    uint8_t dev_Class; // Device Class- 2 for CDC, 3 for HID
    uint16_t intepEP_X_Buffer; // Interupt X Buffer Addr
    uint16_t intepEP_Y_Buffer; // Interupt Y Buffer Addr
    uint16_t oep_X_Buffer; // Output X buffer Addr
    uint16_t oep_Y_Buffer; // Output Y buffer Addr
    uint16_t iep_X_Buffer; // Input X Buffer Addr
    uint16_t iep_Y_Buffer; // Input Y Buffer Addr
    };

    extern const struct tUsbHandle stUsbHandle[CDC_NUM_INTERFACES + HID_NUM_INTERFACES + MSC_NUM_INTERFACES + PHDC_NUM_INTERFACES];
    extern const tDEVICE_REQUEST_COMPARE tUsbRequestList[];

    #ifdef __cplusplus
    }
    #endif

    #endif

    /*------------------------ Nothing Below This Line --------------------------*/

**Attention** This is a public forum