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.
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.
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.
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.
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.
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.