fsmc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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) 2019 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_16;
  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. Timing.AddressSetupTime = 2;
  64. Timing.AddressHoldTime = 1;
  65. Timing.DataSetupTime = 4;
  66. Timing.BusTurnAroundDuration = 1;
  67. Timing.CLKDivision = 16;
  68. Timing.DataLatency = 17;
  69. Timing.AccessMode = FSMC_ACCESS_MODE_A;
  70. /* ExtTiming */
  71. HAL_SRAM_Init(&hsram1, &Timing, NULL);
  72. }
  73. static int FSMC_Initialized = 0;
  74. static void HAL_FSMC_MspInit(void){
  75. /* USER CODE BEGIN FSMC_MspInit 0 */
  76. /* USER CODE END FSMC_MspInit 0 */
  77. GPIO_InitTypeDef GPIO_InitStruct;
  78. if (FSMC_Initialized) {
  79. return;
  80. }
  81. FSMC_Initialized = 1;
  82. /* Peripheral clock enable */
  83. __FSMC_CLK_ENABLE();
  84. /** FSMC GPIO Configuration
  85. PE7 ------> FSMC_DA4
  86. PE8 ------> FSMC_DA5
  87. PE9 ------> FSMC_DA6
  88. PE10 ------> FSMC_DA7
  89. PE11 ------> FSMC_DA8
  90. PE12 ------> FSMC_DA9
  91. PE13 ------> FSMC_DA10
  92. PE14 ------> FSMC_DA11
  93. PE15 ------> FSMC_DA12
  94. PD8 ------> FSMC_DA13
  95. PD9 ------> FSMC_DA14
  96. PD10 ------> FSMC_DA15
  97. PD14 ------> FSMC_DA0
  98. PD15 ------> FSMC_DA1
  99. PD0 ------> FSMC_DA2
  100. PD1 ------> FSMC_DA3
  101. PD4 ------> FSMC_NOE
  102. PD5 ------> FSMC_NWE
  103. PD7 ------> FSMC_NE1
  104. PB7 ------> FSMC_NL
  105. PE0 ------> FSMC_NBL0
  106. PE1 ------> FSMC_NBL1
  107. */
  108. /* GPIO_InitStruct */
  109. GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
  110. |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  111. |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
  112. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  113. GPIO_InitStruct.Pull = GPIO_NOPULL;
  114. GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
  115. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  116. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  117. /* GPIO_InitStruct */
  118. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
  119. |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
  120. |GPIO_PIN_5|GPIO_PIN_7;
  121. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  122. GPIO_InitStruct.Pull = GPIO_NOPULL;
  123. GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
  124. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  125. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  126. /* GPIO_InitStruct */
  127. GPIO_InitStruct.Pin = GPIO_PIN_7;
  128. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  129. GPIO_InitStruct.Pull = GPIO_NOPULL;
  130. GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
  131. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  132. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  133. /* USER CODE BEGIN FSMC_MspInit 1 */
  134. /* USER CODE END FSMC_MspInit 1 */
  135. }
  136. void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram){
  137. /* USER CODE BEGIN SRAM_MspInit 0 */
  138. /* USER CODE END SRAM_MspInit 0 */
  139. HAL_FSMC_MspInit();
  140. /* USER CODE BEGIN SRAM_MspInit 1 */
  141. /* USER CODE END SRAM_MspInit 1 */
  142. }
  143. static int FSMC_DeInitialized = 0;
  144. static void HAL_FSMC_MspDeInit(void){
  145. /* USER CODE BEGIN FSMC_MspDeInit 0 */
  146. /* USER CODE END FSMC_MspDeInit 0 */
  147. if (FSMC_DeInitialized) {
  148. return;
  149. }
  150. FSMC_DeInitialized = 1;
  151. /* Peripheral clock enable */
  152. __FSMC_CLK_DISABLE();
  153. /** FSMC GPIO Configuration
  154. PE7 ------> FSMC_DA4
  155. PE8 ------> FSMC_DA5
  156. PE9 ------> FSMC_DA6
  157. PE10 ------> FSMC_DA7
  158. PE11 ------> FSMC_DA8
  159. PE12 ------> FSMC_DA9
  160. PE13 ------> FSMC_DA10
  161. PE14 ------> FSMC_DA11
  162. PE15 ------> FSMC_DA12
  163. PD8 ------> FSMC_DA13
  164. PD9 ------> FSMC_DA14
  165. PD10 ------> FSMC_DA15
  166. PD14 ------> FSMC_DA0
  167. PD15 ------> FSMC_DA1
  168. PD0 ------> FSMC_DA2
  169. PD1 ------> FSMC_DA3
  170. PD4 ------> FSMC_NOE
  171. PD5 ------> FSMC_NWE
  172. PD7 ------> FSMC_NE1
  173. PB7 ------> FSMC_NL
  174. PE0 ------> FSMC_NBL0
  175. PE1 ------> FSMC_NBL1
  176. */
  177. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
  178. |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  179. |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
  180. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
  181. |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
  182. |GPIO_PIN_5|GPIO_PIN_7);
  183. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
  184. /* USER CODE BEGIN FSMC_MspDeInit 1 */
  185. /* USER CODE END FSMC_MspDeInit 1 */
  186. }
  187. void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram){
  188. /* USER CODE BEGIN SRAM_MspDeInit 0 */
  189. /* USER CODE END SRAM_MspDeInit 0 */
  190. HAL_FSMC_MspDeInit();
  191. /* USER CODE BEGIN SRAM_MspDeInit 1 */
  192. /* USER CODE END SRAM_MspDeInit 1 */
  193. }
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @}
  199. */
  200. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/