STM32F10x_StdPeriph_Examples/FSMC/OneNAND/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    FSMC/OneNAND/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 "stm32_eval.h"
00023 #include "stm32100e_eval_fsmc_onenand.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup FSMC_OneNAND
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 #define BUFFER_SIZE        0x200
00038 #define WRITE_READ_ADDR    0x800
00039 uint16_t TxBuffer[BUFFER_SIZE], RxBuffer[BUFFER_SIZE];
00040 
00041 OneNAND_IDTypeDef OneNand_ID;
00042 uint16_t WriteReadStatus = 0;
00043 uint32_t index = 0;
00044 uint16_t OneNand_SAMSUNG_ID[2] = {0x00EC, 0x0025};
00045 
00046 /* Private function prototypes -----------------------------------------------*/
00047 void Fill_Buffer(uint16_t *pBuffer, uint16_t BufferLenght, uint32_t Offset);
00048 
00049 /* Private functions ---------------------------------------------------------*/
00050 /**
00051   * @brief  Main program.
00052   * @param  None
00053   * @retval None
00054   */
00055 int main(void)
00056 {
00057   /*!< At this stage the microcontroller clock setting is already configured, 
00058        this is done through SystemInit() function which is called from startup
00059        file (startup_stm32f10x_xx.s) before to branch to application main.
00060        To reconfigure the default setting of SystemInit() function, refer to
00061        system_stm32f10x.c file
00062      */
00063   
00064   /* Initialize LEDs on STM32100E-EVAL board */
00065   STM_EVAL_LEDInit(LED1);
00066   STM_EVAL_LEDInit(LED2);
00067   STM_EVAL_LEDInit(LED3);  
00068   
00069   /* FSMC Initialization */
00070   OneNAND_Init();
00071 
00072   /* Read OneNAND memory ID */
00073   OneNAND_ReadID(&OneNand_ID);
00074 
00075   /* Verify the OneNAND ID */ 
00076   if((OneNand_SAMSUNG_ID[0] == OneNand_ID.Manufacturer_ID) && (OneNand_SAMSUNG_ID[1] == OneNand_ID.Device_ID)) 
00077   {
00078     /* Erase the OneNAND Block */
00079     OneNAND_EraseBlock(WRITE_READ_ADDR);
00080     
00081     /* Write data to FSMC OneNAND memory */
00082     /* Fill the buffer to send */
00083     Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x365A);
00084 
00085     OneNAND_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
00086   
00087     /* Read back the written data */
00088     OneNAND_AsynchronousRead(RxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
00089  
00090     /* Verify the written data */
00091     for(index = 0; index < BUFFER_SIZE; index++)
00092     {
00093       if(TxBuffer[index] != RxBuffer[index])
00094       {     
00095         WriteReadStatus++;
00096       } 
00097     }
00098     if (WriteReadStatus == 0)
00099     {   /* OK */
00100       /* Turn on LD1 */
00101       STM_EVAL_LEDToggle(LED1);
00102     }
00103     else
00104     { /* KO */
00105       /* Turn on LD2 */
00106       STM_EVAL_LEDToggle(LED2);     
00107     }
00108   }
00109   else
00110   {
00111     /* Turn on LD3 */
00112     STM_EVAL_LEDToggle(LED3); 
00113   }
00114 
00115   /* Infinite loop */
00116   while (1)
00117   {
00118   }
00119 }
00120 
00121 /**
00122   * @brief  Fill the buffer.
00123   * @param  pBuffer: pointer on the Buffer to fill
00124   * @param  BufferSize: size of the buffer to fill
00125   * @param  Offset: first value to fill on the Buffer
00126   * @retval None
00127   */
00128 void Fill_Buffer(uint16_t *pBuffer, uint16_t BufferLenght, uint32_t Offset)
00129 {
00130   uint16_t IndexTmp = 0;
00131 
00132   /* Put in global buffer diferent values */
00133   for (IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ )
00134   {
00135     pBuffer[IndexTmp] = IndexTmp + Offset;
00136   }
00137 }
00138 
00139 #ifdef  USE_FULL_ASSERT
00140 
00141 /**
00142   * @brief  Reports the name of the source file and the source line number
00143   *   where the assert_param error has occurred.
00144   * @param  file: pointer to the source file name
00145   * @param  line: assert_param error line source number
00146   * @retval None
00147   */
00148 void assert_failed(uint8_t* file, uint32_t line)
00149 { 
00150   /* User can add his own implementation to report the file name and line number,
00151      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00152 
00153   /* Infinite loop */
00154   while (1)
00155   {
00156   }
00157 }
00158 #endif
00159 
00160 /**
00161   * @}
00162   */
00163 
00164 
00165 /******************* (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