SPI 核软件调试记录

时间:2022-08-31 23:09:40

SPI 核软件调试记录

1.首先说说int SpiFlashWaitForFlashReady(void)这一函数,基本上其它函数在执行的时候,都会事先执行一次此函数。

   因为此函数的作用主要是用来等待,所以整个语句在一个循环里面。第一步是检测spi flash 的状态,若spi flash 已经完成了上一次传送,

  状态为XST_SUCCESS,否则,函数直接返回XST_FAILURE 即not ready。检测ReadBuffer[1]中的值 若果为0,则break循环,函数返回XST_SUCCESS

  代码内容如下:

 /*****************************************************************************/
/**
*
* This function waits till the Numonyx serial Flash is ready to accept next
* command.
*
* @param None
*
* @return XST_SUCCESS if successful else XST_FAILURE.
*
* @note This function reads the status register of the Buffer and waits
*. till the WIP bit of the status register becomes 0.
*
******************************************************************************/
int SpiFlashWaitForFlashReady(void)
{
int Status;
u8 StatusReg; while() { /*
* Get the Status Register. The status register content is
* stored at the second byte pointed by the ReadBuffer.
*/
Status = SpiFlashGetStatus(&Spi);
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Check if the flash is ready to accept the next command.
* If so break.
*/
StatusReg = ReadBuffer[];
if((StatusReg & FLASH_SR_IS_READY_MASK) == ) {
break;
}
} return XST_SUCCESS;
}

 2.函数SpiFlashGetStatus先写入一个命令COMMAND_STATUSREG_READ,然后用XSpi_Transfer函数将命令传入spi芯片中。

    当传送过程完成后,退出循环返回XST_SUCCESS 成功的状态,若传送没有完成,则一直执行:while(TransferInProgress);

 /*****************************************************************************/
/**
*
* This function reads the Status register of the Numonyx Flash.
*
* @param SpiPtr is a pointer to the instance of the Spi device.
*
* @return XST_SUCCESS if successful else XST_FAILURE.
*
* @note The status register content is stored at the second byte
* pointed by the ReadBuffer.
*
******************************************************************************/
int SpiFlashGetStatus(XSpi *SpiPtr)
{
int Status; /*
* Prepare the Write Buffer.
*/
WriteBuffer[BYTE1] = COMMAND_STATUSREG_READ; /*
* Initiate the Transfer.
*/
TransferInProgress = TRUE;
Status = XSpi_Transfer(SpiPtr, WriteBuffer, ReadBuffer,
STATUS_READ_BYTES);
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Wait till the Transfer is complete and check if there are any errors
* in the transaction..
*/
while(TransferInProgress);
if(ErrorCount != ) {
ErrorCount = ;
return XST_FAILURE;
} return XST_SUCCESS;
}

3. SpiFlashWriteEnable函数

首先检测spi flash 是否ready , 然后写入写使能命令:COMMAND_WRITE_ENABLE 到WriteBuffer中,最后通过XSPi_Transfer函数将命令发出。

 /*****************************************************************************/
/**
*
* This function enables writes to the Numonyx Serial Flash memory.
*
* @param SpiPtr is a pointer to the instance of the Spi device.
*
* @return XST_SUCCESS if successful else XST_FAILURE.
*
* @note None
*
******************************************************************************/
int SpiFlashWriteEnable(XSpi *SpiPtr)
{
int Status; /*
* Wait while the Flash is busy.
*/
Status = SpiFlashWaitForFlashReady();
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Prepare the WriteBuffer.
*/
WriteBuffer[BYTE1] = COMMAND_WRITE_ENABLE; /*
* Initiate the Transfer.
*/
TransferInProgress = TRUE;
Status = XSpi_Transfer(SpiPtr, WriteBuffer, NULL,
WRITE_ENABLE_BYTES);
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Wait till the Transfer is complete and check if there are any errors
* in the transaction..
*/
while(TransferInProgress);
if(ErrorCount != ) {
ErrorCount = ;
return XST_FAILURE;
} return XST_SUCCESS;
}

4.SpiFlashSectorErase函数,依旧是先检测spi flash 是否ready. 然后就是将要写的内容存入writebuffer中,主要命令和地址信息。

 /*****************************************************************************/
