390_USB v1.10 Student Handout

download 390_USB v1.10 Student Handout

of 46

Transcript of 390_USB v1.10 Student Handout

  • 5/25/2018 390_USB v1.10 Student Handout

    1/46

    Student Handout: 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    1

    Purpose:

    - Set-up your PC to run the labs

    Equipment:

    - PC running Windows XP Professional with Service Pack2 (SP2) and Internet Access- PC should also have at least 2 available Full Speed USB ports and/or a powered hub.- Microsoft Word and Adobe PDF reader.- PICDEM FS USB Board (DM163025) & MPLAB ICD2 (DV164005)

    o Get it fromwww.microchipdirect.com- (Optional) Beagle12 USB Protocol Analyzer and Installation CDROM. Software and

    drivers may also be downloaded fromwww.totalphase.com

    - A 390_USB v1.10Class CDROM- Microsoft Visual C++ 2005 Express CDROM or Internet access- Microsoft Platform SDK 2003 R2 CDROM or Internet access

    Helpful Documents (available on the Class CDROM in\Users Guides & Data Sheets):

    - PIC18F4550 Device Data sheet:

    - (PIC18F4550_DS_39632d.pdf)

    - PICDEM FS USB Demonstration Board Users Guide:

    - (PICDEM FS USB Demo Board Users Guide 51526a.pdf)

    - MCHPFSUSB Firmware Users Guide:

    - (MCHPFSUSB Firmware Users Guide 51679a.pdf)

    - AN956 Migrating Applications to USB from RS-232 UART With Minimal Impact on PCSoftware:

    - (AN956 CDC RS232 API 00956b.pdf)

    - Application For Sublicense To Microchip Universal Serial Bus Vendor ID:- (Application For Sublicense To MCHP USB VID_en025058.pdf)

    Initial Installation/Set-Up

    http://www.microchipdirect.com/http://www.microchipdirect.com/http://www.microchipdirect.com/http://www.totalphase.com/http://www.totalphase.com/http://www.totalphase.com/http://www.totalphase.com/http://www.microchipdirect.com/
  • 5/25/2018 390_USB v1.10 Student Handout

    2/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    2

    Installation Procedure:

    1) Delete any existing \RTC\390_USB folder on your PC

    2) Copy the Class CDROM contents to c:\RTC\390_USB

    3) Remove existing MCHPFSUSB v1.2 or v1.3 Framework Files from your PC:

    o Run MCHPFSUSB v1.2 (or v1.3) uninstall from Windows Add/RemovePrograms

    o Manually Delete \MCHPFSUSB folder

    4) You must remove any installed .infand .sysfiles from current/previous

    MCHPFSUSB or 390_USB installations before proceeding. If you have v1.0 of theMCHPFSUSB Framework installed on your computer, please follow instructions in

    APPENDIX C - Removing MCHPFSUSB v1.0 System Files. If you have v1.2 or v1.3of the MCHPFSUSB Framework, please follow instructions inAPPENDIX D -

    Removing MCHPFSUSB v1.2 & v1.3 System Files. The MCHPFSUSB version# is

    shown on the CDROM in your PICDEM FS USB Kit. RTC Class 390_USB Rev A usesv1.0, 390_USB v1.0x uses v1.2, 390_USB v1.10 uses v1.3. The class version is shown

    on the presentation slides.

    5) Extract the MCHPFSUSB Framework, C:\RTC\390_USB\Development

    Tools\MCHPFSUSB Framework\MCHPFSUSB v1.3.zipto C:\. You should now

    see a new folder C:\MCHPFSUSB1_3

    6) From C:\MCHPFSUSB1_3, run "MCHPFSUSB_Setup_v1.3.exe" - this installs the

    MCHPFSUSB Framework in C:\MCHPFSUSB.

    7) Connect the PICDEM FS USB board into an unused USB port in your computer. WhenWinXP Found New Hardware wizard comes up, select Install from a list or specific

    location and direct it to the folder: C:\MCHPFSUSB\PC\MCHPUSB Driver\Release.

    8) Successful USB enumeration is indicated by alternate flashing of LEDs D1/D2 on thePICDEM FS USB board.

    9) Run the PDFSUSB.exedemo application to verify operation

    (C:\MCHPFSUSB\PC\PDFSUSB\PDFSUSB.exe) - see Ch3 of the PICDEM FS USB

    Users Guide for details on how to run this application.

    10)Install MPLAB v7.61 or higher (www.microchip.com/mplab)o Install in default folder, with default options

    http://www.microchip.com/mplabhttp://www.microchip.com/mplabhttp://www.microchip.com/mplabhttp://www.microchip.com/mplab
  • 5/25/2018 390_USB v1.10 Student Handout

    3/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    3

    11)Install C18 Student Version v3.11 or higher (www.microchip.com/c18)

    o Install in default foldero Set all check boxes in Configuration Options during install

    12)Install Visual C++ 2005 Express Edition & Platform DSK by following the instructionsprovided in Appendix E - Visual C++ 2005 Express Installation

    13)Copy the UVCViewutility to your desktop. The .exe file is available in\Development Tools\UVCView

    14)(Optional) Install & Test the Beagle12 USB Protocol Analyzer by following theinstructions provided in Appendix FInstalling Beagle12

    15)Follow 390_USB v1.10 Presentation Slides and Handout, which runs the labs fromC:\MCHPFSUSB\fw\CDC (Part 2) and C:\RTC\390_USB (Part 3)

    Restoring Software Projects/Labs:

    In Class: Shut down any applications using class files/projects (HyperTerminal, MPLAB IDE,

    Visual C++ 2005). Run390_USB Restore Script.baton the desktop

    At Home: Shut down any applications using class files/projects (HyperTerminal, MPLAB IDE,

    Visual C++ 2005) & place the 390_USB CDROM in your CDROM Drive. Run

    :\Development Tools\MCHPFSUSB Framework\Restore_390USB_Files.bat

    Removing installed MCHPFSUSB .sys & .inf Files:

    Go to APPENDIX D - Removing MCHPFSUSB v1.2 & v1.3 System Files

    Courseware/PC Restoration

    http://www.microchip.com/c18http://www.microchip.com/c18http://www.microchip.com/c18http://www.microchip.com/c18
  • 5/25/2018 390_USB v1.10 Student Handout

    4/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    4

    No Labs. Lecture Only.

    Purpose:

    - To familiarize you with the development environment, the demo firmware and demoapplication

    - To verify that the Microchip general purpose USB Windows driver is installed on yourPC

    Procedure:

    - Launch MPLAB IDE

    - Import C:\MCHPFSUSB\fw\_factory_hex\picdemfsusb.hex- Select MPLAB ICD 2 as a programmer- Program the device- Remove the 9 inch modular cable- Follow instructions in Chapter 3 of the PICDEM FS USB Users Guide on how to run

    the demo.

    Purpose:

    - To familiarize you with the MPLAB development environment, the boot loader firmwareand programmer application

    Exercise 2.2Download HID Mouse Demo via the USB Bootloader

    Exercise 2.1Play with the General Purpose Driver Demo

    Part 2Introduction to Microchip MCHPFSUSB Firmware Solutions

    and Hands-on with CDC Class RS-232 Replacement APIs

    Part 1Introduction to Full Speed USB

  • 5/25/2018 390_USB v1.10 Student Handout

    5/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    5

    Procedure:

    - Launch PDFSUSB.exeif you have not done so already (C:\MCHPFSUSB\PC\PDFSUSB)- Enter boatload mode by holding down push button S2 and hit S1 to reset

    - Select Boot Mode Tab in PDFSUSB.exe- Follow instructions in Chapter 3 of the Users Guide on how to download a hex file

    - Download: C:\MCHPFSUSB\fw\Hid\Mouse\output \MCHPUSB.hex

    Procedure:

    - Launch MPLAB IDE- Open MCHPFSUSB CDC Class firmware workspace

    (C:\MCHPFSUSB\fw\CDC\MCHPUSB.mcw)

    - Build application- Select MPLAB ICD 2 as a programmer- Program the device- Remove the 9 inch modular cable

    If Windows asks you to provide a path to an INF file during CDC Class device driver

    installation, the path is here: C:\MCHPFSUSB\fw\Cdc\inf\win2k_winxp_winvista32

    Refer to AN956 while you are working in this section to get more detailed information.

    (C:\RTC\390_USB\Users Guides & Data Sheets\...00956b.pdf)

    Purpose:

    - To familiarize you with the CDC Class RS-232 Replacement APIs

    Software Used:

    - MCHPFSUSB CDC Class firmware workspace

    (C:\MCHPFSUSB\fw\CDC\MCHPUSB.mcw)

    - HyperTerminal (C:\RTC\390_USB\390_USB Hyperterminal Connection.ht)

    Exercise 2.3.1Sending Literal Data UsingputrsUSBUSART()

    Exercise 2.3CDC Class RS-232 Replacement APIs (App. Note AN956)

  • 5/25/2018 390_USB v1.10 Student Handout

    6/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    6

    Procedure:

    - Find function Exercise_01()in user.c- Write code in this function that sends a literal null-terminated string of text (Hello

    World!\r\n) to the PC when switch 2 is pressed

    - Take a look at examples in Exercise_Example();- Useful functions:

    o BOOL Switch2IsPressed(void); Returns 1 if switch 2 was pressed Returns 0 if switch 2 was not pressed

    o BOOL mUSBUSARTIsTxTrfReady(void)o Use:putrsUSBUSART()

    - Solution code: C:\MCHPFSUSB\fw\Cdc\user\solutions\Exercise1.txt

    Purpose:

    - To familiarize you with the CDC Class RS-232 Replacement APIs

    Software Used:

    - MCHPFSUSB CDC Class firmware workspace

    (C:\MCHPFSUSB\fw\CDC\MCHPUSB.mcw)

    - HyperTerminal (C:\RTC\390_USB\390_USB Hyperterminal Connection.ht)

    Procedure:

    - Find function Exercise_02()in user.c- Write code in this function that sends a null-terminated string of text stored in program

    memory pointed to by ex02_stringto the PC when switch 3 is pressed

    - Useful functions:

    o BOOL Switch3IsPressed(void);o BOOL mUSBUSARTIsTxTrfReady(void)o Use:putrsUSBUSART()

    - Solution code: C:\MCHPFSUSB\fw\Cdc\user\solutions\Exercise2.txt

    Exercise 2.3.2Sending ROM Data UsingputrsUSBUSART()

  • 5/25/2018 390_USB v1.10 Student Handout

    7/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    7

    Purpose:

    - To familiarize you with the CDC Class RS-232 Replacement APIs

    Software Used:

    - MCHPFSUSB CDC Class firmware workspace

    (C:\MCHPFSUSB\fw\CDC\MCHPUSB.mcw)

    - HyperTerminal (C:\RTC\390_USB\390_USB Hyperterminal Connection.ht)

    Procedure:

    - Find functionExercise_03()in user.c- Write code in this function that reads data from USB bus and toggles LED D4 when the

    data read equals ASCII character 1 (0x31)

    - Useful functions & variables:o input_buffer[];omLED_4_Toggle();o Use:getsUSBUSART()

    - Solution code: C:\MCHPFSUSB\fw\Cdc\user\solutions\Exercise3.txt

    Purpose:

    - To familiarize you with the CDC Class RS-232 Replacement APIs

    Software Used:

    - MCHPFSUSB CDC Class firmware workspace(C:\MCHPFSUSB\fw\CDC\MCHPUSB.mcw)

    - HyperTerminal (C:\RTC\390_USB\390_USB Hyperterminal Connection.ht)

    Exercise 2.3.4Sending Non Null-Terminated Data UsingmUSBUSARTTxRam()

    Exercise 2.3.3Receiving Data Using getsUSBUSART()

  • 5/25/2018 390_USB v1.10 Student Handout

    8/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    8

    Procedure:

    - Before starting, comment out call to Exercise_01()in ProcessIO()first- Find function Exercise_04()in user.c- Write code in this function that sends the following 4 bytes of data: 0x30,0x31,0x32,0x33

    when switch 2 is pressed

    - Useful function & variable:o Switch2IsPressed();o BOOL mUSBUSARTIsTxTrfReady(void)o output_buffer[];o Use:mUSBUSARTTxRam()

    - Solution code: C:\MCHPFSUSB\fw\Cdc\user\solutions\Exercise4.txt

    Purpose:

    - To familiarize you with the CDC Class RS-232 Replacement APIs

    Software Used:

    - MCHPFSUSB CDC Class firmware workspace(C:\MCHPFSUSB\fw\CDC\MCHPUSB.mcw)

    - HyperTerminal (C:\RTC\390_USB\390_USB Hyperterminal Connection.ht)

    Procedure:

    - Find function Exercise_05()in user.c- The program currently outputs temperature data on the physical UART port. Change the

    program to output data through the USB port.

    - Follow instructions in Exercise_05()- Useful function & variables:

    o UsemUSBUSARTIsTxTrfReady()o UseputsUSBUSART(...)

    - Solution code:C:\MCHPFSUSB\fw\Cdc\user\solutions\Exercise5.txt

    Exercise 2.3.5Sending Null-Terminated Ram Data UsingputsUSBUSART();

  • 5/25/2018 390_USB v1.10 Student Handout

    9/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    9

    Purpose:

    - Get familiarized with Microsoft Visual C++ 2005- Learn how to dynamically link MPUSBAPI.DLL functions into your application

    - Use theMPUSBGetDLLVersion( )function.

    Software Used:

    - Microsoft Visual C++ 2005 Express Edition

    PC Host-Side Solution Project Available:C:\RTC\390_USB\Pc\Ex3\Ex3.1_solution\Ex3.1_solution.sln

    Procedure:

    1. Creating Win32 Console ApplicationOpen Visual C++ on your Computer: StartProgramsVisual C++ 2005 Express

    EditionVisual C++ 2005 Express Edition

    Or Click on the short cut placed on the desktop.

    Part 3Using the Microchip General Purpose USB Windows Driverand Custom Class Device Firmware

    Exercise 3.1Creating a Win32 Console Application & Linking To

    MPUSBAPI DLL Functions at Run-Time

  • 5/25/2018 390_USB v1.10 Student Handout

    10/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    10

    Create a Win32 Console Application- FileNewProject SelectWin32 Console Application

    - Browse to Location C:\RTC\390_USB\Pc\Ex3- Enter Ex3.1into the project nameand Click on OK---------

    ------

    - A Win32 application wizard dialog box should open. Click Next, andselect Application TypeConsole Application and

    Additional OptionsEmpty Project. Then select Finish

  • 5/25/2018 390_USB v1.10 Student Handout

    11/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    11

    2. Add Files

    Right-click on the Source folder. SelectAddExisting Itemc:\RTC\390_USB\Pc\Ex3\Ex3.1\Ex3.1\Ex3.1.cpp

    3. Build & Run

    Select BuildBuild Solution (or F7)

    Try running your program by selecting DebugStart without Debugging (or

    ctrl+F5).

    To quit, press [4], then enter.

  • 5/25/2018 390_USB v1.10 Student Handout

    12/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    12

    4. Linking MPUSBAPI.DLL at run-time

    Copy the filesmpusbapi.dll, andmpusbapi.h(no underscore)fromC:\MCHPFSUSB\Pc\Mpusbapi\Dll\Borland Cto

    C:\RTC\390_USB\Pc\Ex3\Ex3.1\Ex3.1.

    Include the MPUSBAPI DLL header file mpusbapi.h in the source file (Ex3.1.cpp).

    Add the line#include "mpusbapi.h"after other include lines.

    You should now have the following #includes:

    // #includes...

    #include#include#include"mpusbapi.h"

    5. Invoking functions from a DLL at run time

    You need to use three functions to invoke functions from the DLL when the library is linked

    at run-time:

    LoadLibrary( )

    Win32 API for loading a library into the memory. Returns a handle(HINSTANCE) to thelibrary.

    GetProcAddress( )

    Win32 API for obtaining address of a function from the library that is loaded. Returns theaddress of a function in memory. This address need to be stored in afunction pointer

    variable.

    Then the function can be invoked using thefunction pointer.

    FreeLibrary( )

    Unload the library from memory.

    The flow chart on the following pages outlines the procedure for loading/using/closing the

    DLL functions in a Win32 application.

  • 5/25/2018 390_USB v1.10 Student Handout

    13/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    13

    Flow Chart (Loading/Invoking Functions from a DLL During Run-Time)

    No

    Yes

    No

    main()

    Load the librarylibHandle= LoadLibrary(TEXT(mpusbapi.dll));

    libHandleis NULL

    Library not loaded.

    Check the path of the.DLL file

    Library loaded.

    Now obtain the address of functions from the library and store them in

    function pointers.

    MPUSBGetDLLVersion=(DWORD(*)(void))GetProcAddress(libHandle,"_MPUSBGetDLLVersion");

    MPUSBGetDeviceCount=(DWORD(*)(PCHAR))

    GetProcAddress(libHandle,"_MPUSBGetDeviceCount"); etc

    Are function

    pointers NULL

    Yes Function name incorrector the library does not

    have the function

    Call the functions as per

    requirement

    Close the LibraryFreeLibrary(libHandle)

  • 5/25/2018 390_USB v1.10 Student Handout

    14/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    14

    Loading the Library and Calling the FunctionMPUSBGetDLLVersion( )from the DLL[If you have a soft-copy of this hand-out and dont want to type, then just do a cut and paste.]

    Add the following declaration to the Function Prototype section:

    // Function Prototypes

    voidLoadDLL(void); // Perform run-time load of all MPUSBAPI.DLL Functions

    Add the following global variable declaration:

    // Global Variables

    DWORD temp;

    HINSTANCE libHandle;

    Add theLoadDLL()function call into the main()function:

    intmain(void){

    BOOLEAN bQuit = false; // main loop termination variableDWORD selection; // user menu selection

    // Load DLL when it is necessary, i.e. on start-up!LoadDLL();

    Add the following code within the switchcase 1: statement in main( )to execute theMPUSBGetDLLVersion()DLL function when menu item [1] is selected:

    switch(selection){

    case1:temp = MPUSBGetDLLVersion();printf("MPUSBAPI Version: %d.%d\r\n",HIWORD(temp),LOWORD(temp));break;

  • 5/25/2018 390_USB v1.10 Student Handout

    15/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    15

    Next, define the LoadDLL( )function below the main( ) function:

    //---------------------------------------------------------------------------// LoadDLL(void) Perform Run-Time Loading of ALL MPUSBAPI DLL FunctionsvoidLoadDLL(void){

    libHandle = NULL;libHandle = LoadLibrary(TEXT("mpusbapi.dll"));if(libHandle == NULL){

    printf("Error loading mpusbapi.dll\r\n");}else{

    MPUSBGetDLLVersion=(DWORD(*)(void))\

    GetProcAddress(libHandle,"_MPUSBGetDLLVersion");MPUSBGetDeviceCount=(DWORD(*)(PCHAR))\

    GetProcAddress(libHandle,"_MPUSBGetDeviceCount");MPUSBOpen=(HANDLE(*)(DWORD,PCHAR,PCHAR,DWORD,DWORD))\

    GetProcAddress(libHandle,"_MPUSBOpen");MPUSBWrite=(DWORD(*)(HANDLE,PVOID,DWORD,PDWORD,DWORD))\

    GetProcAddress(libHandle,"_MPUSBWrite");MPUSBRead=(DWORD(*)(HANDLE,PVOID,DWORD,PDWORD,DWORD))\

    GetProcAddress(libHandle,"_MPUSBRead");MPUSBReadInt=(DWORD(*)(HANDLE,PVOID,DWORD,PDWORD,DWORD))\

    GetProcAddress(libHandle,"_MPUSBReadInt");MPUSBClose=(BOOL(*)(HANDLE))GetProcAddress(libHandle,"_MPUSBClose");

    if((MPUSBGetDeviceCount == NULL) || (MPUSBOpen == NULL) ||(MPUSBWrite == NULL) || (MPUSBRead == NULL) ||(MPUSBClose == NULL) || (MPUSBGetDLLVersion == NULL) ||(MPUSBReadInt == NULL))printf("GetProcAddress Error\r\n");

    }//end if else}//end LoadDLL

    Finally, you must add the following code to the end of main()to unload/close the library:

    // Always check to close the library too.if(libHandle != NULL) FreeLibrary(libHandle);

  • 5/25/2018 390_USB v1.10 Student Handout

    16/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    16

    Now build/run the program to see the output when [1] is pressed:

    Purpose:

    Learn how to add commands to the custom class USB firmware framework

    Learn how to open/use/close a communications pipe to a specific endpoint in a specificdevice using the MPUSBAPI DLL functions to perform basic data exchange

    Software Used:

    - Microsoft Visual C++ 2005 Express Edition- MPLAB C18 Compiler

    Device-Side Solution Workspace Available:C:\RTC\390_USB\fw\Ex3.2_solution\MCHPUSB.mcw

    PC Host-Side Solution Project Available:C:\RTC\390_USB\Pc\Ex3\Ex3.2_solution\Ex3.2_solution.sln

    Exercise 3.2Implementing The Read_POT Command/Response

  • 5/25/2018 390_USB v1.10 Student Handout

    17/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    17

    Procedure (Device-Side):

    1. Review Command/Response Protocol

    Label: READ_POT

    Command Code: 0x37Function: Returns the A/D conversion from the position of the potentiometer.

    Result is 10 bits, right justified.Out Buffer Format:

    In Buffer Format:

    2. Modify Device FirmwareStart MPLAB and open workspace Ex3.2

    (C:\RTC\390_USB\fw\Ex3.2\mchpusb.mcw)

    Open user.hand add the new command READ_POTas follows

    typedef union DATA_PACKET{

    byte _byte[USBGEN_EP_SIZE]; //For byte accessword _word[USBGEN_EP_SIZE/2];//For word accessstruct{

    enum{

    NULL_CMD = 0x00,READ_POT = 0x37

    }CMD;

  • 5/25/2018 390_USB v1.10 Student Handout

    18/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    18

    Open user.cand add the new command to theswitch()statement in the

    ServiceRequests()function as follows:

    void ServiceRequests(void){

    mLED_4_Toggle(); // Toggles Port Pin RD3

    if(USBGenRead((byte*)&dataPacket,sizeof(dataPacket))){

    counter = 0; // initialize #return byte(s) countswitch(dataPacket.CMD){

    // **ADD CODE HERE **case READ_POT:

    mLED_3_On();

    ReadPOT();dataPacket._byte[1] = ADRESL;dataPacket._byte[2] = ADRESH;counter=0x03;mLED_3_Off();break;

    default:break;

    }//end switch()

    Build the project, and fix any syntax errors.

    Connect ICD2 to the board and select ICD2 as programmer.

    Program the deviceDisconnect ICD2.

    3. Modify PC ApplicationCreate New Project

    First, close the Ex3.1 Solution: FileClose Solution

    Now, using the procedure from Exercise 3.1, start Microsoft Visual C++ 2005 and create

    a new Win32 console project, named Ex3.2in C:\RTC\390_USB\Pc\Ex3.

    Add the source file C:\RTC\390_USB\Pc\Ex3\Ex3.2\Ex3.2\Ex3.2.cpp

    to the

    project.

    Copy the filesmpusbapi.dll, andmpusbapi.h(no underscore)from

    C:\MCHPFSUSB\Pc\Mpusbapi\Dll\Borland Cto

    C:\RTC\390_USB\Pc\Ex3\Ex3.2\Ex3.2.

    Build, and run. This is essentially the solution from Ex 3.1.

  • 5/25/2018 390_USB v1.10 Student Handout

    19/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    19

  • 5/25/2018 390_USB v1.10 Student Handout

    20/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    20

    4. Modify PC ApplicationImplement Menu [2]Summarize Instances

    Here we are interested in using MPUSBGetDeviceCount()to determine the numberof instances of devices with VID_PID of 04D8_000C that windows is aware of.You

    will need a valid instance index to open a pipe to Ep1 on a specific device usingMPUSBOpen()

    The code will then run a small loop to determine the valid instance indexeswhich may

    be used to open/use/close pipes to endpoints in a specific device.

    Add the following declaration to the Function Prototype section:

    // Function Prototypes

    voidLoadDLL(void); // Load MPUSBAPI.DLL FunctionsvoidGetSummary(void); // Get # instances of VID_PID

    Add the following global variable declaration:

    // Global Variables

    DWORD temp;HINSTANCE libHandle;charvid_pid[]= "vid_04d8&pid_000c"; // Default Demo Application Firmware

    Add the following code within the switchcase 2: statement in main( )to execute theGetSummary()function when menu item [2] is selected:

    switch(selection){

    case1:temp = MPUSBGetDLLVersion();printf("MPUSBAPI Version: %d.%d\r\n",HIWORD(temp),LOWORD(temp));break;

    case2:GetSummary();break;

    Next, define the GetSummary( )function below the LoadDLL( )function:

  • 5/25/2018 390_USB v1.10 Student Handout

    21/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    21

    //---------------------------------------------------------------------------

    voidGetSummary(void){

    HANDLE tempPipe = INVALID_HANDLE_VALUE;DWORD count = 0;DWORD max_count;

    max_count = MPUSBGetDeviceCount(vid_pid);

    printf("\r\n%d device(s) with %s currently attached\r\n",max_count,vid_pid);

    // Note:// The total number of devices using the generic driver could be// bigger than max_count. They could have different vid & pid numbers.// This means if max_count is 2, the valid instance index do not// necessary have to be '0' and '1'.//// Below is a sample code for searching for all valid instance indexes.// MAX_NUM_MPUSB_DEV is defined in _mpusbapi.h

    count = 0;for(inti = 0; i < MAX_NUM_MPUSB_DEV; i++){

    tempPipe = MPUSBOpen(i,vid_pid,NULL,MP_READ,0);if(tempPipe != INVALID_HANDLE_VALUE){

    printf("Instance Index # %d\r\n",i);MPUSBClose(tempPipe);

    count++;}if(count == max_count) break;

    }//end forprintf("\r\n");

    }//end GetSummary

    Now build/run the program, plug in your PICDEM FS USB board, and observe the output when

    [2] is pressed.

    Try plugging in your neighbors PICDEM FS USB Board(s) to the hub to see what happens.

    NOTE: The windows found new hardwarewizard will come up if you plug a device into apreviously unused USB port. Simply direct it to automatically search for the appropriate driverand you should then see its instance includedupon pressing [2] as shown in the following

    image:

  • 5/25/2018 390_USB v1.10 Student Handout

    22/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    22

    Important to note (again) that the instance indexes displayed are only valid for the VID_PID #

    listed.

    In an application where you would have many devices of the same VID_PID#, you could run a

    small routine that cycles from instance#0 to #126 and for each instance#, run MPUSBOpen. If

    you get a valid handle, implement a READ_SERIAL_NUMBER command in the devicefirmware that can be used to associate an instance index with a device serial#. The table of

    device serial#s would be stored in a table.

    5. Modify PC ApplicationImplement Menu [3]Read Potentiometer

    We will create a function GetPotValue()in which we use MPUSBOpen()to openpipes to Ep1 IN and Ep1 OUT endpoints on a specific device. We are then going to

    implement a wrapper function called SendReceivePacket()which facilitates thecommand/response protocol using the DLL functions MPUSBWrite()and

    MPUSBRead(). Finally, we will close the pipes to the Endpoints using

    MPUSBClose().

    The basic flow is: Open EndPointsLoad Command BufferSend Command

    BufferRead/Evaluate Response BufferPrint ResponseClose Endpoints

  • 5/25/2018 390_USB v1.10 Student Handout

    23/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    23

    Add the following declarations to the Function Prototype section:

    // Function Prototypes

    voidLoadDLL(void); // Load MPUSBAPI.DLL FunctionsvoidGetSummary(void); // Get # instances of VID_PIDvoidGetPotValue(void); // Get potentiometer ADC reading (0-1023)DWORD SendReceivePacket(BYTE *SendData, DWORD SendLength, BYTE *ReceiveData,

    DWORD *ReceiveLength, UINT SendDelay, UINT ReceiveDelay);// Wrapper function for command/response paradigm

    voidCheckInvalidHandle(void);// Error handler function

    Add the following global variable declarations:

    // Global Variables

    DWORD temp;HINSTANCE libHandle;charvid_pid[]= "vid_04d8&pid_000c";// Default Demo Application Firmwarecharout_pipe[]= "\\MCHP_EP1";charin_pipe[]= "\\MCHP_EP1"; // Endpoint stringsHANDLE myOutPipe;HANDLE myInPipe; // Handles to the endpoints

    Add the following code within the switchcase 3: statement in main( )to execute the

    GetPotValue()function when menu item [3] is selected:

    switch(selection){

    case1:temp = MPUSBGetDLLVersion();printf("MPUSBAPI Version: %d.%d\r\n",HIWORD(temp),LOWORD(temp));break;

    case2:GetSummary();break;

    case3:

    GetPotValue();break;

  • 5/25/2018 390_USB v1.10 Student Handout

    24/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    24

    Next, define the GetPotValue( )function below the GetSummary( )function:

    //-----------------------------------------------------------------------------voidGetPotValue(void){

    // First we need to open data pipes...DWORD selection;fflush(stdin);printf("Enter a valid instance index to open a USB connection: ");scanf("%d",&selection);

    myOutPipe = MPUSBOpen(selection,vid_pid,out_pipe,MP_WRITE,0);myInPipe = MPUSBOpen(selection,vid_pid,in_pipe,MP_READ,0);if(myOutPipe == INVALID_HANDLE_VALUE || myInPipe == INVALID_HANDLE_VALUE){

    printf("Failed to open data pipes.\r\n");return;

    }//end if

    // The default demo firmware application has a defined application// level protocol.// To perform an A/D conversion on the potentiometer voltage,// the host must send the READ_POT command buffer, which is defined as 0x37// i.e. //// The response buffer from the board has the following format://

    // The command/response buffer sizes must be equal to or larger than the maximum// endpoint size it is communicating with. In this case, 64 bytes.

    BYTE command_buf[64];BYTE response_buf[64]; // Declare command/response buffersDWORD RecvLength = 3; // Declare/Initialize expected # return bytes for this CMD

    #defineREAD_POT 0x37command_buf[0] = READ_POT; // Command

    if(SendReceivePacket(command_buf,1,response_buf,&RecvLength,1000,1000) == 1){

    if(RecvLength == 3 && response_buf[0] == READ_POT){

    printf("\nPICDEM FS USB Potentiometer Reading is %d\r\n",((response_buf[1])+(response_buf[2]*256)));

    }}else

    printf("USB Operation Failed\r\n");

  • 5/25/2018 390_USB v1.10 Student Handout

    25/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    25

    // Let's close the data pipes since we have nothing left to do..MPUSBClose(myOutPipe);MPUSBClose(myInPipe);myOutPipe = myInPipe = INVALID_HANDLE_VALUE;

    }//end GetPotValue()

    Next, add the support functions SendReceivePacket( )and

    CheckInvalidHandle():

    //---------------------------------------------------------------------------// DWORD SendReceivePacket( )//// A typical application would send a command to the target device and expect// a response.// SendReceivePacket is a wrapper function that facilitates the// send command / read response paradigm//// SendData - pointer to data to be sent// SendLength - length of data to be sent// ReceiveData - Points to the buffer that receives the data read from the call// ReceiveLength - Points to the number of bytes read// SendDelay - time-out value for MPUSBWrite operation in milliseconds// ReceiveDelay - time-out value for MPUSBRead operation in milliseconds//// Return Values:

    // 0 (Invalid Pipes),// 1 (Success),// 2 (Partial Failure - incorrect received length)//

    DWORD SendReceivePacket(BYTE *SendData, DWORD SendLength, BYTE *ReceiveData,DWORD *ReceiveLength, UINT SendDelay, UINT ReceiveDelay)

    {DWORD SentDataLength;DWORD ExpectedReceiveLength = *ReceiveLength;

    if(myOutPipe != INVALID_HANDLE_VALUE && myInPipe != INVALID_HANDLE_VALUE){

    if(MPUSBWrite(myOutPipe,SendData,SendLength,&SentDataLength,SendDelay)){

    if(MPUSBRead(myInPipe,ReceiveData, ExpectedReceiveLength,ReceiveLength,ReceiveDelay))

    {if(*ReceiveLength == ExpectedReceiveLength){

    return1; // Success!}

  • 5/25/2018 390_USB v1.10 Student Handout

    26/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    26

    elseif(*ReceiveLength < ExpectedReceiveLength){

    return2; // Partially failed, incorrect receive length}//end if else

    }else

    CheckInvalidHandle();}else

    CheckInvalidHandle();}//end if

    return0; // Operation Failed}//end SendReceivePacket

    //---------------------------------------------------------------------------

    voidCheckInvalidHandle(void){

    if(GetLastError() == ERROR_INVALID_HANDLE){

    // Most likely cause of the error is the board was disconnected.MPUSBClose(myOutPipe);MPUSBClose(myInPipe);myOutPipe = myInPipe = INVALID_HANDLE_VALUE;

    }//end ifelse

    printf("Error Code \r\n",GetLastError());}//end CheckInvalidHandle

    //---------------------------------------------------------------------------

  • 5/25/2018 390_USB v1.10 Student Handout

    27/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    27

    Now build/run the program to see the output when [3] is pressed:

    You have now practiced accessing the information from the DLL

    (MPUSBGetDLLVersion()), and transferred information to and from the PICDEM FS USB

    demo board using MPUSBOpen( ), MPUSBWrite( ), MPUSBRead( ), MPUSBClose(),

    via the DLL and driver files (MPUSBAPI.dll, mchpusb.sys).

  • 5/25/2018 390_USB v1.10 Student Handout

    28/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    28

    The source code for the demo may be found in C:\MCHPFSUSB\fw\demo\user\user.c. See

    the ServiceRequests function which starts at line 169.

    READ_VERSION 0x00

    Returns the firmware VersionFormat

    READ_VERSION, 0x02

    Returns

    READ_VERSION, 0x02, MAJOR, MINOR

    ID_BOARD 0x31

    Sets a binary code on LEDs 3 & 4. ID_CODE is 0-3.

    FormatID_BOARD, ID_CODE

    Returns

    ID_BOARD

    UPDATE_LED 0x32

    Provides direct access to turn LED 3 or 4, on or off.

    Format:UPDATE_LED, LED_NUM, LED_STATUS

    LED_NUM is either 3 or 4.

    LED_STATUS is either 0 or 1.Returns:

    UPDATE_LED

    SET_TEMP_REAL 0x33

    Resets real time temperature logging and sets the temperature mode to Real Time.

    Format:

    SET_TEMP_REALReturns

    SET_TEMP_REAL

    Appendix AMCHPFSUSB Demo Firmware Command Reference

  • 5/25/2018 390_USB v1.10 Student Handout

    29/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    29

    READ_TEMPERATURE 0x34

    Returns a single temperature conversion. Temperature returned is a 16 bit number

    representing degrees C. Bits 0 & 1 are not valid. Bit 2 indicates temperature is valid.The remaining 13 bits represent degrees Celsius, in 1/16

    th(0.0625) degree increments. In

    a fixed point coding scheme, the Binary-point is between bits 6 and 7

    VValidity flag. 1 indicates temperature reading is valid.

    Format:

    READ_TEMPERATURE

    Returns:READ_TEMPERATURE, TEMPL, TEMPH

    SET_TEMP_LOGGING 0x35

    Resets real time temperature logging and sets the temperature mode to Logging.Format:

    SET_TEMP_LOGGING

    ReturnsSET_TEMP_LOGGING

    READ_TEMP_LOGGING 0x36

    Returns the logged temperatures. When logging is enabled, the board will sample thetemperature sensor once every second. This command will read the stored temperature

    values. a single temperature conversion. Temperature returned is a 16 bit number

    representing degrees C. Bits 0 & 1 are not valid. Bit 2 indicates temperature is valid.The remaining 13 bits represent degrees Celsius, in 1/16

    th(0.0625) degree increments.

    The log is a circular buffer, so once 30 samples are logged, new readings will start back

    at the beginning of the buffer.Format:

    READ_TEMPERATURE

    Returns:

    READ_TEMPERATURE, Sample count, TEMPL0, TEMPH0, TEMPL1,

    TEMPH1

    V X X

    High Byte Low Byte

  • 5/25/2018 390_USB v1.10 Student Handout

    30/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    30

    READ_POT 0x37

    Returns the A2D conversion from the position of the potiometer. Result is 10 bits, right

    justified.Format:

    READ_POT

    Returns:READ_POT, ADRESL, ADRESH

  • 5/25/2018 390_USB v1.10 Student Handout

    31/46

    Student Handout: 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    31

    If LEDs D1 & D2 are flashing alternatively, the firmware is working correctly and this procedureis not necessary. If they are dark, or only D1 is flashing this procedure will reload the firmware

    1. Connect ICD 2 to RJ-11 port on the PICDEM FS USB board.2. Connect USB Cable to ICD 23. Start MPLAB

    4. File | Import (navigate to C:\MCHPFSUSB\fw\_factory_hex\picdemfsusb.hex)

    5. Programmer | Select Programmer | MPLAB ICD 2

    Appendix BReloading demofirmware into PICDEM FS USB

  • 5/25/2018 390_USB v1.10 Student Handout

    32/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    32

    6. Select Programmer | Program

    7. Disconnect ICD 2 cable from PICDEM FS USB board.Board re-enumerates and start blinking LEDS D1 and D2.

  • 5/25/2018 390_USB v1.10 Student Handout

    33/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    33

    Un-installing MCHPFSUSB v1.0 Framework, Drivers & .inf Files:

    1. Manually delete the existing C:\MCHPFSUSBfolder. This will remove any user-createdfiles after the installation.

    2. Run c:\RTC\390_USB\Development Tools\MCHPFSUSB Framework\Super

    Device Manager.bat.

    3. In the Device Manager Console, select ViewShow hidden devices

    4. Under v1.0, installed Generic/Custom & CDC driversare both represented by

    question marks ( ) in Other Devices. Right-click/Uninstall all of the Other

    DevicesPIC18F4550 Family Device and Other DevicesPICDEM FS USB

    Demo Board (C) 2004 as shown:

    Appendix C - Removing MCHPFSUSB v1.0 System Files

  • 5/25/2018 390_USB v1.10 Student Handout

    34/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    34

    5. Deleting the v1.0 .inf files: Open the Windows search tool, StartSearchAll

    Files or Folders. Search for files/folders named oem*.*, containing the text

    PIC18F4550 Family Device (used in mchpusb.inf) and look in

    C:\windows\inf. Now delete all of the oemxx.inffiles found by the search tool.

    Repeat for CDC .inf files (mchpcdc.inf) by searching for files containing the text USB

    RS-232 Emulation Driver

  • 5/25/2018 390_USB v1.10 Student Handout

    35/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    35

    Un-installing MCHPFSUSB v1.2 & v1.3 Installed Drivers:

    1. Run c:\RTC\390_USB\Development Tools\MCHPFSUSB Framework\Super

    Device Manager.bat.

    2. In the Device Manager Console, select ViewShow hidden devices

    3. The installed Genericdrivers are represented by the USB Trident symbol ( ) and

    appear under Custom USB Devices. Right-click/Uninstall all of the Custom USBDevicesMicrochip Custom USB Device as shown:

    Appendix D - Removing MCHPFSUSB v1.2 & v1.3 System Files

  • 5/25/2018 390_USB v1.10 Student Handout

    36/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    36

    4. The installed CDC drivers are represented by the Serial Cable symbol ( ) and appear

    under Ports(COM & LPT). The choice of Communications Port by the Factory

    USB team is unfortunate, in that it also refers to physical RS-232 COM port drivers,which we DO NOT wish to delete. Right-click on each instance of Communications

    Port or Microchip CDC RS-232 Emulation Demo , select Properties and verify that

    it is the emulated COM port Microchip CDC RS-232 Emulation Demo:

    Press OK.

  • 5/25/2018 390_USB v1.10 Student Handout

    37/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    37

    Now it is safe to right-click/Un-install this instance (COM13 in this example) of

    Ports(COM & LPT)Communications Port (COM13) as shown:

  • 5/25/2018 390_USB v1.10 Student Handout

    38/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    38

    5. Un-installing MCHPFSUSB v1.2 & v1.3 Installed .inf files: Open the Windows search

    tool, StartSearchAll Files or Folders. Search for files/folders named

    oem*.*, containing the text Microchip Custom USB Device (used in

    mchpusb.inf) and look in C:\windows\inf. Now delete all of the oemxx.inf

    files found by the search tool. Repeat for CDC .inf files (mchpcdc.inf) by searching for

    files containing the text USB RS-232 Emulation Driver

  • 5/25/2018 390_USB v1.10 Student Handout

    39/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    39

    Step 1: Install Visual C++ Express.

    If you have internet access, installVisual C++ Express.(www.microsoft.com/express/2005)

    If you have the Visual C++ 2005 Express CDROM, insert and Autoplay.

    The link to the .iso image is here:http://msdn2.microsoft.com/en-us/express/aa718401.aspx

    Step 2: Install the Microsoft Platform SDK.

    If you have internet access, install thePlatform SDKover the Web from the Download Center.(http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-

    E4C0C0716ADB&displaylang=en)

    Follow the instructions and install the SDK for the x86 platform.

    If you have the Microsoft Platform SDK 2003 R2 CDROM, insert and Autoplay.

    The link to the .iso image is here:http://www.microsoft.com/downloads/details.aspx?familyid=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=en

    Step 3: Update the corewin_express.vsprops&AppSettings.htmfiles.

    Corrected files have been provided in the class CDROM. Execute the batch file

    C:\RTC\390_USB\Development Tools\Microsoft Visual C++ 2005Express\Install_Visual C++.bat

    Step 4: Launch Visual C++ 2005 Express & Update the Visual C++ directories

    in the Projects and Solutions section in the Options dialog box.

    SelectToolsOptions to display the Options Dialog Box

    Expand the Projects and Solutionssection. Select Visual C++ Directories

    Add the following paths to the appropriate subsection for Platform: Win32:

    Executable files:

    C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin

    Appendix EVisual C++ 2005 Express Installation

    http://www.microsoft.com/express/2005http://www.microsoft.com/express/2005http://www.microsoft.com/express/2005http://www.microsoft.com/express/2005http://www.microsoft.com/express/2005http://www.microsoft.com/express/2005http://msdn2.microsoft.com/en-us/express/aa718401.aspxhttp://msdn2.microsoft.com/en-us/express/aa718401.aspxhttp://msdn2.microsoft.com/en-us/express/aa718401.aspxhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADBhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADBhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADBhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADBhttp://msdn2.microsoft.com/en-us/express/aa718401.aspxhttp://www.microsoft.com/express/2005http://www.microsoft.com/express/2005
  • 5/25/2018 390_USB v1.10 Student Handout

    40/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    40

    Include files:

    C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include

    Library files:

    C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib

    Step 5: Generate and build a 390_USB Win32 application to test your paths.

    FileOpenProject

    C:\RTC\390_USB\Pc\Ex3\Ex3.1_solution\Ex3.1_solution.sln

    BuildBuild Solution (or press F7)

    DebugStart without Debugging (or press ctrl+F5)

    Command 1 should properly display the MPUSBAPI DLL Version, 4 should quit (2, 3 not

    implemented:

    Step 6: Register Visual C++ 2005 Express Edition!

    Your copy of Visual C++ 2005 Express Edition is now valid for 30 days. You must register your

    copy with Microsoft.

    HelpRegister Product

  • 5/25/2018 390_USB v1.10 Student Handout

    41/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    41

    Installing The Beagle12 Data Center GUI and USB Drivers:

    1. The Data Center GUI and USB Driver software are provided in the CDROM that shipswith the Beagle12. They may also be downloaded from the company web-site:

    www.totalphase.com

    2. Insert the CDROM and unzip beagle-gui-win32-v2.11.ziptoC:\Program

    Files\Total Phase\Beagle. This creates a sub-folderbeagle-gui-win32-

    v2.11and a sub-sub folder\helpwhich containsmanual.pdfand

    datasheet.pdf

    3. Create a link toBeagle-GUI.exe on the desktop. Keep the CD in the PC for thenext step (USB Driver installation)

    Hardware Installation & Testing:

    1. Using Cable segment #1 only, connect the Beagle12 data capture USB port to ahigh-speed PC USB port (this is the short white USB cable that comes with the

    analyzer):

    Appendix FInstalling Beagle12

    Beagle 12

    PICDEM FSUSB

    BeagleCapture Port

    (High-

    Speed)

    Cable #1 (short)

    Cable #2 (white)

    Cable #3 (PICDEM USB Cable)

    Self-Powered High-SpeedHUB/Host PC

    (Data Center GUI)

    Fig 1. Beagle12 Connection Diagram(Complete)

    USBSegmentAnalyzed

    (Full-Speed)

    http://www.totalphase.com/http://www.totalphase.com/http://www.totalphase.com/
  • 5/25/2018 390_USB v1.10 Student Handout

    42/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    42

    2. If this is the first time connecting to your PC, Windows will present the Found New

    Hardware Wizard.

    3. Select Install from a list of specific location (Advanced) and click Next

    4. Browse, navigate and select the\drivers\win32directory on the CDROM.Wait for the drivers to be installed.

    5. (Optional) Create a CDROMfolder in C:\Program Files\Total Phase\Beagleand copy the CDROM contents herethis will allow you to re-install the package

    without the CDROM.

    6. Connect cable segment #2 (white) and #3 (PICDEM USB Cable). Assuming youhave mchpusb.sys driver installed and the Demo application programmed into the

    PICDEM FS USB, you should hear a chime, and see LEDs D1/D2 toggling,

    indicating successful enumeration of the PICDEM FS USB.

    Running the Data Center Software:

    Start the Data Center GUI:

    1. Press the Connection button:

  • 5/25/2018 390_USB v1.10 Student Handout

    43/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    43

    2. If your Beagle12 properly enumerated, you should see it. Highlight it, and pressConnect to connect the Data Center GUI to the Beagle12.

    3. Select the USB Transactions window:

  • 5/25/2018 390_USB v1.10 Student Handout

    44/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    44

    4. Make sure PICDEM FS USB is connected to PDFSUSB application and is streamingdata to the PC. Press Capture and capture 1 second of transactions.

    5. Isolate (Filter) all transactions related to the READ POT command by entering 37 *into the Data Pattern field and then pressing Apply Filters:

  • 5/25/2018 390_USB v1.10 Student Handout

    45/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    45

    6. The filtered transactions, only showing the READ_POT transactions are thus filtered:

    You should be able to correlate the displayed pot resistance value in PDFSUSB with the

    READ_POT reply packets above (5volts = 1023 = 0x3FF = 10000 ohms, 2.5volts = 512 =

    0x200 = 5000 ohms, 0volts = 0 = 0x000, 0 ohms)

  • 5/25/2018 390_USB v1.10 Student Handout

    46/46

    Student Handout for 390_USB USB From Scratch

    Microchip Technology Inc. 390_USB v1.10

    46

    A CDC device that contains a serial number string in its descriptor table retains it's COM

    port assignment even if moved to another USB port on the system. A device that doesn'tcontain a Serial Number string gets a new COM port number on each attachment to a

    different USB port.

    Here is how to add a 4-digit (example "1234") serial string to the CDC device descriptortable:

    In usbdsc.c:

    - change the device serial string index from 0x00 --> 0x03

    - add the following serial string structure immediately below the product string index:

    rom struct{byte bLength;byte bDscType;word string[4];}sd003={sizeof(sd003),DSC_STR,'1','2','3','4'};

    - modify the typecast statement for array "USB_SD_Ptr[ ]" to the following:

    rom const unsigned char *rom USB_SD_Ptr[]={

    (rom const unsigned char *rom)&sd000,(rom const unsigned char *rom)&sd001,(rom const unsigned char *rom)&sd002,(rom const unsigned char *rom)&sd003};

    When the PICDEM FS USB enumerates, open UVCView and you should see 1234 as the

    serial number for the board. Open Windows Device Manager and observe that the device will

    retain the same COM port number regardless of the USB port its plugged into.

    Appendix GAdding a Serial Number String to the CDC Project