做了两天ZYNQ的EMIO映射到PS端串口1使用的实验终于成功了,原因竟然是SDK收发程序不适用,先是做了逻辑证明CP2012是可以使用的,现在贴出整个用SDK收发控制EMIO的工程:
先上图:
首先BD:将UART通过EMIO引出来
2、XDC:
set_property IOSTANDARD LVCMOS33 [get_ports UART_1_rxd]
set_property IOSTANDARD LVCMOS33 [get_ports UART_1_txd]
set_property PACKAGE_PIN AB10 [get_ports UART_1_txd]
set_property PACKAGE_PIN AB9 [get_ports UART_1_rxd]
3、导入SDK:
可实现helloword测试程序;
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
int main()
{
// init_platform();//无用
print("Hello World\n\r");
// cleanup_platform();//无用
return 0;
}
UART发送数据(未尝试)
设置Tera Term的COM4为波特率9600(匹配上述代码)
设置COM5为波特率115200
UART接收数据
main.c
/******************************************************************************
*
* Copyright (C) 2009 - 2014 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.
*
******************************************************************************/
/*
* helloworld.c: simple test application
*
* This application configures UART 16550 to baud rate 9600.
* PS7 UART (Zynq) is not initialized by this application, since
* bootrom/bsp configures it to baud rate 115200
*
* ------------------------------------------------
* | UART TYPE BAUD RATE |
* ------------------------------------------------
* uartns550 9600
* uartlite Configurable only in HW design
* ps7_uart 115200 (configured by bootrom/bsp)
*/
/*
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
int main()
{
init_platform();
while(1){
print("Hello World\n\r");
}
cleanup_platform();
return 0;
}*/
#include "xparameters.h"
#include "xuartps.h"
#include "xil_printf.h"
#include "sleep.h"
int main()
{
//使用UART0实现发送数据
XUartPs Uart_Ps;//uart对象
//查找uart配置
XUartPs_Config *Config;
Config = XUartPs_LookupConfig(XPAR_XUARTPS_0_DEVICE_ID);//ID来源于xparameters.h
if (Config == NULL)
{
//在bsp中设置为uart1负责stdout
print("failed XUartPs_LookupConfig\n\r");
return XST_FAILURE;
}
else
{
print("succeed XUartPs_LookupConfig\n\r");
}
//uart初始化
int Status;
Status = XUartPs_CfgInitialize(&Uart_Ps, Config, Config->BaseAddress);
if (Status != XST_SUCCESS)
{
print("failed XUartPs_CfgInitialize\n\r");
return XST_FAILURE;
}
else
{
print("succeed XUartPs_CfgInitialize\n\r");
}
//接收缓冲
u8 buf[64];
//接收字节数
u32 recv_cnt = 0;
while (TRUE)
{
usleep(500000);//等待500ms
recv_cnt = XUartPs_Recv(&Uart_Ps, buf, 64);//接收数据
if (recv_cnt > 0)
{
//返回接收到的数据
xil_printf("%s", buf);
//清空缓冲
memset(buf, 0, 64);
}
}
return 0;
}
问题描述参考https://blog.csdn.net/botao_li/article/details/85302027
关于UART接收的一些说明
本实验原本是打算使用通过中断来响应UART数据到达,再使用XUartPs_Recv进行接收,但是无论怎样实验都无法进入中断响应函数。
并且发现来自system.mss里的中断示例程序同样也无法正常进入中断响应函数。
无法确定是不是有一些在Vivado工程或者bsp里的设置不正确导致
根据以往嵌入式程序的开发经验,对于单线程运行的程序而言,持续接收数据如果使用中断来响应接收的话会占用更多的CPU时间(因为保存与重载现场的操作),相比较而言采用轮询的方式可以达成更高的运行效率。对于偶然突发的数据接收,使用中断接收相比较轮询接收,可以实现更快速的响应。
中断函数描述:但是尝试了两天没成功
#include "sys_intr.h"
#include "uartps_intr.h"
void init_intr_sys(void)
{
Init_UartPsIntr(&UartPs,UART_DEVICE_ID);
Init_Intr_System(&Intc);
Setup_Intr_Exception(&Intc);
UartPs_Setup_IntrSystem(&Intc, &UartPs, UART_INT_IRQ_ID);
}
int main(void)
{
init_intr_sys();
XUartPs_Recv(&UartPs, RecvBuffer, TEST_BUFFER_SIZE);
while(1);
return 0;
}