资源简介
该驱动支持MX25系列的NORflash,操作方式支持SPI,QPI,SPAR接口,支持软件SPI,硬件spi配置,都是通过宏定义配置。
代码片段和文件信息
/*
* COPYRIGHT (c) 2010-2012 MACRONIX INTERNATIONAL CO. LTD
* SPI Flash Low Level Driver (LLD) Sample Code
*
* Application program of flash support SPI and QPI interface
* This sample code provides a reference not recommand for directing using.
*
* $Id: MX25_APP.cv 1.4 2012/01/03 08:00:06 modelqa Exp $
*/
#include
#include “MX25_CMD.h“
#define TRANS_LENGTH 16
#define RANDOM_SEED 106
#define FLASH_TARGET_ADDR 0x00000000
#define Error_inc(x) x = x + 1;
/* function prototype */
uint8 FlashID_Test( uint8 QPI_Enable );
uint8 FlashReadWrite_Test( uint8 QPI_Enable );
/*
* Main Program
*/
void main()
{
/* Setting flash access mode: SPI or QPI */
uint8 QPI_Enable = TRUE;
Initial_Spi();
FlashID_Test( QPI_Enable ); // Simple test : flash ID
FlashReadWrite_Test( QPI_Enable ); // Simple test : flash read / write
}
/*
* Simple flash id test
*/
uint8 FlashID_Test( uint8 QPI_Enable )
{
uint32 flash_id = 0;
uint16 error_cnt = 0;
FlashStatus flash_state = {0};
ReturnMsg msg;
if( QPI_Enable )
CMD_EQIO( &flash_state ); // Enter QPI mode
/* Read flash ID */
if( QPI_Enable ){ // Call QPI command
msg = CMD_QPIID( &flash_id &flash_state );
}
else{
msg = CMD_RDID( &flash_id &flash_state );
}
if( msg != (ReturnMsg)FlashOperationSuccess ) // Check returen message
return FALSE;
if( QPI_Enable )
CMD_RSTQIO( &flash_state ); // Exit QPI mode
if( flash_id != FlashID ) // Compare to expected value
Error_inc( error_cnt );
if( error_cnt != 0 )
return FALSE;
else
return TRUE;
}
/*
* Simple flash read/write test
*/
uint8 FlashReadWrite_Test( uint8 QPI_Enable )
{
FlashStatus flash_state = {0};
uint32 flash_addr;
uint32 trans_len = 0;
uint16 i=0 error_cnt = 0;
uint16 seed = 0;
uint8 st_reg = 0;
uint8 memory_addr[TRANS_LENGTH] = {0};
uint8 memory_addr_cmp[TRANS_LENGTH] = {0};
/* Assign initial condition */
flash_addr = FLASH_TARGET_ADDR;
trans_len = TRANS_LENGTH;
seed = RANDOM_SEED;
if( QPI_Enable )
CMD_EQIO( &flash_state ); // Enter QPI mode
/* Prepare data to transfer */
srand( seed );
for( i=0; i< (trans_len); i=i+1 ){
memory_addr[i] = rand()%256; // generate random byte data
}
/* Mmarked these code when not using quad IO mode (except QPI mode)
* Enable Quad IO mode
* Read status register value */
CMD_RDSR( &st_reg &flash_state );
st_reg = st_reg | FLASH_QE_MASK; // set QE bit to 1
CMD_WRSR( st_reg &flash_state ); // write setting to flash
/* Check QE value */
CMD_RDSR( &st_reg &flash_state );
if( (st_reg & FLASH_QE_MASK) != FLASH_QE_MASK )
Error_inc( error_cnt );
/* Erase 4K sector of flash memory
Note: It needs to erase dirty sector before program */
CMD_SE( flash_addr &fl
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 71488 2012-12-05 16:52 MX25_CMD.c
文件 9119 2012-12-05 16:52 MX25_CMD.h
文件 6529 2012-12-05 16:52 MX25_DEF.h
文件 4299 2012-12-05 16:52 MX25_APP.c
----------- --------- ---------- ----- ----
91435 4
- 上一篇:组合式轴系结构设计装配图
- 下一篇:SHT20驱动STM32F103
评论
共有 条评论