目录
前言
一、ov5640模组介绍
1. 图像传感器特性
2. 接口和控制
3. 图像处理能力
4. 应用领域
二、原理图连接
三、设备树配置
四、驱动配置
五、ov5640使用
六、异常记录
总结
摄像头模块是嵌入式系统中常见的外设,用于捕获图像和视频。在本篇文章中,我们将介绍如何在T113-S3平台上调试OV5640摄像头,以捕获图像或视频流。
OV5640是OmniVision Technologies生产的一款1/4英寸CMOS数字图像传感器,通常用于嵌入式系统和移动设备中的摄像头模组。以下是对OV5640摄像头模组的详细介绍:
OV5640摄像头模组广泛应用于各种领域,包括但不限于:
OV5640摄像头模块通过mipi-csi并口连接到到T113-S3 CPU上,通过i2c接口完成摄像头模块的配置
确保连接稳固且没有接触到其他不应接触的引脚。同时,确保摄像头模块的供电电压和电流需求得到满足。具体连接如下图所示:
在device/config/chips/t113/configs/evb1_auto/board.dts设备树文件中完成ov5640模块驱动配置
i2c接口配置如下所示,其中i2c clock可在100k~400k之间可调:
&twi2_pins_a{
pins = "PE12", "PE13";
function = "twi2";
drive-strength = <10>;
};
&twi2_pins_b{
pins = "PE12", "PE13";
function = "gpio_in";
};
/* used for vind0 */
&twi2 {
clock-frequency = <100000>;
pinctrl-0 = <&twi2_pins_a>;
pinctrl-1 = <&twi2_pins_b>;
pinctrl-names = "default", "sleep";
twi_drv_used = <0>;
dmas = <&dma 45>, <&dma 45>;
dma-names = "tx", "rx";
status = "okay";
};
ov5640模组设备树配置:
&vind0{
status = "okay";
csi0: csi@5801000{
compatible = "allwinner,sunxi-csi";
reg = <0x0 0x05801000 0x0 0x1000>;
interrupts = ;
//pinctrl-names = "default","sleep";
pinctrl-names = "default";
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 = "okay";
};
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 = "okay";
};
//NCSI
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";
};
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 = <0>;
vinc1_sensor_list = <0>;
status = "okay";
};
};
其中sensor0_reset为模组复位io管脚,硬件电路需要预留出来,不然一旦模组异常就无法恢复,ov5640驱动程序也有reset和power控制管脚,当ov5640模组异常时可以对其恢复。
由于全志官方SDK暂时还没有对ov5640驱动程序进行验证,所有驱动程序暂时不能通过menuconfig图形界面区配置,只能通过手动修改Makefile的方式进行驱动添加,驱动程序路径如下所示
kernel/linux-5.4/drivers/media/platform/sunxi-vin/modules/sensor/ov5640.c
修改Makefile使驱动程序编译进内核
obj-y += ov5640.o
#obj-m += ov2775_mipi.o
#obj-m += gc2145.o
obj-m += gc0310_mipi.o
#obj-m += gc2355_mipi.o
obj-m += gc030a_mipi.o
obj-m += gc2385_mipi.o
#obj-m += gc5024_mipi.o
obj-m += gc5025_mipi.o
obj-m += c2590_mipi.o
obj-m += sp5409_mipi.o
#obj-m += imx214.o
#obj-m += imx219.o
#obj-m += imx274_slvds.o
#obj-m += imx291_dvp.o
#obj-m += imx291_mipi.o
#obj-m += imx317_mipi.o
#obj-m += imx335_mipi.o
#obj-m += imx326_mipi.o
#obj-m += imx477_mipi.o
#obj-m += ov2710_mipi.o
#obj-m += ov2718_mipi.o
#obj-m += ar0238.o
obj-m += ov8858_r2a_4lane.o
obj-m += ov2680_mipi.o
obj-m += imx278_mipi.o
obj-m += imx278_2lane_mipi.o
obj-m += imx386_2lane_mipi.o
obj-m += imx386_mipi.o
#obj-m += s5k3h5xa.o
#obj-m += ar0238_hispi.o
#obj-m += nvp6134/
#obj-m += nvp6324/
obj-m += nvp6158/
#obj-m += rn6854m_mipi.o
#obj-m += tp9950.o
#obj-m += sc2232_mipi.o
obj-m += n5_dvp.o
ov5640驱动正常加载如下图所示:
正常识别摄像头会有[ov5640]V4L2 IDENT SENSOR = 5640信息打印,上述clk fail等信息无影响,此时在/dev下有video0、video1、video4三个节点,操作video0即可获取到图像数据
抓取摄像头视频流数据:
由于该驱动不支持v4l2-ctl工具进行视频流抓取操作,通过咨询FAE,使用全志官方提供的sdktest进行视频流抓取。
1、修改sdktest测试工具配置文件dvrconfig.ini配置文件,修改视频像素大小为1280*720
2、修改视频保存位置目录:
3、执行sdktest 1 0命令启动视频流数据保存,保存打印如下所示:
图像以mp4格式保存在frontVideo0目录下
视频效果截图如下:
1、oi2c通信异常:sunxi-i2c sunxi-i2c2: SLA+W has been transmitted; ACK not received
在确认i2c硬件连接正常以及i2c有上拉电阻的情况下,一般是由于csi时钟异常引起,特别注意,当csi时钟异常无输出时,ov5640 i2c不会响应。
我这边是由于没有使能csi clk输出导致,csi时钟正确配置如下图:
2、显示[VIN ERR]media entity find link null
由于vinc0、vinc1节点没有配置导致,正确开启则不会报link错误:
通过正确连接硬件、配置摄像头接口和使用适当的软件工具,你可以在T113-S3平台上成功调试OV5640摄像头,捕获图像或视频流。这只是一个简单的示例,你可以根据自己的需求进一步扩展功能,例如实时视频处理或与其他传感器集成。。