我用stm32 spiport103r,开始说Please select first the stm32 spiEVAL board to be used (in stm32_eval.h),但

58cv网址导航stm32 fsmc nor flash
(amoBBS 阿莫电子论坛) -
stm32 fsmc nor flash
最近在调stm32 fsmc nor flash的程序,主要是移植了神州三号上面的
但是没有办通过,请高手指点一下
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name& && && & : fsmc_nor.h
* Author& && && && & : MCD Application Team
* Version& && && && &: V2.0.1
* Date& && && && && &: 06/13/2008
* Description& && &: Header for fsmc_nor.c file.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FSMC_NOR_H
#define __FSMC_NOR_H
/* Includes ------------------------------------------------------------------*/
#include &stm32f10x.h&
/* Exported types ------------------------------------------------------------*/
typedef struct
u16 Manufacturer_C
u16 Device_Code1;
u16 Device_Code2;
u16 Device_Code3;
}NOR_IDTypeD
/* NOR Status */
typedef enum
NOR_SUCCESS = 0,
NOR_ONGOING,
NOR_ERROR,
NOR_TIMEOUT
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void FSMC_NOR_Init(void);
void FSMC_NOR_ReadID(NOR_IDTypeDef* NOR_ID);
NOR_Status FSMC_NOR_EraseBlock(u32 BlockAddr);
NOR_Status FSMC_NOR_EraseChip(void);
NOR_Status FSMC_NOR_WriteHalfWord(u32 WriteAddr, u16 Data);
NOR_Status FSMC_NOR_WriteBuffer(u16* pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite);
NOR_Status FSMC_NOR_ProgramBuffer(u16* pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite);
u16 FSMC_NOR_ReadHalfWord(u32 ReadAddr);
void FSMC_NOR_ReadBuffer(u16* pBuffer, u32 ReadAddr, u32 NumHalfwordToRead);
NOR_Status FSMC_NOR_ReturnToReadMode(void);
NOR_Status FSMC_NOR_Reset(void);
NOR_Status FSMC_NOR_GetStatus(u32 Timeout);
#endif /* __FSMC_NOR_H */
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name& && && & : fsmc_nor.c
* Author& && && && & : MCD Application Team
* Version& && && && &: V2.0.1
* Date& && && && && &: 06/13/2008
* Description& && &: This file provides a set of functions needed to drive the
*& && && && && && && & M29W128FL, M29W128GL and S29GL128P NOR memories mounted
*& && && && && && && & on STM3210E-EVAL board.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include &fsmc_nor.h&
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//#define Bank1_NOR2_ADDR& && & ((u32)0x)
#define Bank1_NOR1_ADDR& && & ((u32)0x)
/* Delay definition */& &
#define BlockErase_Timeout& & ((u32)0x00A00000)
#define ChipErase_Timeout& &((u32)0x)
#define Program_Timeout& && & ((u32)0x)
/* Private macro -------------------------------------------------------------*/
//#define ADDR_SHIFT(A) (Bank1_NOR2_ADDR + (2 * (A)))
#define ADDR_SHIFT(A) (Bank1_NOR1_ADDR + (2 * (A)))
#define NOR_WRITE(Address, Data)(*(vu16 *)(Address) = (Data))
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name: FSMC_NOR_Init
* Description& & : Configures the FSMC and GPIOs to interface with the NOR memory.
*& && && && && && &This function must be called before any write/read operation
*& && && && && && &on the NOR.
* Input& && && & : None
* Output& && && &: None
* Return& && && &: None
*******************************************************************************/
/*******************************************************************************
*函数名称:FSMC_NOR_Init
*说明:配置FSMC及GPIO的接口与NOR闪存。
*此功能之前必须调用任何读/写操作上的NOR。
************************************************** *****************************/
void FSMC_NOR_Init(void)
FSMC_NORSRAMInitTypeDefFSMC_NORSRAMInitS
FSMC_NORSRAMTimingInitTypeD
GPIO_InitTypeDef GPIO_InitS
//FSMC总线使用的GPIO组时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
& && && && && && && && & RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
//FSMC数据线FSMC_D初始化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
& && && && && && && && && && &GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
& && && && && && && && && && &GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |
& && && && && && && && && && &GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//FSMC地址线FSMC_A初始化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
& && && && && && && && && && &GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
& && && && && && && && && && &GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |
& && && && && && && && && && &GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;& && && && && && && && && &
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;// | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//FSMC NOE和NWE初试化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//FSMC NE2初试化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
//FSMC NE1初试化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
p.FSMC_AddressSetupTime = 0x05;
p.FSMC_AddressHoldTime = 0x00;
p.FSMC_DataSetupTime = 0x07;
p.FSMC_BusTurnAroundDuration = 0x00;
p.FSMC_CLKDivision = 0x00;
p.FSMC_DataLatency = 0x00;
p.FSMC_AccessMode = FSMC_AccessMode_B;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_D
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_D
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_L
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_D
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitS
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_E
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_D
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_D
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_D
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
// Enable FSMC Bank1_NOR Bank
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
FSMC_NORSRAMInitTypeDefFSMC_NORSRAMInitS
FSMC_NORSRAMTimingInitTypeD
GPIO_InitTypeDef GPIO_InitS
//FSMC总线使用的GPIO组时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
& && && && && && && && & RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
//FSMC数据线FSMC_D初始化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
& && && && && && && && && && &GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
& && && && && && && && && && &GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |
& && && && && && && && && && &GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//FSMC地址线FSMC_A初始化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
& && && && && && && && && && &GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
& && && && && && && && && && &GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |
& && && && && && && && && && &GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;& && && && && && && && && &
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//FSMC NOE和NWE初试化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//FSMC NE2初试化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOG, &GPIO_InitStructure);
//FSMC NE1初试化,推挽复用输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//--------------FSMC 总线 存储器参数配置------------------------------
p.FSMC_AddressSetupTime = 0x05;& &//地址建立时间& &
p.FSMC_AddressHoldTime = 0x00;& & //地址保持时间
p.FSMC_DataSetupTime = 0x07;& && &//数据建立时间
p.FSMC_BusTurnAroundDuration = 0; //总线恢复时间x00
p.FSMC_CLKDivision = 0x00;& && &// 时钟分频因子
p.FSMC_DataLatency = 0x00;& && &//数据产生时间
p.FSMC_AccessMode = FSMC_AccessMode_B; //FSMC NOR控制器时序
//FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;//使用了FSMC的BANK1的子板块2
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;//使用了FSMC的BANK1的子板块2
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_D//禁止地址数据线复用
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;//存储器类型为Nor
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//存储器数据宽度为16位
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_D//关闭突发模式访问
//等待信号优先级,只有在使能突发访问模式才有效
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_L
//关闭Wrapped burst access mode,只有在使能突发访问模式才有效
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_D
//等待信号设置,只有在使能突发访问模式才有效
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitS
//使能这个BANK的写操作
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_E
//使能/关闭等待信息设置,只在使能突发访问模式才有效
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_D
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_D//关闭Extend Mode
//FSMC_NORSRAMInitStructure.FSMC_AsyncWait = FSMC_AsyncWait_D
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_D//关闭Write Burst Mode
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;//读操作时序参数
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;//写操作时序参数
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
//--------------使能BANK1的子板块2------------------------------
//FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
/******************************************************************************
* Function Name: FSMC_NOR_ReadID
* Description& & : Reads NOR memory's Manufacturer and Device Code.
* Input& && && & : - NOR_ID: pointer to a NOR_IDTypeDef structure which will hold
*& && && && && && &the Manufacturer and Device Code.
* Output& && && &: None
* Return& && && &: None
*******************************************************************************/
/******************************************************************************
*函数名称:FSMC_NOR_ReadID
*说明:读取NOR闪存的制造商和设备代码。
*输入: -NOR_ID:指向一个NOR_IDTypeDef结构,将举办制造商和设备代码。
************************************************** *****************************/
void FSMC_NOR_ReadID(NOR_IDTypeDef* NOR_ID)
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x0090);
NOR_ID-&Manufacturer_Code = *(vu16 *) ADDR_SHIFT(0x0000);
NOR_ID-&Device_Code1 = *(vu16 *) ADDR_SHIFT(0x0001);
NOR_ID-&Device_Code2 = *(vu16 *) ADDR_SHIFT(0x000E);
NOR_ID-&Device_Code3 = *(vu16 *) ADDR_SHIFT(0x000F);
/*******************************************************************************
* Function Name: FSMC_NOR_EraseBlock
* Description& & : Erases the specified Nor memory block.
* Input& && && & : - BlockAddr: address of the block to erase.
* Output& && && &: None
* Return& && && &: NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
*& && && && && && &or NOR_TIMEOUT
*******************************************************************************/
/*******************************************************************************
*函数名称:FSMC_NOR_EraseBlock
*说明:清除指定的NOR存储器块。
*输入: -BlockAddr:该块的地址抹去。
*返回:NOR_Status:返回的值可以是:NOR成功,NOR错误或NOR超时
************************************************** *****************************/
NOR_Status FSMC_NOR_EraseBlock(u32 BlockAddr)
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x0080);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
//NOR_WRITE((Bank1_NOR2_ADDR + BlockAddr), 0x30);
//NOR_WRITE((Bank1_NOR2_ADDR + BlockAddr), 0x0030);//此处必须为0x0030否则会擦不掉数据
NOR_WRITE((Bank1_NOR1_ADDR + BlockAddr), 0x0030);//此处必须为0x0030否则会擦不掉数据
return (FSMC_NOR_GetStatus(BlockErase_Timeout));
/*******************************************************************************
* Function Name: FSMC_NOR_EraseChip
* Description& & : Erases the entire chip.
* Input& && && & : None& && && && && && && &
* Output& && && &: None
* Return& && && &: NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
*& && && && && && &or NOR_TIMEOUT
*******************************************************************************/
/*******************************************************************************
*函数名称:FSMC_NOR_EraseChip
*说明:擦除整个芯片。
*返回:NOR_Status:返回的值可以是:NOR成功,NOR错误或NOR超时
************************************************** *****************************/
NOR_Status FSMC_NOR_EraseChip(void)
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x0080);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x0010);
return (FSMC_NOR_GetStatus(ChipErase_Timeout));
/******************************************************************************
* Function Name: FSMC_NOR_WriteHalfWord
* Description& & : Writes a half-word to the NOR memory.
* Input& && && & : - WriteAddr : NOR memory internal address to write to.
*& && && && && && &- Data : Data to write.
* Output& && && &: None
* Return& && && &: NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
*& && && && && && &or NOR_TIMEOUT
*******************************************************************************/
/******************************************************************************
*函数名称:FSMC_NOR_WriteHalfWord
*说明:写一对NOR闪存半字。
*输入: -WriteAddr:NOR存储器内部地址写入。
* -数据:写入的数据。
*返回:NOR_Status:返回的值可以是:NOR成功,NOR错误或NOR超时
************************************************** *****************************/
NOR_Status FSMC_NOR_WriteHalfWord(u32 WriteAddr, u16 Data)
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00A0);
//NOR_WRITE((Bank1_NOR2_ADDR + WriteAddr), Data);
NOR_WRITE((Bank1_NOR1_ADDR + WriteAddr), Data);
return (FSMC_NOR_GetStatus(Program_Timeout));
/*******************************************************************************
* Function Name: FSMC_NOR_WriteBuffer
* Description& & : Writes a half-word buffer to the FSMC NOR memory.
* Input& && && & : - pBuffer : pointer to buffer.
*& && && && && && &- WriteAddr : NOR memory internal address from which the data
*& && && && && && &will be written.
*& && && && && && &- NumHalfwordToWrite : number of Half words to write.
* Output& && && &: None
* Return& && && &: NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
*& && && && && && &or NOR_TIMEOUT
*******************************************************************************/
/*******************************************************************************
*函数名称& && && && &:FSMC_NOR_WriteBuffer
*说明& && && && && & :& &写一个FSMC的NOR闪存半字的缓冲区。
*输入& && && && && & : -pbuffer& && && &:指向缓冲区。
*& && && && && && && &-WriteAddr& && && &:NOR存储器内部地址的数据将被写入。
*& && && && && && && &-NumHalfwordToWrite:半字数写。
*输出& && && && && & :无
*返回& && && && && & :NOR_Status:返回的值可以是:NOR成功,NOR错误或NOR超时
************************************************** *****************************/
NOR_Status FSMC_NOR_WriteBuffer(u16* pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite)
NOR_Status status = NOR_ONGOING;
& & /* Transfer data to the memory */
& & status = FSMC_NOR_WriteHalfWord(WriteAddr, *pBuffer++);
& & WriteAddr = WriteAddr + 2;
& & NumHalfwordToWrite--;
while((status == NOR_SUCCESS) && (NumHalfwordToWrite != 0));
return (status);
/*******************************************************************************
* Function Name: FSMC_NOR_ProgramBuffer
* Description& & : Writes a half-word buffer to the FSMC NOR memory. This function
*& && && && && && &must be used only with S29GL128P NOR memory.
* Input& && && & : - pBuffer : pointer to buffer.
*& && && && && && &- WriteAddr: NOR memory internal address from which the data
*& && && && && && &will be written.
*& && && && && && &- NumHalfwordToWrite: number of Half words to write.
*& && && && && && &The maximum allowed value is 32 Half words (64 bytes).
* Output& && && &: None
* Return& && && &: NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
*& && && && && && &or NOR_TIMEOUT
*******************************************************************************/
/*******************************************************************************
*函数名称& && && && &:FSMC_NOR_ProgramBuffer
*说明& && && && && & :写一个FSMC的NOR闪存半字的缓冲区。这个函数必须仅用于S29GL128P NOR存储器。
*输入& && && && && & : -pbuffer的:指向缓冲区。
* -WriteAddr& && && &:NOR存储器内部地址的数据将被写入。
* -NumHalfwordToWrite:半字数写。
*& && && && && && && & 最大允许值是32个半字(64字节)。
*返回& && && && && & :NOR_Status:返回的值可以是:NOR成功,NOR错误或NOR超时
************************************************** *****************************/
NOR_Status FSMC_NOR_ProgramBuffer(u16* pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite)
u32 lastloadedaddress = 0x00;
u32 currentaddress = 0x00;
u32 endaddress = 0x00;
/* Initialize variables */
currentaddress = WriteA
endaddress = WriteAddr + NumHalfwordToWrite - 1;
lastloadedaddress = WriteA
/* Issue unlock command sequence */
NOR_WRITE(ADDR_SHIFT(0x005555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
/* Write Write Buffer Load Command */
NOR_WRITE(ADDR_SHIFT(WriteAddr), 0x0025);
NOR_WRITE(ADDR_SHIFT(WriteAddr), (NumHalfwordToWrite - 1));
/* Load Data into NOR Buffer */
while(currentaddress &= endaddress)
& & /* Store last loaded address & data value (for polling) */
& & lastloadedaddress =
& & NOR_WRITE(ADDR_SHIFT(currentaddress), *pBuffer++);
& & currentaddress += 1;
NOR_WRITE(ADDR_SHIFT(lastloadedaddress), 0x29);
return(FSMC_NOR_GetStatus(Program_Timeout));
/******************************************************************************
* Function Name: FSMC_NOR_ReadHalfWord
* Description& & : Reads a half-word from the NOR memory.
* Input& && && & : - ReadAddr : NOR memory internal address to read from.
* Output& && && &: None
* Return& && && &: Half-word read from the NOR memory
*******************************************************************************/
/******************************************************************************
*函数名称:FSMC_NOR_ReadHalfWord
*说明:读取从NOR存储器半字。
*输入: -ReadAddr:NOR存储器内部读取的地址。
*返回:半字从NOR存储器读
************************************************** *****************************/
u16 FSMC_NOR_ReadHalfWord(u32 ReadAddr)
NOR_WRITE(ADDR_SHIFT(0x005555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x002AAA), 0x0055);
//NOR_WRITE((Bank1_NOR2_ADDR + ReadAddr), 0x00F0 );
NOR_WRITE((Bank1_NOR1_ADDR + ReadAddr), 0x00F0 );
//return (*(vu16 *)((Bank1_NOR2_ADDR + ReadAddr)));
return (*(vu16 *)((Bank1_NOR1_ADDR + ReadAddr)));
/*******************************************************************************
* Function Name: FSMC_NOR_ReadBuffer
* Description& & : Reads a block of data from the FSMC NOR memory.
* Input& && && & : - pBuffer : pointer to the buffer that receives the data read
*& && && && && && &from the NOR memory.
*& && && && && && &- ReadAddr : NOR memory internal address to read from.
*& && && && && && &- NumHalfwordToRead : number of Half word to read.
* Output& && && &: None
* Return& && && &: None
*******************************************************************************/
/*******************************************************************************
*函数名称& && && &:FSMC_NOR_ReadBuffer
*说明& && && && && &:读取一个由FSMC的NOR存储器的数据块。
*输入& && && && && &: -pbuffer的:指向的缓冲区,它接收从NOR存储器读取数据。
* -ReadAddr& && && &:NOR存储器内部读取的地址。
* -NumHalfwordToRead:半字数阅读。
************************************************** *****************************/
void FSMC_NOR_ReadBuffer(u16* pBuffer, u32 ReadAddr, u32 NumHalfwordToRead)
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
//NOR_WRITE((Bank1_NOR2_ADDR + ReadAddr), 0x00F0);
NOR_WRITE((Bank1_NOR1_ADDR + ReadAddr), 0x00F0);
for(; NumHalfwordToRead != 0x00; NumHalfwordToRead--) /* while there is data to read */
& & /* Read a Halfword from the NOR */
//& & *pBuffer++ = *(vu16 *)((Bank1_NOR2_ADDR + ReadAddr));
& & *pBuffer++ = *(vu16 *)((Bank1_NOR1_ADDR + ReadAddr));
& & ReadAddr = ReadAddr + 2;
/******************************************************************************
* Function Name: FSMC_NOR_ReturnToReadMode
* Description& & : Returns the NOR memory to Read mode.
* Input& && && & : None
* Output& && && &: None
* Return& && && &: NOR_SUCCESS
*******************************************************************************/
/******************************************************************************
*函数名称:FSMC_NOR_ReturnToReadMode
*说明:返回的NOR内存读取模式。
*返回:NOR_成功
************************************************** *****************************/
NOR_Status FSMC_NOR_ReturnToReadMode(void)
//NOR_WRITE(Bank1_NOR2_ADDR, 0x00F0);
NOR_WRITE(Bank1_NOR1_ADDR, 0x00F0);
return (NOR_SUCCESS);
/******************************************************************************
* Function Name: FSMC_NOR_Reset
* Description& & : Returns the NOR memory to Read mode and resets the errors in
*& && && && && && &the NOR memory Status Register.
* Input& && && & : None
* Output& && && &: None
* Return& && && &: NOR_SUCCESS
*******************************************************************************/
/******************************************************************************
*函数名称:FSMC_NOR_Reset
*说明:返回NOR存储器读取模式,在NOR内存复位状态寄存器的错误。
*返回:NOR_成功
************************************************** *****************************/
NOR_Status FSMC_NOR_Reset(void)
NOR_WRITE(ADDR_SHIFT(0x005555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x002AAA), 0x0055);
//NOR_WRITE(Bank1_NOR2_ADDR, 0x00F0);
NOR_WRITE(Bank1_NOR1_ADDR, 0x00F0);
return (NOR_SUCCESS);
/******************************************************************************
* Function Name: FSMC_NOR_GetStatus
* Description& & : Returns the NOR operation status.
* Input& && && & : - Timeout: NOR progamming Timeout
* Output& && && &: None
* Return& && && &: NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
*& && && && && && &or NOR_TIMEOUT
*******************************************************************************/
/******************************************************************************
*函数名称:FSMC_NOR_GetStatus
*说明& & :返回的NOR操作的状态。
*输入& & : -超时:超时的NOR progamming
*输出& & :无
*返回& & :NOR_Status:返回的值可以是:NOR成功,NOR错误或NOR超时
************************************************** *****************************/
NOR_Status FSMC_NOR_GetStatus(u32 Timeout)
u16 val1 = 0x00, val2 = 0x00;
NOR_Status status = NOR_ONGOING;
u32 timeout = T
/* Poll on NOR memory Ready/Busy signal ------------------------------------*/
while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) != RESET) && (timeout & 0))
& & timeout--;
timeout = T
while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == RESET) && (timeout & 0))& &
& & timeout--;
/* Get the NOR memory operation status -------------------------------------*/
while((Timeout != 0x00) && (status != NOR_SUCCESS))
& & Timeout--;
& & & && &/* Read DQ6 and DQ5 */
//& & val1 = *(vu16 *)(Bank1_NOR2_ADDR);
& & val1 = *(vu16 *)(Bank1_NOR1_ADDR);
//& & val2 = *(vu16 *)(Bank1_NOR2_ADDR);
& & val2 = *(vu16 *)(Bank1_NOR1_ADDR);
& & /* If DQ6 did not toggle between the two reads then return NOR_Success */
& & if((val1 & 0x0040) == (val2 & 0x0040))
& && &return NOR_SUCCESS;
& & if((val1 & 0x0020) != 0x0020)
& && &status = NOR_ONGOING;
//& & val1 = *(vu16 *)(Bank1_NOR2_ADDR);
& & val1 = *(vu16 *)(Bank1_NOR1_ADDR);
//& & val2 = *(vu16 *)(Bank1_NOR2_ADDR);
& & val2 = *(vu16 *)(Bank1_NOR1_ADDR);
& & if((val1 & 0x0040) == (val2 & 0x0040))
& && &return NOR_SUCCESS;
& & else if((val1 & 0x0020) == 0x0020)
& && &return NOR_ERROR;
if(Timeout == 0x00)
& & status = NOR_TIMEOUT;
/* Return the operation status */
return (status);
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
******************************************************************************
* @file& & USART/Printf/main.c
* @authorMCD Application Team
* @version V3.3.0
* @date& & 04/16/2010
* @brief& &Main program body
******************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
* &h2&& COPYRIGHT 2010 STMicroelectronics&/h2&
/* Includes ------------------------------------------------------------------*/
#include &stm32f10x.h&
#include &stm32_eval.h&
#include &stdio.h&
#include &fsmc_nor.h&
#include &stm32f10x_flash.h&
#include &stm32f10x_fsmc.h&
#include &stm32f10x_gpio.h&
#include &stm32f10x_rcc.h&
/** @addtogroup STM32F10x_StdPeriph_Examples
/** @addtogroup USART_Printf
/* Private typedef -----------------------------------------------------------*/
/*神舟III号LED灯相关定义*/
#define RCC_GPIO_LED& && && && && && &RCC_APB2Periph_GPIOF& & /*LED使用的GPIO时钟*/
#define LEDn& && && && && && && && && & 4& && && && && && && &/*LED数量*/
#define GPIO_LED& && && && && && && && &GPIOF& && && && && && & /*LED灯使用的GPIO组*/
#define DS1_PIN& && && && && && && && & GPIO_Pin_6& && && && &/*DS1使用的GPIO管脚*/
#define DS2_PIN& && && && && && && && & GPIO_Pin_7& & & & & & & & & & & & & & & & /*DS2使用的GPIO管脚*/
#define DS3_PIN& && && && && && && && & GPIO_Pin_8& & & & & & & & & & & & /*DS3使用的GPIO管脚*/
#define DS4_PIN& && && && && && && && & GPIO_Pin_9& & & & & & & & & & & & & & & & /*DS4使用的GPIO管脚*/
/* Private define ------------------------------------------------------------*/
#define BUFFER_SIZE& && &0x400
//#define BUFFER_SIZE& && &0x100
#define WRITE_READ_ADDR& & 0x8000
#define RCC_GPIO_LED& & RCC_APB2Periph_GPIOF
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
USART_InitTypeDef USART_InitS
GPIO_InitTypeDef GPIO_InitS
ErrorStatus HSEStartUpS
u32 WriteReadStatus = 0, Index = 0;
NOR_IDTypeDef NOR_ID;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Fill_Buffer(u16 *pBuffer, u16 BufferLenght, u32 Offset);
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker-&Libraries-&Small printf
& &set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name: Armjishu_Delay
* Description& & : Inserts a delay time.
* Input& && && & : nCount: specifies the delay time length.
* Output& && && &: None
* Return& && && &: None
*******************************************************************************/
void Armjishu_Delay(vu32 nCount)
for(; nCount != 0; nCount--);
* @briefMain program
* @paramNone
* @retval None
int main(void)
u16 IndexTmp = 0;
RCC_Configuration();
NVIC_Configuration();
RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE);
GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED, &GPIO_InitStructure);
GPIO_SetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN);
/* USARTx configured as follow:
& && &- BaudRate = 115200 baud
& && &- Word Length = 8 Bits
& && &- One Stop Bit
& && &- No parity
& && &- Hardware flow control disabled (RTS and CTS signals)
& && &- Receive and transmit enabled
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_N
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
STM_EVAL_COMInit(COM1, &USART_InitStructure);
/* Output a message on Hyperterminal using printf function */
printf(&\n\r--------------------------------------------- &);
printf(&\n\r& &-- Nor Flash读写程序&);
printf(&\n\r& &--DS1闪烁表示正常运行&);
printf(&\n\r& &--DS2--亮,表示读写Nor Flash成功&);
printf(&\n\r& &--DS3--亮,表示读写Nor Flash失败&);
printf(&\n\r--------------------------------------------- &);
/*使能FSMC时钟 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/*配置与SRAM连接的FSMC BANK1 NOR/SRAM2*/
FSMC_NOR_Init();
/*读取Nor Flash ID并打印*/
FSMC_NOR_ReadID(&NOR_ID);
printf(&\n\r Nor Flash ID:0x%x 0x%x 0x%x 0x%x&,NOR_ID.Manufacturer_Code,NOR_ID.Device_Code1,NOR_ID.Device_Code2,NOR_ID.Device_Code3);
/*返回写模式*/
FSMC_NOR_ReturnToReadMode();
/*擦除NOR FLASH中,将要写入数据的块*/
FSMC_NOR_EraseBlock(WRITE_READ_ADDR);
/*将写Nor Flash的数据BUFFER填充为从0x1234开始的连续递增的一串数据 */
//Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x1234);
for (IndexTmp = 0; IndexTmp & BUFFER_SIZE; IndexTmp++ )
& & TxBuffer = 0xaa55;
/*将数据写入到Nor Flash中。WRITE_READ_ADDR:写入的起始地址*/
FSMC_NOR_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
//printf(&\n\r FSMC_NOR_WriteBuffer: ADD 0x%x DATA 0x%x&,WRITE_READ_ADDR,BUFFER_SIZE);
/*从NOR FLASH中读回刚写入的数据。?WRITE_READ_ADDR:读出数据的起始地址*/
FSMC_NOR_ReadBuffer(RxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
//printf(&\n\r FSMC_NOR_ReadBuffer: ADD 0x%x DATA 0x%x&,WRITE_READ_ADDR,BUFFER_SIZE);
/*判断读回的数据与写入的数据是否一致*/& &
for (Index = 0x00; (Index & BUFFER_SIZE) && (WriteReadStatus == 0); Index++)
& & if (RxBuffer != TxBuffer)
& && &WriteReadStatus = Index + 1;
& && &printf(&\n\r WriteReadStatus = 0x%x&,Index);
& && &printf(&\n\r RxBuffer = 0x%x&,RxBuffer);
& && &printf(&\n\r TxBuffer = 0x%x&,TxBuffer);
printf(&\n\r Nor Flash读写访问程序运行结果: &);
if (WriteReadStatus == 0)
& && & & & printf(&\n\r Nor Flash读写访问成功&);
//& & & & GPIO_ResetBits(GPIO_LED,DS2_PIN);
& && & & & printf(&\n\r Nor Flash读写访问失败&);
//& & & & GPIO_ResetBits(GPIO_LED, DS3_PIN);& &
//& & & & & & & & GPIO_ResetBits(GPIO_LED, DS1_PIN);
& & & & & & & & Armjishu_Delay(0x3FFFFF);
//& & & & & & & & GPIO_SetBits(GPIO_LED, DS1_PIN);
& & & & & & & & Armjishu_Delay(0x3FFFFF);& & & && &
/*******************************************************************************
* Function Name: RCC_Configuration
* Description& & : Configures the different system clocks.
* Input& && && & : None
* Output& && && &: None
* Return& && && &: None
*******************************************************************************/
void RCC_Configuration(void)
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
& & /* Enable Prefetch Buffer */
& & FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
& & /* Flash 2 wait state */
& & FLASH_SetLatency(FLASH_Latency_2);
& & /* HCLK = SYSCLK */
& & RCC_HCLKConfig(RCC_SYSCLK_Div1);
& & /* PCLK2 = HCLK */
& & RCC_PCLK2Config(RCC_HCLK_Div1);
& & /* PCLK1 = HCLK/2 */
& & RCC_PCLK1Config(RCC_HCLK_Div2);
& & /* PLLCLK = 8MHz * 9 = 72 MHz */
& & RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
& & /* Enable PLL */
& & RCC_PLLCmd(ENABLE);
& & /* Wait till PLL is ready */
& & while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
& & /* Select PLL as system clock source */
& & RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
& & /* Wait till PLL is used as system clock source */
& & while(RCC_GetSYSCLKSource() != 0x08)
/*******************************************************************************
* Function Name: NVIC_Configuration
* Description& & : Configures Vector Table base location.
* Input& && && & : None
* Output& && && &: None
* Return& && && &: None
*******************************************************************************/
void NVIC_Configuration(void)
#ifdefVECT_TAB_RAM
/* Set the Vector Table base location at 0x */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else/* VECT_TAB_FLASH*/
/* Set the Vector Table base location at 0x */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);& &
/*******************************************************************************
* Function name : Fill_Buffer
* Description& &: Fill the global buffer
* Input& && && &: - pBuffer: pointer on the Buffer to fill
*& && && && && &- BufferSize: size of the buffer to fill
*& && && && && &- Offset: first value to fill on the Buffer
* Output param: None
*******************************************************************************/
/*******************************************************************************
*函数名称& && &:Fill_Buffer
*说明& && && & :填写全局缓冲器
*输入& && && & : -pbuffer的:对缓冲区的指针,以填补
*bufferSize:缓冲区的大小,以填补
*Offset& && &:第一个值来填充缓冲区
*输出参数:无
************************************************** *****************************/
void Fill_Buffer(u16 *pBuffer, u16 BufferLenght, u32 Offset)
u16 IndexTmp = 0;
/* Put in global buffer same values */
for (IndexTmp = 0; IndexTmp & BufferL IndexTmp++ )
& & pBuffer = IndexTmp + O
* @briefRetargets the C library printf function to the USART.
* @paramNone
* @retval None
PUTCHAR_PROTOTYPE
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
#ifdefUSE_FULL_ASSERT
* @briefReports the name of the source file and the source line number
*& && && &where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
* @retval None
void assert_failed(uint8_t* file, uint32_t line)
/* User can add his own implementation to report the file name and line number,
& &ex: printf(&Wrong parameters value: file %s on line %d\r\n&, file, line) */
/* Infinite loop */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
/bbs_upload782111/files_37/ourdev_624370AZTYYE.jpg
(原文件名:1.jpg)
...这么多,看完都需要不少时间啊
那配置fsmc的这段代码是在stm32的内部flash中运行还是在 nor flash中运行呢?
zhou_yin_stm32
我的红牛版上就发现该死的奸商的伪劣NOR_FLASH, 我用单步跟踪调试的方法, 读芯片ID操作, 擦除操作, 编程操作 都通过了,就是最后校验的关过不了。 反复实验最后发现其实芯片烧写成功了,但是几秒或几十秒后FLASH芯片内的数据眼睁睁地看着蒸发了。所以总是校验不过去。 板上芯片印着SST39VF1601,读ID却发现与 MX29LV160BB 相同。鬼知道怎么回事? 是不是有黑心商人用旧片子冒名顶替???
没有问题的我刚在红牛板上跑了下,读写NOR FLASH 正常。
用的是神州 3号的例程,不过有问题用下面的操作方法发现读数据时总线出错。
/*使能FSMC时钟 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/*配置与SRAM连接的FSMC BANK1 NOR/SRAM2*/
FSMC_NOR_Init();
/*读取Nor Flash ID并打印*/
FSMC_NOR_ReadID(&NOR_ID);
printf(&\n\r Nor Flash ID:0x%x 0x%x&,NOR_ID.Manufacturer_Code,NOR_ID.Device_Code1);
/*返回写模式*/
FSMC_NOR_ReturnToReadMode();
/*擦除NOR FLASH中,将要写入数据的块*/
FSMC_NOR_EraseBlock(WRITE_READ_ADDR);
/*将写Nor Flash的数据BUFFER填充为从0x1234开始的连续递增的一串数据 */
Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x1234);
/*将数据写入到Nor Flash中。WRITE_READ_ADDR:写入的起始地址*/
FSMC_NOR_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
/*从NOR FLASH中读回刚写入的数据。?WRITE_READ_ADDR:读出数据的起始地址*/
FSMC_NOR_ReadBuffer(RxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
下面是我改的操作过程
& & TFT_DrawPicture(50,50,64,64,(u16*)gImage_bmp1);//32*32& & & & & & & &165,
TFT_Dchars(56,Row(1), &Test NOR FLASH R&W!&);
& & & & /*擦除待写入数据的块*/
//& & state=NAND_EraseBlock(WriteReadAddr); & & & &
//& & state=NAND_WriteSmallPage((u8*)gImage_bmp1, WriteReadAddr, 16);
/*擦除NOR FLASH中,将要写入数据的块*/
FSMC_NOR_EraseBlock(WriteReadAddr);
& &/*将数据写入到Nor Flash中。WRITE_READ_ADDR:写入的起始地址*/
FSMC_NOR_WriteBuffer((u16*)gImage_bmp1, WriteReadAddr, BUFFER_SIZE/2);
FSMC_NOR_ReturnToReadMode();
& &/*从NOR FLASH中读回刚写入的数据。?WRITE_READ_ADDR:读出数据的起始地址*/
FSMC_NOR_ReadBuffer((u16*)RxBuffer, WriteReadAddr, BUFFER_SIZE/2);
& & /*判断读回的数据与写入的数据是否一致*/
& & & & TFT_DrawPicture(50+64,50,64,64,(u16*)RxBuffer);
其实就是 返回读模式放错了位置
请问楼主,我在执行以上程序时,每次到状态返回的地方程序就跑死,你是否遇到过?有哪些地方需要配置?
我用红龙的例程,在三块开发板上跑,有两块是单步运行才能正确读写少量数据,一块可以直接运行,数据读写正确但是ID读出来是错误的,而且块擦除也只是擦除了第一个字。
查看完整版本:}

我要回帖

更多关于 stm32 spi 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信