38
+ − 1 /**
+ − 2 ******************************************************************************
+ − 3 * @file UART/UART_Printf/Src/stm32f4xx_hal_msp.c
+ − 4 * @author MCD Application Team
+ − 5 * @version V1.1.0
+ − 6 * @date 26-June-2014
+ − 7 * @brief HAL MSP module.
+ − 8 ******************************************************************************
+ − 9 * @attention
+ − 10 *
+ − 11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ − 12 *
+ − 13 * Redistribution and use in source and binary forms, with or without modification,
+ − 14 * are permitted provided that the following conditions are met:
+ − 15 * 1. Redistributions of source code must retain the above copyright notice,
+ − 16 * this list of conditions and the following disclaimer.
+ − 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
+ − 18 * this list of conditions and the following disclaimer in the documentation
+ − 19 * and/or other materials provided with the distribution.
+ − 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ − 21 * may be used to endorse or promote products derived from this software
+ − 22 * without specific prior written permission.
+ − 23 *
+ − 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ − 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ − 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ − 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ − 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ − 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ − 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ − 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ − 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ − 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ − 34 *
+ − 35 ******************************************************************************
+ − 36 */
+ − 37
+ − 38 /* Includes ------------------------------------------------------------------*/
+ − 39 #include "baseCPU2.h"
+ − 40
+ − 41 #include "stm32f4xx_hal.h"
+ − 42
+ − 43 /** @addtogroup STM32F4xx_HAL_Examples
+ − 44 * @{
+ − 45 */
+ − 46
+ − 47 /** @defgroup HAL_MSP
+ − 48 * @brief HAL MSP module.
+ − 49 * @{
+ − 50 */
+ − 51
+ − 52 /* Private typedef -----------------------------------------------------------*/
+ − 53 /* Private define ------------------------------------------------------------*/
+ − 54 /* Private macro -------------------------------------------------------------*/
+ − 55 /* Private variables ---------------------------------------------------------*/
+ − 56 /* Private function prototypes -----------------------------------------------*/
+ − 57 /* Private functions ---------------------------------------------------------*/
+ − 58
+ − 59 /** @defgroup HAL_MSP_Private_Functions
+ − 60 * @{
+ − 61 */
+ − 62
+ − 63 void HAL_I2C_ManualControl_MspInit(void)
+ − 64 {
+ − 65 GPIO_InitTypeDef GPIO_InitStruct;
+ − 66
+ − 67 /*##-1- Enable peripherals and GPIO Clocks #################################*/
+ − 68 /* Enable GPIO TX/RX clock */
+ − 69 I2Cx_SCL_GPIO_CLK_ENABLE();
+ − 70 I2Cx_SDA_GPIO_CLK_ENABLE();
+ − 71
+ − 72 /*##-2- Configure peripheral GPIO ##########################################*/
+ − 73 /* I2C CLOCK GPIO pin configuration */
+ − 74 GPIO_InitStruct.Pin = I2Cx_SCL_PIN;
+ − 75 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
+ − 76 GPIO_InitStruct.Pull = GPIO_PULLUP;
+ − 77 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
+ − 78
+ − 79 HAL_GPIO_Init(I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct);
+ − 80
+ − 81 /* I2C DATA GPIO pin configuration */
+ − 82 GPIO_InitStruct.Pin = I2Cx_SDA_PIN;
+ − 83 GPIO_InitStruct.Alternate = GPIO_MODE_INPUT;
+ − 84
+ − 85 HAL_GPIO_Init(I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct);
+ − 86 }
+ − 87
+ − 88 /**
+ − 89 * @brief I2C MSP Initialization
+ − 90 * This function configures the hardware resources used in this example:
+ − 91 * - Peripheral's clock enable
+ − 92 * - Peripheral's GPIO Configuration
+ − 93 * - DMA configuration for transmission request by peripheral
+ − 94 * - NVIC configuration for DMA interrupt request enable
+ − 95 * @param hi2c: I2C handle pointer
+ − 96 * @retval None
+ − 97 */
+ − 98 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
+ − 99 {
+ − 100 GPIO_InitTypeDef GPIO_InitStruct;
+ − 101
+ − 102 /*##-1- Enable peripherals and GPIO Clocks #################################*/
+ − 103 /* Enable GPIO TX/RX clock */
+ − 104 I2Cx_SCL_GPIO_CLK_ENABLE();
+ − 105 I2Cx_SDA_GPIO_CLK_ENABLE();
+ − 106 /* Enable I2C1 clock */
+ − 107 I2Cx_CLK_ENABLE();
+ − 108
+ − 109 /*##-2- Configure peripheral GPIO ##########################################*/
+ − 110 /* I2C TX GPIO pin configuration */
+ − 111 GPIO_InitStruct.Pin = I2Cx_SCL_PIN;
+ − 112 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
+ − 113 GPIO_InitStruct.Pull = GPIO_PULLUP;
+ − 114 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
+ − 115 GPIO_InitStruct.Alternate = I2Cx_SCL_AF;
+ − 116
+ − 117 HAL_GPIO_Init(I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct);
+ − 118
+ − 119 /* I2C RX GPIO pin configuration */
+ − 120 GPIO_InitStruct.Pin = I2Cx_SDA_PIN;
+ − 121 GPIO_InitStruct.Alternate = I2Cx_SDA_AF;
+ − 122
+ − 123 HAL_GPIO_Init(I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct);
+ − 124
+ − 125 /*##-3- Configure the NVIC for I2C #########################################*/
+ − 126 /* NVIC for I2C1 */
+ − 127 HAL_NVIC_SetPriority(I2Cx_ER_IRQn, 1, 2);
+ − 128 HAL_NVIC_EnableIRQ(I2Cx_ER_IRQn);
+ − 129 HAL_NVIC_SetPriority(I2Cx_EV_IRQn, 1, 3);
+ − 130 HAL_NVIC_EnableIRQ(I2Cx_EV_IRQn);
+ − 131 }
+ − 132
+ − 133 /**
+ − 134 * @brief I2C MSP De-Initialization
+ − 135 * This function frees the hardware resources used in this example:
+ − 136 * - Disable the Peripheral's clock
+ − 137 * - Revert GPIO, DMA and NVIC configuration to their default state
+ − 138 * @param hi2c: I2C handle pointer
+ − 139 * @retval None
+ − 140 */
+ − 141 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c)
+ − 142 {
+ − 143 /*##-1- Reset peripherals ##################################################*/
+ − 144 I2Cx_FORCE_RESET();
+ − 145 I2Cx_RELEASE_RESET();
+ − 146
+ − 147 /*##-2- Disable peripherals and GPIO Clocks ################################*/
+ − 148 /* Configure I2C Tx as alternate function */
+ − 149 HAL_GPIO_DeInit(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_PIN);
+ − 150 /* Configure I2C Rx as alternate function */
+ − 151 HAL_GPIO_DeInit(I2Cx_SDA_GPIO_PORT, I2Cx_SDA_PIN);
+ − 152
+ − 153 /*##-3- Disable the NVIC for I2C ###########################################*/
+ − 154 HAL_NVIC_DisableIRQ(I2Cx_ER_IRQn);
+ − 155 HAL_NVIC_DisableIRQ(I2Cx_EV_IRQn);
+ − 156 }
+ − 157
+ − 158
+ − 159 /**
+ − 160 * @brief RTC MSP Initialization
+ − 161 * This function configures the hardware resources used in this example
+ − 162 * @param hrtc: RTC handle pointer
+ − 163 *
+ − 164 * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
+ − 165 * the RTC clock source; in this case the Backup domain will be reset in
+ − 166 * order to modify the RTC Clock source, as consequence RTC registers (including
+ − 167 * the backup registers) and RCC_BDCR register are set to their reset values.
+ − 168 *
+ − 169 * @retval None
+ − 170 */
+ − 171 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
+ − 172 {
+ − 173
+ − 174 if(hrtc->Instance==RTC)
+ − 175 {
+ − 176 /* USER CODE BEGIN RTC_MspInit 0 */
+ − 177 RCC_OscInitTypeDef RCC_OscInitStruct;
+ − 178 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
+ − 179
+ − 180 /*##-1- Configue LSI as RTC clock soucre ###################################*/
+ − 181 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
+ − 182 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ − 183 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
+ − 184 HAL_RCC_OscConfig(&RCC_OscInitStruct);
+ − 185
+ − 186 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
+ − 187 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
+ − 188 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
+ − 189
+ − 190 /* USER CODE END RTC_MspInit 0 */
+ − 191 /* Peripheral clock enable */
+ − 192 __HAL_RCC_RTC_ENABLE();
+ − 193 /* USER CODE BEGIN RTC_MspInit 1 */
+ − 194
+ − 195 /*##-3- Configure the NVIC for RTC WakeUp Timer ############################*/
+ − 196 HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x0F, 0);
+ − 197 HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
+ − 198
+ − 199 /* USER CODE END RTC_MspInit 1 */
+ − 200 }
+ − 201
+ − 202 }
+ − 203
+ − 204
+ − 205 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
+ − 206 {
+ − 207
+ − 208 if(hrtc->Instance==RTC)
+ − 209 {
+ − 210 /* USER CODE BEGIN RTC_MspDeInit 0 */
+ − 211
+ − 212 /* USER CODE END RTC_MspDeInit 0 */
+ − 213 /* Peripheral clock disable */
+ − 214 __HAL_RCC_RTC_DISABLE();
+ − 215 /* USER CODE BEGIN RTC_MspDeInit 1 */
+ − 216
+ − 217 /* USER CODE END RTC_MspDeInit 1 */
+ − 218 }
+ − 219
+ − 220 }
+ − 221
+ − 222
+ − 223
+ − 224 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
+ − 225 {
+ − 226
+ − 227 GPIO_InitTypeDef GPIO_InitStruct;
+ − 228 if(huart->Instance==USART2)
+ − 229 {
+ − 230 __USART2_CLK_ENABLE();
+ − 231 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
+ − 232 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ − 233 GPIO_InitStruct.Pull = GPIO_PULLUP;
+ − 234 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
+ − 235 GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
+ − 236 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ − 237 }
+ − 238 }
+ − 239
+ − 240
+ − 241 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
+ − 242 {
+ − 243 if(huart->Instance==USART2)
+ − 244 {
+ − 245 __USART2_CLK_DISABLE();
+ − 246 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
+ − 247 }
+ − 248 }
+ − 249
+ − 250
+ − 251
+ − 252 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/