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;
53 // WE MAY start writing another 512 bytes before this FIFO is empty!
55 hsram1.Init.PageSize = FMC_PAGE_SIZE_NONE;
58 // 1 clock to read the address, + 1 for synchroniser skew
59 Timing.AddressSetupTime = 5;
60 Timing.AddressHoldTime = 2;
63 // 1 for synchroniser skew (dbx also delayed)
64 // 1 to skip hold time
69 // 1 to write back to fsmc bus.
70 Timing.DataSetupTime = 9;
72 // Allow a clock for us to release signals
73 // Need to avoid both devices acting as outputs
74 // on the multiplexed lines at the same time.
75 Timing.BusTurnAroundDuration = 3;
77 Timing.CLKDivision = 16; // Ignored for async
78 Timing.DataLatency = 17; // Ignored for async
79 Timing.AccessMode = FMC_ACCESS_MODE_A;
82 if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
89 static uint32_t FMC_Initialized = 0;
91 static void HAL_FMC_MspInit(void){
92 /* USER CODE BEGIN FMC_MspInit 0 */
94 /* USER CODE END FMC_MspInit 0 */
95 GPIO_InitTypeDef GPIO_InitStruct = {0};
96 if (FMC_Initialized) {
101 /* Peripheral clock enable */
102 __HAL_RCC_FMC_CLK_ENABLE();
104 /** FMC GPIO Configuration
111 PE13 ------> FMC_DA10
112 PE14 ------> FMC_DA11
113 PE15 ------> FMC_DA12
116 PD10 ------> FMC_DA15
129 // MM: GPIO_SPEED_FREQ_MEDIUM is rated up to 50MHz, which is fine as all the
130 // fsmc timings are > 1 (ie. so clock speed / 2 is around 50MHz).
132 /* GPIO_InitStruct */
133 GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
134 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
135 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
136 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
137 GPIO_InitStruct.Pull = GPIO_NOPULL;
138 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
139 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
141 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
143 /* GPIO_InitStruct */
144 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
145 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
146 |GPIO_PIN_5|GPIO_PIN_7;
147 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
148 GPIO_InitStruct.Pull = GPIO_NOPULL;
149 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
150 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
152 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
154 /* GPIO_InitStruct */
155 GPIO_InitStruct.Pin = GPIO_PIN_7;
156 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
157 GPIO_InitStruct.Pull = GPIO_NOPULL;
158 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
159 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
161 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
163 /* USER CODE BEGIN FMC_MspInit 1 */
165 /* USER CODE END FMC_MspInit 1 */
168 void HAL_SRAM_MspInit(SRAM_HandleTypeDef* sramHandle){
169 /* USER CODE BEGIN SRAM_MspInit 0 */
171 /* USER CODE END SRAM_MspInit 0 */
173 /* USER CODE BEGIN SRAM_MspInit 1 */
175 /* USER CODE END SRAM_MspInit 1 */
178 static uint32_t FMC_DeInitialized = 0;
180 static void HAL_FMC_MspDeInit(void){
181 /* USER CODE BEGIN FMC_MspDeInit 0 */
183 /* USER CODE END FMC_MspDeInit 0 */
184 if (FMC_DeInitialized) {
187 FMC_DeInitialized = 1;
188 /* Peripheral clock enable */
189 __HAL_RCC_FMC_CLK_DISABLE();
191 /** FMC GPIO Configuration
198 PE13 ------> FMC_DA10
199 PE14 ------> FMC_DA11
200 PE15 ------> FMC_DA12
203 PD10 ------> FMC_DA15
216 HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
217 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
218 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
220 HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
221 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
222 |GPIO_PIN_5|GPIO_PIN_7);
224 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
226 /* USER CODE BEGIN FMC_MspDeInit 1 */
228 /* USER CODE END FMC_MspDeInit 1 */
231 void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* sramHandle){
232 /* USER CODE BEGIN SRAM_MspDeInit 0 */
234 /* USER CODE END SRAM_MspDeInit 0 */
236 /* USER CODE BEGIN SRAM_MspDeInit 1 */
238 /* USER CODE END SRAM_MspDeInit 1 */
248 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/