2 ******************************************************************************
4 * Description : This file provides code for the configuration
5 * of the FMC peripheral.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under Ultimate Liberty license
13 * SLA0044, the "License"; You may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at:
17 ******************************************************************************
20 /* Includes ------------------------------------------------------------------*/
23 /* USER CODE BEGIN 0 */
27 SRAM_HandleTypeDef hsram1;
29 /* FMC initialization function */
30 void MX_FMC_Init(void)
32 FMC_NORSRAM_TimingTypeDef Timing = {0};
34 /** Perform the SRAM1 memory initialization sequence
36 hsram1.Instance = FMC_NORSRAM_DEVICE;
37 hsram1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
39 hsram1.Init.NSBank = FMC_NORSRAM_BANK1;
40 hsram1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_ENABLE;
41 hsram1.Init.MemoryType = FMC_MEMORY_TYPE_PSRAM;
42 hsram1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
43 hsram1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
44 hsram1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
45 hsram1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
46 hsram1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
47 hsram1.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
48 hsram1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
49 hsram1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
50 hsram1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
51 hsram1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
52 hsram1.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
54 hsram1.Init.PageSize = FMC_PAGE_SIZE_NONE;
57 // 1 clock to read the address, + 1 for synchroniser skew
58 Timing.AddressSetupTime = 4;
59 Timing.AddressHoldTime = 2;
62 // 1 for synchroniser skew (dbx also delayed)
63 // 1 to skip hold time
68 // 1 to write back to fsmc bus.
69 Timing.DataSetupTime = 8;
71 // Allow a clock for us to release signals
72 // Need to avoid both devices acting as outputs
73 // on the multiplexed lines at the same time.
74 Timing.BusTurnAroundDuration = 2;
76 Timing.CLKDivision = 16; // Ignored for async
77 Timing.DataLatency = 17; // Ignored for async
78 Timing.AccessMode = FMC_ACCESS_MODE_A;
81 if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
88 static uint32_t FMC_Initialized = 0;
90 static void HAL_FMC_MspInit(void){
91 /* USER CODE BEGIN FMC_MspInit 0 */
93 /* USER CODE END FMC_MspInit 0 */
94 GPIO_InitTypeDef GPIO_InitStruct = {0};
95 if (FMC_Initialized) {
100 /* Peripheral clock enable */
101 __HAL_RCC_FMC_CLK_ENABLE();
103 /** FMC GPIO Configuration
110 PE13 ------> FMC_DA10
111 PE14 ------> FMC_DA11
112 PE15 ------> FMC_DA12
115 PD10 ------> FMC_DA15
128 // MM: GPIO_SPEED_FREQ_MEDIUM is rated up to 50MHz, which is fine as all the
129 // fsmc timings are > 1 (ie. so clock speed / 2 is around 50MHz).
131 /* GPIO_InitStruct */
132 GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
133 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
134 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
135 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
136 GPIO_InitStruct.Pull = GPIO_NOPULL;
137 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
138 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
140 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
142 /* GPIO_InitStruct */
143 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
144 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
145 |GPIO_PIN_5|GPIO_PIN_7;
146 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
147 GPIO_InitStruct.Pull = GPIO_NOPULL;
148 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
149 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
151 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
153 /* GPIO_InitStruct */
154 GPIO_InitStruct.Pin = GPIO_PIN_7;
155 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
156 GPIO_InitStruct.Pull = GPIO_NOPULL;
157 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
158 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
160 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
162 /* USER CODE BEGIN FMC_MspInit 1 */
164 /* USER CODE END FMC_MspInit 1 */
167 void HAL_SRAM_MspInit(SRAM_HandleTypeDef* sramHandle){
168 /* USER CODE BEGIN SRAM_MspInit 0 */
170 /* USER CODE END SRAM_MspInit 0 */
172 /* USER CODE BEGIN SRAM_MspInit 1 */
174 /* USER CODE END SRAM_MspInit 1 */
177 static uint32_t FMC_DeInitialized = 0;
179 static void HAL_FMC_MspDeInit(void){
180 /* USER CODE BEGIN FMC_MspDeInit 0 */
182 /* USER CODE END FMC_MspDeInit 0 */
183 if (FMC_DeInitialized) {
186 FMC_DeInitialized = 1;
187 /* Peripheral clock enable */
188 __HAL_RCC_FMC_CLK_DISABLE();
190 /** FMC GPIO Configuration
197 PE13 ------> FMC_DA10
198 PE14 ------> FMC_DA11
199 PE15 ------> FMC_DA12
202 PD10 ------> FMC_DA15
215 HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
216 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
217 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
219 HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
220 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
221 |GPIO_PIN_5|GPIO_PIN_7);
223 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
225 /* USER CODE BEGIN FMC_MspDeInit 1 */
227 /* USER CODE END FMC_MspDeInit 1 */
230 void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* sramHandle){
231 /* USER CODE BEGIN SRAM_MspDeInit 0 */
233 /* USER CODE END SRAM_MspDeInit 0 */
235 /* USER CODE BEGIN SRAM_MspDeInit 1 */
237 /* USER CODE END SRAM_MspDeInit 1 */
247 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/