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.

USB Storage Gadget detecting host plug in

I am using the PSP 3.20.00.14 with my EVMOMAPL137.  My USB port is configured as a file backed storage gadget using g_file_storage.ko using the sd/mmc card (dev/mmcblk0p1) as the backing file.  My application continuously logs information to the SD card.  When a user plugs a host device (Windows) into the usb they need to be able to view (and possibly modify) the contents of the files on the SD card.  It appears that once Windows connects to the backing file, it's state is not updated as Windows does not expect anything other than itself to be making changes to the files.  I have confirmed this by connecting to the gadget, appending to a file's contents with application, and observing no change in the file size on windows.  

This situation requires that my application be able to detect when a host computer connects to the USB port so that I can stop modifying the files and possibly load the file backed storage module if deemed necessary.  Is there a way that my application can be signaled when a host (not a device) connects and disconnects to this port?

  • Nick,

    As you mentioned, SD/MMC should be accessed either only by windows host or the local application. Please make sure that local application completes it read/write to SD/MMC then SD/MMC is unmounted first and then g_file_storage is inserted and then the cable is connected to PC.

    you can monitor the D[3:4] bit of MUSB DEVCTL register which shows the Vbus status. When cable is not connected to PC then these bit will be '00' as Vbus will be 0V and when the cable is connected to PC then value of these bits will be '11' as Vbus will be 5V.

    DEVCTL is at offset of 0x460 from USb base address.

    Regards,

    Ajay

  • At first glance, it appears that this would be the solution to my problem.  But the DEVCTL register is persistently reading as 0x98 (Bits 4:3=11) whether the host is connected ornot.  Even on startup with no host connected, I verified that there was 0V on the VBUS pin, yet DEVCTL was still reading 0x98.  

    cat /proc/devices/musb_hdrc  also shows the port in peripheral mode with DEVCTL as 0x98 regardless of connection status.

    I also noticed another post mentioned the same problem as I am having: http://e2e.ti.com/support/embedded/f/354/p/65332/236033.aspx

    It seems that this may be a legitimate "bug" in the kernel source.  I've recall reading elsewhere that a newer kernel is scheduled to be released for the DA830 near the end of June.   Is this something that I could expect to be resolved?

  • nickb,

    The thread also mentions that after changing the OTGMODE field in CFGCHIP2 register to OTG mode and "not force-peripheral" it works fine. for your use case you can also use

    the other method described in that thread (RESET, SETCONFIG)

    Ajay