.. include:: /keyword.rst ========== Peripheral ========== .. contents:: Sections :local: :depth: 1 .. toctree:: :hidden: Genio 350-EVK Genio 510/700-EVK Genio 1200-EVK -------------------------------- This chapter describes the common information and instructions of Peripheral on |IOT-YOCTO|, such as listing peripheral hardware, operating devices, and so on. Peripheral on different platforms may have some platform-specific instructions or test results. For example, you will use different peripheral interfaces on different platforms. Please refer to the platform-specific section for more details. - :doc:`Genio 350-EVK Peripheral `. - :doc:`Genio 510/700-EVK Peripheral `. - :doc:`Genio 1200-EVK Peripheral `. -------------------------------- .. note:: All cmd operations presented in this chapter are based on the IoT Yocto v22.1, |i350-EVK-REF-BOARD|. You might get different operation result depends on what platform you currently use. I2C --- There are some I2C tools to operate I2C adapters and devices. ``i2cdetect`` will list all available I2C adapters and the I2C devices on a specific I2C bus. You can see the connected I2C device address, e.g. 0x53, and 0x57. .. prompt:: bash # auto # i2cdetect -l i2c-3 i2c i2c-mt65xx I2C adapter i2c-1 i2c i2c-mt65xx I2C adapter i2c-2 i2c i2c-mt65xx I2C adapter i2c-0 i2c i2c-mt65xx I2C adapter # i2cdetect -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- 53 -- -- -- 57 -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- .. note:: Make sure you don't have more than one device with the same address connected to the same I2C bus. Otherwise, the address will conflict. ``i2cdump`` will list all registers of a specific I2C device. .. prompt:: bash # auto # i2cdump -y 0 0x57 No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: a5 a5 92 00 00 81 63 02 00 0f 00 00 00 00 00 00 ???..?c?.?...... 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ... ``i2cset`` and ``i2cget`` will write and read the register value. .. prompt:: bash # auto # i2cget -f -y 0 0x57 0x2 0x92 # i2cset -f -y 0 0x57 0x2 0x93 # i2cget -f -y 0 0x57 0x2 0x93 Please refer to the platform-specific section for more details on each platform. - :ref:`Genio 350-EVK I2C `. - :ref:`Genio 700-EVK I2C `. - :ref:`Genio 1200-EVK I2C `. SPI --- First, you need to probe the SPI device manually by the command: .. prompt:: bash # auto # modprobe spidev After probing, you can find an SPI device under ``/dev``. .. prompt:: bash # auto # ls -l /dev/spidev0.0 crw------- 1 root root 153, 0 Sep 20 12:22 /dev/spidev0.0 To test the SPI device, you can use a pre-installed tool, ``spidev_test``. It verifies that the data sent by Tx should be the same as the data received by Rx. .. note:: Before using ``spidev_test`` to test, SPI_MOSI and SPI_MISO should be shorted. .. prompt:: bash # auto # dd if=/dev/random of=test.bin bs=96 count=1 1+0 records in 1+0 records out 96 bytes copied, 0.000968692 s, 99.1 kB/s # spidev_test -D /dev/spidev0.0 -s 400000 -i test.bin -v spi mode: 0x0 bits per word: 8 max speed: 400000 Hz (400 kHz) TX | A3 62 7A EB CA 8E 69 98 1C A9 A8 E4 2C 9A 6A 0E 94 DA EC 34 84 28 FC AE 7F 27 91 E7 B9 7E D6 32 |.bz...i.....,.j....4.(...'...~.2| TX | 21 4A 08 0A B5 65 B3 3D D7 63 CC 6B 4C 77 A4 D4 C8 FB 57 93 B7 91 4A 34 F6 16 76 FB 72 9C C9 66 |!J...e.=.c.kLw....W...J4..v.r..f| TX | 43 FE E0 90 54 62 E4 BC CF BF 36 81 D4 95 BF FB EF 84 66 E1 30 E0 D2 24 E5 DD 98 24 C0 F8 A1 E3 |C...Tb....6.......f.0..$...$....| RX | A3 62 7A EB CA 8E 69 98 1C A9 A8 E4 2C 9A 6A 0E 94 DA EC 34 84 28 FC AE 7F 27 91 E7 B9 7E D6 32 |.bz...i.....,.j....4.(...'...~.2| RX | 21 4A 08 0A B5 65 B3 3D D7 63 CC 6B 4C 77 A4 D4 C8 FB 57 93 B7 91 4A 34 F6 16 76 FB 72 9C C9 66 |!J...e.=.c.kLw....W...J4..v.r..f| RX | 43 FE E0 90 54 62 E4 BC CF BF 36 81 D4 95 BF FB EF 84 66 E1 30 E0 D2 24 E5 DD 98 24 C0 F8 A1 E3 |C...Tb....6.......f.0..$...$....| You can refer to the source of ``spidev_test`` `here `_ for how to use the SPI device. Please refer to the platform-specific section for more details on each platform. - :ref:`Genio 350-EVK SPI `. - :ref:`Genio 700-EVK SPI `. - :ref:`Genio 1200-EVK SPI `. USB --- The USB ports on the board may have different usages, such as USB master/slave, image flush port, and the console port. Please refer to the platform-specific section for more details on each platform. - :ref:`Genio 350-EVK USB `. - :ref:`Genio 1200-EVK USB `. PWM --- Please refer to the platform-specific section for more details on each platform. - :ref:`Genio 350-EVK PWM `. - :ref:`Genio 700-EVK PWM `. - :ref:`Genio 1200-EVK PWM `. UART ---- You can use ``sysfs`` to find out the UART devices. .. prompt:: bash # auto # ls -l /sys/class/tty/ttyS* lrwxrwxrwx 1 root root 0 Sep 20 10:43 /sys/class/tty/ttyS0 -> ../../devices/platform/soc/11002000.uart0/tty/ttyS0 lrwxrwxrwx 1 root root 0 Sep 20 10:43 /sys/class/tty/ttyS1 -> ../../devices/platform/soc/11003000.uart1/tty/ttyS1 lrwxrwxrwx 1 root root 0 Sep 20 10:43 /sys/class/tty/ttyS2 -> ../../devices/platform/soc/11004000.uart2/tty/ttyS2 By default, the console log is transferred to the host through ``ttyS0``. Please refer to the platform-specific section for more details on each platform. - :ref:`Genio 350-EVK UART `. - :ref:`Genio 700-EVK UART `. - :ref:`Genio 1200-EVK UART `. .. note:: The UART DMA mode (``CONFIG_MTK_UART_APDMA``) is enabled by default. If you prefer not to use the DMA mode, you will need to disable it manually. GPIO ---- You can use GPIO tools to operate the GPIO pin. ``gpiodetect`` will list all available GPIO chips. .. prompt:: bash # auto # gpiodetect gpiochip0 [1000b000.pinctrl] (156 lines) ``gpioinfo`` will list all states of GPIO pins. .. prompt:: bash # auto # gpioinfo | head gpiochip0 - 156 lines: line 0: unnamed unused input active-high line 1: unnamed unused input active-high line 2: unnamed unused input active-high line 3: unnamed unused input active-high line 4: unnamed unused input active-high line 5: unnamed unused input active-high line 6: unnamed unused input active-high line 7: unnamed unused input active-high line 8: unnamed unused input active-high ... ``gpioset`` and ``gpioget`` will write and read the specific GPIO pin. If you short GPIO pin 32 and GPIO pin 34, you can set one pin and get the value back from another pin. .. prompt:: bash # auto # gpioset gpiochip0 32=0 # gpioget gpiochip0 34 0 # gpioset gpiochip0 32=1 # gpioget gpiochip0 34 1 Please refer to the platform-specific section for more details on each platform. - :ref:`Genio 350-EVK GPIO `. - :ref:`Genio 700-EVK GPIO `. - :ref:`Genio 1200-EVK GPIO `. Pin Header ---------- The boards have the pin header. Some follow Raspberry Pi HAT configuration and some don't. Please refer to the platform-specific section for more details. - :ref:`Genio 350-EVK Raspberry Pi HAT `. - :ref:`Genio 700-EVK Pin Header `. - :ref:`Genio 1200-EVK Pin Header `. .. _peripheral-uvc-gadget: UVC Gadget ---------- This section covers the usage of UVC gadget for Genio 510/700/1200-EVK. It includes instructions on generating the gadget node, setting up and launching the camera, and the interaction between the PC and EVK. This section will use the Genio 700-EVK USB port0 micro-b for demonstrating the UVC gadget example. .. note:: The Genio 350-EVK lacks a USB 3.0 port, so its UVC gadget may be limited by the USB 2.0 bandwidth. Firstly, in accordance with `Linux USB gadget `_ , UVC configuration through `Configfs `_ is required. Please refer to the ``uvc.sh`` script below. .. code-block:: bash :caption: `uvc.sh` :name: `uvc.sh` #! /bin/sh cd /sys/kernel/config/usb_gadget/g1 echo "" > UDC rm -rf configs/c.1/ffs.adb rm -rf configs/c.1/rndis.usb0 echo "0x046D" > idVendor echo "0x087C" > idProduct echo "0x0010" > bcdDevice echo "0xef" > bDeviceClass echo "0x02" > bDeviceSubClass echo "0x01" > bDeviceProtocol mkdir strings/0x409 echo "0123456789ABCDEF" > strings/0x409/serialnumber echo "Mediatek Inc." > strings/0x409/manufacturer echo "uvc gadget" > strings/0x409/product mkdir functions/uvc.usb0 mkdir functions/uvc.usb0/control/header/h echo 3072 > functions/uvc.usb0/streaming_maxpacket echo 7 > functions/uvc.usb0/streaming_maxburst cd functions/uvc.usb0/control/ ln -s header/h class/fs ln -s header/h class/ss cd ../../../ mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p cat < functions/uvc.usb0/streaming/uncompressed/u/360p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/wWidth 640 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/wHeight 360 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwMinBitRate 55296000 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwMaxBitRate 55296000 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwMaxVideoFrameBufferSize 460800 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval 333333 EOF mkdir -p functions/uvc.usb0/streaming/uncompressed/u/720p cat < functions/uvc.usb0/streaming/uncompressed/u/720p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/wWidth 1280 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/wHeight 720 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/dwMinBitRate 147456000 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/dwMaxBitRate 147456000 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/dwMaxVideoFrameBufferSize 1843200 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/720p/dwFrameInterval 333333 EOF mkdir -p functions/uvc.usb0/streaming/uncompressed/u/1080p cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/wWidth 1920 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/wHeight 1080 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/dwMinBitRate 147456000 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/dwMaxBitRate 147456000 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/dwMaxVideoFrameBufferSize 1843200 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/uncompressed/u/1080p/dwFrameInterval 333333 EOF mkdir -p functions/uvc.usb0/streaming/mjpeg/m/360p cat < functions/uvc.usb0/streaming/mjpeg/m/360p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/wWidth 640 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/wHeight 360 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/dwMinBitRate 18432000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/dwMaxBitRate 55296000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/dwMaxVideoFrameBufferSize 460800 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/360p/dwFrameInterval 333333 1000000 5000000 EOF mkdir -p functions/uvc.usb0/streaming/mjpeg/m/720p cat < functions/uvc.usb0/streaming/mjpeg/m/720p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/wWidth 1280 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/wHeight 720 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/dwMinBitRate 29491200 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/dwMaxBitRate 29491200 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize 1843200 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/720p/dwFrameInterval 333333 EOF mkdir -p functions/uvc.usb0/streaming/mjpeg/m/1080p cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/wWidth 1920 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/wHeight 1080 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/dwMinBitRate 165888000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/dwMaxBitRate 995328000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/dwMaxVideoFrameBufferSize 960000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/1080p/dwFrameInterval 333333 EOF mkdir -p functions/uvc.usb0/streaming/mjpeg/m/2160p cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/bmCapabilities 0 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/wWidth 3840 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/wHeight 2160 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/dwMinBitRate 165888000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/dwMaxBitRate 995328000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/dwMaxVideoFrameBufferSize 960000 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/dwDefaultFrameInterval 333333 EOF cat < functions/uvc.usb0/streaming/mjpeg/m/2160p/dwFrameInterval 333333 EOF mkdir functions/uvc.usb0/streaming/header/h cd functions/uvc.usb0/streaming/header/h ln -s ../../mjpeg/m/ cd ../../class/fs ln -s ../../header/h cd ../../class/hs ln -s ../../header/h cd ../../class/ss ln -s ../../header/h cd ../../../control cd ../../../ mkdir configs/c.1 ln -s functions/uvc.usb0/ configs/c.1 echo $(ls /sys/class/udc | awk 'NR==1') > UDC echo "uvc.sh done!" If using a USB 2.0 port, the frame buffer should be set to 1024 to prevent insufficient bandwidth issues. .. code-block:: bash echo 1024 > functions/uvc.usb0/streaming_maxpacket echo 1 > functions/uvc.usb0/streaming_maxburst .. note:: The configuration of the UVC gadget `configfs` should be tailored to specific usage requirements. Here, an executable example is provided on Genio 700-EVK. Next, ``adb push`` this file to the Genio 700-EVK and execute it. .. code-block:: bash # from PC adb push uvc.sh /tmp # from EVK cd /tmp chmod 777 uvc.sh ./uvc.sh After executing ``uvc.sh`` and connecting a USB camera, the open-source example program from https://github.com/wlhe/uvc-gadget will be utilized to display the USB camera's feed to the UVC gadget. The generation of the gadget node can be confirmed by using ``ls /sys/class/video4linux/ -l``. In the following example, the generated UVC gadget node is ``/dev/video7``, while the USB camera node is ``/dev/video5``. .. code-block:: bash root@genio-700-evk:/mnt# ls /sys/class/video4linux/ -l total 0 lrwxrwxrwx 1 root root 0 Apr 28 2022 video0 -> ../../devices/platform/soc/1a030000.jpgenc/video4linux/video0 lrwxrwxrwx 1 root root 0 Apr 28 2022 video1 -> ../../devices/platform/soc/1a040000.jpgdec/video4linux/video1 lrwxrwxrwx 1 root root 0 Dec 13 09:03 video2 -> ../../devices/platform/soc/14001000.mdp3-rdma0/video4linux/video2 lrwxrwxrwx 1 root root 0 Dec 13 09:03 video3 -> ../../devices/platform/soc/18000000.vdec/video4linux/video3 lrwxrwxrwx 1 root root 0 Dec 13 09:03 video4 -> ../../devices/platform/soc/1a020000.venc/video4linux/video4 lrwxrwxrwx 1 root root 0 Dec 13 09:03 video5 -> ../../devices/platform/soc/11201000.usb1/11200000.xhci1/usb3/3-1/3-1.2/3-1.2:1.2/video4linux/video5 lrwxrwxrwx 1 root root 0 Dec 13 09:03 video6 -> ../../devices/platform/soc/11201000.usb1/11200000.xhci1/usb3/3-1/3-1.2/3-1.2:1.2/video4linux/video6 lrwxrwxrwx 1 root root 0 Dec 13 09:03 video7 -> ../../devices/platform/soc/112b1000.usb/gadget/video4linux/video7 root@genio-700-evk:/mnt# .. note:: After inserting the USB camera, video5 and video6 will be generated under the USB host xHCI; use the lower number to avoid errors. After confirming the presence of the UVC gadget node and USB camera node, the `UVC-gadget `_ test program can be used to interconnect them. Referring to the ``uvc-gadget -h`` command below provides insight into the option functions offered by this tool. .. code-block:: bash root@genio-700-evk:/mnt# uvc-gadget -h Usage: uvc-gadget [options] Available options are -b Use bulk mode -d Do not use any real V4L2 capture device -f Select frame format 0 = V4L2_PIX_FMT_YUYV 1 = V4L2_PIX_FMT_MJPEG -h Print this help screen and exit -i image MJPEG image -m Streaming mult for ISOC (b/w 0 and 2) -n Number of Video buffers (b/w 2 and 32) -o Select UVC IO method: 0 = MMAP 1 = USER_PTR -r Select frame resolution: 0 = 360p, VGA (640x360) 1 = 720p, WXGA (1280x720) -s Select USB bus speed (b/w 0 and 2) 0 = Full Speed (FS) 1 = High Speed (HS) 2 = Super Speed (SS) -t Streaming burst (b/w 0 and 15) -u device UVC Video Output device -v device V4L2 Video Capture device root@genio-700-evk:/mnt# Here, it is necessary to specify ``-u`` and ``-v``, corresponding to the nodes of the UVC gadget and the USB camera, and to set the resolution to 720p as well as the MJPEG decoding format. .. code-block:: bash uvc-gadget -u /dev/video7 -v /dev/video5 -r 1 -f 1 -s 1 It's important to know which UDC port the UVC gadget is bound to, which can be checked using ``cat /sys/kernel/config/usb_gadget/g1/UDC``. .. code-block:: bash root@genio-700-evk:/mnt# cat /sys/kernel/config/usb_gadget/g1/UDC 112b1000.usb Here, ``112b1000.usb`` refers to the Genio 700-EVK USB port0 micro-b. By connecting it to the PC using an A-to-B cable, the UVC camera can be viewed on the PC using the built-in Windows Camera Preview app. .. figure:: /_asset/sw_yocto_app-dev_peripheral_peripheral-common_uvcgadget_example.png :align: center :width: 900px