int main()
{XUartPs_Config *Config //定义一个XUartPs_Config的指针变量,这里的XUartPs_Config应该是一个宏定义变量
int Status
int SentCount = 0, RecvCount = 0 //以上两行定义三个整形变量
u8 HelloZynq[] = "Hello Zynq\n" //定义一个u8的字符串变量,这里的u8应该是一个宏定义变量
u8 RecvBuf[3] = "" //同上
XGpio Gpio //定义一个XGpio类型的变量,这里的XGpio应该是一个宏定义变量
XGpioPs Gpiops //定义一个XGpioPs类型的变量,这里的XGpioPs应该是一个宏定义变量
XGpioPs_Config *ConfigPtr //定义一个XGpioPs_Config的指针变量,这里的XGpioPs_Config应该是一个宏定义变量
u8 axi_Gpio_Data, ps_Gpio_Data //定义两个u8类型变量,这里的u8应该是一个宏定义变量
Config = XUartPs_LookupConfig(XPAR_PS7_UART_1_DEVICE_ID) //调用XUartPs_LookupConfig函数
if (NULL == Config) { //判断 Config变量是否为NULL空值
return XST_FAILURE} //是的话,返回XST_FAILURE值
Status = XUartPs_CfgInitialize(&Uart_Ps, Config, Config->BaseAddress)//调用XUartPs_CfgInitialize 函数
if (Status != XST_SUCCESS) { //XST_SUCCESS应该是一个预先定义好的常量
return XST_FAILURE}
while (SentCount < (sizeof(HelloZynq) - 1)) { //通过判断SentCount的大小,退出循环
SentCount += XUartPs_Send(&Uart_Ps, &HelloZynq[SentCount], 1)} //调用XUartPs_Send函数
Status = XGpio_Initialize(&Gpio, XPAR_AXI_GPIO_0_DEVICE_ID)//调用XGpio_Initialize函数
if (Status != XST_SUCCESS) {
return XST_FAILURE}
XGpio_SetDataDirection(&Gpio, 1, 0x0) //调用XGpio_SetDataDirection函数
ConfigPtr = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID)//调用XGpioPs_LookupConfig函数
Status = XGpioPs_CfgInitialize(&Gpiops, ConfigPtr, ConfigPtr->BaseAddr)//调用XGpioPs_CfgInitialize函数
if (Status != XST_SUCCESS) {
return XST_FAILURE}
XGpioPs_SetDirection(&Gpiops, 2, 0xF) //调用XGpioPs_SetDirection函数
XGpioPs_SetOutputEnable(&Gpiops, 2, 0xF)//调用XGpioPs_SetOutputEnable函数
while (1){ //进入循环
RecvCount = 0
while (RecvCount < 3) {
while (!XUartPs_IsReceiveData(Config->BaseAddress)) //调用XUartPs_IsReceiveData函数
XUartPs_Recv(&Uart_Ps, &RecvBuf[RecvCount], 1)//调用XUartPs_Recv函数
if (RecvBuf[RecvCount] == '\r') {
RecvBuf[RecvCount] = '\n'
XUartPs_Send(&Uart_Ps, &RecvBuf[RecvCount], 1)//调用XUartPs_Send函数
break }
XUartPs_Send(&Uart_Ps, &RecvBuf[RecvCount++], 1)}//调用XUartPs_Send函数
if (RecvBuf[0] >= '0' && RecvBuf[0] <= '9') axi_Gpio_Data = RecvBuf[0] - '0'
else if (RecvBuf[0] >= 'a' && RecvBuf[0] <= 'z') axi_Gpio_Data = RecvBuf[0] - 'a' + 10
else if (RecvBuf[0] >= 'A' && RecvBuf[0] <= 'Z') axi_Gpio_Data = RecvBuf[0] - 'A' + 10
XGpio_DiscreteWrite(&Gpio, 1, axi_Gpio_Data) //调用XGpio_DiscreteWrite函数
if (RecvBuf[1] >= '0' && RecvBuf[1] <= '9') ps_Gpio_Data = RecvBuf[1] - '0'
else if (RecvBuf[1] >= 'a' && RecvBuf[1] <= 'z') ps_Gpio_Data = RecvBuf[1] - 'a' + 10
else if (RecvBuf[1] >= 'A' && RecvBuf[1] <= 'Z')ps_Gpio_Data = RecvBuf[1] - 'A' + 10
XGpioPs_Write(&Gpiops, 2, ps_Gpio_Data)}//调用XGpioPs_Write函数
return 0}
//程序的本质就是不断的调用不同的函数,然后分析返回值,判读返回值的结果,是否要继续执行下面的代码。
波特率为9600
工程的网盘下载链接:https://pan.baidu.com/s/1ID426Zd85LgtAzhQMZpzNA
密码:6irgStep1 新建衫丛工程,调用一个zynq核并配置
配置选中这个SD卡,工程做完后会从SD卡启动
将这个SDIO设置为50M
这里选择一个DDR的型号(不同的开发板有所不同),点击OK完成配置
配置完成后的zynq核(这个看起来和配置之前一样)
Step2 调用axi_uart核并设置波特率
点击工具栏的Add IP按钮在d出的搜索框中输入axi_uart,然后选择这个AXI Uartlite核双击添加进来
双击这个AXI Uartlite核,这里的Baud Rate可以选择不同的波特率,我这里选择这个默认的9600(这个波特率可以
根据自己的需求选择),其它的选项都保持默认,点击OK完成配置
Step3 axi_uart进行自动连线将IP核和zynq核连接起来
点击这个Run Block Automation 引出DDR和PS的管脚
点击OK
如下图所示
点击这个Run Connection Automation将所有的模块连接起来
在d出的对话框中勾选全部,点击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},
}
此时的串口打印的输出数据
---------------------
存放锋敏派在ZYNQ芯片内部ROM不可更改,用于找到FSBL并启动它(从SD或者QSPI或者NAND),ug585第六章
用于引导U-Boot
用于引导Linux Kernel
petalinux工具可以构建2和3还有内核
BOOT.BIN包括fsbl,bitstream,用户程序(uboot)
image.ub包括了kernel(devicetree DTB和rootfs通过设置可选包不包含在ub内)
主要是分析下FSBL工程的main函数
调用ps7_init函数
主要是对PS端配置信息进行初始化 *** 作,包括MIO,PLL,CLK and DDR
我们在vivado软件中可以通过图形化的方式对ZYNQ PS端外设进行相关配置,那么这些配置信息会写入到hdf文件,SDK(或petalinux)会对hdf文件进行解析并生成对应的寄存器配置表,然后FSBL工程中会通过ps7_init函数将拿李寄存器配置表写入到对应的寄存器中,完成对MIO/PLL/CLK/DDR等外设的硬件配置。
先调用Xil_DCacheFlush函数完成刷DCache缓存的 *** 作,然后再调用Xil_DCacheDisable禁用DCache缓存。
调用RegisterHandlers函数
调用DDRInitCheck函数
调用InitPcap函数
处理器配置访问端口
这个寄存器记录ZYNQ的银贺启动方式(QSPI、SD、NAND、Nor、JTAG)
可以通过MIO3 MIO4 MIO5这三个引脚去配置ZYNQ的启动方式
ZYNQ上电复位的时候,会将这三个引脚的电平状态保存在BOOT_MODE寄存器当中。
每一种启动方式会有不同的处理方式。
第一、先初始化对应的flash设备
第二、再将MoveImage函数指针指向Flash设备的读写函数实体
调用LoadBootImage函数
FSBL的主要工作是启动U-Boot(终极目标),也要将bitstream文件加载到PL端。
找到U-Boot、bitstream
在读取U-Boot拷贝DDR中对应的加载地址,读取bitstream加载到PL端
调用FsblHandoff(HandoffAddress)
启动完U-Boot之后,FSBL的使命的就完成了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)