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_ENABLE;
53 hsram1.Init.PageSize = FMC_PAGE_SIZE_NONE;
56 // 1 clock to read the address, + 1 for synchroniser skew
57 Timing.AddressSetupTime = 2;
58 Timing.AddressHoldTime = 1;
61 // 1 for synchroniser skew (dbx also delayed)
62 // 1 to skip hold time
67 // 1 to write back to fsmc bus.
68 Timing.DataSetupTime = 4;
70 // Allow a clock for us to release signals
71 // Need to avoid both devices acting as outputs
72 // on the multiplexed lines at the same time.
73 Timing.BusTurnAroundDuration = 1;
75 Timing.CLKDivision = 16; // Ignored for async
76 Timing.DataLatency = 17; // Ignored for async
77 Timing.AccessMode = FMC_ACCESS_MODE_A;
80 if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
87 static uint32_t FMC_Initialized = 0;
89 static void HAL_FMC_MspInit(void){
90 /* USER CODE BEGIN FMC_MspInit 0 */
92 /* USER CODE END FMC_MspInit 0 */
93 GPIO_InitTypeDef GPIO_InitStruct = {0};
94 if (FMC_Initialized) {
99 /* Peripheral clock enable */
100 __HAL_RCC_FMC_CLK_ENABLE();
102 /** FMC GPIO Configuration
109 PE13 ------> FMC_DA10
110 PE14 ------> FMC_DA11
111 PE15 ------> FMC_DA12
114 PD10 ------> FMC_DA15
127 // MM: GPIO_SPEED_FREQ_MEDIUM is rated up to 50MHz, which is fine as all the
128 // fsmc timings are > 1 (ie. so clock speed / 2 is around 50MHz).
130 /* GPIO_InitStruct */
131 GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
132 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
133 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
134 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
135 GPIO_InitStruct.Pull = GPIO_NOPULL;
136 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
137 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
139 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
141 /* GPIO_InitStruct */
142 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
143 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
144 |GPIO_PIN_5|GPIO_PIN_7;
145 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
146 GPIO_InitStruct.Pull = GPIO_NOPULL;
147 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
148 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
150 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
152 /* GPIO_InitStruct */
153 GPIO_InitStruct.Pin = GPIO_PIN_7;
154 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
155 GPIO_InitStruct.Pull = GPIO_NOPULL;
156 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
157 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
159 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
161 /* USER CODE BEGIN FMC_MspInit 1 */
163 /* USER CODE END FMC_MspInit 1 */
166 void HAL_SRAM_MspInit(SRAM_HandleTypeDef* sramHandle){
167 /* USER CODE BEGIN SRAM_MspInit 0 */
169 /* USER CODE END SRAM_MspInit 0 */
171 /* USER CODE BEGIN SRAM_MspInit 1 */
173 /* USER CODE END SRAM_MspInit 1 */
176 static uint32_t FMC_DeInitialized = 0;
178 static void HAL_FMC_MspDeInit(void){
179 /* USER CODE BEGIN FMC_MspDeInit 0 */
181 /* USER CODE END FMC_MspDeInit 0 */
182 if (FMC_DeInitialized) {
185 FMC_DeInitialized = 1;
186 /* Peripheral clock enable */
187 __HAL_RCC_FMC_CLK_DISABLE();
189 /** FMC GPIO Configuration
196 PE13 ------> FMC_DA10
197 PE14 ------> FMC_DA11
198 PE15 ------> FMC_DA12
201 PD10 ------> FMC_DA15
214 HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
215 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
216 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
218 HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
219 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
220 |GPIO_PIN_5|GPIO_PIN_7);
222 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
224 /* USER CODE BEGIN FMC_MspDeInit 1 */
226 /* USER CODE END FMC_MspDeInit 1 */
229 void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* sramHandle){
230 /* USER CODE BEGIN SRAM_MspDeInit 0 */
232 /* USER CODE END SRAM_MspDeInit 0 */
234 /* USER CODE BEGIN SRAM_MspDeInit 1 */
236 /* USER CODE END SRAM_MspDeInit 1 */
246 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/