• AVR Freaks

Hot!SOLVED - Harmony v2.06 USB Auto Attach Not Attaching

Author
laffelt
Super Member
  • Total Posts : 143
  • Reward points : 0
  • Joined: 2008/05/08 18:05:53
  • Location: 0
  • Status: offline
2019/09/26 07:43:14 (permalink)
0

SOLVED - Harmony v2.06 USB Auto Attach Not Attaching

I am using Harmony v2.06, XC32 v2.10, and PIC32MZ2048EFG064 to provide an auto-mounting USB host for flash drives. Previous to this project I had immediate success with Harmony v1.09 and PIC32MZ2048EFH144 to provide the exact same feature. This time around my callback function to detect the attach or detach function is never being called. I have attached images of my Harmony configuration for the USB port and file system, they are identical to what was used in v1.09 as far as I can tell. Note: I am not a USB expert! This is the first time I have dived this deep into how it works :-)
 
Here is my initialization code and the two call back functions straight from the previous successful code which also is exactly the same as shown in the v2.06 examples:
 

During my initialization:

    SYS_FS_EventHandlerSet(mySYSFSEventHandler, (uintptr_t) NULL);
    USB_HOST_EventHandlerSet(myUSBHostEventHandler, 0);
    USB_HOST_BusEnable(0);
    sysState.driveMounted = FALSE;
 
 
Further into the main code are the two event handlers:
 
USB_HOST_EVENT_RESPONSE myUSBHostEventHandler(USB_HOST_EVENT event, void * eventData, uintptr_t context)
{
    switch (event)
    {
        case USB_HOST_EVENT_DEVICE_UNSUPPORTED:
            break;
        default:
            break;

    }

    return (USB_HOST_EVENT_RESPONSE_NONE);
}

