参考:https://blog.51cto.com/u_15294654/3111978
参考:https://blog.csdn.net/xiangkezhi167810/article/details/112257386
硬件:
- Linux:linux-zero-5.2.y
- U-Boot:u-boot-3s-current
- Buildroot:buildroot-2020.02.4
操作步骤:
- 修改设备树
- 增加Linux配置
- 重新构建一个buildroot文件系统
- 测试
硬件分析
在Lichee Pi Zero Dock开发板上实现:
由上可以知道:
CSI_SDA:PE22
CSI_SCK:PE21
如上RGB_LCD接口与CSI摄像头接口无法同时使用!!
一、修改设备树
sun8i-v3s.dtsi
// camera use for 20220709
csi1: csi@1cb4000 {
compatible = "allwinner,sun8i-v3s-csi";
reg = <0x01cb4000 0x1000>;
interrupts = <GIC_SPI 84 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_CSI>,
<&ccu CLK_CSI1_SCLK>,
<&ccu CLK_DRAM_CSI>;
clock-names = "bus", "mod", "ram";
resets = <&ccu RST_BUS_CSI>;
status = "disabled";
};
pio: pinctrl@1c20800 {
compatible = "allwinner,sun8i-v3s-pinctrl";
reg = <0x01c20800 0x400>;
interrupts = <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_PIO>, <&osc24M>, <&osc32k>;
clock-names = "apb", "hosc", "losc";
gpio-controller;
#gpio-cells = <3>;
interrupt-controller;
#interrupt-cells = <3>;
emac_rgmii_pins: emac-rgmii-pins {
pins = "PD0", "PD1", "PD2", "PD3", "PD4",
"PD5", "PD7", "PD8", "PD9", "PD10",
"PD12", "PD13", "PD15", "PD16", "PD17";
function = "emac";
drive-strength = <40>;
};
i2c0_pins: i2c0-pins {
pins = "PB6", "PB7";
function = "i2c0";
};
pwm0_pins: pwm0 {
pins = "PB4";
function = "pwm0";
};
pwm1_pins: pwm1{
pins = "PB5";
function = "pwm1";
};
uart0_pb_pins: uart0-pb-pins {
pins = "PB8", "PB9";
function = "uart0";
};
lcd_rgb666_pins_a: lcd-rgb666-pe {
pins = "PE0", "PE1", "PE2", "PE3", "PE4", "PE5",
"PE6", "PE7", "PE8", "PE9", "PE10", "PE11",
"PE12", "PE13", "PE14", "PE15", "PE16", "PE17",
"PE18", "PE19", "PE23", "PE24";
function = "lcd";
};
mmc0_pins: mmc0-pins {
pins = "PF0", "PF1", "PF2", "PF3",
"PF4", "PF5";
function = "mmc0";
drive-strength = <30>;
bias-pull-up;
};
mmc1_pins: mmc1-pins {
pins = "PG0", "PG1", "PG2", "PG3",
"PG4", "PG5";
function = "mmc1";
drive-strength = <30>;
bias-pull-up;
};
spi0_pins: spi0-pins {
pins = "PC0", "PC1", "PC2", "PC3";
function = "spi0";
};
/*******camera use for 20220709 start************/
csi1_8bit: csi1-8bit@0 {
pins = "PE6","PE7","PE8","PE9","PE10","PE11","PE12","PE13","PE14","PE15";
bias-disable;
function = "csi";
};
csi1_clk: csi1-clk@0 {
pins = "PE0","PE2","PE3";
bias-disable;
function = "csi";
};
csi1_mclk: csi1-mclk@0 {
pins = "PE1";
bias-disable;
function = "csi";
};
i2c1_pins: i2c1 {
pins = "PE21", "PE22";
function = "i2c1";
};
/***********camera use for 20220709 end**********/
};
sun8i-v3s-licheepi-zero-dock.dts
/**************dvp camera use for 20220709 start************/
&csi1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&csi1_clk &csi1_8bit>;
port {
csi1_ep: endpoint {
remote-endpoint = <&ov2640_0>;
hsync-active = <0>;
vsync-active = <0>;
bus-width = <10>;
pclk-sample = <1>;
};
// csi1_ep: endpoint {
// remote-endpoint = <&ov7725_0>;
// hsync-active = <0>;
// vsync-active = <1>;
// bus-width = <8>;
// pclk-sample = <1>;
// };
};
};
&i2c1 {
pinctrl-0 = <&i2c1_pins>;
pinctrl-names = "default";
status = "okay";
// ov7725: camera@21 {
// compatible = "ovti,ov7725";
// reg = <0x21>;
// pinctrl-names = "default";
// pinctrl-0 = <&csi1_mclk>;
// clocks = <&ccu CLK_CSI1_MCLK>;
// clock-names = "xclk";
// assigned-clocks = <&ccu CLK_CSI1_MCLK>;
// assigned-clock-rates = <24000000>;
// port {
// ov7725_0: endpoint {
// remote-endpoint = <&csi1_ep>;
// //bus-width = <10>;
// };
// };
// };
ov2640: camera@30 {
compatible = "ovti,ov2640";
reg = <0x30>;
pinctrl-names = "default";
pinctrl-0 = <&csi1_mclk>;
clocks = <&ccu CLK_CSI1_MCLK>;
clock-names = "xvclk";
assigned-clocks = <&ccu CLK_CSI1_MCLK>;
assigned-clock-rates = <24000000>;
port {
ov2640_0: endpoint {
remote-endpoint = <&csi1_ep>;
bus-width = <10>;
};
};
};
};
/**************dvp camera use for 20220709 end************/
编译设备树:make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
二、增加Linux驱动配置
Linux源码根目录下运行命令:
make clean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- licheepi_zero_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
三、构建Buildroot文件系统
- ffmpeg
- fswebcam
使用I2c工具调试
可以用 i2ctools 里面的 i2cdetect 检测摄像头是否存在
# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
# i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
#
各种折腾后终于出现了
# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
成功的上电信息
U-Boot SPL 2017.01-rc2 (May 31 2022 - 23:43:42)
DRAM: 64 MiB
Trying to boot from MMC1
U-Boot 2017.01-rc2 (May 31 2022 - 23:43:42 +0800) Allwinner Technology
CPU: Allwinner V3s (SUN8I 1681)
Model: Lichee Pi Zero
DRAM: 64 MiB
MMC: SUNXI SD/MMC: 0
*** Warning - bad CRC, using default environment
Setting up a 800x480 lcd console (overscan 0x0)
dotclock: 33000kHz = 33000kHz: (1 * 3MHz * 66) / 6
In: serial@01c28000
Out: serial@01c28000
Err: serial@01c28000
U-Boot 2017.01-rc2 (May 31 2022 - 23:43:42 +0800) Allwinner Technology
CPU: Allwinner V3s (SUN8I 1681)
Model: Lichee Pi Zero
DRAM: 64 MiB
MMC: SUNXI SD/MMC: 0
*** Warning - bad CRC, using default environment
Setting up a 800x480 lcd console (overscan 0x0)
dotclock: 33000kHz = 33000kHz: (1 * 3MHz * 66) / 6
In: serial@01c28000
Out: serial@01c28000
Err: serial@01c28000
Net: No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
reading /boot.scr
282 bytes read in 15 ms (17.6 KiB/s)
## Executing script at 41900000
reading zImage
4152248 bytes read in 213 ms (18.6 MiB/s)
reading sun8i-v3s-licheepi-zero-dock.dtb
12748 bytes read in 26 ms (478.5 KiB/s)
## Flattened Device Tree blob at 41800000
Booting using the fdt blob at 0x41800000
Loading Device Tree to 42df9000, end 42dff1cb ... OK
Cannot setup simplefb: node not found
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.2.0-licheepi-zero (liefyuan@ubuntu) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01)) #7 SMP Sun Jul 10 23:54:29 CST 2022
[ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[ 0.000000] CPU: div instructions available: patching division code
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: Lichee Pi Zero with Dock
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] percpu: Embedded 16 pages/cpu s34560 r8192 d22784 u65536
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 16256
[ 0.000000] Kernel command line: console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 earlyprintk rw
[ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 55060K/65536K available (6144K kernel code, 289K rwdata, 1668K rodata, 1024K init, 252K bss, 10476K reserved, 0K cma-reserved, 0K highmem)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU event tracing is enabled.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] random: get_random_bytes called from start_kernel+0x2f8/0x48c with crng_init=0
[ 0.000000] arch_timer: cp15 timer(s) running at 24.00MHz (virt).
[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[ 0.000008] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns
[ 0.000020] Switching to timer-based delay loop, resolution 41ns
[ 0.000219] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[ 0.000463] Console: colour dummy device 80x30
[ 0.000521] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000)
[ 0.000537] pid_max: default: 32768 minimum: 301
[ 0.000700] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.000716] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.001531] CPU: Testing write buffer coherency: ok
[ 0.002060] /cpus/cpu@0 missing clock-frequency property
[ 0.002087] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.002881] Setting up static identity map for 0x40100000 - 0x40100060
[ 0.003089] rcu: Hierarchical SRCU implementation.
[ 0.003626] smp: Bringing up secondary CPUs ...
[ 0.003648] smp: Brought up 1 node, 1 CPU
[ 0.003657] SMP: Total of 1 processors activated (48.00 BogoMIPS).
[ 0.003665] CPU: All CPU(s) started in SVC mode.
[ 0.004748] devtmpfs: initialized
[ 0.008397] VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
[ 0.008720] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.008752] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[ 0.009001] pinctrl core: initialized pinctrl subsystem
[ 0.010166] NET: Registered protocol family 16
[ 0.010696] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.011923] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
[ 0.011942] hw-breakpoint: maximum watchpoint size is 8 bytes.
[ 0.035912] SCSI subsystem initialized
[ 0.036100] usbcore: registered new interface driver usbfs
[ 0.036161] usbcore: registered new interface driver hub
[ 0.036263] usbcore: registered new device driver usb
[ 0.036489] mc: Linux media interface: v0.10
[ 0.036528] videodev: Linux video capture interface: v2.00
[ 0.036773] Advanced Linux Sound Architecture Driver Initialized.
[ 0.038063] clocksource: Switched to clocksource arch_sys_counter
[ 0.050446] NET: Registered protocol family 2
[ 0.051295] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.051337] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.051364] TCP bind hash table entries: 1024 (order: 1, 8192 bytes, linear)
[ 0.051388] TCP: Hash tables configured (established 1024 bind 1024)
[ 0.051541] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.051596] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.051906] NET: Registered protocol family 1
[ 0.053837] Initialise system trusted keyrings
[ 0.054221] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[ 0.091499] Key type asymmetric registered
[ 0.091523] Asymmetric key parser 'x509' registered
[ 0.091629] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[ 0.091643] io scheduler mq-deadline registered
[ 0.091650] io scheduler kyber registered
[ 0.092688] sun4i-usb-phy 1c19400.phy: Couldn't request ID GPIO [ 0.096547] sun8i-v3s-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver [ 0.097017] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pb not found, using dummy regulator [ 0.167079] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled [ 0.170636] printk: console [ttyS0] disabled [ 0.190953] 1c28000.serial: ttyS0 at MMIO 0x1c28000 (irq = 37, base_baud = 1500000) is a U6_16550A [ 0.697756] printk: console [ttyS0] enabled [ 0.727134] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 0.733764] ehci-platform: EHCI generic platform driver [ 0.739291] ehci-platform 1c1a000.usb: EHCI Host Controller [ 0.744902] ehci-platform 1c1a000.usb: new USB bus registered, assigned bus number 1 [ 0.752904] ehci-platform 1c1a000.usb: irq 26, io mem 0x01c1a000 [ 0.788077] ehci-platform 1c1a000.usb: USB 2.0 started, EHCI 1.00 [ 0.795319] hub 1-0:1.0: USB hub found [ 0.799290] hub 1-0:1.0: 1 port detected [ 0.803921] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 0.810249] ohci-platform: OHCI generic platform driver [ 0.815802] ohci-platform 1c1a400.usb: Generic Platform OHCI controller [ 0.822527] ohci-platform 1c1a400.usb: new USB bus registered, assigned bus number 2 [ 0.830491] ohci-platform 1c1a400.usb: irq 27, io mem 0x01c1a400 [ 0.903204] hub 2-0:1.0: USB hub found [ 0.907044] hub 2-0:1.0: 1 port detected [ 0.914442] usbcore: registered new interface driver usb-storage [ 0.921774] input: 1c22800.lradc as /devices/platform/soc/1c22800.lradc/input/input0 [ 0.931108] sun6i-rtc 1c20400.rtc: registered as rtc0 [ 0.936173] sun6i-rtc 1c20400.rtc: RTC enabled [ 0.940914] i2c /dev entries driver [ 0.945914] input: ns2009_ts as /devices/platform/soc/1c2ac00.i2c/i2c-0/0-0048/input/input1 [ 0.954949] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pe not found, using dummy regulator [ 0.968494] ov2640 1-0030: ov2640 Product ID 26:42 Manufacturer ID 7f:a2 [ 0.975209] i2c i2c-1: OV2640 Probed [ 0.981754] sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=0) [ 0.990488] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pf not found, using dummy regulator [ 1.026966] sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB [ 1.034281] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pg not found, using dummy regulator [ 1.069095] sunxi-mmc 1c10000.mmc: initialized, max. request size: 16384 KB [ 1.077208] usbcore: registered new interface driver usbhid [ 1.082879] usbhid: USB HID core driver [ 1.089091] sun4i-codec 1c22c00.codec: ASoC: codec-analog@01c23000 not registered [ 1.096596] sun4i-codec 1c22c00.codec: Failed to register our card [ 1.104161] Initializing XFRM netlink socket [ 1.108592] NET: Registered protocol family 17 [ 1.113693] Registering SWP/SWPB emulation handler [ 1.119763] Loading compiled-in X.509 certificates [ 1.131462] usb_phy_generic usb_phy_generic.0.auto: usb_phy_generic.0.auto supply vcc not found, using dummy regulator [ 1.142959] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver [ 1.148811] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 3 [ 1.158534] hub 3-0:1.0: USB hub found [ 1.162464] hub 3-0:1.0: 1 port detected [ 1.169009] debugfs: Directory '1c22c00.codec' with parent 'V3s Audio Codec' already present! [ 1.177558] sun4i-codec 1c22c00.codec: ASoC: Failed to create component debugfs directory: -17 [ 1.187657] sun4i-codec 1c22c00.codec: Codec <-> 1c22c00.codec mapping ok [ 1.195003] mmc0: host does not support reading read-only switch, assuming write-enable [ 1.204437] sun6i-rtc 1c20400.rtc: setting system clock to 1970-01-01T00:00:05 UTC (5) [ 1.212778] vcc5v0: disabling [ 1.215756] ALSA device list: [ 1.218785] #0: V3s Audio Codec [ 1.222988] mmc0: new high speed SDHC card at address 1234 [ 1.230765] mmcblk0: mmc0:1234 SA32G 29.1 GiB [ 1.237685] mmcblk0: p1 p2 [ 1.264226] random: fast init done [ 1.284676] EXT4-fs (mmcblk0p2): recovery complete [ 1.290566] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null) [ 1.298848] VFS: Mounted root (ext4 filesystem) on device 179:2. [ 1.306699] devtmpfs: mounted [ 1.310953] Freeing unused kernel memory: 1024K [ 1.315631] Run /sbin/init as init process [ 1.432930] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null) Starting syslogd: OK Starting klogd: OK Running sysctl: OK Starting mdev... OK modprobe: can't change directory to '5.2.0-licheepi-zero': No such file or directory
Initializing random number generator: OK
Saving random seed: [ 2.895596] random: dd: uninitialized urandom read (512 bytes read)
OK
Starting system message bus: [ 2.956060] random: dbus-uuidgen: uninitialized urandom read (12 bytes read)
[ 2.963489] random: dbus-uuidgen: uninitialized urandom read (8 bytes read)
done
Starting network: OK
Starting dhcpcd...
no valid interfaces found
no interfaces have a carrier
forked to background, child pid 149
#
意外收获
RAW看图软件 7yuv
测试
视频录制:
ffmpeg -f video4linux2 -s 800x600 -r 30 -i /dev/video0 test.avi
ffmpeg -f v4l2 -s 800x600 -r 30 -i /dev/video0 test.avi
拍摄照片:
fswebcam -S 20 -d /dev/video0 -p UYVY -r 800x600 --dumpframe dump.bin fswebcam.jpg
fswebcam -S 1 -d /dev/video0 -p UYVY -r 800x600 test.jpg
不知道为啥,照片有横纹:
今天的文章全志V3s学习记录(13)OV2640的使用[通俗易懂]分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/87166.html