SPI 核软件调试记录
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 核软件调试记录的更多相关文章
- SPI核软件调试结果
SPI核软件调试结果 一.硬件搭建 配置如下: 1.采用手动复位: 2.输入时钟27M,AXI总线工作频率100M: 3.axi_quad_spi 配置为标准模式: 4.配合软件例程的使用,挂载了CP ...
- Video Timing Controller v6.1软件调试记录
Video Timing Controller v6.1软件调试记录 GUI配置: . case XVTC_VMODE_PAL: //576i@50 { TimingPtr->Interlace ...
- Video Test Pattern Generator(7.0)软件调试记录
Video Test Pattern Generator(7.0)软件调试记录 . XVidC_VideoMode XVIDC_VM_576_50_I = XVIDC_VM_720x576_50_I ...
- <读书笔记>软件调试之道 :问题的核心-修复后的反思
声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记.欢迎转载! ---------------------------------------- ...
- <读书笔记>软件调试之道 :问题的核心-如何修复缺陷
声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记.欢迎转载! 修复缺陷 对于一个好的修复来说,不仅仅是让软件运行正确,还需要为将来奠定基础.一 ...
- <读书笔记>软件调试之道 :问题的核心-诊断
声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记. 不要急于动手! 尽管可以利用各种工具和技术以及软件自身查找缺陷,但是你最重要的财富是你的智 ...
- <读书笔记>软件调试之道 :问题的核心-重现问题
声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记. 重现第一,提问第二 问题重现是实证过程的最强大武器,如果不能重现问题,你也无法证明修复了它 ...
- Windbg在软件调试中的应用
Windbg在软件调试中的应用 Windbg是微软提供的一款免费的,专门针对Windows应用程序的调试工具.借助于Windbg, 我们常见的软件问题:软件异常,死锁,内存泄漏等,就可以进行高效的排查 ...
- 《软件调试的艺术》学习笔记——GDB使用技巧摘要
<软件调试的艺术>学习笔记——GDB使用技巧摘要 <软件调试的艺术>,因为名是The Art of Debugging with GDB, DDD, and Eclipse. ...
随机推荐
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
- OSPF路由协议(一)
实验要求:使用OSPF协议,使各个PC之间能够相互通信 拓扑如下: 配置如下: R1enableconfigure terminal interface f0/0ip address 192.168. ...
- selenium 定位无标签的元素
转载需注明出处. 如: ::before 伪元素xpath css_selector. id. class_name各种定位失效,可以选择用, .get_attribute('innerHTML')方 ...
- HDU5658:CA Loves Palindromic (回文树,求区间本质不同的回文串数)
CA loves strings, especially loves the palindrome strings. One day he gets a string, he wants to kno ...
- 《DSP using MATLAB》Problem 6.13
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 使用JQuery反向选择checkbox
HTML代码: <input id="haspda" type="checkbox" name="haspda" value=&quo ...
- maven settings.xml配置优化
<?xml version="1.0" encoding="UTF-8"?> <settings> <localRepositor ...
- java 8大数据类型
第一类:逻辑型boolean 第二类:文本型char 1.JAVA中,char占2字节,16位.可在存放汉字 2.char赋值 char a='a'; //任意单个字符,加单引号. char a=' ...
- struts2 中的数据访问servletAPI
ActionContext包含其他数据对象,包括值栈 每次请求都会创建一个ActionContext对象 通过ActionContext访问数据 在action中读取 在jsp页面中读取 1 ...
- linux——git安装使用
系统环境centos7 安装git命令 yum install git -y 安装好之后使用命令查看git版本 git –version [root@bogon ~]# git --version g ...