100ASK百问网 D1s/T113-s3开发板 适配ov5640

本实验采用百问网的100ASK_T113-PRO Base V1.1 ,链接:韦东山全志T113开发板
D1s也可以参考进行修改并适配。
本实验所需的文件(含tina根文件系统、SD镜像、设备树、内核配置文件)供大家对比参考:source.zip

Tina 测试镜像:tina_t113-100ask_uart3.img(使用该镜像时,需要连接七寸屏和ov5640摄像头)

本文章已在全志论坛实验成功:100ASK百问网 D1s/T113-s3开发板 适配ov5640 | 全志在线开发者论坛

1.硬件配置

查看百问网提供的T113开发板原理图100ASK_T113-Pro_Base-SCH.pdf
通过查看到第3页的摄像头原理图

image-20221109150249258.png
①将PE引脚使用跳线帽连接至CSI引脚。
image-20221109150552515.png
②根据所使用的摄像头,利用跳线帽,使AVDD、DVDD、DIOVDD选择不同的电压
image-20221109151017738.png
我所使用的是ov5640,使用2.8V的AVDD、1.5V的DVDD、2.8V的DIOVDD
image-20221109151320749.png
③根据摄像头的引脚信息,上接至T113开发板的DVP接口
image-20221109151735784.png

2.修改设备树

注意:T113中的网口和CSI接口复用,注意设备树中网口的PE的复用功能需要修改为CSI的PE的复用功能。需要在设备树中删除掉网口相关配置,防止占用。

文件名:sun8iw20p1-t113-100ask-t113-pro.dts

文件目录:buildroot_100ask_t113-pro/buildroot/output/build/linux-origin_master/arch/arm/boot/dts/

&vind0 {
	
	csi_top = <378000000>;
	csi_isp = <327000000>;
	status = "okay"; /* enable twi and ver1 spi-nand max freq 30M */

	actuator0: actuator@5809450 {
		device_type = "actuator0";
		actuator0_name = "ad5820_act";
		actuator0_slave = <0x18>;
		actuator0_af_pwdn = <>;
		actuator0_afvdd = "afvcc-csi";
		actuator0_afvdd_vol = <2800000>;
		status = "okay";
	};
	flash0: flash@5809460 {
		device_type = "flash0";
		flash0_type = <2>;
		flash0_en = <>;
		flash0_mode = <>;
		flash0_flvdd = "";
		flash0_flvdd_vol = <>;
		device_id = <0>;
		status = "okay";
	};
	sensor0: sensor@5809470 {
		reg = <0x0 0x05809470 0x0 0x10>;
		device_type = "sensor0";
		compatible = "allwinner,sunxi-sensor";
		sensor0_mname = "ov5640";
		sensor0_twi_cci_id = <2>;
		sensor0_twi_addr = <0x78>;
		sensor0_mclk_id = <0>;
		sensor0_pos = "rear";
		sensor0_isp_used = <0>;
		sensor0_fmt = <0>;
		sensor0_stby_mode = <0>;
		sensor0_vflip = <0>;
		sensor0_hflip = <0>;
		sensor0_iovdd-supply = <>;
		sensor0_iovdd_vol = <1800000>;
		sensor0_avdd-supply = <>;
		sensor0_avdd_vol = <2800000>;
		sensor0_dvdd-supply = <>;
		sensor0_dvdd_vol = <1500000>;
		sensor0_power_en = <>;
		sensor0_reset = <>;
		//sensor0_reset = <&pio PE 15 GPIO_ACTIVE_LOW>;
		//sensor0_pwdn = <&pio PE 14 GPIO_ACTIVE_LOW>;
		//sensor0_reset = <&pio PE 13 GPIO_ACTIVE_LOW>;
		sensor0_pwdn = <>;
		sensor0_sm_vs = <>;
		flash_handle = <&flash0>;
		act_handle = <&actuator0>;
		device_id = <0>;
		status  = "okay";
	};
	sensor1:sensor@5809480 {
		device_type = "sensor1";
		sensor1_mname = "ov5647";
		sensor1_twi_cci_id = <3>;
		sensor1_twi_addr = <0x6c>;
		sensor1_mclk_id = <1>;
		sensor1_pos = "front";
		sensor1_isp_used = <0>;
		sensor1_fmt = <0>;
		sensor1_stby_mode = <0>;
		sensor1_vflip = <0>;
		sensor1_hflip = <0>;
		sensor1_iovdd-supply = <>;
		sensor1_iovdd_vol = <>;
		sensor1_avdd-supply = <>;
		sensor1_avdd_vol = <>;
		sensor1_dvdd-supply = <>;
		sensor1_dvdd_vol = <>;
		sensor1_power_en = <>;
		sensor1_reset = <&pio PE 7 GPIO_ACTIVE_LOW>;
		sensor1_pwdn = <&pio PE 6 GPIO_ACTIVE_LOW>;
		status	= "disabled";
	};
	vinc0:vinc@5809000 {
		vinc0_csi_sel = <0>;
		vinc0_mipi_sel = <0xff>;
		vinc0_isp_sel = <0>;
		vinc0_isp_tx_ch = <0>;
		vinc0_tdm_rx_sel = <0xff>;
		vinc0_rear_sensor_sel = <0>;
		vinc0_front_sensor_sel = <0>;
		vinc0_sensor_list = <0>;
		status = "okay";
	};
	vinc1:vinc@5809200 {
		vinc1_csi_sel = <0>;
		vinc1_mipi_sel = <0xff>;
		vinc1_isp_sel = <0>;
		vinc1_isp_tx_ch = <1>;
		vinc1_tdm_rx_sel = <0xff>;
		vinc1_rear_sensor_sel = <0>;
		vinc1_front_sensor_sel = <1>;
		vinc1_sensor_list = <0>;
		status = "disabled";
	};
};