/**
*
* This function erases the contents of the specified Sector in the Numonyx
* Serial Flash device.
*
* @param SpiPtr is a pointer to the instance of the Spi device.
* @param Addr is the address within a sector of the Buffer, which is to
* be erased.
*
* @return XST_SUCCESS if successful else XST_FAILURE.
*
* @note The erased bytes will be read back as 0xFF.
*
******************************************************************************/
int SpiFlashSectorErase(XSpi *SpiPtr, u32 Addr)
{
int Status; /*
* Wait while the Flash is busy.
*/
Status = SpiFlashWaitForFlashReady();
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Prepare the WriteBuffer.
*/
WriteBuffer[BYTE1] = COMMAND_SECTOR_ERASE;
WriteBuffer[BYTE2] = (u8) (Addr >> );
WriteBuffer[BYTE3] = (u8) (Addr >> );
WriteBuffer[BYTE4] = (u8) (Addr); /*
* Initiate the Transfer.
*/
TransferInProgress = TRUE;
Status = XSpi_Transfer(SpiPtr, WriteBuffer, NULL,
SECTOR_ERASE_BYTES);
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Wait till the Transfer is complete and check if there are any errors
* in the transaction..
*/
while(TransferInProgress);
if(ErrorCount != ) {
ErrorCount = ;
return XST_FAILURE;
} return XST_SUCCESS;
}

5.SpiFlashWrite函数,依旧是检测是否ready,然后写入地址和命令,接下来就是用一个for循环 把将要写入的数据一个一个存入writeBuffer中,然后通过Xspi_Transfer函数

一起发送出去。

 /*****************************************************************************/
/**
*
* This function writes the data to the specified locations in the Numonyx Serial
* Flash memory.
*
* @param SpiPtr is a pointer to the instance of the Spi device.
* @param Addr is the address in the Buffer, where to write the data.
* @param ByteCount is the number of bytes to be written.
*
* @return XST_SUCCESS if successful else XST_FAILURE.
*
* @note None
*
******************************************************************************/
int SpiFlashWrite(XSpi *SpiPtr, u32 Addr, u32 ByteCount, u8 WriteCmd)
{
u32 Index;
int Status; /*
* Wait while the Flash is busy.
*/
Status = SpiFlashWaitForFlashReady();
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Prepare the WriteBuffer.
*/
WriteBuffer[BYTE1] = WriteCmd;
WriteBuffer[BYTE2] = (u8) (Addr >> );
WriteBuffer[BYTE3] = (u8) (Addr >> );
WriteBuffer[BYTE4] = (u8) Addr; /*
* Fill in the TEST data that is to be written into the Numonyx Serial
* Flash device.
*/
for(Index = ; Index < ByteCount + READ_WRITE_EXTRA_BYTES; Index++) {
WriteBuffer[Index] = (u8)((Index - ) + TestByte);
} /*
* Initiate the Transfer.
*/
TransferInProgress = TRUE;
Status = XSpi_Transfer(SpiPtr, WriteBuffer, NULL,
(ByteCount + READ_WRITE_EXTRA_BYTES));
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Wait till the Transfer is complete and check if there are any errors
* in the transaction.
*/
while(TransferInProgress);
if(ErrorCount != ) {
ErrorCount = ;
return XST_FAILURE;
} return XST_SUCCESS;
}

6.SpiFlashRead 函数,先检测spi flash 是否ready,然后将readcmd命令和读地址存入writeBuffer, 接下来就是先判断read函数接收的是那种命令,根据接收的命令来

处理ByteCount的值,最后就是用transfer函数将要写入的命令发给spi flash, 然后将读到的数据存入readbuffer中。

 /*****************************************************************************/
