前言
基于ZYNQ来进行的图像处理平台,OV5640和一些IP核的基本知识就不讲了,网上都有很多,自己可以慢慢研究,我就直接上整体框架。
OV5640图像采集是我们自定义的 IP 核,负责将 OV5640的数据转成视频流数据;视频流数据经过 Video in to AXI4-Stream IP 核转换成 AXI4-Stream IP 格式数据流,然后通过 VDMA 的写通道转成 AXI4 Memory Map 格式,并最终写入 DDR 内存中。VDMA 通过 AXISmartconnect IP 核与 AXI_HP 端口进行连接,从而高效访问 DDR3,VDMA 从 DDR3 中读取的视频或图像数据传输给 AXI4-Stream to Video Out IP 核。AXI4-Stream to Video Out IP 核在 VTC IP 核的控制下,把AXI4-Stream 格式的数据转换成视频输出的数据格式(如 RGB888),并将输出的视频数据流连接至RGB2LCD IP 核(rgb2lcd)的输入端。
一、硬件架构
1.硬件连接配置
打开PS和PL的连接HP AXI
打开串口和emio(串口方便调试,emio做OV5640的驱动)
串口引脚和配置两位emio来做驱动
时钟100M
内存按自己的配置来
怎么导入IP核就不说了,直接看各个IP核的配置,要配置的就4个v_axi4s_vid_out_0,v_vid_in_axi4s_0,axi_vdma_0,axi_dynclk_0(自己的动态时钟管理IP核)。
端口的引出和命名
整体架构
约束文件
set_property IOSTANDARD LVCMOS33 [get_ports lcd_lcd_hs]
set_property IOSTANDARD LVCMOS33 [get_ports lcd_lcd_vs]
set_property IOSTANDARD LVCMOS33 [get_ports lcd_lcd_de]
set_property IOSTANDARD LVCMOS33 [get_ports lcd_lcd_pclk]
set_property IOSTANDARD LVCMOS33 [get_ports lcd_bl0]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[23]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[22]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[21]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[20]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[19]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[18]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[17]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[16]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[15]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[14]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[13]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[12]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[11]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[10]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[9]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[8]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[7]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[6]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[5]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[4]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[2]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[1]}]
set_property IOSTANDARD LVCMOS33 [get_ports {lcd_rgb_o[0]}]
set_property PACKAGE_PIN R14 [get_ports lcd_lcd_de]
set_property PACKAGE_PIN W15 [get_ports lcd_lcd_hs]
set_property PACKAGE_PIN T10 [get_ports lcd_lcd_pclk]
set_property PACKAGE_PIN V15 [get_ports lcd_lcd_vs]
set_property PACKAGE_PIN T11 [get_ports lcd_bl0]
set_property PACKAGE_PIN W16 [get_ports {lcd_rgb_o[0]}]
set_property PACKAGE_PIN V16 [get_ports {lcd_rgb_o[1]}]
set_property PACKAGE_PIN R18 [get_ports {lcd_rgb_o[2]}]
set_property PACKAGE_PIN T17 [get_ports {lcd_rgb_o[3]}]
set_property PACKAGE_PIN W13 [get_ports {lcd_rgb_o[4]}]
set_property PACKAGE_PIN V12 [get_ports {lcd_rgb_o[5]}]
set_property PACKAGE_PIN T15 [get_ports {lcd_rgb_o[6]}]
set_property PACKAGE_PIN T14 [get_ports {lcd_rgb_o[7]}]
set_property PACKAGE_PIN P18 [get_ports {lcd_rgb_o[8]}]
set_property PACKAGE_PIN Y17 [get_ports {lcd_rgb_o[9]}]
set_property PACKAGE_PIN Y16 [get_ports {lcd_rgb_o[10]}]
set_property PACKAGE_PIN V18 [get_ports {lcd_rgb_o[11]}]
set_property PACKAGE_PIN N17 [get_ports {lcd_rgb_o[12]}]
set_property PACKAGE_PIN V17 [get_ports {lcd_rgb_o[13]}]
set_property PACKAGE_PIN Y14 [get_ports {lcd_rgb_o[14]}]
set_property PACKAGE_PIN W14 [get_ports {lcd_rgb_o[15]}]
set_property PACKAGE_PIN Y19 [get_ports {lcd_rgb_o[16]}]
set_property PACKAGE_PIN Y18 [get_ports {lcd_rgb_o[17]}]
set_property PACKAGE_PIN W19 [get_ports {lcd_rgb_o[18]}]
set_property PACKAGE_PIN W18 [get_ports {lcd_rgb_o[19]}]
set_property PACKAGE_PIN U17 [get_ports {lcd_rgb_o[20]}]
set_property PACKAGE_PIN T16 [get_ports {lcd_rgb_o[21]}]
set_property PACKAGE_PIN R17 [get_ports {lcd_rgb_o[22]}]
set_property PACKAGE_PIN R16 [get_ports {lcd_rgb_o[23]}]
#----------------------摄像头接口的时钟---------------------------
set_property CLOCK_DEDICATED_ROUTE FALSE [get_nets cam_pclk_IBUF]
#----------------------摄像头接口---------------------------
set_property IOSTANDARD LVCMOS33 [get_ports cam_rst_n]
set_property IOSTANDARD LVCMOS33 [get_ports cam_pclk]
set_property IOSTANDARD LVCMOS33 [get_ports cam_vsync]
set_property IOSTANDARD LVCMOS33 [get_ports cam_href]
set_property IOSTANDARD LVCMOS33 [get_ports cam_pwdn]
set_property IOSTANDARD LVCMOS33 [get_ports {cam_data[*]}]
set_property PACKAGE_PIN D18 [get_ports cam_pclk]
set_property PACKAGE_PIN G15 [get_ports cam_href]
set_property PACKAGE_PIN H15 [get_ports cam_vsync]
set_property PACKAGE_PIN E19 [get_ports cam_rst_n]
set_property PACKAGE_PIN H16 [get_ports cam_pwdn]
set_property PACKAGE_PIN E17 [get_ports {cam_data[7]}]
set_property PACKAGE_PIN D20 [get_ports {cam_data[6]}]
set_property PACKAGE_PIN D19 [get_ports {cam_data[5]}]
set_property PACKAGE_PIN A20 [get_ports {cam_data[4]}]
set_property PACKAGE_PIN B19 [get_ports {cam_data[3]}]
set_property PACKAGE_PIN E18 [get_ports {cam_data[2]}]
set_property PACKAGE_PIN F17 [get_ports {cam_data[1]}]
set_property PACKAGE_PIN F16 [get_ports {cam_data[0]}]
/*emio*/
set_property IOSTANDARD LVCMOS33 [get_ports {emio_sccb_tri_io[1]}]
set_property IOSTANDARD LVCMOS33 [get_ports {emio_sccb_tri_io[0]}]
set_property PACKAGE_PIN L16 [get_ports {emio_sccb_tri_io[0]}]
set_property PACKAGE_PIN L17 [get_ports {emio_sccb_tri_io[1]}]
set_property PULLUP true [get_ports {emio_sccb_tri_io[1]}]
2.导出硬件
左侧 Flow Navigator 导航栏中找到 PROGRAM AND DEBUG,点击该选项中的“Generate Bitstream”,对设计进行综合、实现、并生成 Bitstream 文件。
在生成 Bitstream 之后,在菜单栏中选择 File Export > Export hardware 导出硬件,并在弹出的对话框 中,勾选“Include bitstream”。然后在菜单栏选择 File > Launch SDK,启动 SDK 软件。
注意:生成Bitstream 文件比较慢并不是软件卡了,泪的教训。
二、SDK程序
1.新建项目
首先在菜单栏选择 File > New > Application
Project, 新建一个 SDK 应用工程。在弹出的对话框中,输入工程名。在弹出的对话框中选择希望使用的工程模板,这里我们选择空模板。
2.导入文件
添加文件 LCD的显示和动态时钟,emio驱动OV5640,VDMA的api
main.c
//****************************************Copyright (c)***********************************//
//原子哥在线教学平台:www.yuanzige.com
//技术支持:www.openedv.com
//淘宝店铺:http://openedv.taobao.com
//关注微信公众平台微信号:"正点原子",免费获取ZYNQ & FPGA & STM32 & LINUX资料。
//版权所有,盗版必究。
//Copyright(C) 正点原子 2018-2028
//All rights reserved
//----------------------------------------------------------------------------------------
// File name: main.c
// Last modified Date: 2019/07/01 15:59:46
// Last Version: V1.0
// Descriptions: OV5640摄像头驱动LCD示例
//----------------------------------------------------------------------------------------
// Created by: 正点原子
// Created date: 2019/07/01 15:59:52
// Version: V1.0
// Descriptions: The original version
//
//----------------------------------------------------------------------------------------
//****************************************************************************************//
/***************************** Include Files *********************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xil_types.h"
#include "xil_cache.h"
#include "xparameters.h"
#include "xaxivdma.h"
#include "xaxivdma_i.h"
#include "display_ctrl/display_ctrl.h"
#include "vdma_api/vdma_api.h"
#include "emio_sccb_cfg/emio_sccb_cfg.h"
#include "ov5640/ov5640_init.h"
//宏定义
#define BYTES_PIXEL 3 //像素字节数,RGB888占3个字节
#define FRAME_BUFFER_NUM 3 //帧缓存个数3
#define DYNCLK_BASEADDR XPAR_AXI_DYNCLK_0_BASEADDR //动态时钟基地址
#define VDMA_ID XPAR_AXIVDMA_0_DEVICE_ID //VDMA器件ID
#define DISP_VTC_ID XPAR_VTC_0_DEVICE_ID //VTC器件ID
//全局变量
//frame buffer的起始地址
unsigned int const frame_buffer_addr = (XPAR_PS7_DDR_0_S_AXI_BASEADDR
+ 0x1000000);
XAxiVdma vdma;
DisplayCtrl dispCtrl;
VideoMode vd_mode;
int main(void)
{
u32 status;
u16 cmos_h_pixel; //ov5640 DVP 输出水平像素点数
u16 cmos_v_pixel; //ov5640 DVP 输出垂直像素点数
u16 total_h_pixel; //ov5640 水平总像素大小
u16 total_v_pixel; //ov5640 垂直总像素大小
cmos_h_pixel = 480;
cmos_v_pixel = 272;
total_h_pixel = 1800;
total_v_pixel = 1000;
emio_init(); //初始化EMIO
status = ov5640_init( cmos_h_pixel, //初始化ov5640
cmos_v_pixel,
total_h_pixel,
total_v_pixel);
if(status == 0)
xil_printf("OV5640 detected successful!\r\n");
else
xil_printf("OV5640 detected failed!\r\n");
vd_mode = VMODE_480x272; //4.3寸屏,480*272分辨率
//配置VDMA
run_vdma_frame_buffer(&vdma, VDMA_ID, vd_mode.width, vd_mode.height,
frame_buffer_addr,0,0,BOTH);
//初始化Display controller
DisplayInitialize(&dispCtrl, DISP_VTC_ID, DYNCLK_BASEADDR);
//设置VideoMode
DisplaySetMode(&dispCtrl, &vd_mode);
DisplayStart(&dispCtrl);
return 0;
}
实验结果
正常显示,成功了。要完整项目的评论发邮箱。