Vitis 这个工具出来的时候,中文里还是一大片资料建议用2018.3的老旧IDE,具体名字我已经忘了,这次2023.2不但在Vivado带来了Linter这么牛逼实用的工具,Vitis也套上了VSC的皮,非常漂亮.
但是开发和各种调试什么都有一点点的差别,软件上也用SDP这个宏定义给区分开了,新的库使用起来更加简单,我这里简单新建一个工程,其中EMIO引出的引脚接到PL LED,AXI GPIO引脚接到PL KEY并使用中断,PS串口调试拉出来,算是非常简单的例子了.
导出xsa后启动Vitis,就能看到这个界面,需要先选workspace到我们一个创建好给vitis工作的目录.
Open Workspace 指定工作目录后就是这样.
第二步Create Platform Component
从这里创建一个Hello World的App.
左下角完成编译,先跑个Hello World.
调试一下确保基础配置正常.
接下来程序就不是特别难了,配置也简单很多,注释也在代码中了.
/******************************************************************************
* Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
* SPDX-License-Identifier: MIT
******************************************************************************/
/*
* 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 <xgpioPS.h>
#include <xgpio_l.h>
#include <xstatus.h>
#include "platform.h"
#include "xil_printf.h"
#include "xgpio.h"
#include "xgpiops.h"
#include "xparameters.h"
#include "xscugic.h"
#include "xinterrupt_wrap.h"
#define EMIO_LED 54
XGpioPs_Config *XGpioPsConfigPtr;
XGpioPs GpioPs;
XGpio_Config *GpioConfigPtr;
XGpio Gpio;
void GpioHandler(void *CallbackRef)
{
XGpio *GpioPtr = (XGpio *)CallbackRef;
XGpioPs_WritePin(&GpioPs, EMIO_LED, ~XGpioPs_ReadPin(&GpioPs, EMIO_LED));
// 清中断
XGpio_InterruptClear(GpioPtr, XGPIO_IR_CH1_MASK);
}
int main()
{
int Status;
init_platform();
// LED 相关初始化,LED在EMIO->IO0.
XGpioPsConfigPtr = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_BASEADDR);
if(XGpioPsConfigPtr == NULL){
print("Led Gpio Initialization Failed\r\n");
return XST_FAILURE;
}
XGpioPs_CfgInitialize(&GpioPs,XGpioPsConfigPtr,XGpioPsConfigPtr->BaseAddr);
XGpioPs_SetDirectionPin(&GpioPs, EMIO_LED, 1);
XGpioPs_SetOutputEnablePin(&GpioPs, EMIO_LED, 1);
// 按键初始化,按键在AXI GPIO
GpioConfigPtr = XGpio_LookupConfig(XPAR_XGPIO_0_BASEADDR);
Status = XGpio_Initialize(&Gpio, XPAR_XGPIO_0_BASEADDR);
if (Status != XST_SUCCESS) {
print("Led Gpio Initialization Failed\r\n");
return XST_FAILURE;
}
// 设置为输入并启用中断
XGpio_SetDataDirection(&Gpio, 1 /* 两个通道,我们是通道1. */, 1);
XGpio_InterruptEnable(&Gpio, XGPIO_IR_CH1_MASK);
XGpio_InterruptGlobalEnable(&Gpio);
Status = XSetupInterruptSystem(&Gpio, &GpioHandler,
GpioConfigPtr->IntrId,
GpioConfigPtr->IntrParent,
XINTERRUPT_DEFAULT_PRIORITY);
if (Status != XST_SUCCESS) {
print("Intr Gpio Initialization Failed\r\n");
return XST_FAILURE;
}
while (1) {
}
cleanup_platform();
return 0;
}
实际测试.
更多参考代码.