/Projects/STM32H747I-EVAL/Examples/QSPI/QSPI_MemoryMappedDual/CM7/Src/stm32h7xx_hal_msp.c

https://github.com/STMicroelectronics/STM32CubeH7 · C · 192 lines · 72 code · 33 blank · 87 comment · 0 complexity · c20f53812b53268b54cc4d3a03961f0e MD5 · raw file

  1. /**
  2. ******************************************************************************
  3. * @file QSPI/QSPI_MemoryMappedDual/CM7/Src/stm32h7xx_hal_msp.c
  4. * @author MCD Application Team
  5. * @brief HAL MSP module for Cortex-M7.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 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 QSPI_MemoryMappedDual
  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 QSPI MSP Initialization
  38. * This function configures the hardware resources used in this example:
  39. * - Peripheral's clock enable
  40. * - Peripheral's GPIO Configuration
  41. * - NVIC configuration for QSPI interrupt
  42. * @param hqspi: QSPI handle pointer
  43. * @retval None
  44. */
  45. void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi)
  46. {
  47. GPIO_InitTypeDef GPIO_InitStruct;
  48. /*##-1- Enable peripherals and GPIO Clocks #################################*/
  49. /* Enable the QuadSPI memory interface clock */
  50. QSPI_CLK_ENABLE();
  51. /* Reset the QuadSPI memory interface */
  52. QSPI_FORCE_RESET();
  53. QSPI_RELEASE_RESET();
  54. /* Enable GPIO clocks */
  55. QSPI_CS_GPIO_CLK_ENABLE();
  56. QSPI_CLK_GPIO_CLK_ENABLE();
  57. QSPI_BK1_D0_GPIO_CLK_ENABLE();
  58. QSPI_BK1_D1_GPIO_CLK_ENABLE();
  59. QSPI_BK1_D2_GPIO_CLK_ENABLE();
  60. QSPI_BK1_D3_GPIO_CLK_ENABLE();
  61. QSPI_BK2_D0_GPIO_CLK_ENABLE();
  62. QSPI_BK2_D1_GPIO_CLK_ENABLE();
  63. QSPI_BK2_D2_GPIO_CLK_ENABLE();
  64. QSPI_BK2_D3_GPIO_CLK_ENABLE();
  65. /* Enable DMA clock */
  66. QSPI_MDMA_CLK_ENABLE();
  67. /*##-2- Configure peripheral GPIO ##########################################*/
  68. /* QSPI CS GPIO pin configuration */
  69. GPIO_InitStruct.Pin = QSPI_CS_PIN;
  70. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  71. GPIO_InitStruct.Pull = GPIO_PULLUP;
  72. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  73. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  74. HAL_GPIO_Init(QSPI_CS_GPIO_PORT, &GPIO_InitStruct);
  75. /* QSPI CLK GPIO pin configuration */
  76. GPIO_InitStruct.Pin = QSPI_CLK_PIN;
  77. GPIO_InitStruct.Pull = GPIO_NOPULL;
  78. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  79. HAL_GPIO_Init(QSPI_CLK_GPIO_PORT, &GPIO_InitStruct);
  80. /* - Configure QSPI Bank1 */
  81. /* QSPI D0 GPIO pin configuration */
  82. GPIO_InitStruct.Pin = QSPI_BK1_D0_PIN;
  83. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  84. HAL_GPIO_Init(QSPI_BK1_D0_GPIO_PORT, &GPIO_InitStruct);
  85. /* QSPI D1 GPIO pin configuration */
  86. GPIO_InitStruct.Pin = QSPI_BK1_D1_PIN;
  87. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  88. HAL_GPIO_Init(QSPI_BK1_D1_GPIO_PORT, &GPIO_InitStruct);
  89. /* QSPI D2 GPIO pin configuration */
  90. GPIO_InitStruct.Pin = QSPI_BK1_D2_PIN;
  91. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  92. HAL_GPIO_Init(QSPI_BK1_D2_GPIO_PORT, &GPIO_InitStruct);
  93. /* QSPI D3 GPIO pin configuration */
  94. GPIO_InitStruct.Pin = QSPI_BK1_D3_PIN;
  95. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  96. HAL_GPIO_Init(QSPI_BK1_D3_GPIO_PORT, &GPIO_InitStruct);
  97. /* - Configure QSPI Bank2 */
  98. /* QSPI D0 GPIO pin configuration */
  99. GPIO_InitStruct.Pin = QSPI_BK2_D0_PIN;
  100. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  101. HAL_GPIO_Init(QSPI_BK2_D0_GPIO_PORT, &GPIO_InitStruct);
  102. /* QSPI D1 GPIO pin configuration */
  103. GPIO_InitStruct.Pin = QSPI_BK2_D1_PIN;
  104. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  105. HAL_GPIO_Init(QSPI_BK2_D1_GPIO_PORT, &GPIO_InitStruct);
  106. /* QSPI D2 GPIO pin configuration */
  107. GPIO_InitStruct.Pin = QSPI_BK2_D2_PIN;
  108. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  109. HAL_GPIO_Init(QSPI_BK2_D2_GPIO_PORT, &GPIO_InitStruct);
  110. /* QSPI D3 GPIO pin configuration */
  111. GPIO_InitStruct.Pin = QSPI_BK2_D3_PIN;
  112. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  113. HAL_GPIO_Init(QSPI_BK2_D3_GPIO_PORT, &GPIO_InitStruct);
  114. /*##-3- Configure the NVIC for QSPI #########################################*/
  115. /* NVIC configuration for QSPI interrupt */
  116. HAL_NVIC_SetPriority(QUADSPI_IRQn, 0x0F, 0);
  117. HAL_NVIC_EnableIRQ(QUADSPI_IRQn);
  118. }
  119. /**
  120. * @brief QSPI MSP De-Initialization
  121. * This function frees the hardware resources used in this example:
  122. * - Disable the Peripheral's clock
  123. * - Revert GPIO and NVIC configuration to their default state
  124. * @param hqspi: QSPI handle pointer
  125. * @retval None
  126. */
  127. void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi)
  128. {
  129. /*##-1- Disable the NVIC for QSPI ###########################################*/
  130. HAL_NVIC_DisableIRQ(QUADSPI_IRQn);
  131. /*##-1- Disable peripherals ################################################*/
  132. /* De-Configure QSPI pins */
  133. HAL_GPIO_DeInit(QSPI_CS_GPIO_PORT, QSPI_CS_PIN);
  134. HAL_GPIO_DeInit(QSPI_CLK_GPIO_PORT, QSPI_CLK_PIN);
  135. HAL_GPIO_DeInit(QSPI_BK1_D0_GPIO_PORT, QSPI_BK1_D0_PIN);
  136. HAL_GPIO_DeInit(QSPI_BK1_D1_GPIO_PORT, QSPI_BK1_D1_PIN);
  137. HAL_GPIO_DeInit(QSPI_BK1_D2_GPIO_PORT, QSPI_BK1_D2_PIN);
  138. HAL_GPIO_DeInit(QSPI_BK1_D3_GPIO_PORT, QSPI_BK1_D3_PIN);
  139. HAL_GPIO_DeInit(QSPI_BK2_D0_GPIO_PORT, QSPI_BK2_D0_PIN);
  140. HAL_GPIO_DeInit(QSPI_BK2_D1_GPIO_PORT, QSPI_BK2_D1_PIN);
  141. HAL_GPIO_DeInit(QSPI_BK2_D2_GPIO_PORT, QSPI_BK2_D2_PIN);
  142. HAL_GPIO_DeInit(QSPI_BK2_D3_GPIO_PORT, QSPI_BK2_D3_PIN);
  143. /*##-3- Reset peripherals ##################################################*/
  144. /* Reset the QuadSPI memory interface */
  145. QSPI_FORCE_RESET();
  146. QSPI_RELEASE_RESET();
  147. /* Disable the QuadSPI memory interface clock */
  148. QSPI_CLK_DISABLE();
  149. }
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. /**
  157. * @}
  158. */
  159. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/