fsmc_sram.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name : fsmc_sram.c
  3. * Author : MCD Application Team
  4. * Version : V2.0.3
  5. * Date : 09/22/2008
  6. * Description : This file provides a set of functions needed to drive the
  7. * IS61WV51216BLL SRAM memory mounted on STM3210E-EVAL board.
  8. ********************************************************************************
  9. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  11. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  12. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  13. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  14. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  15. *******************************************************************************/
  16. #include "stm32f10x.h"
  17. /* Private typedef -----------------------------------------------------------*/
  18. /* Private define ------------------------------------------------------------*/
  19. #define Bank1_SRAM3_ADDR ((u32)0x68000000)
  20. /* Private macro -------------------------------------------------------------*/
  21. /* Private variables ---------------------------------------------------------*/
  22. /* Private function prototypes -----------------------------------------------*/
  23. /* Private functions ---------------------------------------------------------*/
  24. /*******************************************************************************
  25. * Function Name : FSMC_SRAM_Init
  26. * Description : Configures the FSMC and GPIOs to interface with the SRAM memory.
  27. * This function must be called before any write/read operation
  28. * on the SRAM.
  29. * Input : None
  30. * Output : None
  31. * Return : None
  32. *******************************************************************************/
  33. void FSMC_SRAM_Init(void)
  34. {
  35. FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
  36. FSMC_NORSRAMTimingInitTypeDef p;
  37. GPIO_InitTypeDef GPIO_InitStructure;
  38. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE |
  39. RCC_APB2Periph_GPIOF, ENABLE);
  40. /*-- GPIO Configuration ------------------------------------------------------*/
  41. /* SRAM Data lines configuration */
  42. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
  43. GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
  44. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  45. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  46. GPIO_Init(GPIOD, &GPIO_InitStructure);
  47. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
  48. GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
  49. GPIO_Pin_15;
  50. GPIO_Init(GPIOE, &GPIO_InitStructure);
  51. /* SRAM Address lines configuration */
  52. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  53. GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
  54. GPIO_Pin_14 | GPIO_Pin_15;
  55. GPIO_Init(GPIOF, &GPIO_InitStructure);
  56. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  57. GPIO_Pin_4 | GPIO_Pin_5;
  58. GPIO_Init(GPIOG, &GPIO_InitStructure);
  59. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  60. GPIO_Init(GPIOD, &GPIO_InitStructure);
  61. /* NOE and NWE configuration */
  62. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
  63. GPIO_Init(GPIOD, &GPIO_InitStructure);
  64. /* NE3 NE4 configuration */
  65. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_12;
  66. GPIO_Init(GPIOG, &GPIO_InitStructure);
  67. /* NBL0, NBL1 configuration */
  68. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  69. GPIO_Init(GPIOE, &GPIO_InitStructure);
  70. /*-- FSMC Configuration ------------------------------------------------------*/
  71. p.FSMC_AddressSetupTime = 0;
  72. p.FSMC_AddressHoldTime = 0;
  73. p.FSMC_DataSetupTime = 2;
  74. p.FSMC_BusTurnAroundDuration = 0;
  75. p.FSMC_CLKDivision = 0;
  76. p.FSMC_DataLatency = 0;
  77. p.FSMC_AccessMode = FSMC_AccessMode_A;
  78. FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
  79. FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  80. FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  81. FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  82. FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  83. FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  84. FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  85. FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  86. FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  87. FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  88. FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  89. FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  90. FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  91. FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
  92. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  93. FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
  94. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  95. /* Enable FSMC Bank1_SRAM Bank */
  96. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
  97. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
  98. }
  99. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/