STM32F10x_StdPeriph_Examples/FSMC/SRAM/main.c

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