/**
*
* This function reads the data from the Numonyx Serial Flash Memory
*
* @param SpiPtr is a pointer to the instance of the Spi device.
* @param Addr is the starting address in the Flash Memory from which the
* data is to be read.
* @param ByteCount is the number of bytes to be read.
*
* @return XST_SUCCESS if successful else XST_FAILURE.
*
* @note None
*
******************************************************************************/
int SpiFlashRead(XSpi *SpiPtr, u32 Addr, u32 ByteCount, u8 ReadCmd)
{
int Status; /*
* Wait while the Flash is busy.
*/
Status = SpiFlashWaitForFlashReady();
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Prepare the WriteBuffer.
*/
WriteBuffer[BYTE1] = ReadCmd;
WriteBuffer[BYTE2] = (u8) (Addr >> );
WriteBuffer[BYTE3] = (u8) (Addr >> );
WriteBuffer[BYTE4] = (u8) Addr; if (ReadCmd == COMMAND_DUAL_READ) {
ByteCount += DUAL_READ_DUMMY_BYTES;
} else if (ReadCmd == COMMAND_DUAL_IO_READ) {
ByteCount += DUAL_READ_DUMMY_BYTES;
} else if (ReadCmd == COMMAND_QUAD_IO_READ) {
ByteCount += QUAD_IO_READ_DUMMY_BYTES;
} else if (ReadCmd==COMMAND_QUAD_READ) {
ByteCount += QUAD_READ_DUMMY_BYTES;
} /*
* Initiate the Transfer.
*/
TransferInProgress = TRUE;
Status = XSpi_Transfer( SpiPtr, WriteBuffer, ReadBuffer,
(ByteCount + READ_WRITE_EXTRA_BYTES));
if(Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Wait till the Transfer is complete and check if there are any errors
* in the transaction.
*/
while(TransferInProgress);
if(ErrorCount != ) {
ErrorCount = ;
return XST_FAILURE;
} return XST_SUCCESS;
}

SPI 核软件调试记录的更多相关文章

  1. SPI核软件调试结果

    SPI核软件调试结果 一.硬件搭建 配置如下: 1.采用手动复位: 2.输入时钟27M,AXI总线工作频率100M: 3.axi_quad_spi 配置为标准模式: 4.配合软件例程的使用,挂载了CP ...

  2. Video Timing Controller v6&period;1软件调试记录

    Video Timing Controller v6.1软件调试记录 GUI配置: . case XVTC_VMODE_PAL: //576i@50 { TimingPtr->Interlace ...

  3. Video Test Pattern Generator&lpar;7&period;0&rpar;软件调试记录

    Video Test Pattern Generator(7.0)软件调试记录 . XVidC_VideoMode XVIDC_VM_576_50_I = XVIDC_VM_720x576_50_I ...

  4. &lt&semi;读书笔记&gt&semi;软件调试之道 :问题的核心-修复后的反思

    声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记.欢迎转载! ---------------------------------------- ...

  5. &lt&semi;读书笔记&gt&semi;软件调试之道 :问题的核心-如何修复缺陷

    声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记.欢迎转载! 修复缺陷 对于一个好的修复来说,不仅仅是让软件运行正确,还需要为将来奠定基础.一 ...

  6. &lt&semi;读书笔记&gt&semi;软件调试之道 :问题的核心-诊断

    声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记. 不要急于动手! 尽管可以利用各种工具和技术以及软件自身查找缺陷,但是你最重要的财富是你的智 ...

  7. &lt&semi;读书笔记&gt&semi;软件调试之道 :问题的核心-重现问题

    声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记. 重现第一,提问第二 问题重现是实证过程的最强大武器,如果不能重现问题,你也无法证明修复了它 ...

  8. Windbg在软件调试中的应用

    Windbg在软件调试中的应用 Windbg是微软提供的一款免费的,专门针对Windows应用程序的调试工具.借助于Windbg, 我们常见的软件问题:软件异常,死锁,内存泄漏等,就可以进行高效的排查 ...

  9. 《软件调试的艺术》学习笔记——GDB使用技巧摘要

    <软件调试的艺术>学习笔记——GDB使用技巧摘要 <软件调试的艺术>,因为名是The Art of Debugging with GDB, DDD, and Eclipse. ...

随机推荐

  1. AngularJS 2&period;0

    https://angular.io/docs/ts/latest/guide/learning-angular.html QuickStart: git clone https://github.c ...

  2. 使用 openssl 生成证书

    一.openssl 简介 目前最流行的 SSL 密码库工具官网:https://www.openssl.org/source/ 构成部分 密码算法库 密钥和证书封装管理功能 SSL通信API接口 用途 ...

  3. javaSE第十八天

    第十八天    192 1:Map(掌握)    192 (1)定义:    192 (2)Map和Collection的区别?    192 (3)Map接口功能概述(自己补齐)    192 A: ...

  4. Bluetooth Obex

    OPP 1.2 which uses OBEX over L2CAP. OPP 1.1 connection and transfer happens over RFCOMM->L2CAP.

  5. 最简单的视频编码器:基于libx264(编码YUV为H&period;264)

    ===================================================== 最简单的视频编码器系列文章列表: 最简单的视频编码器:编译 最简单的视频编码器:基于libx ...

  6. 平时作业七 Java

    以下是几本计算机书籍的基本信息编号 书名 价格 出版社1 JAVA基础 32 清华大学出版社2 JAVA WEB开发 40 电子工业出版社3 面向对象程序设计 28 清华大学出版社4 Struts开发 ...

  7. Gitlab使用Webhook实现Push代码后的jenkins自动构建

    本文出自https://www.cnblogs.com/kevingrace/p/6479813.html 怕以后找不到,所以先写到自己博客中 Gitlab利用Webhook实现Push代码后的jen ...

  8. ZooKeeper系列&lpar;8&rpar;:ZooKeeper伸缩性

    一.ZooKeeper中Observer 1.1 ZooKeeper角色 经过前面的介绍,我想大家都已经知道了在ZooKeeper集群当中有两种角色Leader和Follower.Leader可以接受 ...

  9. C&num;&colon; Delegate and Event

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. jQuery使用最广泛的javascript函数库

    网站建设中,jQuery之最方便的的库了,当用到其中的JavaScript函数库的时候,不禁会想居然还有这么简单的操作? 一.选择网页元素 jQuery的基本设计思想和主要用法,就是"选择某 ...