STM32F10x_StdPeriph_Examples/FSMC/NOR/main.c

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