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.

Starterware/AM3352: Mentor USB controller documentation

Part Number: AM3352

Tool/software: Starterware

Hi,

I need to get the full documentation of mentor usb OTG controller to find all the registers. 

Can anybody put me on the path to get this doc? 

Thank you. 

  • Access to this documentation is highly restricted. Could you please outline your need for it?
  • I am working on a project which is to transfer an old embedded linux system/applications to the latest linux with different hardware framework. We want to change the system at least as possible.
    The old system emulates 3 peripherals, i.e. keyboard, mouse and mass storage, from user space, built as a module, and insmod the module after linux kernel start up. The way to control and read/write data is directly through Registers and PHY address, without using any lib API. The interrupts on peripheral USB endpoints, e.g. SETUP, DATAIN and DATAOUT, is also bound with some other applications operation. I read gadget driver examples. But I haven't figured out how to create a gadget driver and make it cooperate with the applications.
    So if I can access the registers and know how to read/write to endpoints, I can keep the structure to the most extent.
  • On the top of your post, it says "Tool/software: Starterware", but later you mentioned you are migrating from an older linux system to the latest Linux. What is exactly the OS you use? If Linux, what is the older kernel version? and what is the newer version?
  • I am working on am3352, testing with starter kit, developing with sdk 3.3.0.4, and I posted some questions on how to access some registers. Hence I choose the tool/software Starterware again.
    The old version is 2.4.25, and newer version is 4.4.41.

    The old arch is powerpc. 

  • I strongly recommend you to not go that route - implementing your own usb driver to directly access usb controller in Linux kernel. The source code you have on the previous powerpc platform doesn't help you much for implementing the similar functions on AM3352, because they use different usb controllers. It would take you much longer time to get it working than leverage the existing gadget drivers provided in Linux kernel.

    The Linux kernel already provides some usb gadget drivers, including HID and mass_storage. The mass_storage gadget is ready to use, you only need to provide the backend storage through module parameters. For the HID gadget, you would have to implement a simple userspace application to feed in the input data. Kernel documentation has an example showing how to do it.

    Then you just need enable kernel usb configfs to combine both together to make a composite gadget driver, including both HID and mass_storage functions.
  • Thank you, Bin.
    But I have nearly no knowledge of kernel drivers, including how to bind my emulation devices with a gadget driver, how to config parameters, etc. I am having a hard time researching it. Compared with jump into the sea of kernel drivers, and limited by project deadline, seeking for registers in new usb controllers and follow the old structures and logics seems easier for me.
  • I understand that you are not comfortable with Linux kernel, but I also don't see how you can finish the project just with the AM335x USB controller Mentor documentation with your previous powerpc system. there is no one-to-one register mapping between different usb controllers, you cannot just replace the register offsets in MUSB into your powerpc platform, the usb controller will not simply work.
  • Hi Bin,

    Can I use gadgetfs to achieve my goal? Looks like gadgetfs is more simple than sub gadget driver.

    Is it possible to add control functions in gadgetfs to process messages sent from other application? I found the description in usb.c

    - First, dev_config() is called when /dev/gadget/$CHIP is configured

    + *   (by writing configuration and device descriptors).  Afterwards it

    + *   may serve as a source of device events, used to handle all control

    + *   requests other than basic enumeration.

    So, after config /dev/gadget/$CHIP, other application can send control message to the file descriptor of /dev/gadget/$CHIP.  Is it correct?

    Also, could you tell me how to set up fifo and DMA while using gadgetfs?

    Thank you.

  • yingjie gu said:
    Can I use gadgetfs to achieve my goal? Looks like gadgetfs is more simple than sub gadget driver.

    I am not sure what "sub gadget driver" is, but usb gadgetfs should work for your goal. But I believe usb configfs is even simpler for you, unless your HID and mass_storage functions are customized, so that the HID and mass_storage gadget drivers provided in the Linux kernel do not meet your requirement.

    yingjie gu said:
    Is it possible to add control functions in gadgetfs to process messages sent from other application? I found the description in usb.c

    There are many usb.c files in the kernel, I am not sure which one you looked at, but you should be able to add control functions in gadgetfs, since you will have to implement the whole gadget driver using gadgetfs.

    yingjie gu said:
    Also, could you tell me how to set up fifo and DMA while using gadgetfs?

    No matter you use gadgetfs or configfs, you don't have to worry about usb fifo and DMA, those are already handled by the usb controller driver. 

  • Hi Bin,

    I have tried gadgetfs and configfs on my starter kit. There is only one USB Micro B connection on board, which I also used as a UART connection for booting. I used configfs creates hid device on /dev/hidg0 .  When I tried to write to /dev/hidg0, sometimes I got return value of 0 from write(fd, bug,len) .  But most of the time, the system hang there. Similar thing happened for gadgetfs.  The following is my configfs commands and writing usb file is also attached.  The select() always returns 1, and /dev/hidg0 file descriptor is ready. I know I should write a real kbd report to this ep. But for simplicity, I only write a small buf to it.  

    Could you help to find out what's the problem? Is it related to the fact that the only Micro B is converted to UART through a hub?

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# echo "0x1234" >idVendor

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# echo "0x5678" >idProduct

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# mkdir strings/0x409

    root@m335x-evm:/sys/kernel/config/usb_gadget/g1# echo "foo1" >strings/0x409/maufacturer

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# echo "foo2" >strings/0x409/product

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# echo "foo3" >strings/0x409/seiialnumber

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# mkdir configs/c.1

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# mkdir configs/c.1/strings/0x409

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# mkdir functions/hid.kbd

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# ln -s functions/hid.kbd/ configs/c.1

    root@am335x-evm:/sys/kernel/config/usb_gadget/g1# echo "musb-hdrc.0.auto" > UDC

    #include <fcntl.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    
    #define NAME "/dev/hidg0"
    
    int main(void)
    {
    	int fd;
    	int status;
    	char buf[4]={'1','2','3','\0'};
    	fd_set rfds;
    	int retval;
    	
            fd=open(NAME, O_RDWR,0666);
    
    	//fd=open(NAME, O_RDWR);
    
            FD_ZERO(&rfds);
            FD_SET(STDIN_FILENO, &rfds);
            FD_SET(fd, &rfds);
    	int i = 2;
    	while(i){
    		retval = select(fd+1,&rfds,NULL,NULL,NULL);
    		if(retval == -1)
    		{
    			i--;
    			fprintf(stderr,"retval=-1\n");
    			continue;
    		}
    		else if(retval >0){
    
    			break;
    		}
    	}
    	if(!i && (retval == -1)){
    		fprintf(stderr, "fd not ready\n");
    		close(fd);
    		return -1;
    	}
    
    	if(FD_ISSET(fd, &rfds)){
    		status = write (fd,buf,3);
    		fprintf(stderr, "write to %s = %d\n",NAME,status);
    		if(status<0){
    			close(fd);
    			return -1;
    		}
    	}
    	close(fd);
    	return 0;
    }
    

  • Have you followed the kernel doc Documentation/usb/gadget_hid.txt to patch the kernel driver then test it with the hid_gadget_test application?

  • Yes, I followed /Documentation/usb/gadget_hid.txt to implement configfs. I didn't find the hid_gadget_test application, so I copied the example codes of hid_gadget_test from this file and create my own tempwrite.c  

    On my Starter Kit, I can see /dev/hidgX is created. But on my booting PC where the Starter Kit connected to via usb cable,  no usb devices is enumerated, , except for ttyUSB0 and ttyUSB1. I checked before and after unplugged/ replugged the usb cable after enable/config  configfs. 

  • gadget_hid.txt doesn't talk about configfs. The most important part is you have to patch the kernel gadget hid driver as in the documentation to tell what hid device it is. It is all documented in gadget_hid.txt.

    hid_gadget_test source code is in gadget_hid.txt, you have done it correctly. But don't modify it at first, use it as is to ensure you have correct foundation before start your own development.

    To just use hid gadget, you can first not use configfs, just use command 'modprobe g_hid' to load the hid gadget driver. Then run hid_gadget_test on the board, connecting to the host PC, it should enumerate it as a input device - keyboard.
  • Hi Bin,

    I found out why it doesn't work. the attributes in functions/hid.kbd/ must be set before  UDC is linked to musb-hdrc.0.auto.

    Now I can type it on SK and shown on my host PC.

    I have one more question, hope you can give me some idea. 

    If I need to do a USB softreset by setting USB register, do I have to remove configfs gadget before setting it and re-create configfs gadget after it? Or in other words, does USB softreset affect the already in-effect configfs gadget functionality? 

  • yingjie gu said:
    I found out why it doesn't work. the attributes in functions/hid.kbd/ must be set before  UDC is linked to musb-hdrc.0.auto.

    Glad you solved the issue. Yes, linking to the UDC has to be the very last step.

    yingjie gu said:
    Or in other words, does USB softreset affect the already in-effect configfs gadget functionality? 

    I never tried it with configfs, but with the legacy usb gadget drivers, I found each usb controller has different behavior (caused by the different controller driver design I guess) - some require re-load the gadget driver, some don't.

    But I don't remember how the musb controller on AM335x behaves. Please give it a test and let me know how it goes. But I am sure you don't have to "re-create" the configfs gadget, "unlink from UDC, do softreset, then link to UDC again" should be sufficient.

  • I haven't had my own customized board running yet, and I will test the USB softreset after it's done. 

    I am trying to emulate HID and mass-storage by configfs. HID is working. But mass-storage has problem being emulated. 

    I plugged in a USB disk on Starter Kit, and it's listed as /dev/sdb  /dev/sdb1

    When run g_mass_storage directly with following attributes

     #modprobe g_mass_storage idVendor=0x1234 idProduct=0x5678 iManufacturer=gyjm iProduct=gyjp iSerialNumber=gyjs file=/dev/sdb1 stall=0 removable=1

    'dmesg' on Starter Kit shows:

    root@am335x-evm:/sys/kernel/config/usb_gadget# dmesg -T 

    [Fri Oct 27 19:37:20 2017] Mass Storage Function, version: 2009/09/11

    [Fri Oct 27 19:37:20 2017] LUN: removable file: (no medium)

    [Fri Oct 27 19:37:20 2017] LUN: removable file: /dev/sdb1

    [Fri Oct 27 19:37:20 2017] Number of LUNs=1

    [Fri Oct 27 19:37:20 2017] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11

    [Fri Oct 27 19:37:20 2017] g_mass_storage gadget: g_mass_storage ready

    [Fri Oct 27 19:37:21 2017] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage

    And my PC reports: The disk you inserted was not readable by this computer.  But anyway, it's enumerated.

    Then I configfs mass-storage with steps I believe is correct. HID is enumerated, but mass-storage is not. The following is a mass-storage related configuration. 

    #mkdir functions/mass_storage.1

    #echo 0 > functions/mass_storage.1/stall

    #echo /dev/sdb1 > functions/mass_storage.1/lun.0/file

    #echo 1 > functions/mass_storage.1/lun.0/removable

    #ln -s functions/mass_storage.1 configs/c.1

    #echo musb-hdrc.0.auto > UDC

    I got the following dmesg:

    [Fri Oct 27 19:08:25 2017] Mass Storage Function, version: 2009/09/11

    [Fri Oct 27 19:08:25 2017] LUN: removable file: (no medium)

    file is 'no medium'. I am not sure whether this is cause of the failure of enumeration.  On PC, dmesg shows no mass-storage.

    Do you have any idea of this problem?

  • yingjie gu said:

    [Fri Oct 27 19:37:20 2017] LUN: removable file: (no medium)

    [Fri Oct 27 19:37:20 2017] LUN: removable file: /dev/sdb1

    This message is normal, it is just how the driver works in two stages.

    yingjie gu said:

    [Fri Oct 27 19:37:20 2017] LUN: removable file: /dev/sdb1

    ...

    And my PC reports: The disk you inserted was not readable by this computer.

    PC cannot read it that is because PC expects the usb disk should have MBR, but /dev/sdb1 doesn't have it, it is just a partition. I believe PC should be able read it if you use 'file=/dev/sdb' instead.

    yingjie gu said:
    Then I configfs mass-storage with steps I believe is correct. HID is enumerated, but mass-storage is not. The following is a mass-storage related configuration. 

    Is the PC Windows or Linux? It doesn't surprise me if you use Windows PC.

    But if you use Linux PC and you believe you use configfs correctly, you have to look at the enumeration logs on the PC to figure out what goes wrong.

  • I am using OSX. After changing to /dev/sdb, OSX can enumerate the storage, although somehow it makes my Virtualbox crash.

    When I try to bypass OSX and make configfs gadget being enumerated directly by Virtualbox Linux, kbd/ms is ok, storage is still not enumerated. But this is not an urgent problem.

    There is one more question. Please help to take a look.
    I use USB0 as USB peripheral, and need to, in kernel mode, disconnect USB0 from USBSS and reconnect it after specific time upon my application requirements. The TRM shows a register for USB0 softreset, but it doesn't fit my need as I can't control when the USB0 is reconnected.

    In user space, I called system("echo ' ' > UDC") to disconnect USB0. But in kernel module, it's not recommended to do so.

    How can I disconnect and reconnect USB0 as I wish in kernel mode while using configfs?
    Thanks a lot.
  • What do you mean in kernel mode?
    Applications are all user space focused, where all the requirements go to. Why you cannot disconnect from user space? How kernel receives the disconnect/reconnect events in your application. The kernel usb driver doesn't provide an interface to disconnect if you don't want to achieve it via configfs or sysfs.