首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

STM32-FSMC-NOR FLASH(6)

STM32-FSMC-NOR FLASH(6)

{
NOR_WRITE(Bank1_NOR2_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
*******************************************************************************/ NOR_Status FSMC_NOR_Reset(void)
{
NOR_WRITE(ADDR_SHIFT(0x005555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x002AAA), 0x0055);
NOR_WRITE(Bank1_NOR2_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
*******************************************************************************/ NOR_Status FSMC_NOR_GetStatus(u32 Timeout)
{
u16 val1 = 0x00, val2 = 0x00;
NOR_Status status = NOR_ONGOING;
u32 timeout = Timeout;
/* Poll on NOR memory Ready/Busy signal ------------------------------------*/   while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) != RESET) && (timeout > 0))
{
timeout--;
}
timeout = Timeout;

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);
val2 = *(vu16 *)(Bank1_NOR2_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);
val2 = *(vu16 *)(Bank1_NOR2_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****/
2.main.c
/******************** (C) COPYRIGHT 2008 STMicroelectronics
********************
* File Name          : main.c
* Author             : MCD Application Team
* Version            : V2.0.1
* Date               : 06/13/2008
* Description        : 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.
*******************************************************************************/ /* Includes ------------------------------------------------------------------*/
#include "fsmc_nor.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define BUFFER_SIZE        0x400
#define WRITE_READ_ADDR    0x8000
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
u16 TxBuffer[BUFFER_SIZE];
u16 RxBuffer[BUFFER_SIZE];
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);
/* Private functions ---------------------------------------------------------*/
/******************************************************************************* * Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/ int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* PF.06 and PF.07  config to drive LD1 and LD2 *****************************/   /* Enable GPIOF clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
/* Configure PF.06 and PF.07 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);

/* Write/read to/from FSMC SRAM
memory  *************************************/
/* Enable the FSMC Clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);   /* Configure FSMC Bank1 NOR/SRAM2 */
FSMC_NOR_Init();

/* Read NOR memory ID */
FSMC_NOR_ReadID(&NOR_ID);
FSMC_NOR_ReturnToReadMode();
/* Erase the NOR memory block to write on */
FSMC_NOR_EraseBlock(WRITE_READ_ADDR);
/* Write data to FSMC NOR memory */
/* Fill the buffer to send */
Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x3210);
FSMC_NOR_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);   /* Read data from FSMC NOR memory */
FSMC_NOR_ReadBuffer(RxBuffer, WRITE_READ_ADDR,
BUFFER_SIZE);
/* Read back NOR memory and check content correctness */
for (Index = 0x00; (Index < BUFFER_SIZE) && (WriteReadStatus == 0); Index++)
{
if (RxBuffer[Index] != TxBuffer[Index])
{
WriteReadStatus = Index + 1;
}
}
if (WriteReadStatus == 0)
{ /* OK */
/* Turn on LD1 */
GPIO_SetBits(GPIOF, GPIO_Pin_6);
}
else
{ /* KO */
/* Turn on LD2 */
GPIO_SetBits(GPIOF, GPIO_Pin_7);
}
while (1)
{
}
}
/******************************************************************************* * 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);
博泰典藏网btdcw.com包含总结汇报、高中教育、经管营销、行业论文、计划方案、农林牧渔、外语学习、工程科技、表格模板、高等教育、旅游景点以及STM32-FSMC-NOR FLASH等内容。
继承事业,薪火相传
返回列表