fsmc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**
  2. ******************************************************************************
  3. * File Name : FSMC.c
  4. * Description : This file provides code for the configuration
  5. * of the FSMC peripheral.
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2016 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "fsmc.h"
  36. #include "gpio.h"
  37. /* USER CODE BEGIN 0 */
  38. /* USER CODE END 0 */
  39. SRAM_HandleTypeDef hsram1;
  40. /* FSMC initialization function */
  41. void MX_FSMC_Init(void)
  42. {
  43. FSMC_NORSRAM_TimingTypeDef Timing;
  44. /** Perform the SRAM1 memory initialization sequence
  45. */
  46. hsram1.Instance = FSMC_NORSRAM_DEVICE;
  47. hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
  48. /* hsram1.Init */
  49. hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;
  50. hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_ENABLE;
  51. hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_PSRAM;
  52. hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_8;
  53. hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
  54. hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
  55. hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
  56. hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
  57. hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
  58. hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
  59. hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
  60. hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
  61. hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
  62. /* Timing */
  63. /*
  64. Timing.AddressSetupTime = 3;
  65. Timing.AddressHoldTime = 2;
  66. Timing.DataSetupTime = 5;
  67. */
  68. Timing.AddressSetupTime = 2;
  69. Timing.AddressHoldTime = 1;
  70. Timing.DataSetupTime = 4;
  71. Timing.BusTurnAroundDuration = 0;
  72. Timing.CLKDivision = 16;
  73. Timing.DataLatency = 17;
  74. Timing.AccessMode = FSMC_ACCESS_MODE_A;
  75. /* ExtTiming */
  76. HAL_SRAM_Init(&hsram1, &Timing, NULL);
  77. }
  78. static int FSMC_Initialized = 0;
  79. static void HAL_FSMC_MspInit(void){
  80. /* USER CODE BEGIN FSMC_MspInit 0 */
  81. /* USER CODE END FSMC_MspInit 0 */
  82. GPIO_InitTypeDef GPIO_InitStruct;
  83. if (FSMC_Initialized) {
  84. return;
  85. }
  86. FSMC_Initialized = 1;
  87. /* Peripheral clock enable */
  88. __FSMC_CLK_ENABLE();
  89. /** FSMC GPIO Configuration
  90. PE7 ------> FSMC_DA4
  91. PE8 ------> FSMC_DA5
  92. PE9 ------> FSMC_DA6
  93. PE10 ------> FSMC_DA7
  94. PD14 ------> FSMC_DA0
  95. PD15 ------> FSMC_DA1
  96. PD0 ------> FSMC_DA2
  97. PD1 ------> FSMC_DA3
  98. PD4 ------> FSMC_NOE
  99. PD5 ------> FSMC_NWE
  100. PD7 ------> FSMC_NE1
  101. PB7 ------> FSMC_NL
  102. */
  103. /* GPIO_InitStruct */
  104. GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  105. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  106. GPIO_InitStruct.Pull = GPIO_NOPULL;
  107. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  108. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  109. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  110. /* GPIO_InitStruct */
  111. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
  112. |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7;
  113. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  114. GPIO_InitStruct.Pull = GPIO_NOPULL;
  115. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  116. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  117. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  118. /* GPIO_InitStruct */
  119. GPIO_InitStruct.Pin = GPIO_PIN_7;
  120. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  121. GPIO_InitStruct.Pull = GPIO_NOPULL;
  122. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  123. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  124. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  125. /* USER CODE BEGIN FSMC_MspInit 1 */
  126. /* USER CODE END FSMC_MspInit 1 */
  127. }
  128. void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram){
  129. /* USER CODE BEGIN SRAM_MspInit 0 */
  130. /* USER CODE END SRAM_MspInit 0 */
  131. HAL_FSMC_MspInit();
  132. /* USER CODE BEGIN SRAM_MspInit 1 */
  133. /* USER CODE END SRAM_MspInit 1 */
  134. }
  135. static int FSMC_DeInitialized = 0;
  136. static void HAL_FSMC_MspDeInit(void){
  137. /* USER CODE BEGIN FSMC_MspDeInit 0 */
  138. /* USER CODE END FSMC_MspDeInit 0 */
  139. if (FSMC_DeInitialized) {
  140. return;
  141. }
  142. FSMC_DeInitialized = 1;
  143. /* Peripheral clock enable */
  144. __FSMC_CLK_DISABLE();
  145. /** FSMC GPIO Configuration
  146. PE7 ------> FSMC_DA4
  147. PE8 ------> FSMC_DA5
  148. PE9 ------> FSMC_DA6
  149. PE10 ------> FSMC_DA7
  150. PD14 ------> FSMC_DA0
  151. PD15 ------> FSMC_DA1
  152. PD0 ------> FSMC_DA2
  153. PD1 ------> FSMC_DA3
  154. PD4 ------> FSMC_NOE
  155. PD5 ------> FSMC_NWE
  156. PD7 ------> FSMC_NE1
  157. PB7 ------> FSMC_NL
  158. */
  159. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
  160. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
  161. |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7);
  162. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
  163. /* USER CODE BEGIN FSMC_MspDeInit 1 */
  164. /* USER CODE END FSMC_MspDeInit 1 */
  165. }
  166. void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram){
  167. /* USER CODE BEGIN SRAM_MspDeInit 0 */
  168. /* USER CODE END SRAM_MspDeInit 0 */
  169. HAL_FSMC_MspDeInit();
  170. /* USER CODE BEGIN SRAM_MspDeInit 1 */
  171. /* USER CODE END SRAM_MspDeInit 1 */
  172. }
  173. /**
  174. * @}
  175. */
  176. /**
  177. * @}
  178. */
  179. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/