文件名:sun8iw20p1.dtsi

文件目录:buildroot_100ask_t113-pro/buildroot/output/build/linux-origin_master/arch/arm/boot/dts/

	vind0: vind@5800800 {
			compatible = "allwinner,sunxi-vin-media", "simple-bus";
			#address-cells = <2>;
			#size-cells = <2>;
			ranges;
			device_id = <0>;
			csi_top = <336000000>;
			csi_isp = <327000000>;
			reg = <0x0 0x05800800 0x0 0x200>,
				<0x0 0x05800000 0x0 0x800>;
			clocks = <&ccu CLK_CSI_TOP>, <&ccu CLK_PLL_VIDEO1_2X>,
				<&ccu CLK_CSI0_MCLK>, <&dcxo24M>, <&ccu CLK_PLL_VIDEO1>,
				<&ccu CLK_BUS_CSI>, <&ccu CLK_MBUS_CSI>;
			clock-names = "csi_top", "csi_top_src",
					"csi_mclk0", "csi_mclk0_24m", "csi_mclk0_pll",
					"csi_bus", "csi_mbus";
			resets = <&ccu RST_BUS_CSI>;
			reset-names = "csi_ret";
			pinctrl-names = "mclk0-default", "mclk0-sleep";
			pinctrl-0 = <&csi_mclk0_pins_a>;
			pinctrl-1 = <&csi_mclk0_pins_b>;
			status = "okay";

			csi0: csi@5801000{
				compatible = "allwinner,sunxi-csi";
				reg = <0x0 0x05801000 0x0 0x1000>;
				interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
				pinctrl-names = "default","sleep";
				pinctrl-0 = <&csi0_pins_a>;
				pinctrl-1 = <&csi0_pins_b>;
				device_id = <0>;
				iommus = <&mmu_aw 1 1>;
				status = "okay";
			};
			isp0: isp@5809410 {
				compatible = "allwinner,sunxi-isp";
				reg = <0x0 0x05809410 0x0 0x10>;
				device_id = <0xfe>;

				status = "okay";
			};
			isp1: isp@5809420 {
				compatible = "allwinner,sunxi-isp";
				reg = <0x0 0x05809420 0x0 0x10>;
				device_id = <0xff>;
				status = "okay";
			};
			scaler0: scaler@5809430 {
				compatible = "allwinner,sunxi-scaler";
				reg = <0x0 0x05809430 0x0 0x10>;
				device_id = <0xfe>;
				status = "okay";
			};
			scaler1: scaler@5809440 {
				compatible = "allwinner,sunxi-scaler";
				reg = <0x0 0x05809440 0x0 0x10>;
				device_id = <0xff>;
				status = "okay";
			};
			actuator0: actuator@5809450 {
				compatible = "allwinner,sunxi-actuator";
				device_type = "actuator0";
				reg = <0x0 0x05809450 0x0 0x10>;
				actuator0_name = "ad5820_act";
				actuator0_slave = <0x18>;
				actuator0_af_pwdn = <>;
				actuator0_afvdd = "afvcc-csi";
				actuator0_afvdd_vol = <2800000>;
				status = "disabled";
			};
			flash0: flash@5809460 {
				device_type = "flash0";
				compatible = "allwinner,sunxi-flash";
				reg = <0x0 0x05809460 0x0 0x10>;
				flash0_type = <2>;
				flash0_en = <>;
				flash0_mode = <>;
				flash0_flvdd = "";
				flash0_flvdd_vol = <>;
				device_id = <0>;
				status = "disabled";
			};
			sensor0: sensor@5809470 {
				reg = <0x0 0x05809470 0x0 0x10>;
				device_type = "sensor0";
				compatible = "allwinner,sunxi-sensor";
				sensor0_mname = "ov5640";
				sensor0_twi_cci_id = <2>;
				sensor0_twi_addr = <0x78>;
				sensor0_mclk_id = <0>;
				sensor0_pos = "rear";
				sensor0_isp_used = <0>;
				sensor0_fmt = <0>;
				sensor0_stby_mode = <0>;
				sensor0_vflip = <0>;
				sensor0_hflip = <0>;
				sensor0_iovdd-supply = <>;
				sensor0_iovdd_vol = <>;
				sensor0_avdd-supply = <>;
				sensor0_avdd_vol = <>;
				sensor0_dvdd-supply = <>;
				sensor0_dvdd_vol = <>;
				sensor0_power_en = <>;
				sensor0_reset = <&pio PE 9 GPIO_ACTIVE_LOW>;
				sensor0_pwdn = <&pio PE 8 GPIO_ACTIVE_LOW>;
				sensor0_sm_vs = <>;
				flash_handle = <&flash0>;
				act_handle = <&actuator0>;
				device_id = <0>;
				status	= "okay";
			};
			sensor1: sensor@5809480 {
				reg = <0x0 0x05809480 0x0 0x10>;
				device_type = "sensor1";
				compatible = "allwinner,sunxi-sensor";
				sensor1_mname = "ov5647";
				sensor1_twi_cci_id = <3>;
				sensor1_twi_addr = <0x6c>;
				sensor1_mclk_id = <1>;
				sensor1_pos = "front";
				sensor1_isp_used = <0>;
				sensor1_fmt = <0>;
				sensor1_stby_mode = <0>;
				sensor1_vflip = <0>;
				sensor1_hflip = <0>;
				sensor1_iovdd-supply = <>;
				sensor1_iovdd_vol = <>;
				sensor1_avdd-supply = <>;
				sensor1_avdd_vol = <>;
				sensor1_dvdd-supply = <>;
				sensor1_dvdd_vol = <>;
				sensor1_power_en = <>;
				sensor1_reset = <&pio PE 7 GPIO_ACTIVE_LOW>;
				sensor1_pwdn = <&pio PE 6 GPIO_ACTIVE_LOW>;
				sensor1_sm_vs = <>;
				flash_handle = <>;
				act_handle = <>;
				device_id = <1>;
				status	= "okay";
			};
			vinc0: vinc@5809000 {
				compatible = "allwinner,sunxi-vin-core";
				device_type = "vinc0";
				reg = <0x0 0x05809000 0x0 0x200>;
				interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
				vinc0_csi_sel = <0>;
				vinc0_mipi_sel = <0xff>;
				vinc0_isp_sel = <0>;
				vinc0_tdm_rx_sel = <0xff>;
				vinc0_rear_sensor_sel = <0>;
				vinc0_front_sensor_sel = <0>;
				vinc0_sensor_list = <0>;
				device_id = <0>;
				iommus = <&mmu_aw 1 1>;
				status = "okay";
			};
			vinc1: vinc@5809200 {
				device_type = "vinc1";
				compatible = "allwinner,sunxi-vin-core";
				reg = <0x0 0x05809200 0x0 0x200>;
				interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>;
				vinc1_csi_sel = <0>;
				vinc1_mipi_sel = <0xff>;
				vinc1_isp_sel = <1>;
				vinc1_tdm_rx_sel = <0xff>;
				vinc1_rear_sensor_sel = <0>;
				vinc1_front_sensor_sel = <0>;
				vinc1_sensor_list = <0>;
				device_id = <1>;
				iommus = <&mmu_aw 1 1>;
				status = "okay";
			};

		};

