“Linux内核-摄像头驱动移植”的版本间的差异
(→实验步骤) |
(→实验原理) |
||
第2行: | 第2行: | ||
DCMI(Digital Camera Interface),DCMI是一个同步并行接口,能够从外部8bit、10bit、12bit或14bit的CMOS摄像头接收高速数据流,支持不同的数据格式:YCbCr4:2:2/RGB565渐进式视频和压缩数据(JPEG)。<br> | DCMI(Digital Camera Interface),DCMI是一个同步并行接口,能够从外部8bit、10bit、12bit或14bit的CMOS摄像头接收高速数据流,支持不同的数据格式:YCbCr4:2:2/RGB565渐进式视频和压缩数据(JPEG)。<br> | ||
− | [[Image:58-1-1-1.png|640px]] <br> | + | <center>[[Image:58-1-1-1.png|640px]]</center> <br> |
FS-MP1A可以外接8bit的COM Camera,接口定义如下: | FS-MP1A可以外接8bit的COM Camera,接口定义如下: | ||
− | [[Image:58-1-1-2.png]] <br> | + | <center>[[Image:58-1-1-2.png]]</center> <br> |
接口与MPU管脚对应关系如下: | 接口与MPU管脚对应关系如下: | ||
− | [[Image:58-1-1-3.png]] | + | <center>[[Image:58-1-1-3.png]] </center> |
− | [[Image:58-1-1-4.png]] <br> | + | <center>[[Image:58-1-1-4.png]]</center> <br> |
− | [[Image:58-1-1-5.png]] | + | <center>[[Image:58-1-1-5.png]] </center> |
− | [[Image:58-1-1-6.png]] <br> | + | <center>[[Image:58-1-1-6.png]]</center> <br> |
− | [[Image:58-1-1-7.png]]<br> | + | <center>[[Image:58-1-1-7.png]]</center><br> |
− | {| | + | {|align=center border=1 |
|- | |- | ||
!原理图网络编号 !! 对应管脚 !! 管脚功能 !! 管脚功能码 | !原理图网络编号 !! 对应管脚 !! 管脚功能 !! 管脚功能码 |
2021年3月24日 (三) 15:44的版本
实验原理
DCMI(Digital Camera Interface),DCMI是一个同步并行接口,能够从外部8bit、10bit、12bit或14bit的CMOS摄像头接收高速数据流,支持不同的数据格式:YCbCr4:2:2/RGB565渐进式视频和压缩数据(JPEG)。
![58-1-1-1.png](/images/thumb/d/d9/58-1-1-1.png/640px-58-1-1-1.png)
FS-MP1A可以外接8bit的COM Camera,接口定义如下:
![58-1-1-2.png](/images/0/0f/58-1-1-2.png)
接口与MPU管脚对应关系如下:
![58-1-1-3.png](/images/1/18/58-1-1-3.png)
![58-1-1-4.png](/images/f/f1/58-1-1-4.png)
![58-1-1-5.png](/images/d/da/58-1-1-5.png)
![58-1-1-6.png](/images/0/0d/58-1-1-6.png)
![58-1-1-7.png](/images/6/67/58-1-1-7.png)
原理图网络编号 | 对应管脚 | 管脚功能 | 管脚功能码 |
---|---|---|---|
DCMI_D0 | PH9 | DCMI_D0 | AF13 |
DCMI_D1 | PH10 | DCMI_D0 | AF13 |
DCMI_D2 | PH11 | DCMI_D0 | AF13 |
DCMI_D3 | PH12 | DCMI_D0 | AF13 |
DCMI_D4 | PH14 | DCMI_D0 | AF13 |
DCMI_D5 | PI4 | DCMI_D0 | AF13 |
DCMI_D6 | PB8 | DCMI_D0 | AF13 |
DCMI_D7 | PE6 | DCMI_D0 | AF13 |
DCMI_RESET | PA3 | GPIO | ANALOG |
DCMI_PWDN | PA4 | GPIO | ANALOG |
DCMI_PIXCK | PA6 | DCMI_PIXCLK | AF13 |
DCMI_VSYNC | PB7 | DCMI_VSYNC | AF13 |
- DCMI设备树节点
- CMOS Camera设备树节点
- 2.8V电源定义
- 24M时钟定义
参考文档:
Documentation/devicetree/bindings/media/st,stm32-dcmi.txt Documentation/devicetree/bindings/media/video-interfaces.txt
内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:
arch/arm/boot/dts/stm32mp151.dtsi
stm32mp151中dcmi定义如下:
dcmi: dcmi@4c006000 { compatible = "st,stm32-dcmi"; reg = <0x4c006000 0x400>; interrupts = <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>; resets = <&rcc CAMITF_R>; clocks = <&rcc DCMI>; clock-names = "mclk"; dmas = <&dmamux1 75 0x400 0xe0000001>; dma-names = "tx"; status = "disabled"; };
上述代码只对dcmi做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。
参考帮助文档及内核中其它STM32MP157设备树中对于dcmi的定义,修改dcmi内容如下:
&dcmi { status = "okay"; pinctrl-names = "default", "sleep"; pinctrl-0 = <&dcmi_pins_a>; pinctrl-1 = <&dcmi_sleep_pins_a>; port { dcmi_0: endpoint { remote-endpoint = <&ov5640_0>; bus-width = <8>; hsync-active = <0>; vsync-active = <0>; pclk-sample = <1>; pclk-max-frequency = <77000000>; }; }; };
由于stm32mp15-pinctrl.dtsi中对于DCMI管脚的定义与FS-MP1A实际使用管脚一致,所以无需修改
FS-MP1A支持多款COMS Camera,本节以ov5640为例:
参考文档:
Documentation/devicetree/bindings/media/i2c/ov5640.txt
参考帮助文档及内核中其它STM32MP157设备树中对于ov5640的定义,修改dcmi内容如下:
ov5640: camera@3c { compatible = "ovti,ov5640"; reg = <0x3c>; clocks = <&clk_ext_camera>; clock-names = "xclk"; DOVDD-supply = <&v2v8>; powerdown-gpios = <&gpioa 4 (GPIO_ACTIVE_HIGH | GPIO_PUSH_PULL)>; reset-gpios = <&gpioa 3 (GPIO_ACTIVE_LOW | GPIO_PUSH_PULL)>; rotation = <180>; status = "okay"; port { ov5640_0: endpoint { remote-endpoint = <&dcmi_0>; bus-width = <8>; data-shift = <2>; /* lines 9:2 are used */ hsync-active = <0>; vsync-active = <0>; pclk-sample = <1>; pclk-max-frequency = <77000000>; }; }; };
前文已经说过如何添加电源节点,本节不再重复,在根节点添加&v2v8节点,内容如下:
v2v8_audio: regulator-v2v8 { compatible = "regulator-fixed"; regulator-name = "v2v8"; regulator-min-microvolt = <2800000>; regulator-max-microvolt = <2800000>; regulator-always-on; regulator-boot-on; };
参考文档:
Documentation/devicetree/bindings/clock/fixed-clock.yaml
参考帮助文档或内核中其他设备树文件,对于时钟的定义,增加内容如下:
clocks { clk_ext_camera: clk-ext-camera { #clock-cells = <0>; compatible = "fixed-clock"; clock-frequency = <24000000>; }; };
实验目的
熟悉基于Linux操作系统下的摄像头设备驱动移植配置过程。
实验平台
华清远见开发环境,FS-MP1A平台;
实验步骤
- 导入交叉编译工具链
- 增加DCMI设备树节点
- 增加OV5640节点
- &i2c5 {
- pinctrl-names = "default", "sleep";
- pinctrl-0 = <&i2c5_pins_a>;
- ……
- pinctrl-names = "default", "sleep";
- ov5640: camera@3c {
- compatible = "ovti,ov5640";
- reg = <0x3c>;
- clocks = <&clk_ext_camera>;
- clock-names = "xclk";
- DOVDD-supply = <&v2v8>;
- powerdown-gpios = <&gpioa 4 (GPIO_ACTIVE_HIGH | GPIO_PUSH_PULL)>;
- reset-gpios = <&gpioa 3 (GPIO_ACTIVE_LOW | GPIO_PUSH_PULL)>;
- rotation = <180>;
- status = "okay";
- port {
- ov5640_0: endpoint {
- remote-endpoint = <&dcmi_0>;
- bus-width = <8>;
- data-shift = <2>; /* lines 9:2 are used */
- hsync-active = <0>;
- vsync-active = <0>;
- pclk-sample = <1>;
- pclk-max-frequency = <77000000>;
- };
- };
- ov5640: camera@3c {
- };
- 增加2.8V电源和24M时钟
- /{
- memory@c0000000 {
- device_type = "memory";
- reg = <0xc0000000 0x20000000>;
- };
- ……
- memory@c0000000 {
- v2v8: regulator-2p8v {
- compatible = "regulator-fixed";
- regulator-name = "v2v8";
- regulator-min-microvolt = <2800000>;
- regulator-max-microvolt = <2800000>;
- regulator-always-on;
- regulator-boot-on;
- };
- clocks {
- clk_ext_camera: clk-ext-camera {
- #clock-cells = <0>;
- compatible = "fixed-clock";
- clock-frequency = <24000000>;
- };
- };
- v2v8: regulator-2p8v {
- 配置内核
- 编译内核及设备树
- 重启测试
linux@ubuntu:$ source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在文件末尾添加如下内容:
&dcmi { status = "okay"; pinctrl-names = "default", "sleep"; pinctrl-0 = <&dcmi_pins_a>; pinctrl-1 = <&dcmi_sleep_pins_a>; port { dcmi_0: endpoint { remote-endpoint = <&ov5640_0>; bus-width = <8>; hsync-active = <0>; vsync-active = <0>; pclk-sample = <1>; pclk-max-frequency = <77000000>; }; }; };
修改arch/arm/dts/stm32mp15xx-fsmp1x.dtsi文件,在I2C5节点中添加OV5640设备信息,红色字体为增加内容:
};
修改arch/arm/dts/stm32mp15xx-fsmp1x.dtsi文件,在根节点最后添加2.8V电源和24M时钟,红色字体为增加内容:
};
配置内核支持ov5640,并列出主要选项,如下
linux@ubuntu:$ make menuconfig Device Drivers ---> <*> Multimedia support ---> [*] V4L platform devices ---> <*> STM32 Digital Camera Memory Interface (DCMI) support I2C Encoders, decoders, sensors and other helper chips ---> <*> OmniVision OV5640 sensor support
linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040
将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,系统启动后启动信息中包含如下信息:
在屏幕的界面上选择“Camera preview”应用进入摄像头预览程序,启动界面后即可看到摄像头实时采集的图像。
![58-1-4-2.png](/images/1/1e/58-1-4-2.png)