• AVR Freaks

Hot!Learning to write PIC USB Host drivers

Author
mhwang
Junior Member
  • Total Posts : 97
  • Reward points : 0
  • Joined: 2006/11/10 14:43:14
  • Location: Los Angeles, CA
  • Status: offline
2011/09/05 22:00:25 (permalink)
0

Learning to write PIC USB Host drivers

Hi, I'm trying to get learn how to write a driver for a USB HID Host device. I've gone through all the application notes and example programs I can find from Microchip, but it gets confusing pretty fast. After looking at the code for the keyboard and mouse examples I still find myself confused about what the overall flow of the program should look like--things like when and where I should call USBTasks(). Does anyone know of any book/document I should read to learn how to write these programs? Trying to dissect the example code has been a frustrating experience.
#1

9 Replies Related Threads

    dagentooboy
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2011/09/04 18:18:01
    • Location: 0
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/06 06:32:47 (permalink)
    0
    I am having the same problem. I have a good open source example of what the driver needs to look like but I am lost as to how to continue with the PIC32. I started with the Generic driver demo and used the USBConfig program and added my VID/PID to the TPL tab and it still says it cannot enumerate device.
    #2
    takataka
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2011/09/06 02:54:53
    • Location: 0
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/06 20:49:54 (permalink)
    0
    Hello,
    I am confused, too.

    I got a PIC32 USB Starter Kit II. I need to get things to work as USB Host, and need to connect USB keyboard.
    I don't know what headers file should be include, what functions should be called.
    I am looking for these information.

    #3
    Aussie Susan
    Super Member
    • Total Posts : 3686
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/07 19:53:42 (permalink)
    0
    The "Microchip Application Library" contains a number of example projects that you can use to learn how to create a USB Host. I found that taking one that "sort of" does what I want and modifying that is a good way to start. There is even a "USB Host-HID-Keyboard" example. Also there aer a couple of application notes (probably the ones referred to by the OP) that show the overall structure and calling sequences that are needed. As for the "USBTasks()" function, call it often (at least once every mSec). I follow the example code structure and place one inside the "while(1)" main program loop. In once of my applications, I also use the Microchip WiFi/TCP stack and I found that I needed to add calls to USBTasks() inside some of the wait loops in that. Susan (Sorry for the bad layout but I can't correct it)
    #4
    dagentooboy
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2011/09/04 18:18:01
    • Location: 0
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/08 05:27:54 (permalink)
    0
    I am trying to interface with a Cannon camera. I haven't found any examples that even come close.
    #5
    takataka
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2011/09/06 02:54:53
    • Location: 0
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/08 18:45:30 (permalink)
    0
    Hi, Susan. Thanks very much!

    I examine "USB Host - HID - Keyboard" in example codes, and I am beginning to understand slowly.

    USBInitialize() should be called.
    USBTasks() should be called in while loop.
    App_Detect_Device() is called in while loop, which calls USBHostHID_ApiDeviceDetect(), and which is USBHostHIDDeviceDetect().
    The suitable functions is called by the state of variable 'App_State_Keyboard'.

    I will try to modify that code for my application.

    #6
    mhwang
    Junior Member
    • Total Posts : 97
    • Reward points : 0
    • Joined: 2006/11/10 14:43:14
    • Location: Los Angeles, CA
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/10 19:17:46 (permalink)
    0
    In the USB Host mouse demo, there's a while(1) loop.  Sometimes USBTasks() is called inside the case structures--in the DEVICE_NOT_CONNECTED case it's called at the beginning, and in the GET_INPUT_REPORT case it's called at the end.  What's the purpose of calling the function at the locations?  These are the kinds of things that really confuse me.  I don't know where other people learned to write these drivers, but given the lack of documentation, there must be some real pros out there.
            while(1)
            {
                USBTasks();
                App_Detect_Device();
                switch(App_State_Mouse)
                {
                    case DEVICE_NOT_CONNECTED:
                                 USBTasks();
                                 ...
                        break;
                    case DEVICE_CONNECTED:
                                 ...
                        break;
                    case READY_TO_TX_RX_REPORT:
                                  ...
                        break;
                    case GET_INPUT_REPORT:
                                ...
                                USBTasks();
                        break;
                    case INPUT_REPORT_PENDING:
                                ...
                        break;
                   case ERROR_REPORTED:
                        break;
                    default:
                        break;
                }
            }
     
    #7
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2011/09/12 08:52:35 (permalink)
    0

    Sometimes USBTasks() is called inside the case structures--in the DEVICE_NOT_CONNECTED case it's called at the beginning, and in the GET_INPUT_REPORT case it's called at the end.  What's the purpose of calling the function at the locations?

    These calls are just redundant wink

    but given the lack of documentation

    With quick look, I believe this app note is still fine to know the outline of the host stack. (Though I haven't read it until now Smile)

    AN1141: USB Embedded Host Stack Programmerís Guide
    http://ww1.microchip.com/...en/AppNotes/01141a.pdf

    Also, the help file gives you more details.
    C:\Microchip Solutions v2011-07-14\Microchip\Help\MCHPFSUSB Library Help.chm
    - Embedded Host section

    Tsuneo
    #8
    Tom700
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2020/03/25 03:25:36
    • Location: 0
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2020/03/26 02:33:36 (permalink)
    0
    Hi Guys,
     
    Have you succeeded with you HID host? How Does it work?
    I'm looking at PIC32MM0064GPM028 to make a HID Host to interface a USB barcode reader to uC via USART.
    I wonder if the above pic has enough flash to handle this?
     
    best regards
    Tom 
    #9
    Aussie Susan
    Super Member
    • Total Posts : 3686
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re:Learning to write PIC USB Host drivers 2020/03/26 18:48:38 (permalink)
    0
    You are tapping in to a thread that is nearly 9 years old.
    I would suggest that you start a new thread, describe what you are trying to do, what works, what doesn't and what you have tried to do to fix the issue.
    Susan
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5