3.修改内核配置

在buildroot目录下,输入

make linux-menuconfig

image-20221109145454273.png
进入内核配置界面中的下面目录:
Location:
│ → Device Drivers
│ → Multimedia support
image-20221109152009291.png
对于Media USB Adapters:
image-20221109152849827.png
对于V4L platform devices:
image-20221109152936891.png
对于SUNXI platform devices:
image-20221109153018084.png
对于Memory-to-memory multimedia devices:
image-20221109153105873.png
修改完成后,保存并退出。
image-20221109153243966.png

4.重新编译和烧写

在buildroot目录下执行

make linux-rebuild

image-20221109153504420.png
执行完成后,再打包生成SD卡镜像,输入

make -j4

image-20221109153704912.png

5.使用tina的根文件系统启动

将烧录到sd卡的t113系统挂载到ubuntu中 使用 df -h 查看分区
image-20221109154118301.png
进入分区

cd /media/book/dd79b15c-ce3f-4d2d-8a75-437303b2df61/

拷贝lib中的驱动到桌面备用

sudo cp -rf lib/modules/5.4.61 ~/Desktop

删除全部文件

sudo rm -rf *

image-20221109154226939.png
将source文件夹中的tina_rootfs目录下的rootfs.img拷贝到Ubuntu中,解压tina系统

