STM32F10x_StdPeriph_Examples/FSMC/NAND/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    FSMC/NAND/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body 
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm3210e_eval_fsmc_nand.h"
00023 #include "stm32_eval.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup FSMC_NAND
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 #define BUFFER_SIZE         0x400
00036 #define NAND_ST_MakerID     0x20
00037 #define NAND_ST_DeviceID    0x76
00038 
00039 /* Private macro -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 NAND_IDTypeDef NAND_ID;
00042 NAND_ADDRESS WriteReadAddr;
00043 uint8_t TxBuffer[BUFFER_SIZE], RxBuffer[BUFFER_SIZE];
00044 uint32_t PageNumber = 2, WriteReadStatus = 0, status= 0;
00045 uint32_t j = 0;
00046 
00047 /* Private function prototypes -----------------------------------------------*/
00048 void Fill_Buffer(uint8_t *pBuffer, uint16_t BufferLenght, uint32_t Offset);
00049 
00050 /* Private functions ---------------------------------------------------------*/
00051 
00052 /**
00053   * @brief   Main program.
00054   * @param  None
00055   * @retval None
00056   */
00057 int main(void)
00058 {
00059   /*!< At this stage the microcontroller clock setting is already configured, 
00060        this is done through SystemInit() function which is called from startup
00061        file (startup_stm32f10x_xx.s) before to branch to application main.
00062        To reconfigure the default setting of SystemInit() function, refer to
00063        system_stm32f10x.c file
00064      */     
00065 
00066   /* Initialize Leds mounted on STM3210X-EVAL board */
00067   STM_EVAL_LEDInit(LED1);
00068   STM_EVAL_LEDInit(LED2);
00069   STM_EVAL_LEDInit(LED3);
00070   
00071   /* Enable the FSMC Clock */
00072   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
00073   
00074   /* FSMC Initialization */
00075   NAND_Init();
00076 
00077   /* NAND read ID command */
00078   NAND_ReadID(&NAND_ID);
00079 
00080   /* Verify the NAND ID */
00081   if((NAND_ID.Maker_ID == NAND_ST_MakerID) && (NAND_ID.Device_ID == NAND_ST_DeviceID))
00082   {
00083 
00084     /* NAND memory address to write to */
00085     WriteReadAddr.Zone = 0x00;
00086     WriteReadAddr.Block = 0x00;
00087     WriteReadAddr.Page = 0x00;
00088 
00089     /* Erase the NAND first Block */
00090     status = NAND_EraseBlock(WriteReadAddr);
00091 
00092     /* Write data to FSMC NAND memory */
00093     /* Fill the buffer to send */
00094     Fill_Buffer(TxBuffer, BUFFER_SIZE , 0x66);
00095 
00096     status = NAND_WriteSmallPage(TxBuffer, WriteReadAddr, PageNumber);
00097 
00098     /* Read back the written data */
00099     status = NAND_ReadSmallPage (RxBuffer, WriteReadAddr, PageNumber);
00100    
00101     /* Verify the written data */
00102     for(j = 0; j < BUFFER_SIZE; j++)
00103     {
00104       if(TxBuffer[j] != RxBuffer[j])
00105       {
00106         WriteReadStatus++;
00107       }
00108     }
00109 
00110     if (WriteReadStatus == 0)
00111     { 
00112       /* OK */
00113       /* Turn on LED1 */
00114       STM_EVAL_LEDOn(LED1);
00115     }
00116     else
00117     { 
00118       /* KO */
00119       /* Turn on LED2 */
00120       STM_EVAL_LEDOn(LED2);
00121     }
00122   }
00123   else
00124   {
00125     /* Turn on LED3 */
00126     STM_EVAL_LEDOn(LED3);
00127   }
00128 
00129   while(1)
00130   {
00131   }
00132 }
00133 
00134 /**
00135   *   Function name : Fill_Buffer
00136   * @brief  Fill the buffer
00137   * @param  pBuffer: pointer on the Buffer to fill
00138   * @param  BufferSize: size of the buffer to fill
00139   * @param  Offset: first value to fill on the Buffer
00140   */
00141 void Fill_Buffer(uint8_t *pBuffer, uint16_t BufferLenght, uint32_t Offset)
00142 {
00143   uint16_t IndexTmp = 0;
00144 
00145   /* Put in global buffer same values */
00146   for (IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ )
00147   {
00148     pBuffer[IndexTmp] = IndexTmp + Offset;
00149   }
00150 }
00151 
00152 #ifdef  USE_FULL_ASSERT
00153 
00154 /**
00155   * @brief  Reports the name of the source file and the source line number
00156   *         where the assert_param error has occurred.
00157   * @param  file: pointer to the source file name
00158   * @param  line: assert_param error line source number
00159   * @retval None
00160   */
00161 void assert_failed(uint8_t* file, uint32_t line)
00162 { 
00163   /* User can add his own implementation to report the file name and line number,
00164      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00165 
00166   /* Infinite loop */
00167   while (1)
00168   {
00169   }
00170 }
00171 #endif
00172 /**
00173   * @}
00174   */ 
00175 
00176 /**
00177   * @}
00178   */
00179 
00180 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32