/** ****************************************************************************** * File Name : FSMC.c * Description : This file provides code for the configuration * of the FSMC peripheral. ****************************************************************************** * * COPYRIGHT(c) 2016 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "fsmc.h" #include "gpio.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ SRAM_HandleTypeDef hsram1; /* FSMC initialization function */ void MX_FSMC_Init(void) { FSMC_NORSRAM_TimingTypeDef Timing; /** Perform the SRAM1 memory initialization sequence */ hsram1.Instance = FSMC_NORSRAM_DEVICE; hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE; /* hsram1.Init */ hsram1.Init.NSBank = FSMC_NORSRAM_BANK1; hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_ENABLE; hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_PSRAM; hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16; hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE; hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW; hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE; hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS; hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE; hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE; hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE; hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE; hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE; /* Timing */ // 1 clock to read the address, + 1 for synchroniser skew Timing.AddressSetupTime = 2; Timing.AddressHoldTime = 1; // Writes to device: // 1 for synchroniser skew (dbx also delayed) // 1 to skip hold time // 1 to write data. // Reads from device: // 3 for syncroniser // 1 to write back to fsmc bus. Timing.DataSetupTime = 4; // Allow a clock for us to release signals // Need to avoid both devices acting as outputs // on the multiplexed lines at the same time. Timing.BusTurnAroundDuration = 1; Timing.CLKDivision = 16; // Ignored for async Timing.DataLatency = 17; // Ignored for async Timing.AccessMode = FSMC_ACCESS_MODE_A; /* ExtTiming */ HAL_SRAM_Init(&hsram1, &Timing, NULL); } static int FSMC_Initialized = 0; static void HAL_FSMC_MspInit(void){ /* USER CODE BEGIN FSMC_MspInit 0 */ /* USER CODE END FSMC_MspInit 0 */ GPIO_InitTypeDef GPIO_InitStruct; if (FSMC_Initialized) { return; } FSMC_Initialized = 1; /* Peripheral clock enable */ __FSMC_CLK_ENABLE(); /** FSMC GPIO Configuration PE7 ------> FSMC_DA4 PE8 ------> FSMC_DA5 PE9 ------> FSMC_DA6 PE10 ------> FSMC_DA7 PE11 ------> FSMC_DA8 PE12 ------> FSMC_DA9 PE13 ------> FSMC_DA10 PE14 ------> FSMC_DA11 PE15 ------> FSMC_DA12 PD14 ------> FSMC_DA0 PD15 ------> FSMC_DA1 PD0 ------> FSMC_DA2 PD1 ------> FSMC_DA3 PD4 ------> FSMC_NOE PD5 ------> FSMC_NWE PD7 ------> FSMC_NE1 PD8 ------> FSMC_DA13 PD9 ------> FSMC_DA14 PD10 ------> FSMC_DA15 PB7 ------> FSMC_NL PE0 ------> FSMC_NBL0 PE1 ------> FSMC_NBL1 */ // MM: GPIO_SPEED_FREQ_MEDIUM is rated up to 50MHz, which is fine as all the // fsmc timings are > 1 (ie. so clock speed / 2 is around 50MHz). /* GPIO_InitStruct */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; //HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_FSMC; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /* GPIO_InitStruct */ GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; //HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_FSMC; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* GPIO_InitStruct */ GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;//HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_FSMC; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN FSMC_MspInit 1 */ /* USER CODE END FSMC_MspInit 1 */ } void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram){ /* USER CODE BEGIN SRAM_MspInit 0 */ /* USER CODE END SRAM_MspInit 0 */ HAL_FSMC_MspInit(); /* USER CODE BEGIN SRAM_MspInit 1 */ /* USER CODE END SRAM_MspInit 1 */ } static int FSMC_DeInitialized = 0; static void HAL_FSMC_MspDeInit(void){ /* USER CODE BEGIN FSMC_MspDeInit 0 */ /* USER CODE END FSMC_MspDeInit 0 */ if (FSMC_DeInitialized) { return; } FSMC_DeInitialized = 1; /* Peripheral clock enable */ __FSMC_CLK_DISABLE(); /** FSMC GPIO Configuration PE7 ------> FSMC_DA4 PE8 ------> FSMC_DA5 PE9 ------> FSMC_DA6 PE10 ------> FSMC_DA7 PE11 ------> FSMC_DA8 PE12 ------> FSMC_DA9 PE13 ------> FSMC_DA10 PE14 ------> FSMC_DA11 PE15 ------> FSMC_DA12 PD14 ------> FSMC_DA0 PD15 ------> FSMC_DA1 PD0 ------> FSMC_DA2 PD1 ------> FSMC_DA3 PD4 ------> FSMC_NOE PD5 ------> FSMC_NWE PD7 ------> FSMC_NE1 PD8 ------> FSMC_DA13 PD9 ------> FSMC_DA14 PD10 ------> FSMC_DA15 PB7 ------> FSMC_NL PE0 ------> FSMC_NBL0 PE1 ------> FSMC_NBL1 */ HAL_GPIO_DeInit(GPIOE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15); HAL_GPIO_DeInit(GPIOD, GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10); HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7); /* USER CODE BEGIN FSMC_MspDeInit 1 */ /* USER CODE END FSMC_MspDeInit 1 */ } void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram){ /* USER CODE BEGIN SRAM_MspDeInit 0 */ /* USER CODE END SRAM_MspDeInit 0 */ HAL_FSMC_MspDeInit(); /* USER CODE BEGIN SRAM_MspDeInit 1 */ /* USER CODE END SRAM_MspDeInit 1 */ } /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/