123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- /* 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 */
|