cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Explorer
Explorer
3,289 Views
Registered: ‎07-05-2017

can't make FPGA into a USB Storage gadget device Petalinux 2017.3

Jump to solution
Attempting to make the FPGA work like a USB storage device. I followed the link:
 
 
The Section is under 
Peripheral Mode Kernel Configuration
 Did all the device tree and Kernel configurations and build an image. first of all, I'm missing the configfs.ko module in my build, even though I followed the kernel configuration options described in the link above.
I executed all the commands described in the Peripheral Mode.
 
Here below are the commands I typed in Zedboard build. I'm using Petalinux 2017.3.
 
Has anything change in the process?
 
Steps for mounting the sdcard for accessing the compiled modules
zynq> mount /dev/mmcblk0p1 /mnt

Install the following modules
zynq> insmod /mnt/configfs.ko   --- Thiis file does not exist
zynq> insmod /mnt/libcomposite.ko
zynq> insmod /mnt/usb_f_mass_storage.ko

zynq> dd if=/dev/zero of=/tmp/mydev count=10 bs=1M
zynq> mount -t configfs none /sys/kernel/config
zynq> cd /sys/kernel/config/usb_gadget
zynq> mkdir g1
zynq> cd g1
zynq> echo "64" > bMaxPacketSize0
zynq> echo "0x200" > bcdUSB
zynq> echo "0x100" > bcdDevice
zynq> echo "0x03FD" > idVendor
zynq> echo "0x0500" > idProduct
zynq> mkdir functions/mass_storage.ms0
Number of LUNs=8
Mass Storage Function, version: 2009/09/11
LUN: removable file: (no medium)
zynq> mkdir configs/c1.1
zynq> echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file
zynq> echo 1 > functions/mass_storage.ms0/lun.0/removable
zynq> ln -s functions/mass_storage.ms0 configs/c1.1/
zynq> echo "ci_hdrc.0" > UDC  -- get an error here
 
I get an error on the last command
echo "ci_hdrc.0" > UDC
-sh: echo: Write error: No Such device
  
In Zedboard, there is a  /sys/class/udc  
 
Can someone point to what I'm doing wrong?
 
Thanks,
0 Kudos
Reply
1 Solution

Accepted Solutions
Explorer
Explorer
3,414 Views
Registered: ‎07-05-2017

Hi Aravindb,

 

After many trials and errors, this is what seems to work for me on the  Zedboard with Zynq XC7Z020-1CLG484C using 2017.3 petalinux.

 

Device Tree modification

Screenshot from 2018-05-22 10-11-17.png

 

Kernel menu configuration:

Screenshot from 2018-05-22 09-51-16.png

 

Screenshot from 2018-05-22 10-01-41.png

 

after doing:

>petalinux-build

>petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/spi_design_1_wrapper.bit --pmufw images/linux/u-boot.elf --u-boot

 

Boot the Petalinux on my Target FPGA.

 

Screenshot from 2018-05-22 10-03-51.png

 

 

Then I had to create a disk drive directory:

 

cd /tmp

mkdir <my_disk_drive>

mount -a -t msdos /tmp/mydev  /tm/<my_disk_drive>

Screenshot from 2018-05-22 10-05-01.png

 

 

Plugged the micro-USB to FPGA target board USB port and the USB Type-A to windows. I see the removable storage drive of 128 megabytes. I formated it and copied files back and forth to it. Now I am in process of writing file operations in C program to create, open,  write, read, and close files on both sides of the interfaces (Linux and Windows).

 

Thanks!

 

 

 

 

 

View solution in original post

0 Kudos
Reply
6 Replies
Moderator
Moderator
3,224 Views
Registered: ‎02-07-2018

Hi ,

 

You can try below steps for peripheral mode.

 

2.petalinux-config –c kernel

 

  1. Device Drivers  ---> [*] USB support  ---> <*>   USB Gadget Support  ---> <M>   USB functions configurable through configfs (Change this as M)

                                                                                                                     --> <M>     Gadget Filesystem (Change this as M)

                                                                                                                              

  1. File systems -->Pseudo filesystems --> {M} Userspace-driven configuration filesystem (Change this as M)

 

Please add below change in this dtsi file: project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi  for peripheral mode.

 

/include/ "system-conf.dtsi"

/ {

};

&usb0 {

    status = "okay";

};

 

&dwc3_0 {

    status = "okay";

    dr_mode = "peripheral";

};

 

petalinux-build

petalinux-package --boot --fsbl images/linux/zynqmp_fsbl.elf --fpga images/linux/design_1_wrapper.bit --pmufw images/linux/pmufw.elf --u-boot

 

Inserting module in sequence:

 

 cd lib/modules/4.9.0-xilinx-v2017.3/

     cd kernel/fs/configfs/

     modprobe  configfs.ko

 

    cd ../..

     cd drivers/usb/gadget

     modprobe libcomposite.ko

 

     cd function/

    insmod usb_f_mass_storage.ko

 

     cd ../legacy/

 

    insmod gadgetfs.ko

 

     dd if=/dev/zero of=/tmp/mydev count=256 bs=1M

     insmod g_mass_storage.ko file=/tmp/mydev removable=1

 

after this step connect the USB male to male cable between target USB port and host USB port, it will detect as a USB drive.

 

Thanks & regards

Aravind

 

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

 

 

0 Kudos
Reply
Explorer
Explorer
3,209 Views
Registered: ‎07-05-2017

Hi Aravind,

 

Thanks for your response:

 

1. Kernel configuration, I followed your suggestion, but I could not change the

File systems --> Pseudo filesystme -- {M} Userspace-driven configuration filesystem  (to M)  it is stuck to -*- 

 

-*- Userspace-driven configuration filesystem

No matter what I typeed can't get rid of the -*- and change it to [M].