unsquashfs  rootfs.img

image-20221109154403419.png
拷贝tina系统中的文件到当前目录

sudo cp /home/book/squashfs-root/* ./ -rfd

进入lib/modules目录下删除5.4.61文件夹

cd lib/modules/
sudo rm -rf 5.4.61

将5.4.61文件夹拷贝回去

sudo cp ~/Desktop/5.4.61/ ./ -rf

从虚拟机中弹出SD卡。

6.使用camerademo测试

将SD卡插入T113开发板,上电启动。启动界面如下:
image-20221109154951185.png
进入sunxi-vin目录:

cd /lib/modules/5.4.61/kernel/drivers/media/platform/sunxi-vin/

装载vin_io.ko驱动

image-20221109155129126.png
进入sensor目录:

cdcd modules/sensor/

装载ov5640.ko驱动:

insmod ov5640.ko

image-20221109155315315.png
回到sunxi-vin目录:
image-20221109155454930.png
装载vin_v4l2.ko驱动:

insmod vin_v4l2.ko

image-20221109155553474.png
注意:上述大部分打印信息为我调试时加的打印,与自带驱动无关,全志自带的驱动程序是正常。

插入U盘或无系统的TF卡将获取到的图片提取出来查看。

挂载U盘。

image-20221109160052051.png

mount /dev/sda1 /mnt/

使用camerademo拍摄照片,存放到U盘内

camerademo NV21 640 480 30 bmp  /mnt 5

image-20221109160458918.png
卸载U盘分区

umount /mnt/

拔下u盘,插入电脑中,即可查看到刚刚在T113开发板上使用ov5640拍摄的5张照片
image-20221109160739850.pngads/files/1668762528153-image-20221109160052051.png)](https://bbs.aw-ol.com/assets/uploads/files/1668762528153-image-20221109160052051.png)

1.我这边,使用了你提供的镜像SD镜像,进行烧录,然后再根据你下面的步骤(解压tina的rootfs.img,保留buildroot的lib中的驱动保存然后,删除全部文件,换成tina根文件,最后把/lib/module/5.4.61也替换成之前buildroot中lib/module下的5.4.61这个目录)进行。硬件连接也是按照此教程进行。

2.启动开发板,进入系统

  1. 也是按照此教程进行驱动挂载,可是到了最后的vin_v4l2.ko,出现了下面的错误:

    这里应该的II2报错,没有读取到我的设备。

你先确保 硬件连接没有问题,那样才能识别到芯片。 注意和网卡的复用关系。
进入系统后 先确保 驱动模块可以正常装置 识别到模块。

之后再去尝试调试软件的操作。

目前的话,我是驱动挂载都已经出问题了,硬件连接是按照这个教程,跳线帽那些都是对应教程的,应该是不会错的,因为我用的也是ov5640,然后地址也是0x78,而且我用的是这个教程提供的镜像,但是在我挂载的时候,IIC会输出上图的那些信息。这里比较不懂的就是那个网卡和摄像头的一个复用方式,因为我没设置配置什么,都是完全用这个教程提供的东西。

我按照你这个教程,最后提示


,open /dev/video0 fail!这是什么原因呀,用的教程里面提供的source文件

查看一下驱动是否装载成功,我查看了您的打印信息,发现您没有video0节点,请检测硬件连接和驱动

好的,我先查一下,然后看是否能解决



,硬件也是按照教程接的,驱动挂载也没报错

跳线帽位置不对,请都靠右安装
image


已把跳帽全接在右侧,还是不行

在第5部,我生成的文件名和教程里不一样,会跟这个有关系吗?

请使用该镜像进行测试:https://bbs.aw-ol.com/assets/uploads/files/1691489145928-tina_t113-100ask_uart3.img

我用PhoenixSuit.exe将你给的包下载至开发板,启动后使用insmod ov5640.ko,然后发送camerademo指令进行测试,依旧提示 open 、dev/video0 fail!


请问,往下该怎么排查问题

请按顺序装载驱动

insmod videobuf2-memops.ko 
insmod videobuf2-vmalloc.ko 
insmod videobuf2-dma-contig.ko 
insmod vin_io.ko 
insmod ov5640.ko 
insmod vin_v4l2.ko 

按照你提供的镜像和驱动加载方法,已验证成功,证明硬件是没有问题的。但是我们需要进行代码开发,必须在buildroot_100ask_t113-pro验证成功,然后移植到tina-d1-h上面。我们该如何解决在buildroot_100ask_t113-pro上面出现的open /dev/video0 fail!问题呢?

我又仔细看了帖子,发现 kernel configuration 中Media test drivers 也配置了,之前失败有没有可能和这个有关系?还有Network support是否也需要配置呢?

您好,如果您需要进行您对应的产品开发,恕我们不能提供详细操作步骤中出问题并解决,我们更无法给您提供解决所有bug,并提供技术支持,对于配置文件我们也公开在的source目录下。
您需要在tina-d1-h上实现,可以参考全志论坛中的帖子,这个帖子有详细的步骤:D1-H (MQ-Pro)驱动 OV5640 摄像头 | 全志在线开发者论坛

网口和摄像头有复用,需要在设备树中删除掉网口相关配置,防止占用。

这是其中一个步骤,还差一个步骤论坛里没有写清楚,导致找不到video 0节点,因此重复论坛操作都会报 open video0 fail!写教程一定要完整呀,你们漏一步,初学者就要经历千百遍尝试。

感谢您的反馈,我们会修改完善教程。