674 lines
16 KiB
C
674 lines
16 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file stm32g4xx_hal_msp.c
|
|
* @brief This file provides code for the MSP Initialization
|
|
* and de-Initialization codes.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2025 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "main.h"
|
|
/* USER CODE BEGIN Includes */
|
|
|
|
/* USER CODE END Includes */
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* USER CODE BEGIN TD */
|
|
|
|
/* USER CODE END TD */
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* USER CODE BEGIN Define */
|
|
|
|
/* USER CODE END Define */
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* USER CODE BEGIN Macro */
|
|
|
|
/* USER CODE END Macro */
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN PV */
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* External functions --------------------------------------------------------*/
|
|
/* USER CODE BEGIN ExternalFunctions */
|
|
|
|
/* USER CODE END ExternalFunctions */
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
void HAL_HRTIM_MspPostInit(HRTIM_HandleTypeDef *hhrtim);
|
|
/**
|
|
* Initializes the Global MSP.
|
|
*/
|
|
void HAL_MspInit(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN MspInit 0 */
|
|
|
|
/* USER CODE END MspInit 0 */
|
|
|
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
/* System interrupt init*/
|
|
|
|
/** Configure the internal voltage reference buffer high impedance mode
|
|
*/
|
|
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE);
|
|
|
|
/** Disable the Internal Voltage Reference buffer
|
|
*/
|
|
HAL_SYSCFG_DisableVREFBUF();
|
|
|
|
/** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
|
|
*/
|
|
HAL_PWREx_DisableUCPDDeadBattery();
|
|
|
|
/* USER CODE BEGIN MspInit 1 */
|
|
|
|
/* USER CODE END MspInit 1 */
|
|
}
|
|
|
|
static uint32_t HAL_RCC_ADC345_CLK_ENABLED=0;
|
|
|
|
/**
|
|
* @brief ADC MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hadc: ADC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
if(hadc->Instance==ADC3)
|
|
{
|
|
/* USER CODE BEGIN ADC3_MspInit 0 */
|
|
|
|
/* USER CODE END ADC3_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clocks
|
|
*/
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC345;
|
|
PeriphClkInit.Adc345ClockSelection = RCC_ADC345CLKSOURCE_SYSCLK;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
HAL_RCC_ADC345_CLK_ENABLED++;
|
|
if(HAL_RCC_ADC345_CLK_ENABLED==1){
|
|
__HAL_RCC_ADC345_CLK_ENABLE();
|
|
}
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**ADC3 GPIO Configuration
|
|
PB13 ------> ADC3_IN5
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN ADC3_MspInit 1 */
|
|
|
|
/* USER CODE END ADC3_MspInit 1 */
|
|
}
|
|
else if(hadc->Instance==ADC4)
|
|
{
|
|
/* USER CODE BEGIN ADC4_MspInit 0 */
|
|
|
|
/* USER CODE END ADC4_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clocks
|
|
*/
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC345;
|
|
PeriphClkInit.Adc345ClockSelection = RCC_ADC345CLKSOURCE_SYSCLK;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
HAL_RCC_ADC345_CLK_ENABLED++;
|
|
if(HAL_RCC_ADC345_CLK_ENABLED==1){
|
|
__HAL_RCC_ADC345_CLK_ENABLE();
|
|
}
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**ADC4 GPIO Configuration
|
|
PB14 ------> ADC4_IN4
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_14;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN ADC4_MspInit 1 */
|
|
|
|
/* USER CODE END ADC4_MspInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief ADC MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hadc: ADC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
|
|
{
|
|
if(hadc->Instance==ADC3)
|
|
{
|
|
/* USER CODE BEGIN ADC3_MspDeInit 0 */
|
|
|
|
/* USER CODE END ADC3_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
HAL_RCC_ADC345_CLK_ENABLED--;
|
|
if(HAL_RCC_ADC345_CLK_ENABLED==0){
|
|
__HAL_RCC_ADC345_CLK_DISABLE();
|
|
}
|
|
|
|
/**ADC3 GPIO Configuration
|
|
PB13 ------> ADC3_IN5
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
|
|
|
|
/* USER CODE BEGIN ADC3_MspDeInit 1 */
|
|
|
|
/* USER CODE END ADC3_MspDeInit 1 */
|
|
}
|
|
else if(hadc->Instance==ADC4)
|
|
{
|
|
/* USER CODE BEGIN ADC4_MspDeInit 0 */
|
|
|
|
/* USER CODE END ADC4_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
HAL_RCC_ADC345_CLK_ENABLED--;
|
|
if(HAL_RCC_ADC345_CLK_ENABLED==0){
|
|
__HAL_RCC_ADC345_CLK_DISABLE();
|
|
}
|
|
|
|
/**ADC4 GPIO Configuration
|
|
PB14 ------> ADC4_IN4
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14);
|
|
|
|
/* USER CODE BEGIN ADC4_MspDeInit 1 */
|
|
|
|
/* USER CODE END ADC4_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief COMP MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hcomp: COMP handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
if(hcomp->Instance==COMP5)
|
|
{
|
|
/* USER CODE BEGIN COMP5_MspInit 0 */
|
|
|
|
/* USER CODE END COMP5_MspInit 0 */
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**COMP5 GPIO Configuration
|
|
PB13 ------> COMP5_INP
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN COMP5_MspInit 1 */
|
|
|
|
/* USER CODE END COMP5_MspInit 1 */
|
|
}
|
|
else if(hcomp->Instance==COMP7)
|
|
{
|
|
/* USER CODE BEGIN COMP7_MspInit 0 */
|
|
|
|
/* USER CODE END COMP7_MspInit 0 */
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**COMP7 GPIO Configuration
|
|
PB14 ------> COMP7_INP
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_14;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN COMP7_MspInit 1 */
|
|
|
|
/* USER CODE END COMP7_MspInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief COMP MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hcomp: COMP handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
|
|
{
|
|
if(hcomp->Instance==COMP5)
|
|
{
|
|
/* USER CODE BEGIN COMP5_MspDeInit 0 */
|
|
|
|
/* USER CODE END COMP5_MspDeInit 0 */
|
|
|
|
/**COMP5 GPIO Configuration
|
|
PB13 ------> COMP5_INP
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
|
|
|
|
/* USER CODE BEGIN COMP5_MspDeInit 1 */
|
|
|
|
/* USER CODE END COMP5_MspDeInit 1 */
|
|
}
|
|
else if(hcomp->Instance==COMP7)
|
|
{
|
|
/* USER CODE BEGIN COMP7_MspDeInit 0 */
|
|
|
|
/* USER CODE END COMP7_MspDeInit 0 */
|
|
|
|
/**COMP7 GPIO Configuration
|
|
PB14 ------> COMP7_INP
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14);
|
|
|
|
/* USER CODE BEGIN COMP7_MspDeInit 1 */
|
|
|
|
/* USER CODE END COMP7_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief CORDIC MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hcordic: CORDIC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef* hcordic)
|
|
{
|
|
if(hcordic->Instance==CORDIC)
|
|
{
|
|
/* USER CODE BEGIN CORDIC_MspInit 0 */
|
|
|
|
/* USER CODE END CORDIC_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_CORDIC_CLK_ENABLE();
|
|
/* USER CODE BEGIN CORDIC_MspInit 1 */
|
|
|
|
/* USER CODE END CORDIC_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief CORDIC MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hcordic: CORDIC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef* hcordic)
|
|
{
|
|
if(hcordic->Instance==CORDIC)
|
|
{
|
|
/* USER CODE BEGIN CORDIC_MspDeInit 0 */
|
|
|
|
/* USER CODE END CORDIC_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_CORDIC_CLK_DISABLE();
|
|
/* USER CODE BEGIN CORDIC_MspDeInit 1 */
|
|
|
|
/* USER CODE END CORDIC_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief DAC MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hdac: DAC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
|
|
{
|
|
if(hdac->Instance==DAC1)
|
|
{
|
|
/* USER CODE BEGIN DAC1_MspInit 0 */
|
|
|
|
/* USER CODE END DAC1_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_DAC1_CLK_ENABLE();
|
|
/* USER CODE BEGIN DAC1_MspInit 1 */
|
|
|
|
/* USER CODE END DAC1_MspInit 1 */
|
|
}
|
|
else if(hdac->Instance==DAC4)
|
|
{
|
|
/* USER CODE BEGIN DAC4_MspInit 0 */
|
|
|
|
/* USER CODE END DAC4_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_DAC4_CLK_ENABLE();
|
|
/* USER CODE BEGIN DAC4_MspInit 1 */
|
|
|
|
/* USER CODE END DAC4_MspInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief DAC MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hdac: DAC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
|
|
{
|
|
if(hdac->Instance==DAC1)
|
|
{
|
|
/* USER CODE BEGIN DAC1_MspDeInit 0 */
|
|
|
|
/* USER CODE END DAC1_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_DAC1_CLK_DISABLE();
|
|
/* USER CODE BEGIN DAC1_MspDeInit 1 */
|
|
|
|
/* USER CODE END DAC1_MspDeInit 1 */
|
|
}
|
|
else if(hdac->Instance==DAC4)
|
|
{
|
|
/* USER CODE BEGIN DAC4_MspDeInit 0 */
|
|
|
|
/* USER CODE END DAC4_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_DAC4_CLK_DISABLE();
|
|
/* USER CODE BEGIN DAC4_MspDeInit 1 */
|
|
|
|
/* USER CODE END DAC4_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief FMAC MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hfmac: FMAC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_FMAC_MspInit(FMAC_HandleTypeDef* hfmac)
|
|
{
|
|
if(hfmac->Instance==FMAC)
|
|
{
|
|
/* USER CODE BEGIN FMAC_MspInit 0 */
|
|
|
|
/* USER CODE END FMAC_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_FMAC_CLK_ENABLE();
|
|
/* USER CODE BEGIN FMAC_MspInit 1 */
|
|
|
|
/* USER CODE END FMAC_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief FMAC MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hfmac: FMAC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_FMAC_MspDeInit(FMAC_HandleTypeDef* hfmac)
|
|
{
|
|
if(hfmac->Instance==FMAC)
|
|
{
|
|
/* USER CODE BEGIN FMAC_MspDeInit 0 */
|
|
|
|
/* USER CODE END FMAC_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_FMAC_CLK_DISABLE();
|
|
/* USER CODE BEGIN FMAC_MspDeInit 1 */
|
|
|
|
/* USER CODE END FMAC_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief HRTIM MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hhrtim: HRTIM handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_HRTIM_MspInit(HRTIM_HandleTypeDef* hhrtim)
|
|
{
|
|
if(hhrtim->Instance==HRTIM1)
|
|
{
|
|
/* USER CODE BEGIN HRTIM1_MspInit 0 */
|
|
|
|
/* USER CODE END HRTIM1_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_HRTIM1_CLK_ENABLE();
|
|
/* USER CODE BEGIN HRTIM1_MspInit 1 */
|
|
|
|
/* USER CODE END HRTIM1_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void HAL_HRTIM_MspPostInit(HRTIM_HandleTypeDef* hhrtim)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
if(hhrtim->Instance==HRTIM1)
|
|
{
|
|
/* USER CODE BEGIN HRTIM1_MspPostInit 0 */
|
|
|
|
/* USER CODE END HRTIM1_MspPostInit 0 */
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
/**HRTIM1 GPIO Configuration
|
|
PA8 ------> HRTIM1_CHA1
|
|
PA9 ------> HRTIM1_CHA2
|
|
PA10 ------> HRTIM1_CHB1
|
|
PA11 ------> HRTIM1_CHB2
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF13_HRTIM1;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN HRTIM1_MspPostInit 1 */
|
|
|
|
/* USER CODE END HRTIM1_MspPostInit 1 */
|
|
}
|
|
|
|
}
|
|
/**
|
|
* @brief HRTIM MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hhrtim: HRTIM handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_HRTIM_MspDeInit(HRTIM_HandleTypeDef* hhrtim)
|
|
{
|
|
if(hhrtim->Instance==HRTIM1)
|
|
{
|
|
/* USER CODE BEGIN HRTIM1_MspDeInit 0 */
|
|
|
|
/* USER CODE END HRTIM1_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_HRTIM1_CLK_DISABLE();
|
|
/* USER CODE BEGIN HRTIM1_MspDeInit 1 */
|
|
|
|
/* USER CODE END HRTIM1_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief TIM_Base MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param htim_base: TIM_Base handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
|
{
|
|
if(htim_base->Instance==TIM1)
|
|
{
|
|
/* USER CODE BEGIN TIM1_MspInit 0 */
|
|
|
|
/* USER CODE END TIM1_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_TIM1_CLK_ENABLE();
|
|
/* USER CODE BEGIN TIM1_MspInit 1 */
|
|
|
|
/* USER CODE END TIM1_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief TIM_Base MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param htim_base: TIM_Base handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
|
{
|
|
if(htim_base->Instance==TIM1)
|
|
{
|
|
/* USER CODE BEGIN TIM1_MspDeInit 0 */
|
|
|
|
/* USER CODE END TIM1_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_TIM1_CLK_DISABLE();
|
|
/* USER CODE BEGIN TIM1_MspDeInit 1 */
|
|
|
|
/* USER CODE END TIM1_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief UART MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param huart: UART handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
if(huart->Instance==USART1)
|
|
{
|
|
/* USER CODE BEGIN USART1_MspInit 0 */
|
|
|
|
/* USER CODE END USART1_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clocks
|
|
*/
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
|
|
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_USART1_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**USART1 GPIO Configuration
|
|
PB6 ------> USART1_TX
|
|
PB7 ------> USART1_RX
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN USART1_MspInit 1 */
|
|
|
|
/* USER CODE END USART1_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief UART MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param huart: UART handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
|
{
|
|
if(huart->Instance==USART1)
|
|
{
|
|
/* USER CODE BEGIN USART1_MspDeInit 0 */
|
|
|
|
/* USER CODE END USART1_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_USART1_CLK_DISABLE();
|
|
|
|
/**USART1 GPIO Configuration
|
|
PB6 ------> USART1_TX
|
|
PB7 ------> USART1_RX
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
|
|
|
|
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
|
|
|
/* USER CODE END USART1_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|