stm32f0xx_hal_msp.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**
  2. ******************************************************************************
  3. * File Name : stm32f0xx_hal_msp.c
  4. * Description : This file provides code for the MSP Initialization
  5. * and de-Initialization codes.
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2016 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx_hal.h"
  36. extern DMA_HandleTypeDef hdma_adc;
  37. extern void Error_Handler(void);
  38. /* USER CODE BEGIN 0 */
  39. /* USER CODE END 0 */
  40. /**
  41. * Initializes the Global MSP.
  42. */
  43. void HAL_MspInit(void)
  44. {
  45. /* USER CODE BEGIN MspInit 0 */
  46. /* USER CODE END MspInit 0 */
  47. __HAL_RCC_SYSCFG_CLK_ENABLE();
  48. /* System interrupt init*/
  49. /* SVC_IRQn interrupt configuration */
  50. HAL_NVIC_SetPriority(SVC_IRQn, 0, 0);
  51. /* PendSV_IRQn interrupt configuration */
  52. HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
  53. /* SysTick_IRQn interrupt configuration */
  54. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  55. /* USER CODE BEGIN MspInit 1 */
  56. /* USER CODE END MspInit 1 */
  57. }
  58. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  59. {
  60. GPIO_InitTypeDef GPIO_InitStruct;
  61. if(hadc->Instance==ADC1)
  62. {
  63. /* USER CODE BEGIN ADC1_MspInit 0 */
  64. /* USER CODE END ADC1_MspInit 0 */
  65. /* Peripheral clock enable */
  66. __HAL_RCC_ADC1_CLK_ENABLE();
  67. /**ADC GPIO Configuration
  68. PA5 ------> ADC_IN5
  69. */
  70. GPIO_InitStruct.Pin = SPEED_Pin;
  71. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  72. GPIO_InitStruct.Pull = GPIO_NOPULL;
  73. HAL_GPIO_Init(SPEED_GPIO_Port, &GPIO_InitStruct);
  74. /* Peripheral DMA init*/
  75. hdma_adc.Instance = DMA1_Channel1;
  76. hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY;
  77. hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE;
  78. hdma_adc.Init.MemInc = DMA_MINC_DISABLE;
  79. hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
  80. hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
  81. hdma_adc.Init.Mode = DMA_CIRCULAR;
  82. hdma_adc.Init.Priority = DMA_PRIORITY_LOW;
  83. if (HAL_DMA_Init(&hdma_adc) != HAL_OK)
  84. {
  85. Error_Handler();
  86. }
  87. __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc);
  88. /* USER CODE BEGIN ADC1_MspInit 1 */
  89. /* USER CODE END ADC1_MspInit 1 */
  90. }
  91. }
  92. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  93. {
  94. if(hadc->Instance==ADC1)
  95. {
  96. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  97. /* USER CODE END ADC1_MspDeInit 0 */
  98. /* Peripheral clock disable */
  99. __HAL_RCC_ADC1_CLK_DISABLE();
  100. /**ADC GPIO Configuration
  101. PA5 ------> ADC_IN5
  102. */
  103. HAL_GPIO_DeInit(SPEED_GPIO_Port, SPEED_Pin);
  104. /* Peripheral DMA DeInit*/
  105. HAL_DMA_DeInit(hadc->DMA_Handle);
  106. }
  107. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  108. /* USER CODE END ADC1_MspDeInit 1 */
  109. }
  110. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  111. {
  112. GPIO_InitTypeDef GPIO_InitStruct;
  113. if(huart->Instance==USART1)
  114. {
  115. /* USER CODE BEGIN USART1_MspInit 0 */
  116. /* USER CODE END USART1_MspInit 0 */
  117. /* Peripheral clock enable */
  118. __HAL_RCC_USART1_CLK_ENABLE();
  119. /**USART1 GPIO Configuration
  120. PA9 ------> USART1_TX
  121. PA10 ------> USART1_RX
  122. */
  123. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
  124. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  125. GPIO_InitStruct.Pull = GPIO_PULLUP;
  126. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  127. GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
  128. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  129. /* USER CODE BEGIN USART1_MspInit 1 */
  130. /* USER CODE END USART1_MspInit 1 */
  131. }
  132. }
  133. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  134. {
  135. if(huart->Instance==USART1)
  136. {
  137. /* USER CODE BEGIN USART1_MspDeInit 0 */
  138. /* USER CODE END USART1_MspDeInit 0 */
  139. /* Peripheral clock disable */
  140. __HAL_RCC_USART1_CLK_DISABLE();
  141. /**USART1 GPIO Configuration
  142. PA9 ------> USART1_TX
  143. PA10 ------> USART1_RX
  144. */
  145. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  146. }
  147. /* USER CODE BEGIN USART1_MspDeInit 1 */
  148. /* USER CODE END USART1_MspDeInit 1 */
  149. }
  150. /* USER CODE BEGIN 1 */
  151. /* USER CODE END 1 */
  152. /**
  153. * @}
  154. */
  155. /**
  156. * @}
  157. */
  158. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/