/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32h7xx_hal_msp.c * @brief This file provides code for the MSP Initialization * and de-Initialization codes. ****************************************************************************** * @attention * * Copyright (c) 2024 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 */ extern DMA_HandleTypeDef hdma_uart8_rx; extern DMA_HandleTypeDef hdma_uart8_tx; /* 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 */ /** * Initializes the Global MSP. */ void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ PWREx_AVDTypeDef sConfigAVD = {0}; PWR_PVDTypeDef sConfigPVD = {0}; __HAL_RCC_SYSCFG_CLK_ENABLE(); /* System interrupt init*/ /* PendSV_IRQn interrupt configuration */ HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); /* Peripheral interrupt init */ /* RCC_IRQn interrupt configuration */ HAL_NVIC_SetPriority(RCC_IRQn, 5, 0); HAL_NVIC_EnableIRQ(RCC_IRQn); /** AVD Configuration */ sConfigAVD.AVDLevel = PWR_AVDLEVEL_3; sConfigAVD.Mode = PWR_AVD_MODE_NORMAL; HAL_PWREx_ConfigAVD(&sConfigAVD); /** Enable the AVD Output */ HAL_PWREx_EnableAVD(); /** PVD Configuration */ sConfigPVD.PVDLevel = PWR_PVDLEVEL_6; sConfigPVD.Mode = PWR_PVD_MODE_NORMAL; HAL_PWR_ConfigPVD(&sConfigPVD); /** Enable the PVD Output */ HAL_PWR_EnablePVD(); /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ } /** * @brief CRC MSP Initialization * This function configures the hardware resources used in this example * @param hcrc: CRC handle pointer * @retval None */ void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc) { if(hcrc->Instance==CRC) { /* USER CODE BEGIN CRC_MspInit 0 */ /* USER CODE END CRC_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_CRC_CLK_ENABLE(); /* USER CODE BEGIN CRC_MspInit 1 */ /* USER CODE END CRC_MspInit 1 */ } } /** * @brief CRC MSP De-Initialization * This function freeze the hardware resources used in this example * @param hcrc: CRC handle pointer * @retval None */ void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc) { if(hcrc->Instance==CRC) { /* USER CODE BEGIN CRC_MspDeInit 0 */ /* USER CODE END CRC_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_CRC_CLK_DISABLE(); /* USER CODE BEGIN CRC_MspDeInit 1 */ /* USER CODE END CRC_MspDeInit 1 */ } } /** * @brief RNG MSP Initialization * This function configures the hardware resources used in this example * @param hrng: RNG handle pointer * @retval None */ void HAL_RNG_MspInit(RNG_HandleTypeDef* hrng) { RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; if(hrng->Instance==RNG) { /* USER CODE BEGIN RNG_MspInit 0 */ /* USER CODE END RNG_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RNG; PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_HSI48; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_RNG_CLK_ENABLE(); /* USER CODE BEGIN RNG_MspInit 1 */ /* USER CODE END RNG_MspInit 1 */ } } /** * @brief RNG MSP De-Initialization * This function freeze the hardware resources used in this example * @param hrng: RNG handle pointer * @retval None */ void HAL_RNG_MspDeInit(RNG_HandleTypeDef* hrng) { if(hrng->Instance==RNG) { /* USER CODE BEGIN RNG_MspDeInit 0 */ /* USER CODE END RNG_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_RNG_CLK_DISABLE(); /* USER CODE BEGIN RNG_MspDeInit 1 */ /* USER CODE END RNG_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 PeriphClkInitStruct = {0}; if(huart->Instance==UART8) { /* USER CODE BEGIN UART8_MspInit 0 */ /* USER CODE END UART8_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_UART8; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_UART8_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); /**UART8 GPIO Configuration PE0 ------> UART8_RX PE1 ------> UART8_TX */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF8_UART8; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /* UART8 DMA Init */ /* UART8_RX Init */ hdma_uart8_rx.Instance = DMA2_Stream7; hdma_uart8_rx.Init.Request = DMA_REQUEST_UART8_RX; hdma_uart8_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_uart8_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_uart8_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_uart8_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_uart8_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_uart8_rx.Init.Mode = DMA_NORMAL; hdma_uart8_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH; hdma_uart8_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; if (HAL_DMA_Init(&hdma_uart8_rx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(huart,hdmarx,hdma_uart8_rx); /* UART8_TX Init */ hdma_uart8_tx.Instance = DMA2_Stream6; hdma_uart8_tx.Init.Request = DMA_REQUEST_UART8_TX; hdma_uart8_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_uart8_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_uart8_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_uart8_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_uart8_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_uart8_tx.Init.Mode = DMA_NORMAL; hdma_uart8_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH; hdma_uart8_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; if (HAL_DMA_Init(&hdma_uart8_tx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(huart,hdmatx,hdma_uart8_tx); /* UART8 interrupt Init */ HAL_NVIC_SetPriority(UART8_IRQn, 5, 0); HAL_NVIC_EnableIRQ(UART8_IRQn); /* USER CODE BEGIN UART8_MspInit 1 */ /* USER CODE END UART8_MspInit 1 */ } else if(huart->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1; PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /**USART1 GPIO Configuration PB14 ------> USART1_TX PB15 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_USART1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USART1 interrupt Init */ HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } else if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspInit 0 */ /* USER CODE END USART2_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_USART2_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**USART2 GPIO Configuration PD5 ------> USART2_TX PD6 ------> USART2_RX */ GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USART2 interrupt Init */ HAL_NVIC_SetPriority(USART2_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ /* USER CODE END USART2_MspInit 1 */ } else if(huart->Instance==USART3) { /* USER CODE BEGIN USART3_MspInit 0 */ /* USER CODE END USART3_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_USART3_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**USART3 GPIO Configuration PD8 ------> USART3_TX PD9 ------> USART3_RX */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART3; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USART3 interrupt Init */ HAL_NVIC_SetPriority(USART3_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART3_IRQn); /* USER CODE BEGIN USART3_MspInit 1 */ /* USER CODE END USART3_MspInit 1 */ } else if(huart->Instance==USART6) { /* USER CODE BEGIN USART6_MspInit 0 */ /* USER CODE END USART6_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART6; PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_USART6_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); /**USART6 GPIO Configuration PC6 ------> USART6_TX PC7 ------> USART6_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_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART6; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* USART6 interrupt Init */ HAL_NVIC_SetPriority(USART6_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART6_IRQn); /* USER CODE BEGIN USART6_MspInit 1 */ /* USER CODE END USART6_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==UART8) { /* USER CODE BEGIN UART8_MspDeInit 0 */ /* USER CODE END UART8_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_UART8_CLK_DISABLE(); /**UART8 GPIO Configuration PE0 ------> UART8_RX PE1 ------> UART8_TX */ HAL_GPIO_DeInit(GPIOE, GPIO_PIN_0|GPIO_PIN_1); /* UART8 DMA DeInit */ HAL_DMA_DeInit(huart->hdmarx); HAL_DMA_DeInit(huart->hdmatx); /* UART8 interrupt DeInit */ HAL_NVIC_DisableIRQ(UART8_IRQn); /* USER CODE BEGIN UART8_MspDeInit 1 */ /* USER CODE END UART8_MspDeInit 1 */ } else 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 PB14 ------> USART1_TX PB15 ------> USART1_RX */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15); /* USART1 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } else if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspDeInit 0 */ /* USER CODE END USART2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART2_CLK_DISABLE(); /**USART2 GPIO Configuration PD5 ------> USART2_TX PD6 ------> USART2_RX */ HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6); /* USART2 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspDeInit 1 */ /* USER CODE END USART2_MspDeInit 1 */ } else if(huart->Instance==USART3) { /* USER CODE BEGIN USART3_MspDeInit 0 */ /* USER CODE END USART3_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART3_CLK_DISABLE(); /**USART3 GPIO Configuration PD8 ------> USART3_TX PD9 ------> USART3_RX */ HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9); /* USART3 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART3_IRQn); /* USER CODE BEGIN USART3_MspDeInit 1 */ /* USER CODE END USART3_MspDeInit 1 */ } else if(huart->Instance==USART6) { /* USER CODE BEGIN USART6_MspDeInit 0 */ /* USER CODE END USART6_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART6_CLK_DISABLE(); /**USART6 GPIO Configuration PC6 ------> USART6_TX PC7 ------> USART6_RX */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_6|GPIO_PIN_7); /* USART6 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART6_IRQn); /* USER CODE BEGIN USART6_MspDeInit 1 */ /* USER CODE END USART6_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */