MYIR-ZYNQ7000系列-zturn教程(17):用axi_uart发送数据

开发板环境:vivado 2017.1 ,开发板型号xc7z020clg400-1,这个工程主要用axi_uart发送数据,IP核设置的

波特率为9600

工程的网盘下载链接:https://pan.baidu.com/s/1ID426Zd85LgtAzhQMZpzNA 密码:6irg

Step1 新建工程,调用一个zynq核并配置

配置选中这个SD卡,工程做完后会从SD卡启动

将这个SDIO设置为50M

这里选择一个DDR的型号(不同的开发板有所不同),点击OK完成配置

配置完成后的zynq核(这个看起来和配置之前一样)

Step2 调用axi_uart核并设置波特率

点击工具栏的Add IP按钮在弹出的搜索框中输入axi_uart,然后选择这个AXI Uartlite核双击添加进来

双击这个AXI Uartlite核,这里的Baud  Rate可以选择不同的波特率,我这里选择这个默认的9600(这个波特率可以

根据自己的需求选择),其它的选项都保持默认,点击OK完成配置

Step3   axi_uart进行自动连线将IP核和zynq核连接起来

点击这个Run Block Automation  引出DDR和PS的管脚

点击OK

如下图所示

点击这个Run  Connection  Automation将所有的模块连接起来

在弹出的对话框中勾选全部,点击OK

连接成功后如下图所示

Step4   生成综合文件和生成顶层文件

综合

生成顶层文件

Step 5  新建xdc文件并设置管脚

set_property PACKAGE_PIN T11 [get_ports uart_rtl_rxd]
set_property PACKAGE_PIN T10 [get_ports uart_rtl_txd]
set_property IOSTANDARD LVCMOS33 [get_ports uart_rtl_rxd]
set_property IOSTANDARD LVCMOS33 [get_ports uart_rtl_txd]

Step 6   生成bit文件,导出硬件配置,打开SDK

点击Generate  Bitstream生成bit文件

File->Export->Export Hardware  导出硬件配置

勾选,点击OK

打开SDK

Step 7 新建一个fsbl

File -->Application Project

点击Next

点击Finish

Step 8 新建一个axi_uart_test工程

File -->Application Project

点击Next

选择hello_world模板,点击Finish

然后将这个主程序复制到这个新建hello_world模板里

/******************************************************************************
*
* Copyright (C) 2002 - 2015 Xilinx, Inc.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/*****************************************************************************/
/**
*
* @file xuartlite_low_level_example.c
*
* This file contains a design example using the low-level driver functions
* and macros of the UartLite driver (XUartLite).
*
* @note
*
* The user must provide a physical loopback such that data which is
* transmitted will be received.
*
* MODIFICATION HISTORY:
* <pre>
* Ver   Who  Date	 Changes
* ----- ---- -------- ---------------------------------------------------------
* 1.00b rpm  04/25/02 First release
* 1.00b sv   06/13/05 Minor changes to comply to Doxygen and coding guidelines
* 2.00a ktn  10/20/09 Updated to use HAL processor APIs and minor changes
*		      for coding guidelines.
* 3.2   ms   01/23/17 Added xil_printf statement in main function to
*                     ensure that "Successfully ran" and "Failed" strings
*                     are available in all examples. This is a fix for
*                     CR-965028.
* </pre>
******************************************************************************/

/***************************** Include Files *********************************/

#include "xparameters.h"
#include "xstatus.h"
#include "xuartlite_l.h"
#include "xil_printf.h"

/************************** Constant Definitions *****************************/


/*
 * The following constants map to the XPAR parameters created in the
 * xparameters.h file. They are defined here such that a user can easily
 * change all the needed parameters in one place.
 */
#define UARTLITE_BASEADDR	   XPAR_UARTLITE_0_BASEADDR

/*
 * The following constant controls the length of the buffers to be sent
 * and received with the UartLite, this constant must be 16 bytes or less so the
 * entire buffer will fit into the transmit and receive FIFOs of the UartLite.
 */
#define TEST_BUFFER_SIZE sizeof(uart_data)


/**************************** Type Definitions *******************************/


/***************** Macros (Inline Functions) Definitions *********************/


/************************** Function Prototypes ******************************/

int UartLiteLowLevelExample(u32 UartliteBaseAddress);


/************************** data ******************************/
struct sensor_register {
    u8 value;
};

static const struct sensor_register uart_data[] = {

    { 0x01},
    { 0x02},
    { 0x03},
    { 0x04},
    { 0x05},
    { 0x06},
    { 0x07},
    { 0x08},
    { 0x09},
    { 0x10},
    { 0x11},
    { 0x12},
    { 0x13},
    { 0x14},
    { 0x15},
    { 0x16},
    { 0x17},

};

/*****************************************************************************/

/************************** Variable Definitions *****************************/

/*
 * The following buffers are used in this example to send and receive data
 * with the UartLite.
 */
u8 SendBuffer[sizeof(uart_data)]; /* Buffer for Transmitting Data */
u8 RecvBuffer[sizeof(uart_data)]; /* Buffer for Receiving Data */


/*****************************************************************************/

/**
*
* Main function to call the example.
*
* @param	None.
*
* @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful.
*
* @note		None.
*
******************************************************************************/


int main(void)
{
	int Status;

	/*
	 * Run the UartLite Low level example, specify the BaseAddress that is
	 * generated in xparameters.h.
	 */
	Status = UartLiteLowLevelExample(UARTLITE_BASEADDR);
	if (Status != XST_SUCCESS) {
		xil_printf("Uartlite lowlevel Example Failed\r\n");
		return XST_FAILURE;
	}

	xil_printf("Successfully ran Uartlite lowlevel Example\r\n");
	return XST_SUCCESS;
}


/*****************************************************************************/
/**
*
* This function does a minimal test on the UartLite device using the low-level
* driver macros and functions. This function sends data and expects to receive
* the data through the UartLite. A physical loopback must be done by the user
* with the transmit and receive signals of the UartLite.
*
* @param	UartliteBaseAddress is the base address of the UartLite device
*		and is the XPAR_<UARTLITE_instance>_BASEADDR value from
*		xparameters.h.
*
* @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful.
*
* @note		None.
*
******************************************************************************/
int UartLiteLowLevelExample(u32 UartliteBaseAddress)
{
	int Index;

	/*
	 * Initialize the send buffer bytes with a pattern to send and the
	 * the receive buffer bytes to zero.
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = uart_data[Index].value;
		RecvBuffer[Index] = 0;
	}


	/*
	 * Send the entire transmit buffer.
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		XUartLite_SendByte(UartliteBaseAddress, SendBuffer[Index]);
	}

	/*
	 * Receive the entire buffer's worth. Note that the RecvByte function
	 * blocks waiting for a character.
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		RecvBuffer[Index] = XUartLite_RecvByte(UartliteBaseAddress);
	}

	/*
	 * Check the receive buffer data against the send buffer and verify the
	 * data was correctly received.
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		if (SendBuffer[Index] != RecvBuffer[Index]) {
			return XST_FAILURE;
		}
	}

	return XST_SUCCESS;
}


复制完成后如下图所示

这里程序做一些基本的讲解:

这里是uart发送数据部分,可以填充不同的数据

/************************** data ******************************/
struct sensor_register {
    u8 value;
};

static const struct sensor_register uart_data[] = {

    { 0x01},
    { 0x02},
    { 0x03},
    { 0x04},
    { 0x05},
    { 0x06},
    { 0x07},
    { 0x08},
    { 0x09},
    { 0x10},
    { 0x11},
    { 0x12},
    { 0x13},
    { 0x14},
    { 0x15},
    { 0x16},
    { 0x17},

};

下面这个接收和发送Buffer里都有这个sizeof(uart_data),这个函数主要计算这个定义的数组里放了多少个数据

(这样就不用每次加数据要改这个发送和接收Buffer的大小了)

u8 SendBuffer[sizeof(uart_data)]; /* Buffer for Transmitting Data */
u8 RecvBuffer[sizeof(uart_data)]; /* Buffer for Receiving Data */

这里对发送Buffer和接收Buffer进行填充

 for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
        SendBuffer[Index] = uart_data[Index].value;
        RecvBuffer[Index] = 0;
    }

这个是发送,发送Buffer里的数据

/*
     * Send the entire transmit buffer.
     */
    for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
        XUartLite_SendByte(UartliteBaseAddress, SendBuffer[Index]);
    }

这个是接收外面发送进来的数据

/*
     * Receive the entire buffer's worth. Note that the RecvByte function
     * blocks waiting for a character.
     */
    for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
        RecvBuffer[Index] = XUartLite_RecvByte(UartliteBaseAddress);
    }

这里对数据进行校验看发送和接收的是不是一样,这个一般可以用rx和tx回环来进行验证

/*
     * Check the receive buffer data against the send buffer and verify the
     * data was correctly received.
     */
    for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
        if (SendBuffer[Index] != RecvBuffer[Index]) {
            return XST_FAILURE;
        }
    }

Step 9 生成一个BOOT.bin文件放到SD卡里运行

右击工程选择Create Boot Image 

点击 Create  Image  生成BOOT.bin文件

将这个BOOT.bin文件拷贝到SD卡插到开发板上,然后将这个rx和tx端连接一个带有串口转换芯片的uart线,这样就可以

从串口调试助手打印uart发送的数据(因分配的管脚是fpga管脚是CMOS电平,电脑是TTL电平所以要用一个带有串口

转换芯片的uart线就可以使用了)

上电后串口打印的输出数据

将数据区域填充不同的数据

/************************** data ******************************/
struct sensor_register {
    u8 value;
};

static const struct sensor_register uart_data[] = {

    { 0x01},
    { 0x02},
    { 0x03},
    { 0x04},
    { 0x05},
    { 0x06},
    { 0x07},
    { 0x08},
    { 0x09},
    { 0x10},

};

此时的串口打印的输出数据

<think>我们正在讨论Zynq7000开发板(如ZedBoard)使用中是否需要配置跳线帽的问题。根据引用[1]中的描述:“ZedBoard开发板实物如图1-3所示。JP标示为跳线帽的位置。”,这表明跳线帽(JP)在开发板上是存在的,并且可能需要配置。因此,答案是肯定的,使用Zynq7000开发板时,通常需要根据具体需求配置跳线帽。###为什么需要配置跳线帽?跳线帽(Jumper)是一种硬件连接器,用于改变电路板上的电气连接。在Zynq7000开发板上,跳线帽通常用于以下目的: 1. **启动模式选择**:Zynq芯片支持多种启动方式(如JTAG、QSPI Flash、SD卡等)。通过跳线帽设置不同的引脚电平组合,可以决定芯片上电后的启动方式[^1]。 2. **外设接口选择**:例如,选择使用PS端还是PL端的UART、USB或以太网接口。跳线帽可以切换信号路由,避免冲突。 3. **电源管理**:某些开发板通过跳线帽选择电源输入方式(如USB供电或外部电源适配器)。4.**调试接口使能**:例如,启用/禁用JTAG接口,或选择调试模式。###如何配置跳线帽?以ZedBoard为例(引用[1]):1.**启动模式设置**:-参考开发板手册中的“BootMode Jumpers”部分(通常位于JP7附近)。-常见的启动模式跳线设置:- JTAG模式:MIO[5:0] =000000(所有跳线帽置于下方)- SD卡启动:MIO[5:0]=001010(具体跳线帽位置需查手册)-错误设置会导致板卡无法启动或无法烧录程序。2.**外设接口选择**:-例如,选择UART通信接口:-若需通过USB转串口(UART0)连接,需将跳线帽置于JP14(UART0使能)[^1]。-以太网接口选择:跳线帽JP11用于切换PS端或PL端的以太网PHY。 ###注意事项-**操作前断电**:更换跳线帽前务必断开电源,避免短路损坏板卡。-**参考官方文档**:不同开发板(如MYIR-ZYNQ7000ZTURN)的跳线位置可能不同,请查阅对应手册(如引用[2][^2]和引用[4][^4]中提到的开发板)。-**典型错误**:-若Vitis报错“Cannot resetAPU”(如用户之前的问题),检查JTAG跳线帽是否松动或模式设置错误(例如,启动模式被误设为非JTAG)。###示例:ZedBoard启动模式跳线设置(简表) |启动模式|跳线帽位置(JP7)| MIO[5:0]| |------------|-------------------|----------| |JTAG|全下方|000000| |QSPI Flash|上-----下|001001|| SD卡|下-----下|001010|>注:具体设置以实际板卡手册为准。###结论**是,使用Zynq7000开发板时必须正确配置跳线帽**,否则可能导致启动失败、外设无法工作或调试异常(如之前的APU复位错误)。建议:1.查阅开发板手册(如ZedBoard的[UG1185])。2.根据当前开发阶段(调试/部署)调整跳线帽。调试时通常选择JTAG模式,部署时选择Flash或SD卡启动[^3]。§§相关问题§§1. Zynq7000开发板的启动模式有哪些?如何配置?2.跳线帽设置错误导致JTAG连接失败应如何排查?3.如何通过跳线帽选择Zynq7000开发板的外设接口?[^1]: Avnet推出的ZedBoard开发板依据Zynq7000的资源定制外设,可以充分利用PS和PL的资源优势进行项目前期技术评估。ZedBoard开发板利用Zynq7000的资源外设原理框如图1-2所示。ZedBoard开发板实物如图1-3所示。JP标示为跳线帽的位置。[^2]:MYIR-ZYNQ7000系列-zturn教程(4):gpio_emio。step1这是已经新建好的vivdao工程(如果大家不会新建vivado工程请参考我上篇博文hello_worldMYIR-ZYNQ7000系列-zturn教程(2):Hello_World_虚无缥缈vs威武的博客-优快云博客_zturn里面有新建工程的步骤)。 [^3]:基于ZYNQ7开发板的UBOOT+ vxWorks6.9开发和配置流程。配置参数,通过网络tftp方式加载启动vxWorks镜像: setipaddr192.168.50.133set serverip192.168.50.12 setenv loadaddr0x1000000 setenv bootcmd runbootcmdvxsetenvbootcmdvx"tftpboot vxWorks.elf;bootvx" saveenv。[^4]:产品推荐 |基于Xilinx Zynq-7015 FPGA的MYC-C7Z015开发板。基于 XilinxZynq-7015,双Cortex-A9+FPGA全可编程处理器;PS部分(ARM)与PL部分(FPGA)之间采用AXI高速片上总线通信,吉比特级带宽,突破传统ARM+FPGA架构的通信瓶颈,通过PL部分(FPGA)灵活配置丰富的外设接口,如串口、以太网口、视频接口等,可满足工业以太网等应用的拓展性需求。</think>### Zynq7000开发板跳线帽配置指南 在Zynq7000开发板(如ZedBoard、MYIR-ZYNQ等)使用中,**跳线帽(JP)配置是必须考虑的关键步骤**。根据引用[1]中明确指出的"JP标示为跳线帽的位置",以及实际开发经验,以下是关键要点: #### 一、必须配置跳线帽的场景 1. **启动模式选择** - Zynq7000支持多种启动方式:JTAG调试、QSPI Flash、SD卡启动等 - 通过跳线帽组合设置MIO[5:0]引脚电平,决定启动模式(如JTAG模式通常需全置0) - 错误配置会导致Vitis报"APU复位错误"或无法连接JTAG[^1][^2] 2. **外设接口切换** - 复用引脚分配:如UART/USB/Ethernet接口选择 - 示例:ZedBoard上JP14用于切换USB-UART连接 - PL/PS资源分配:通过跳线决定外设由处理器系统(PS)还是可编程逻辑(PL)控制[^4] 3. **调试接口使能** - JTAG连接使能:部分开发板需短接JTAG使能跳线帽 - 安全模式:某些跳线设置会禁用调试接口(导致DAP状态0xF0000021错误) #### 二、典型跳线配置示例(以ZedBoard为例) | 功能 | 跳线组 | 配置方式 | 影响 | |--------------|--------|--------------------------|--------------------| | 启动模式 | JP7 | MIO[5:0]=001010 (SD启动) | 决定系统启动介质 | | USB-UART | JP14 | 短接1-2引脚 | 启用控制台串口 | | JTAG使能 | JP11 | 全部短接 | 允许Vitis调试连接 | | 以太网PHY选择| JP12 | 选择PS/PL | 切换网络控制器 | #### 三、操作建议 1. **查阅官方文档** - 开发板手册中"Jumper Settings"章节是首要参考(如ZedBoard的UG1185文档) - 启动模式配置表通常在硬件手册前几页[^1] 2. **调试阶段配置** ```plaintext 推荐设置: - 启动模式:JTAG (MIO[5:0]=000000) - 调试接口:全部使能 - 串口通信:短接UART跳线 ``` 这能避免"AP transaction error"等连接问题[^2] 3. **部署时调整** - SD卡启动:根据引用[3],需设置为MIO[5:0]=001010 - 网络启动:配合UBOOT设置TFTP参数[^3] #### 四、故障排查 当出现JTAG连接错误(如DAP status 0xF0000021)时: 1. 检查所有跳线帽是否松动或氧化 2. 验证启动模式是否设置为JTAG 3. 用万用表测量跳线帽连通性 4. 对照开发板原理图检查信号路径[^1] > **重要提示**:跳线错误可能引发严重后果,如MYC-C7Z015开发板错误的以太网跳线会导致PHY芯片不可达[^4]。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值