See image below.

Screenshot from 2018-05-10 14-36-06.png

 

2. Changing the dtsi file in <petalinux_proj>/meta-user/recipes-bsp/device-tree/files/system-user.dtsi gives build errors. Here was the original system-user.dtsi

 

Screenshot from 2018-05-10 14-41-00.png

 

 

Here are the suggested change to system-user.dtsi

 

Screenshot from 2018-05-10 14-43-12.png

 

Petalinux-build gives  device tree errors: See image below

 

Screenshot from 2018-05-10 14-50-27.png

 

I re- modified the system-user.dtsi to this: Let me know if this is okay.

Screenshot from 2018-05-10 14-55-10.png

Petalinux-build  (based on above system-user.dtsi)

Screenshot from 2018-05-10 14-59-53.png

 

3. petalinux-package --boot --fsbl images/linux/zynqmp_fsbl.elf --fpga images/linux/design_1_wrapper.bit --pmufw images/linux/pmufw.elf --u-boot

 

Closest match I can think of based on my /images/linux directory files is to do this:

petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/tutorial_wrapper.bit --pmufw images/linux/u-boot.elf --u-boot

 

Screenshot from 2018-05-10 15-04-35.png

 

executing this command:

petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/tutorial_wrapper.bit --pmufw images/linux/u-boot.elf --u-boot

I got errors:

ERROR: Invalid arg "--pmufw" for system arch "arm".

Screenshot from 2018-05-10 15-12-22.png

 

So I assumed to change the command to this;

petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/tutorial_wrapper.bit --u-boot images/linux/u-boot.elf --u-boot

command worked:

Screenshot from 2018-05-10 15-17-43.png

 

Copied BOOT.BIN and imag.ub to SD card: Now on FPGA Board:

 

cd /lib/modules/4.9.0-xilinx-v2017.3/kernel/

 

See below there is no /fs/configfs/ directory

 

Screenshot from 2018-05-10 15-23-26.png

 

 

modprobe configsfs.ko   does not work: (modprobe: module configfs.ko not foun in moudules.dep)

 

Screenshot from 2018-05-10 15-29-26.png

 

cd drivers/usb/gadget

modprobe libcomposite.ko (ok)

 

Screenshot from 2018-05-10 15-58-05.png

cd function/

insmod usb_f_mass_storage.ko (ok)

Screenshot from 2018-05-10 15-59-33.png

 

 

cd ../legacy/

insmod gadgetfs.ko 

>gadgetfs: USB Gadget filesystem, version 24 Aug 2004

 

Screenshot from 2018-05-10 16-01-01.png

 

dd if=/dev/zero of=/tmp/mydev cont=256 bs=1M

 

Screenshot from 2018-05-10 16-03-10.png

insmod g_mass_storage.ko

>udc-core: couldn't find an available UDC - added [g_mass_storage] to list of pending drivers

Screenshot from 2018-05-10 16-04-19.png

 

 

file=/tmp/mydev removable=1

Screenshot from 2018-05-10 16-06-54.png

 

Note:ignore  the console word wrap, I think buffer size has an issue that is why the text looks on top of each other.

 

 

Now I plugged a Type-A male USB in PC and u-usb in port (J13) that says OTG USB on the Zedboard. Did NOT see any USB enumeration on the PC.

 

0 Kudos
Reply
Explorer
Explorer
3,127 Views
Registered: ‎07-05-2017

What is this below device tree modification you suggested in the system-user.dtsi mean?

 

&dwc3_0 {

    status = "okay";

    dr_mode = "peripheral";

};

 

 

There is no "&dwc3_0" reference in my pcw.dtsi, hence I get petalinux compile errors.

0 Kudos
Reply
Explorer
Explorer
3,415 Views
Registered: ‎07-05-2017

Hi Aravindb,

 

After many trials and errors, this is what seems to work for me on the  Zedboard with Zynq XC7Z020-1CLG484C using 2017.3 petalinux.

 

Device Tree modification

Screenshot from 2018-05-22 10-11-17.png

 

Kernel menu configuration:

Screenshot from 2018-05-22 09-51-16.png

 

Screenshot from 2018-05-22 10-01-41.png

 

after doing:

>petalinux-build

>petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/spi_design_1_wrapper.bit --pmufw images/linux/u-boot.elf --u-boot

 

Boot the Petalinux on my Target FPGA.

 

Screenshot from 2018-05-22 10-03-51.png

 

 

Then I had to create a disk drive directory:

 

cd /tmp

mkdir <my_disk_drive>

mount -a -t msdos /tmp/mydev  /tm/<my_disk_drive>

Screenshot from 2018-05-22 10-05-01.png

 

 

Plugged the micro-USB to FPGA target board USB port and the USB Type-A to windows. I see the removable storage drive of 128 megabytes. I formated it and copied files back and forth to it. Now I am in process of writing file operations in C program to create, open,  write, read, and close files on both sides of the interfaces (Linux and Windows).

 

Thanks!

 

 

 

 

 

View solution in original post

0 Kudos
Reply
Visitor
Visitor
2,880 Views
Registered: ‎07-19-2018

Hi ! 

 

 

0 Kudos
Reply
Visitor
Visitor
1,872 Views
Registered: ‎05-06-2019

Hi,

I am using UZ3EG board, for me g_mass_storage.ko driver is not found.

configuration is attached.usb_support_2.jpgusb_gadget.jpgusb_gadget_precomposed_configuratons.jpgusb_peripheral_controller.jpgfile_system_usb_driven.jpg

also should I make dts change in &usb0 or &dwc3_0 ? below is my change :

&usb0 {
status = "okay";
};

&dwc3_0 {
status = "okay";
dr_mode = "peripheral";
phy-names = "usb3-phy";
};

0 Kudos
Reply