/Projects/STM32H743I-EVAL/Examples/FMC/FMC_SRAM/Src/stm32h7xx_hal_msp.c

https://github.com/STMicroelectronics/STM32CubeH7 · C · 184 lines · 66 code · 37 blank · 81 comment · 0 complexity · 902422299160e5cf45e701ecbb0e5294 MD5 · raw file

  1. /**
  2. ******************************************************************************
  3. * @file FMC/FMC_SRAM/Src/stm32h7xx_hal_msp.c
  4. * @author MCD Application Team
  5. * @brief HAL MSP module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. /** @addtogroup STM32H7xx_HAL_Examples
  22. * @{
  23. */
  24. /** @defgroup FMC_SRAM
  25. * @{
  26. */
  27. /* Private typedef -----------------------------------------------------------*/
  28. /* Private define ------------------------------------------------------------*/
  29. /* Private macro -------------------------------------------------------------*/
  30. /* Private variables ---------------------------------------------------------*/
  31. /* Private function prototypes -----------------------------------------------*/
  32. /* Private functions ---------------------------------------------------------*/
  33. /** @defgroup HAL_MSP_Private_Functions
  34. * @{
  35. */
  36. /**
  37. * @brief SRAM MSP Initialization
  38. * This function configures the hardware resources used in this example:
  39. * - Peripheral's clock enable
  40. * - Peripheral's GPIO Configuration
  41. * @param hsram: SRAM handle pointer
  42. * @retval None
  43. */
  44. void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
  45. {
  46. static MDMA_HandleTypeDef mdma_handle;
  47. GPIO_InitTypeDef gpio_init_structure;
  48. /* Enable FMC clock */
  49. __HAL_RCC_FMC_CLK_ENABLE();
  50. /* Enable chosen DMAx clock */
  51. __HAL_RCC_MDMA_CLK_ENABLE();
  52. /* Enable GPIOs clock */
  53. __HAL_RCC_GPIOD_CLK_ENABLE();
  54. __HAL_RCC_GPIOE_CLK_ENABLE();
  55. __HAL_RCC_GPIOF_CLK_ENABLE();
  56. __HAL_RCC_GPIOG_CLK_ENABLE();
  57. /* Common GPIO configuration */
  58. gpio_init_structure.Mode = GPIO_MODE_AF_PP;
  59. gpio_init_structure.Pull = GPIO_PULLUP;
  60. gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  61. gpio_init_structure.Alternate = GPIO_AF12_FMC;
  62. /* GPIOD configuration */
  63. gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3| GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |\
  64. GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\
  65. GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  66. HAL_GPIO_Init(GPIOD, &gpio_init_structure);
  67. /* GPIOE configuration */
  68. gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3| GPIO_PIN_4 | GPIO_PIN_7 |\
  69. GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\
  70. GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  71. HAL_GPIO_Init(GPIOE, &gpio_init_structure);
  72. /* GPIOF configuration */
  73. gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
  74. GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  75. HAL_GPIO_Init(GPIOF, &gpio_init_structure);
  76. /* GPIOG configuration */
  77. gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |\
  78. GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14;
  79. HAL_GPIO_Init(GPIOG, &gpio_init_structure);
  80. /* GPIOH configuration */
  81. gpio_init_structure.Pin = /*GPIO_PIN_3 | GPIO_PIN_6 |*/ GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\
  82. GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  83. HAL_GPIO_Init(GPIOH, &gpio_init_structure);
  84. /* GPIOI configuration */
  85. gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 |
  86. GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
  87. GPIO_PIN_9 | GPIO_PIN_10;
  88. HAL_GPIO_Init(GPIOI, &gpio_init_structure);
  89. /* GPIOB configuration */
  90. gpio_init_structure.Pin = GPIO_PIN_7;
  91. HAL_GPIO_Init(GPIOB, &gpio_init_structure);
  92. /* Configure common MDMA parameters */
  93. mdma_handle.Init.Request = MDMA_REQUEST_SW;
  94. mdma_handle.Init.TransferTriggerMode = MDMA_BLOCK_TRANSFER;
  95. mdma_handle.Init.Priority = MDMA_PRIORITY_HIGH;
  96. mdma_handle.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE;
  97. mdma_handle.Init.SourceInc = MDMA_SRC_INC_WORD;
  98. mdma_handle.Init.DestinationInc = MDMA_DEST_INC_WORD;
  99. mdma_handle.Init.SourceDataSize = MDMA_SRC_DATASIZE_WORD;
  100. mdma_handle.Init.DestDataSize = MDMA_DEST_DATASIZE_WORD;
  101. mdma_handle.Init.DataAlignment = MDMA_DATAALIGN_PACKENABLE;
  102. mdma_handle.Init.SourceBurst = MDMA_SOURCE_BURST_SINGLE;
  103. mdma_handle.Init.DestBurst = MDMA_DEST_BURST_SINGLE;
  104. mdma_handle.Init.BufferTransferLength = 128;
  105. mdma_handle.Init.SourceBlockAddressOffset = 0;
  106. mdma_handle.Init.DestBlockAddressOffset = 0;
  107. mdma_handle.Instance = MDMA_Channel1;
  108. /* Associate the DMA handle */
  109. __HAL_LINKDMA(hsram, hmdma, mdma_handle);
  110. /* Deinitialize the Stream for new transfer */
  111. HAL_MDMA_DeInit(&mdma_handle);
  112. /* Configure the DMA Stream */
  113. HAL_MDMA_Init(&mdma_handle);
  114. /* NVIC configuration for DMA transfer complete interrupt */
  115. HAL_NVIC_SetPriority(MDMA_IRQn, 0x0F, 0);
  116. HAL_NVIC_EnableIRQ(MDMA_IRQn);
  117. }
  118. /**
  119. * @brief SRAM MSP De-Initialization
  120. * This function frees the hardware resources used in this example:
  121. * - Disable the Peripheral's clock
  122. * - Revert GPIO configuration to their default state
  123. * @param hsram: SRAM handle pointer
  124. * @retval None
  125. */
  126. void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
  127. {
  128. /*## Disable peripherals and GPIO Clocks ###################################*/
  129. static MDMA_HandleTypeDef mdma_handle;
  130. /* Disable NVIC configuration for DMA interrupt */
  131. HAL_NVIC_DisableIRQ(MDMA_IRQn);
  132. /* Deinitialize the stream for new transfer */
  133. mdma_handle.Instance = MDMA_Channel1;
  134. HAL_MDMA_DeInit(&mdma_handle);
  135. /* GPIO pins clock, FMC clock and DMA clock can be shut down in the applications
  136. by surcharging this __weak function */
  137. }
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @}
  143. */
  144. /**
  145. * @}
  146. */
  147. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/