void mySYSFSEventHandler(SYS_FS_EVENT event, void * eventData, uintptr_t context)
{
    switch (event)
    {
        case SYS_FS_EVENT_MOUNT:
            BEEP_Start(DOUBLE_CHIRP);
            sysState.driveMounted = TRUE;
            sysState.updateScreen = TRUE;
            break;

        case SYS_FS_EVENT_UNMOUNT:
            BEEP_Start(DOUBLE_CHIRP);
            sysState.driveMounted = FALSE;
            sysState.updateScreen = TRUE;
            break;

        default:
            break;
    }
}

 
The mySYSFSEventHandler is never called so I started looking at the USB registers in debug mode. When the drive is inserted into the USB port I see changes in the USBOTG SFR, bit HOSTMODE becomes set as does FSDEV. The SESSION bit is always set along with VBUS set to 3. This indicated to me that the system is recognizing that a full speed device was inserted and that we are in host mode, exactly as expected.
So I started stepping thru the task calls and found that the system is constantly in a debounce state and the timer never times out. Here is some pseudo-code of the functions called and state values:

 
SYS_Tasks();
{
    ...
    DRV_USBHS_Tasks(sysObj.drvUSBObject);
    {
         ...
         switch(hDriver->usbDrvCommonObj.state)
         {
              ...
              case DRV_USBHS_TASK_STATE_RUNNING:
              ...
                  else if ( ((DRV_USBHS_OPMODE_DUAL_ROLE == hDriver->usbDrvCommonObj.operationMode) &&
                            (hDriver->usbDrvCommonObj.isHostRoleActive)) ||
                  (DRV_USBHS_OPMODE_HOST == hDriver->usbDrvCommonObj.operationMode) )
                 {
                        _DRV_USBHS_HOST_ATTACH_DETACH_STATE_MACHINE(hDriver);
                        // actually _DRV_USBHS_HOST_AttachDetachStateMachine()
                       {
 
                            ...
                            switch(hDriver->usbDrvHostObj.attachState)
                            {
                                 ...
                                 case DRV_USBHS_HOST_ATTACH_STATE_DEBOUNCING:
                                 if(hDriver->usbDrvHostObj.timerExpired) // fails all the time!
 


 
So the system is running, trying to attach the drive, but is constantly in a debounce state as hDriver->usbDrvHostObj.timerExpired is never set to TRUE
 
Sorry for the long windedness! If anyone has seen this or can help it would be greatly appreciated!
 
post edited by laffelt - 2019/10/29 12:33:26

Attached Image(s)

#1

12 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 512
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/27 05:19:49 (permalink)
    0
    Is this first attach attach failing or attach failing after a dismount?
    - Check you have plenty of heap. Heap in some demos was only 500, but found heap 10K or more needed for reliable USB and filesystem.
    - Haven't been able to get a clear number for what heap should be in Harmony. Wish Harmony had a heap calculator.
    - Ensure well over 100uF on USB 5V (I use a 6V 150uF ceramic cap). If not enough then some flash drives will fail (they all draw different initialization and run currents).
    - Try different USB sticks (different brand, different size, new/old, etc.)
    - Check the chip's errata for the fine print
    - Ensure USBID pin is properly driven, can't be unassigned.
    - Consider updating. I'm using: MPLABXv525, XC32v230, HarmonyV206, MHCPluginV2060. Read the release notes for each version from yours to latest to ensure anything that might affect you is covered.
    - Try to enable diag output from the Harmony and library code as it can offer clues (I haven't been able to make this work but others say it can really help with harmony and library issues).
     
    Post your results to above, it will help resolve issue.
    Paul
     
    #2
    laffelt
    Super Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2008/05/08 18:05:53
    • Location: 0
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/27 06:29:45 (permalink)
    0
    Paul,
     
    Thanks for your reply!
     
    - Every attach is failing, never attaches at all
    - Heap is 4096, I will try higher
    - I have a 100uF/6.3V, ill put a scope on it to check it. VBUS bits are set to 3 but it might be dancing and Im not seeing it.
    - Good idea, I will try others
    - USBID is grounded, we only do Host mode.
    - Interesting idea, IDE might be an issue with the MHC plugin ... 
    - Never heard of this, where is it?
     
    I'll report back later
    #3
    JPortici
    Super Member
    • Total Posts : 820
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/27 08:13:34 (permalink)
    0
    Do you have access to a microchip demo board? I'm sure there is an example targeting the MZ.
    Otherwise you can adapt the example to match your hardware
     
    Another solution, i had all sorts of issues with harmony 2 and usb.. But i can tell you for certain that the usb MSD driver in harmony 3 is working for PIC32MZ and MK.
     
    #4
    Paul PortSol
    Super Member
    • Total Posts : 512
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/27 09:42:48 (permalink)
    0
    - Also VBUS monitor pin (Pin 73 of 144pin) should be connected by 100ohm to USB 5V pin.
    - VBUS Power (Pin74 of 144pin) should be connected to 3V3
    - If using TPS2051 check the exact part number, some have active High, others have active low outputs.
    - Add a parallel 100nF to your 100uF (for high frequency noise/response)
    - Try a different PCB (sometimes on the bench things can get zapped, ESD and such, sometimes recover with time but board probably never again reliable enough for field installation)
     
    #5
    nigelwright7557
    Super Member
    • Total Posts : 308
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/27 09:53:30 (permalink)
    0
    I changed one of my projects from Harmony 2.04 to the newer Harmony 2.06.
    I found it worked great.
    However if I closed down the pc program for more than 5 seconds then went back in the PIC stopped replying to the PC.
    I was advised to go back to Harmony 2.04 and that fixed it.
     
    #6
    Paul PortSol
    Super Member
    • Total Posts : 512
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/30 04:15:49 (permalink)
    0
    nigelwright7557,
    Did you ever compare the v2.04 and v2.06 to see if you could spot where the problem was in v2.06?
     
    (If it is a generated file you can patch it and set read-only so it doesn't get overwritten by MHC, I had to do that with the ADC for PIC32MZ because MHC keeps loosing ADC settings for PIC32MZ in v2.06)
    Paul
    #7
    laffelt
    Super Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2008/05/08 18:05:53
    • Location: 0
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/30 08:19:14 (permalink)
    0
    Thanks for all the feedback!
     
    I am close to the production release on the product, I can't afford the time to go up to Harmony 3 but I do have it installed and ready for use. 
     
    - VBUS is connected directly to the VBUS on the USB connector, no 100 ohm resistor, VBUS is current controlled by a TPS2553 with the current limit set to 175mA. Enable line is positive true and tied to 5V
    - I have a 100uF on VBUS, I will can more capacitance but will try other things first
    - I have put a fast scope on the VBUS and it is solid +5V, and the VBUS bits in USBOTG are set to 3 (0b11) so the chip says the VBUS is above the minimum threshold.
    - VUSB3V3 is connected to 3.3V.
     
    This design is identical to what worked in Harmony V1.09 with MZ parts, I am guessing that there might be issues with v2.06 and will try to use V2.04. I will also try another board as I have more proto's to work with.
     
    Thanks Everyone!
    #8
    laffelt
    Super Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2008/05/08 18:05:53
    • Location: 0
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/09/30 08:21:25 (permalink)
    0
    And I have checked the errata (usually close to #1 thing I do) and the only USB items have to do with Suspend and Resume operation. this port is on full power all the time so users can plug a flash drive in at any time.
     
    Larry
     
    #9
    Paul PortSol
    Super Member
    • Total Posts : 512
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/10/01 04:28:08 (permalink)
    0
    a1) Try loading your old V1.09 code to see it still works on new board, that will show if its V2.06 or Hardware issue.
    a2) Try your v2.06 code on the known good v1.09 board.
    b1) use MHC to generate a simple USB Host example, see bottom option in [MHC_CreatingProjectWithoutBSP_v00PR.txt]. 
    b2) If it works compare the minimal project to your project, maybe a bit of code got broke, or an MHC setting got mixed up. (I use "beyond compare").
    c) Post your USB & PIC portion of your schematic (Including all 6 USB pins on PIC)
    * Future: Recommend adding the 100ohm on VBUS.
    d) Check the MHC Pin Settings for *All USB Pins, including unused pins*, and especially USBID pin.
     
    Here is the Microchip Reply to my ticket on USBID pin in PIC32MZ:
    /////////////////////////////
    I set-up hardware for this and made some testings for both device mode and host mode applications and below are my findings:

    Host Mode:

    Test 1:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 0; //setup RF3 as output
    LATFbits.LATF3 = 1; //set to High
    Result: USB Module is NOT working as Host.

    Test 2:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 0; //setup RF3 as output
    LATFbits.LATF3 = 0; //set to Low
    Result: USB Module is working as Host.

    Test 3:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 1; //setup RF3 as input
    Add 10K pull-up resistor to RF3 to VDD
    Result: USB Module is NOT working as Host.

    Test 4:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 1; //setup RF3 as input
    Add 10K pull-down resistor to RF3 to GND
    Result: USB Module is working as Host.


    Device Mode:

    Test 1:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 0; //setup RF3 as output
    LATFbits.LATF3 = 1; //set to High
    Result: USB Module is working as device.

    Test 2:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 0; //setup RF3 as output
    LATFbits.LATF3 = 0; //set to Low
    Result: USB Module is NOT working as device.

    Test 3:
    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 1; //setup RF3 as input
    Add 10K pull-up resistor to RF3 to VDD
    Result: USB Module is working as device.

    #pragma config FUSBIDIO = OFF
    TRISFbits.TRISF3 = 1; //setup RF3 as input
    Add 10K pull-down resistor to RF3 to GND
    Result: USB Module is NOT working as device.

    Based on the testings above, if the USB module is enabled, even if the USBID is disabled in the configuration bits, since the USB module is enabled, it still being sampled by the USB module. If the USBID pin is Low, it indicates Host mode, if High it is Device mode. This was specified in PIC32 Family Reference Manual under section 51.2 (http://ww1.microchip.com/downloads/en/DeviceDoc/61232A.pdf).
    With this, if the USB Module is enabled and used in the application, the RF3 cannot be used as GPIO alone, because it is still being sampled to detect if the USB module will function as a host or device.
    I will inform the business unit team about this so as to include this in our documentations.

    Note that the PIC32MZ EF family of parts have shared functionality between the USBID and RF3 pins.
    In general, our recommendation for users is to tie VUSB3V3 to VSS (ground) when the USB functionality is not going to be used. But, if VUSB3V3 is tied to VSS, then the shared functionality of the USBID pin is lost. In order to have access to RF3 as an I/O pin, VUSB3V3 will need to be tied to VDD, thus increasing the power consumption of the device but allow the pin to be used as a general I/O pin.


    Best Regards,
    /////////////////////////////
     
     
    #10
    Paul PortSol
    Super Member
    • Total Posts : 512
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/10/01 04:33:28 (permalink)
    0
    See options in attached [MHC_CreatingProjectWithoutBSP_v00PR.txt]
    #11
    laffelt
    Super Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2008/05/08 18:05:53
    • Location: 0
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/10/11 06:13:05 (permalink)
    0
    To All,
     
    I finally found the problem after purchasing a demo board and running the USB example. The USB stack uses a timer to proceed through its state machines and it takes the first timer available with no indication in Harmony that this timer configuration must not be changed. It would have been more obvious if the code used one of the timers well down the list but unfortunately it took the first timer available. I was using that timer for my basic core timing interrupt which caused all the problems. Once I used the next 16 bit timer down in the list everything works perfectly. There was no issues with the hardware as I expected based on previous functional designs.
     
    Thanks for all your input!
     
    Larry
    #12
    nigelwright7557
    Super Member
    • Total Posts : 308
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: offline
    Re: Harmony v2.06 USB Auto Attach Not Attaching 2019/10/11 22:06:22 (permalink)
    0
    I had problems with 2.06 when I exited the pc USB program and re-entered after at least 5 seconds.
    The PIC would no longer talk to the pc.
    I was advised to go back to 2.04 and then it worked fine.
     
    Some of my customers said the PIC USB wasn't attaching after a new install of the PC program.
    We found in the end they had to boot up pc with PIC USB attached and the pc then found it ok.
     
     
     
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5