【ZYNQ】AXI-Quad-SPI SDK 开发记录 测试
前人工作
如前人工作,在Navigate to BSP Settings中找到历例程
file:///F:/Xilinx/Vitis/2019.2/data/embeddedsw/XilinxProcessorIPLib/drivers/spi_v4_5/doc/html/api/example.html
使用XSpi_LowLevelExample例子,源代码的AI解析
int XSpi_LowLevelExample(u32 BaseAddress)
{u32 Control;int NumBytesSent = 0;int NumBytesRcvd = 0;u32 Count;/** Set up the device in loopback mode and enable master mode.*/Control = XSpi_ReadReg(BaseAddress, XSP_CR_OFFSET);Control |= (XSP_CR_MASTER_MODE_MASK); // Enable master modeXSpi_WriteReg(BaseAddress, XSP_CR_OFFSET, Control);
代码中,摁住ctrl+左键 可以跳转到函数的定义,XSpi_ReadReg 就是寄存器读,通过基地址+偏移地址。
在xspi_h.c
#define XSP_DGIER_OFFSET 0x1C /**< Global Intr Enable Reg */
#define XSP_IISR_OFFSET 0x20 /**< Interrupt status Reg */
#define XSP_IIER_OFFSET 0x28 /**< Interrupt Enable Reg */
#define XSP_SRR_OFFSET 0x40 /**< Software Reset register */
#define XSP_CR_OFFSET 0x60 /**< Control register */
#define XSP_SR_OFFSET 0x64 /**< Status Register */
#define XSP_DTR_OFFSET 0x68 /**< Data transmit */
#define XSP_DRR_OFFSET 0x6C /**< Data receive */
#define XSP_SSR_OFFSET 0x70 /**< 32-bit slave select */
#define XSP_TFO_OFFSET 0x74 /**< Tx FIFO occupancy */
#define XSP_RFO_OFFSET 0x78 /**< Rx FIFO occupancy */
u8 Buffer[BUFFER_SIZE];// change to u8
#define XSP_CR_OFFSET 0x60 /**< Control register */
【pg153-axi-quad-spi.pdf】网上找
60h是cr寄存器
最低位,LOOP 是否回环,默认0,不回环
/** Set up the device in loopback mode and enable master mode.*/Control = XSpi_ReadReg(BaseAddress, XSP_CR_OFFSET);Control |= (XSP_CR_MASTER_MODE_MASK); // Enable master modeXSpi_WriteReg(BaseAddress, XSP_CR_OFFSET, Control);
XSP_CR_MASTER_MODE_MASK 就代表把 Bits[2]给变成1
#define XSP_CR_LOOPBACK_MASK 0x00000001 /**< Local loopback mode */
#define XSP_CR_ENABLE_MASK 0x00000002 /**< System enable */
#define XSP_CR_MASTER_MODE_MASK 0x00000004 /**< Enable master mode */
#define XSP_CR_CLK_POLARITY_MASK 0x00000008 /**< Clock polarity highor low */
#define XSP_CR_CLK_PHASE_MASK 0x00000010 /**< Clock phase 0 or 1 */
#define XSP_CR_TXFIFO_RESET_MASK 0x00000020 /**< Reset transmit FIFO */
#define XSP_CR_RXFIFO_RESET_MASK 0x00000040 /**< Reset receive FIFO */
#define XSP_CR_MANUAL_SS_MASK 0x00000080 /**< Manual slave selectassert */
#define XSP_CR_TRANS_INHIBIT_MASK 0x00000100 /**< Master transactioninhibit */
/** Fill up the transmitter with data, assuming the receiver can hold* the same amount of data.*/while ((XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) &XSP_SR_TX_FULL_MASK) == 0) {XSpi_WriteReg((BaseAddress), XSP_DTR_OFFSET,Buffer[NumBytesSent++]);}
#define XSP_SR_TX_FULL_MASK 0x00000008 /**< Transmit Reg/FIFO is full */
SR状态寄存器,读取SR寄存器32bit内容
当发射tx 的fifo没有满的时候,把发射数据写进去
#define XSP_DTR_OFFSET 0x68 /**< Data transmit */
/** Enable the device.*/Control = XSpi_ReadReg(BaseAddress, XSP_CR_OFFSET);Control |= XSP_CR_ENABLE_MASK;Control &= ~XSP_CR_TRANS_INHIBIT_MASK;XSpi_WriteReg(BaseAddress, XSP_CR_OFFSET, Control);
开启设备
清除传输禁止位
/** Initialize the buffer with zeroes so that it can be used to receive* data.*/for (Count = 0; Count < BUFFER_SIZE; Count++) {Buffer[Count] = 0x0;}
/** Wait for the transmit FIFO to transition to empty before checking* the receive FIFO, this prevents a fast processor from seeing the* receive FIFO as empty*/while (!(XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) &XSP_SR_TX_EMPTY_MASK));
循环读取SR状态寄存器,看tx数据是不是空
/** Transmitter is full, now receive the data just looped back until* the receiver is empty.*/while ((XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) &XSP_SR_RX_EMPTY_MASK) == 0) {//when RX fifo is no emptyBuffer[NumBytesRcvd++] = XSpi_ReadReg((BaseAddress),XSP_DRR_OFFSET);}
如果接收的寄存器不是空的了,(说明有数据来了),就把DRR接收data寄存器的数据读到fifo缓存里面。
流程:
1.设置控制寄存器CR,设置模式
2.定义缓存fifo
3.检查状态寄存器SR,把缓存fifo发到tx的data寄存器(DTR)
4.开启spi设备,CR使能,CR清楚禁止位
5.接收数据
6.验证数据
**
- 调试验证
**
开始调试
在代码里面打断点
右侧代码行双击 打断点
/******************************************************************************
*
* Copyright (C) 2002 - 2019 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.
*
* 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
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
*
*
*
******************************************************************************/
/******************************************************************************/
/**
* @file xspi_low_level_example.c
*
* This file contains a design example using the low-level driver of the
* SPI driver (XSpi). These macros are found in xspi_l.h. A simple loopback
* test is done within an SPI device in polled mode. This example works only with
* 8-bit wide data transfers.
*
* @note
* This example works only with 8-bit wide data transfers in standard SPI mode.
* This example will not work if the axi_qspi device is confiured in dual/quad
* modes.
*
* To make this example work for 16 bit transfers change u8 Buffer[BUFFER_SIZE]
* to u16 Buffer[BUFFER_SIZE]. The SPI Core should also be configured for 16 bit
* access during the build time.
*
* To make this example work for 32 bit transfers change u8 Buffer[BUFFER_SIZE]
* to u32 Buffer[BUFFER_SIZE]. The SPI Core should also be configured for 32 bit
* access during the build time.
*
*
*<pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- ----------------------------------------------------------
* 1.00b rpm 04/24/02 First release
* 1.00b jhl 09/10/02 Added code to ensure it works with a fast processor.
* 1.00b sv 05/16/05 Minor changes to comply to Doxygen and coding guidelines
* 3.00a ktn 10/28/09 Converted all register accesses to 32 bit access.
* 3.02a sdm 05/04/11 Added a note about dual/quad modes in axi_qspi.
* 4.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 "xspi_l.h"
#include "xil_printf.h"#include "stdio.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 SPI_BASEADDR XPAR_SPI_0_BASEADDR/**************************** Type Definitions ********************************//***************** Macros (Inline Functions) Definitions **********************//************************** Function Prototypes *******************************/int XSpi_LowLevelExample(u32 BaseAddress);/************************** Variable Definitions ******************************//** This is the size of the buffer to be transmitted/received in this example.*/
#define BUFFER_SIZE 32/** The buffer used for Transmission/Reception of the SPI test data*/
u32 Buffer[BUFFER_SIZE];// change to u32/******************************************************************************/
/**
* This function is the main function of the SPI Low Level example.
*
* @param None
*
* @return XST_SUCCESS to indicate success, else XST_FAILURE to indicate
* Failure.
*
* @note None
*
*******************************************************************************/
int main(void)
{int Status;/** Run the example, specify the Base Address that is generated in* xparameters.h*/Status = XSpi_LowLevelExample(SPI_BASEADDR);if (Status != XST_SUCCESS) {xil_printf("Spi lowlevel Example Failed\r\n");printf("Spi lowlevel Example Failed\r\n");return XST_FAILURE;}xil_printf("Successfully ran Spi lowlevel Example\r\n");printf("Successfully ran Spi lowlevel Example\r\n");return XST_SUCCESS;
}/******************************************************************************/
/**
*
* This function does a simple loopback test within an SPI device.
*
* @param BaseAddress is the BaseAddress of the SPI device
*
* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note None
*
*******************************************************************************/
int XSpi_LowLevelExample(u32 BaseAddress)
{u32 Control;int NumBytesSent = 0;int NumBytesRcvd = 0;u32 Count;/** Set up the device in loopback mode and enable master mode.*/Control = XSpi_ReadReg(BaseAddress, XSP_CR_OFFSET);Control |= (XSP_CR_LOOPBACK_MASK | XSP_CR_MASTER_MODE_MASK); // Enable master modeXSpi_WriteReg(BaseAddress, XSP_CR_OFFSET, Control);/** Initialize the buffer with some data.*/for (Count = 0; Count < BUFFER_SIZE; Count++) {Buffer[Count] = Count;// 0-31}/** Fill up the transmitter with data, assuming the receiver can hold* the same amount of data.*/while ((XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) &XSP_SR_TX_FULL_MASK) == 0) {//when TX fifo is not fullXSpi_WriteReg((BaseAddress), XSP_DTR_OFFSET,Buffer[NumBytesSent++]);}/** Enable the device.*/Control = XSpi_ReadReg(BaseAddress, XSP_CR_OFFSET);Control |= XSP_CR_ENABLE_MASK;Control &= ~XSP_CR_TRANS_INHIBIT_MASK;XSpi_WriteReg(BaseAddress, XSP_CR_OFFSET, Control);/** Initialize the buffer with zeroes so that it can be used to receive* data.*/for (Count = 0; Count < BUFFER_SIZE; Count++) {Buffer[Count] = 0x0;}/** Wait for the transmit FIFO to transition to empty before checking* the receive FIFO, this prevents a fast processor from seeing the* receive FIFO as empty*/while (!(XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) &XSP_SR_TX_EMPTY_MASK));/** Transmitter is full, now receive the data just looped back until* the receiver is empty.*/while ((XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) &XSP_SR_RX_EMPTY_MASK) == 0) {//when RX fifo is no emptyBuffer[NumBytesRcvd++] = XSpi_ReadReg((BaseAddress),XSP_DRR_OFFSET);}/** If no data was sent or the data that was sent was not received,* then return an error*/if ((NumBytesSent != NumBytesRcvd) || (NumBytesSent == 0)) {return XST_FAILURE;}return XST_SUCCESS;
}
相关文章:

【ZYNQ】AXI-Quad-SPI SDK 开发记录 测试
前人工作 如前人工作,在Navigate to BSP Settings中找到历例程 file:///F:/Xilinx/Vitis/2019.2/data/embeddedsw/XilinxProcessorIPLib/drivers/spi_v4_5/doc/html/api/example.html使用XSpi_LowLevelExample例子,源代码的AI解析 int XSpi_LowLeve…...

Django提交表单出错提示错误
使用ArticleColumnForm表单,向数据库提交内容,内容包括column。如果同一用户提交的column重复,则提示表单出错,表单提交失败后,重新渲染表单提交html页面,其中提示错误信息。 涉及的代码包括: …...

鸿蒙开发 组件之间的传值
1.Prop:父组件传递给子组件,单向传递,子组件改变值,父组件UI不更新。 引入子组件 并赋值,子组件用Prop 接收 import headerView from ../../common/bean/BaseNavHeaderView headerView({titlestr:添加地址,isback…...

[晕事]今天做了件晕事35 VM发送给gateway太多ARP,导致攻击检查?
最近遇到一个问题,说网关学不到新起来VM的mac地址,通过tshark抓包发现,VM已经发出去GARP了。而且连续发送了24个GARP。 就认为是网关的问题,为什么没网关没有学到?就让测试同事开网络设备的ticket。 后来听同事说&…...

虹科干货丨多设备协同无忧:Linux环境下PCAN固定设备ID通道分配指南
来源:虹科汽车电子 虹科干货丨多设备协同无忧:Linux环境下PCAN固定设备ID通道分配指南 原文链接:https://mp.weixin.qq.com/s/ABg6YFXGwi8lb6SW4bEaew 欢迎关注虹科,为您提供最新资讯! #PCAN #汽车电子 导读 在车辆…...

【python】flask操作数据库工具SQLAlchemy,详细用法和应用实战
✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全…...

web前端项目已有阿里巴巴图标基础上,再次导入阿里巴巴图标的方法
如果是第一次导入阿里巴巴图标请参考: vue项目引入阿里云图标_vue引用阿里云图标fontclass-CSDN博客 本文主要想讲在项目原有阿里巴巴图标基础上,再次导入阿里巴巴图标的解决办法: 1.iconfont.json对应修改就行,这个简单一看就明白; 2.iconfont.js主要改动<symbol><…...

头歌openGauss-存储过程第2关:修改存储过程
任务描述 本关任务: 修改存储过程pro0101,并调用; --修改sel_course表中成绩<60的记录为成绩10,然后将计算机学院所有学生的选课成绩输出; --a、需要先删除存储过程pro0101; drop procedure if exists p…...

ThreadLocal简单使用案例
业务场景:保存业务数据表的时候,同时记录下日志。 import java.sql.Connection; import java.sql.DriverManager;public class DBUtil {// 数据库配置private static final String driver "com.mysql.jdbc.Driver";private static final Stri…...

创建型设计模式之建造者模式
文章目录 概述定义建造者模式原理结构图小结 概述 建造者模式又被称为生成器模式,是一种创建型设计模式。 和之前的单例,工厂一样,同属于创建型设计模式。 定义 建造者模式是将一个复杂对象的构建与表示分离,使得同样的构建过程…...

mainwindow 无菜单栏 可拖动,边界可扩大,动画浮现上边框
mainwindow 无菜单栏 可拖动,边界可扩大,动画浮现上边框 #ifndef ANIMATIONWIN_H #define ANIMATIONWIN_H #include namespace Ui {class animationWin; } class animationWin : public QWidget {Q_OBJECT public: explicit animationWin(QWidget *parent = nullptr); …...

机器学习云环境测试
等待创建完成后,点击 PyTorch 打开,创建一个全新的 notebook 在 Cell 中输入如下代码,并点击 Run 完成后点击 New Cell ,在 New Cell 中输入如下代码 输入完成后点击 Run ,运行 New Cell 。(每个 Cell 代…...

扩散模型自动管道AutoPipeline
推荐:write_own_pipeline.ipynb - Colab (google.com) 为您的任务选择一个 AutoPipeline 首先选择一个检查点。例如,如果您对使用 runwayml/stable-diffusion-v1-5 检查点的文本到图像感兴趣,请使用 AutoPipelineForText2Image: f…...

Map六种遍历方式
下面是三组(6种),Map 遍历方式的核心代码。 遍历方式有使用到增强for和迭代器。最下面有张图片,对做题有参考意义。 参考代码: Map map new HashMap();map.put("小猫","cat");map.put("小…...

集合-1 数组ArrayListLinkedList
一.数组 1.什么是数组? 数组是一种用连续的内存空间存储相同类型数据的线性数据结构。 2.为什么数组下标是从0开始? (1)数组根据下标查找元素是基于寻址公式:元素地址数组首地址索引i*数组存储数据类型的大小 &am…...

42-1 应急响应之账户排查
一、用户信息排查 在服务器被入侵后,攻击者可能会建立相关账户(有时是隐藏或克隆账户),方便进行远程控制。攻击者会采用的方法主要有如下几种: 直接建立一个新的账户:攻击者直接创建一个新的账户,有时为了混淆视听,账户名称与系统常用名称相似。 激活一个系统中的默认…...

Python3 笔记:sort() 和 sorted() 的区别
1、sort() 可以对列表中的元素进行排序,会改变原列表,之前的顺序不复存在。 list.sort(key, reverse None) key:默认值是None,可指定项目进行排序,此参数可省略。 reverse&#…...

vue 引入 emoji 表情包
vue 引入 emoji 表情包 一、安装二、组件内使用 一、安装 npm install --save emoji-mart-vue二、组件内使用 import { Picker } from "emoji-mart-vue"; //引入组件<picker :include"[people,Smileys]" :showSearch"false" :showPreview&q…...

mysql 数据库 增量备份
mysql 数据库 增量备份 https://dev.mysql.com/doc/mysql-enterprise-backup/8.0/en/mysqlbackup.incremental.html 和版本 有关系啊 xtrabackup mysql增量备份与恢复使用详解 https://www.jb51.net/database/297844fzd.htm 存储 引擎 怎么看? 适用于MyISAM存储引…...

SpringBoot之@Builder 注解
(1)Builder 生成的构造器不是完美的,如果没有提供必须的参数,构造器可能会创建出不完整或者不合法的对象,导致代码报错。 Builder 注解产生的 Builder 类的构造方法默认并不能限定必传参数。 (2ÿ…...

云计算的能源消耗如何影响环境?
嗨,亲爱的读者朋友们,今天我们要聊一聊云计算的能源消耗对环境的影响。随着科技的飞速发展,云计算已经成为了企业和个人处理数据的首选方式。但是,你可曾想过,这些“云”究竟消耗了多少能源,对我们的环境又…...

openwrt设置开机自启 tailscale为例
首先下载 tailscale 到 /root 目录下,并按照以下命令运行一次 /root/tailscale/tailscaled --state/root/tailscale/tailscaled.state & /root/tailscale/tailscale up &弹出登录地址并授权即可 创建一个启动脚本位置在/etc/init.d下 vim /etc/init.d/ta…...

副业树洞聊天项目/树洞倾诉/陪陪系统源码/树洞源码下载搭建
随着社会的发展和人们生活水平的提高,越来越多的人在面临心理压力、情感困扰或生活困境时,需要一个可以宣泄、倾诉和寻求支持的平台。而传统的人际交往方式往往会遇到难以排解的问题,比如担心被他人知晓自己的隐私等,这就导致了人…...

UWB论文:Introduction to Impulse Radio UWB Seamless Access Systems(2):脉冲;超宽带;测距;定位
3) 测距/接收器 像全球定位系统(GPS)这样的系统依赖于单向测距One Way Ranging(OWR),其中多个卫星(代表固定节点,称为锚点anchors)定期传输同步的无线电数据包集合,这允许…...

Spring MVC/Web
1.Spring MVC 的介绍 Spring Web MVC是基于Servlet API构建的原始Web框架,也是Spring框架的一部分。它提供了灵活可扩展的MVC架构,方便开发者构建高性能的Web应用程序,并与 Spring 生态系统无缝集成。 2.MVC 设计模式 MVC(Model…...

C++中获取int最大与最小值(补)
上文中,我们学习了C中获取int最大与最小值的两种方法:C库和移位运算,这篇文章将解决在移位运算中遇到的各种报错,并提出一种新的生成int最值的方法 上文链接:http://t.csdnimg.cn/cn7Ad 移位运算取最值常见报错 Dev…...

一个开源的工具类轮子是怎么造出来的
心路历程 为什么要做 在22年9月的某一天,在公司开需求评审时,接到了一个给PDF、图片添加水印的需求。做为一个刚工作的CURD程序员,在遇到这些问题时,第一反应是去github上找找有没有类似的开源框架。但是,出乎我意料…...

零基础学Java第二十二天之迭代器 Iterator
迭代器 Iterator 的理解和相关集合 使用 1、理解 迭代器(Iterator)是设计模式中的一种,它允许程序员遍历容器(例如列表、集合等)中的元素,而无需了解容器底层的实现细节。在编程中,迭代器提供了…...

微服务架构-异步消息传递设计模式
微服务架构-异步消息传递设计模式 异步消息允许服务发送消息后立即返回,而不需要等待消息被处理完毕,这种异步方式可以大大提高系统的处理速度、和吞吐量。 微服务架构,通常涉及多个服务之间的相互调用,如果通信只是在少数几个微…...

基于SSM的大学生兼职管理系统
基于SSM的大学生兼职管理系统的设计与实现~ 开发语言:Java数据库:MySQL技术:SpringSpringMVCMyBatis工具:IDEA/Ecilpse、Navicat、Maven 系统展示 登录界面 企业界面 前台学生界面 管理员界面 摘要 随着大学生兼职市场的日益繁…...