The USB OTG port of pcDuino can be used to flash image to pcDuino3 through PhoneixSuit, it can be used to VNC to pcDuino3, and it can also be used to make pcDuino3 as a human computer interaction device to the host PC. In this post, we show how to run the USB OTG port into an extra USB host.
The default settings of all the hardware configurations are stored in a file named ‘script.bin’. This is a binary configuration file compiled from a fex test file. We can learn more about the fex file from Sunxi Wiki in the Fex Guide. To change the value of script.bin, we need to first decompile it back to the text format, edit, and then recompile it to the binary format.
There is an open source tool sets that can be used to do this from sunxi-tools.
Install dependency library
$sudo apt-get update $sudo apt-get install git $sudo apt-get install libusb-1.0.0-dev $sudo apt-get install pkg-config
We can install the sunxi-tools using the following commands:
$git clone https://github.com/linux-sunxi/sunxi-tools $cd sunxi-tools $make
The script.bin is stored in the NAND flash boot partition. It is normally not available after pcDuino finishes the booting process. We can mount it with:
$sudo mount /dev/nanda /boot
The directory will have the following contents:
Converting script.bin to fex:
The following commands are executed under the sunxi-tools directory.
$sudo cp /boot/script.bin /boot/script_orig.bin $./bin2fex /boot/script.bin > script.fex
Edit script.fex using text editor, and locating usb section:
;[usbc0]: The configuration of controller 0
;usb_used: Enable bit. If USB is enabled or not. 1: enable; 0: disable.
;usb_port_type: Type of USB port. 0：device only;1：host only;2:OTG
;usb_detect_type: Detect type. 0: Not detect; 1: detect vbus/id; 2: Detect id/dpdm
usb_used = 1
usb_port_type = 0
usb_detect_type = 0
usb_id_gpio = port:PH04<0><1><default><default>
usb_det_vbus_gpio = “axp_ctrl”
usb_drv_vbus_gpio = port:PB09<1><0><default><0>
;usb_restrict_gpio = port:PH00<1><0><default><0>
usb_host_init_state = 0
usb_restric_flag = 0
usb_restric_voltage = 3550000
We just need to change usb_port_type from 0 to 1 to make it a USB host.
Converting fex to script.bin:
The following commands are executed at sunxi-tools directory:
$./fex2bin script.fex >script.bin $sudo cp script.bin /boot/script.bin $sudo umount /boot
Power cycle pcDuino3, and plug in a USB flash drive to pcDuino3 OTG using a USB OTG cable, we can see that it got detected by pcDuino3: