/**
* @brief Increment the NAND memory address
* @param Address: address to be incremented.
* @retval The new status of the increment address operation. It can be:
* - NAND_VALID_ADDRESS: When the new address is valid address
* - NAND_INVALID_ADDRESS: When the new address is invalid address
*/
uint32_t FSMC_NAND_AddressIncrement(NAND_ADDRESS* Address)
{
uint32_t status = NAND_VALID_ADDRESS;
Address->Page++;
if(Address->Page == NAND_BLOCK_SIZE)
{
Address->Page = 0;
Address->Block++;
if(Address->Block == NAND_ZONE_SIZE)
{
Address->Block = 0;
Address->Zone++;
if(Address->Zone == NAND_MAX_ZONE)
{
status = NAND_INVALID_ADDRESS;
}
}
}
return (status);
}
//MAIN.C
/* Includes ------------------------------------------------------------------*/
#include "fsmc_largenand.h"
#include "stm32_eval.h"
/** @addtogroup STM32F10x_StdPeriph_Examples
* @{
*/
/** @addtogroup FSMC_NAND
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define BUFFER_SIZE 0x2000
#define NAND_ST_MakerID 0xEC//0x20
#define NAND_ST_DeviceID 0xF1//0x76
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
NAND_IDTypeDef NAND_ID;
GPIO_InitTypeDef GPIO_InitStructure;
NAND_ADDRESS WriteReadAddr;
uint8_t TxBuffer[BUFFER_SIZE], RxBuffer[BUFFER_SIZE];
__IO uint32_t PageNumber = 2, WriteReadStatus = 0, status= 0;
uint32_t j = 0;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void Fill_Buffer(uint8_t *pBuffer, uint16_t BufferLenght, uint32_t Offset);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* System Clocks Configuration */
RCC_Configuration();
/* Initialize Leds mounted on STM3210X-EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
/* Enable the FSMC Clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* FSMC Initialization */
FSMC_NAND_Init();
/* NAND read ID command */
FSMC_NAND_ReadID(&NAND_ID);
/* Verify the NAND ID */
if((NAND_ID.Maker_ID == NAND_ST_MakerID) && (NAND_ID.Device_ID == NAND_ST_DeviceID))
{
/* NAND memory address to write to */
WriteReadAddr.Zone = 0x00;
WriteReadAddr.Block = 0x01;
WriteReadAddr.Page = 0x02;
/* Erase the NAND first Block */
status = FSMC_NAND_EraseLargeBlock(WriteReadAddr);
WriteReadAddr.Page = 0x04;
/* Read back the written data */
status = FSMC_NAND_ReadLargePage (RxBuffer, WriteReadAddr, 1);
WriteReadAddr.Page = 0x06;
status = FSMC_NAND_ReadLargePage (RxBuffer, WriteReadAddr, 1/*PageNumber*/);
//这里读出来的都是FF,正确
/* Write data to FSMC NAND memory */
/* Fill the buffer to send */
Fill_Buffer(TxBuffer, BUFFER_SIZE , 0x55);
WriteReadAddr.Page = 0x04;
status = FSMC_NAND_WriteLargePage(TxBuffer, WriteReadAddr, 1/*PageNumber*/);
WriteReadAddr.Page = 0x04;
/* Read back the written data */
status = FSMC_NAND_ReadLargePage (RxBuffer, WriteReadAddr, 1);
/* Verify the written data */
for(j = 0; j < 2048; j++)
{
if(TxBuffer[j] != RxBuffer[j])
{
WriteReadStatus++;
}
}/* Read back the written data */
//比较都正确
WriteReadAddr.Page = 0x06;
status = FSMC_NAND_WriteLargePage(TxBuffer, WriteReadAddr, 1/*PageNumber*/);
WriteReadAddr.Page = 0x06;
status = FSMC_NAND_ReadLargePage (RxBuffer, WriteReadAddr, 1/*PageNumber*/);
/* Verify the written data */
for(j = 0; j < 2048; j++)
{
if(TxBuffer[j] != RxBuffer[j])
{
WriteReadStatus++;
}
}
//比较到1600个后就不正确啦. 有时多有时少.问题就在这里.....!!!!!!!!
if (WriteReadStatus == 0)
{
/* OK */
/* Turn on LED1 */
STM_EVAL_LEDOff(LED1);
}
else
{
/* KO */
/* Turn on LED2 */
STM_EVAL_LEDOff(LED2);
}
}
else
{
/* Turn on LED3 */
STM_EVAL_LEDOff(LED3);
}
while(1)
{
}
}
/**
* @brief Configures the different system clocks.
* @param None
* @retval None
*/
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Inte**ce,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
}
/**
* Function name : Fill_Buffer
* @brief Fill the buffer
* @param pBuffer: pointer on the Buffer to fill
* @param BufferSize: size of the buffer to fill
* @param Offset: first value to fill on the Buffer
*/
void Fill_Buffer(uint8_t *pBuffer, uint16_t BufferLenght, uint32_t Offset)
{
uint16_t IndexTmp = 0;
/* Put in global buffer same values */
for (IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ )
{
pBuffer[IndexTmp] = IndexTmp + Offset;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: 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 */
while (1)
{
}
}
#endif
帮我找找问题吧. |