ZYBOZ7从入门到进阶-4 zyboz7PS端通过MIO点亮LED

版权声明:本文为博主原创文章,未经博主允许不得转载。https://blog.csdn.net/a646123070

上一节,我们学会了使用zyboz7 7020裸机实现hello world。下面,我们将进一步研究ps端的应用---ps端通过MIO点亮LED灯。

由于我们点亮的是ps端的MIO7口的ld4,没用用到pl端的外设。所以,在vivado中设计的硬件部分和上一篇文章的一样,这里我们不在进行创建,直接复制上一篇的工程,然后修改软件部分。

复制的工程包含如下文件,为了避免后续不必要的麻烦,我们先把hello_1.sdk文件夹删除,然后我们也可以把剩余各个文件夹的名字改为ps_led.xx。

图一
图一

之后,我们打开工程。(双击hello_1.xpr或者改名字之后的ps_led.xpr)

因为上一步我们把sdk文件删除了,所以,我们需要重新生成。(在vivado软件中点击file-->export-->export hardware,之后点击file-->launch SDK)

在打开的SDK软件中,新建应用程序。(file-->new-->application project)在弹出的页面填写好工程名称和BSP名称之后点击NEXT,进入下一步,之后选择新建空工程,点击finish结束。

完成上述工作之后,在project explorer下会有三个文件夹显示出来。(没有的可以在file-->open projects from file system中打开)

之后,双击打开 ps-led-->src-->helloworld.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();

    print("Hello World\n\r");

    cleanup_platform();
    return 0;
}*/
#include "xgpiops.h"
#include "sleep.h"
int main()
{
static XGpioPs psGpioInstancePtr;
XGpioPs_Config* GpioConfigPtr;
int iPinNumber= 7; //DS23 连接的是 MIO10
u32 uPinDirection = 0x1; //1 表示输出, 0 表示输入
int xStatus;
//--MIO 的初始化
GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
//XPAR_PS7_GPIO_0_DEVICE_ID在XParameter.c文件中,表示了GPIO的id,以此来得到该设备
if(GpioConfigPtr == NULL)
return XST_FAILURE;
xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr,GpioConfigPtr,
GpioConfigPtr->BaseAddr);
if(XST_SUCCESS != xStatus)
print(" PS GPIO INIT FAILED \n\r");
//--MIO 的输入输出操作
XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumber,uPinDirection);// 配 置MIO 输出方向
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumber,1);//配置 MIO 的第 7位输出
while(1)
{
XGpioPs_WritePin(&psGpioInstancePtr, iPinNumber, 1);
//点亮 MIO 的第 7 位输出1
sleep(1);//延时
XGpioPs_WritePin(&psGpioInstancePtr, iPinNumber, 0);
//熄灭 MIO 的第 7 位输出0
sleep(1);//延时
}
return 0;
}

之后,我们把开发板连接到主机,供电随意选择,启动选择JTAG启动(jp5的跳帽选择JTAG)。

接着点击SDK软件中的RUN-->run configurations

在弹出的页面中双击 xilinx c/c++ application (system debugger),然后点击run,

如果弹出以下页面,点击yes即可。

稍等片刻你就会看到开发板的ld4一亮一灭(循环)。

至此,PS端通过MIO点灯就结束了,文中步骤描述不详细的请参考我之前写过的ZYBO从入门到进阶1 2 3,待大家清楚操作流程之后,后续文章配图会有所减少。

文中使用到的资源、工程我已打包上传到csdn资源中心。

作者学生一枚,文中难免有错误,指教、改错请→[email protected]

猜你喜欢

转载自blog.csdn.net/a646123070/article/details/84192579