You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
982 lines
27 KiB
982 lines
27 KiB
/* 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) 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 */
|
|
/**
|
|
* Initializes the Global MSP.
|
|
*/
|
|
void HAL_MspInit(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN MspInit 0 */
|
|
|
|
/* USER CODE END MspInit 0 */
|
|
|
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
|
|
/* System interrupt init*/
|
|
|
|
/* USER CODE BEGIN MspInit 1 */
|
|
|
|
/* USER CODE END MspInit 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief DMA2D MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hdma2d: DMA2D handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef* hdma2d)
|
|
{
|
|
if(hdma2d->Instance==DMA2D)
|
|
{
|
|
/* USER CODE BEGIN DMA2D_MspInit 0 */
|
|
|
|
/* USER CODE END DMA2D_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_DMA2D_CLK_ENABLE();
|
|
/* USER CODE BEGIN DMA2D_MspInit 1 */
|
|
|
|
/* USER CODE END DMA2D_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief DMA2D MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hdma2d: DMA2D handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)
|
|
{
|
|
if(hdma2d->Instance==DMA2D)
|
|
{
|
|
/* USER CODE BEGIN DMA2D_MspDeInit 0 */
|
|
|
|
/* USER CODE END DMA2D_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_DMA2D_CLK_DISABLE();
|
|
/* USER CODE BEGIN DMA2D_MspDeInit 1 */
|
|
|
|
/* USER CODE END DMA2D_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief LTDC MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hltdc: LTDC handle pointer
|
|
* @retval None
|
|
*/
|
|
/**
|
|
* @brief LTDC MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hltdc: LTDC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef* hltdc)
|
|
{
|
|
if(hltdc->Instance==LTDC)
|
|
{
|
|
/* USER CODE BEGIN LTDC_MspDeInit 0 */
|
|
|
|
/* USER CODE END LTDC_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_LTDC_CLK_DISABLE();
|
|
|
|
/**LTDC GPIO Configuration
|
|
PE5 ------> LTDC_G0
|
|
PE6 ------> LTDC_G1
|
|
PI9 ------> LTDC_VSYNC
|
|
PI10 ------> LTDC_HSYNC
|
|
PF10 ------> LTDC_DE
|
|
PA2 ------> LTDC_R1
|
|
PH8 ------> LTDC_R2
|
|
PH9 ------> LTDC_R3
|
|
PH10 ------> LTDC_R4
|
|
PH11 ------> LTDC_R5
|
|
PH12 ------> LTDC_R6
|
|
PG6 ------> LTDC_R7
|
|
PG7 ------> LTDC_CLK
|
|
PA8 ------> LTDC_B3
|
|
PH13 ------> LTDC_G2
|
|
PH14 ------> LTDC_G3
|
|
PH15 ------> LTDC_G4
|
|
PI0 ------> LTDC_G5
|
|
PI1 ------> LTDC_G6
|
|
PI2 ------> LTDC_G7
|
|
PD6 ------> LTDC_B2
|
|
PG12 ------> LTDC_B1
|
|
PG13 ------> LTDC_R0
|
|
PG14 ------> LTDC_B0
|
|
PI4 ------> LTDC_B4
|
|
PI5 ------> LTDC_B5
|
|
PI6 ------> LTDC_B6
|
|
PI7 ------> LTDC_B7
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOE, GPIO_PIN_5|GPIO_PIN_6);
|
|
|
|
HAL_GPIO_DeInit(GPIOI, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_0|GPIO_PIN_1
|
|
|GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
|
|
|GPIO_PIN_7);
|
|
|
|
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_10);
|
|
|
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_8);
|
|
|
|
HAL_GPIO_DeInit(GPIOH, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
|
|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
|
|
|
|
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_12|GPIO_PIN_13
|
|
|GPIO_PIN_14);
|
|
|
|
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_6);
|
|
|
|
/* LTDC interrupt DeInit */
|
|
HAL_NVIC_DisableIRQ(LTDC_IRQn);
|
|
/* USER CODE BEGIN LTDC_MspDeInit 1 */
|
|
|
|
/* USER CODE END LTDC_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief QSPI MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hqspi: QSPI handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
if(hqspi->Instance==QUADSPI)
|
|
{
|
|
/* USER CODE BEGIN QUADSPI_MspInit 0 */
|
|
|
|
/* USER CODE END QUADSPI_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_QSPI;
|
|
PeriphClkInitStruct.QspiClockSelection = RCC_QSPICLKSOURCE_CLKP;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_QSPI_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**QUADSPI GPIO Configuration
|
|
PF6 ------> QUADSPI_BK1_IO3
|
|
PF7 ------> QUADSPI_BK1_IO2
|
|
PF8 ------> QUADSPI_BK1_IO0
|
|
PF9 ------> QUADSPI_BK1_IO1
|
|
PB2 ------> QUADSPI_CLK
|
|
PB6 ------> QUADSPI_BK1_NCS
|
|
*/
|
|
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_AF9_QUADSPI;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
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_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* QUADSPI interrupt Init */
|
|
HAL_NVIC_SetPriority(QUADSPI_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(QUADSPI_IRQn);
|
|
/* USER CODE BEGIN QUADSPI_MspInit 1 */
|
|
|
|
/* USER CODE END QUADSPI_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief QSPI MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hqspi: QSPI handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
|
|
{
|
|
if(hqspi->Instance==QUADSPI)
|
|
{
|
|
/* USER CODE BEGIN QUADSPI_MspDeInit 0 */
|
|
|
|
/* USER CODE END QUADSPI_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_QSPI_CLK_DISABLE();
|
|
|
|
/**QUADSPI GPIO Configuration
|
|
PF6 ------> QUADSPI_BK1_IO3
|
|
PF7 ------> QUADSPI_BK1_IO2
|
|
PF8 ------> QUADSPI_BK1_IO0
|
|
PF9 ------> QUADSPI_BK1_IO1
|
|
PB2 ------> QUADSPI_CLK
|
|
PB6 ------> QUADSPI_BK1_NCS
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9);
|
|
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_2|GPIO_PIN_6);
|
|
|
|
/* QUADSPI interrupt DeInit */
|
|
HAL_NVIC_DisableIRQ(QUADSPI_IRQn);
|
|
/* USER CODE BEGIN QUADSPI_MspDeInit 1 */
|
|
|
|
/* USER CODE END QUADSPI_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief RTC MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hrtc: RTC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
|
|
{
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
if(hrtc->Instance==RTC)
|
|
{
|
|
/* USER CODE BEGIN RTC_MspInit 0 */
|
|
|
|
/* USER CODE END RTC_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
|
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_RTC_ENABLE();
|
|
/* USER CODE BEGIN RTC_MspInit 1 */
|
|
|
|
/* USER CODE END RTC_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief RTC MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hrtc: RTC handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
|
|
{
|
|
if(hrtc->Instance==RTC)
|
|
{
|
|
/* USER CODE BEGIN RTC_MspDeInit 0 */
|
|
|
|
/* USER CODE END RTC_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_RTC_DISABLE();
|
|
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
|
|
|
/* USER CODE END RTC_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief SD MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hsd: SD handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
if(hsd->Instance==SDMMC1)
|
|
{
|
|
/* USER CODE BEGIN SDMMC1_MspInit 0 */
|
|
|
|
/* USER CODE END SDMMC1_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDMMC;
|
|
PeriphClkInitStruct.PLL2.PLL2M = 32;
|
|
PeriphClkInitStruct.PLL2.PLL2N = 200;
|
|
PeriphClkInitStruct.PLL2.PLL2P = 2;
|
|
PeriphClkInitStruct.PLL2.PLL2Q = 2;
|
|
PeriphClkInitStruct.PLL2.PLL2R = 2;
|
|
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_1;
|
|
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
|
|
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
|
|
PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL2;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_SDMMC1_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
/**SDMMC1 GPIO Configuration
|
|
PC8 ------> SDMMC1_D0
|
|
PC9 ------> SDMMC1_D1
|
|
PC10 ------> SDMMC1_D2
|
|
PC11 ------> SDMMC1_D3
|
|
PC12 ------> SDMMC1_CK
|
|
PD2 ------> SDMMC1_CMD
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
|
|GPIO_PIN_12;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/* SDMMC1 interrupt Init */
|
|
HAL_NVIC_SetPriority(SDMMC1_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(SDMMC1_IRQn);
|
|
/* USER CODE BEGIN SDMMC1_MspInit 1 */
|
|
|
|
/* USER CODE END SDMMC1_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief SD MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hsd: SD handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd)
|
|
{
|
|
if(hsd->Instance==SDMMC1)
|
|
{
|
|
/* USER CODE BEGIN SDMMC1_MspDeInit 0 */
|
|
|
|
/* USER CODE END SDMMC1_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_SDMMC1_CLK_DISABLE();
|
|
|
|
/**SDMMC1 GPIO Configuration
|
|
PC8 ------> SDMMC1_D0
|
|
PC9 ------> SDMMC1_D1
|
|
PC10 ------> SDMMC1_D2
|
|
PC11 ------> SDMMC1_D3
|
|
PC12 ------> SDMMC1_CK
|
|
PD2 ------> SDMMC1_CMD
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
|
|GPIO_PIN_12);
|
|
|
|
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
|
|
|
|
/* SDMMC1 interrupt DeInit */
|
|
HAL_NVIC_DisableIRQ(SDMMC1_IRQn);
|
|
/* USER CODE BEGIN SDMMC1_MspDeInit 1 */
|
|
|
|
/* USER CODE END SDMMC1_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==UART4)
|
|
{
|
|
/* USER CODE BEGIN UART4_MspInit 0 */
|
|
|
|
/* USER CODE END UART4_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_UART4;
|
|
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_UART4_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
/**UART4 GPIO Configuration
|
|
PA0 ------> UART4_TX
|
|
PA1 ------> UART4_RX
|
|
*/
|
|
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_UART4;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN UART4_MspInit 1 */
|
|
|
|
/* USER CODE END UART4_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_GPIOA_CLK_ENABLE();
|
|
/**USART1 GPIO Configuration
|
|
PA9 ------> USART1_TX
|
|
PA10 ------> USART1_RX
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
|
|
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(GPIOA, &GPIO_InitStruct);
|
|
|
|
/* 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_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
/**USART2 GPIO Configuration
|
|
PA3 ------> USART2_RX
|
|
PD5 ------> USART2_TX
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN USART2_MspInit 1 */
|
|
|
|
/* USER CODE END USART2_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==UART4)
|
|
{
|
|
/* USER CODE BEGIN UART4_MspDeInit 0 */
|
|
|
|
/* USER CODE END UART4_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_UART4_CLK_DISABLE();
|
|
|
|
/**UART4 GPIO Configuration
|
|
PA0 ------> UART4_TX
|
|
PA1 ------> UART4_RX
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1);
|
|
|
|
/* USER CODE BEGIN UART4_MspDeInit 1 */
|
|
|
|
/* USER CODE END UART4_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
|
|
PA9 ------> USART1_TX
|
|
PA10 ------> USART1_RX
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
|
|
|
|
/* 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
|
|
PA3 ------> USART2_RX
|
|
PD5 ------> USART2_TX
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3);
|
|
|
|
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5);
|
|
|
|
/* USER CODE BEGIN USART2_MspDeInit 1 */
|
|
|
|
/* USER CODE END USART2_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief HCD MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hhcd: HCD handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
if(hhcd->Instance==USB_OTG_FS)
|
|
{
|
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
|
|
|
|
/* USER CODE END USB_OTG_FS_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
|
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Enable USB Voltage detector
|
|
*/
|
|
HAL_PWREx_EnableUSBVoltageDetector();
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
/**USB_OTG_FS GPIO Configuration
|
|
PA11 ------> USB_OTG_FS_DM
|
|
PA12 ------> USB_OTG_FS_DP
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
|
/* USB_OTG_FS interrupt Init */
|
|
HAL_NVIC_SetPriority(OTG_FS_EP1_OUT_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(OTG_FS_EP1_OUT_IRQn);
|
|
HAL_NVIC_SetPriority(OTG_FS_EP1_IN_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(OTG_FS_EP1_IN_IRQn);
|
|
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
|
|
|
|
/* USER CODE END USB_OTG_FS_MspInit 1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief HCD MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hhcd: HCD handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_HCD_MspDeInit(HCD_HandleTypeDef* hhcd)
|
|
{
|
|
if(hhcd->Instance==USB_OTG_FS)
|
|
{
|
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
|
|
|
|
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
|
|
|
|
/**USB_OTG_FS GPIO Configuration
|
|
PA11 ------> USB_OTG_FS_DM
|
|
PA12 ------> USB_OTG_FS_DP
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
|
|
|
|
/* USB_OTG_FS interrupt DeInit */
|
|
HAL_NVIC_DisableIRQ(OTG_FS_EP1_OUT_IRQn);
|
|
HAL_NVIC_DisableIRQ(OTG_FS_EP1_IN_IRQn);
|
|
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
|
|
|
|
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
static uint32_t FMC_Initialized = 0;
|
|
|
|
static void HAL_FMC_MspInit(void){
|
|
/* USER CODE BEGIN FMC_MspInit 0 */
|
|
|
|
/* USER CODE END FMC_MspInit 0 */
|
|
GPIO_InitTypeDef GPIO_InitStruct ={0};
|
|
if (FMC_Initialized) {
|
|
return;
|
|
}
|
|
FMC_Initialized = 1;
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_FMC;
|
|
PeriphClkInitStruct.FmcClockSelection = RCC_FMCCLKSOURCE_PLL;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_FMC_CLK_ENABLE();
|
|
|
|
/** FMC GPIO Configuration
|
|
PF0 ------> FMC_A0
|
|
PF1 ------> FMC_A1
|
|
PF2 ------> FMC_A2
|
|
PF3 ------> FMC_A3
|
|
PF4 ------> FMC_A4
|
|
PF5 ------> FMC_A5
|
|
PC0 ------> FMC_SDNWE
|
|
PH2 ------> FMC_SDCKE0
|
|
PH3 ------> FMC_SDNE0
|
|
PF11 ------> FMC_SDNRAS
|
|
PF12 ------> FMC_A6
|
|
PF13 ------> FMC_A7
|
|
PF14 ------> FMC_A8
|
|
PF15 ------> FMC_A9
|
|
PG0 ------> FMC_A10
|
|
PG1 ------> FMC_A11
|
|
PE7 ------> FMC_D4
|
|
PE8 ------> FMC_D5
|
|
PE9 ------> FMC_D6
|
|
PE10 ------> FMC_D7
|
|
PE11 ------> FMC_D8
|
|
PE12 ------> FMC_D9
|
|
PE13 ------> FMC_D10
|
|
PE14 ------> FMC_D11
|
|
PE15 ------> FMC_D12
|
|
PD8 ------> FMC_D13
|
|
PD9 ------> FMC_D14
|
|
PD10 ------> FMC_D15
|
|
PD14 ------> FMC_D0
|
|
PD15 ------> FMC_D1
|
|
PG2 ------> FMC_A12
|
|
PG4 ------> FMC_BA0
|
|
PG5 ------> FMC_BA1
|
|
PG8 ------> FMC_SDCLK
|
|
PD0 ------> FMC_D2
|
|
PD1 ------> FMC_D3
|
|
PG15 ------> FMC_SDNCAS
|
|
PE0 ------> FMC_NBL0
|
|
PE1 ------> FMC_NBL1
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|
|
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_11|GPIO_PIN_12
|
|
|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_4
|
|
|GPIO_PIN_5|GPIO_PIN_8|GPIO_PIN_15;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
|
|
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|
|
|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
|
|
|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN FMC_MspInit 1 */
|
|
|
|
/* USER CODE END FMC_MspInit 1 */
|
|
}
|
|
|
|
void HAL_SDRAM_MspInit(SDRAM_HandleTypeDef* hsdram){
|
|
/* USER CODE BEGIN SDRAM_MspInit 0 */
|
|
|
|
/* USER CODE END SDRAM_MspInit 0 */
|
|
HAL_FMC_MspInit();
|
|
/* USER CODE BEGIN SDRAM_MspInit 1 */
|
|
|
|
/* USER CODE END SDRAM_MspInit 1 */
|
|
}
|
|
|
|
static uint32_t FMC_DeInitialized = 0;
|
|
|
|
static void HAL_FMC_MspDeInit(void){
|
|
/* USER CODE BEGIN FMC_MspDeInit 0 */
|
|
|
|
/* USER CODE END FMC_MspDeInit 0 */
|
|
if (FMC_DeInitialized) {
|
|
return;
|
|
}
|
|
FMC_DeInitialized = 1;
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_FMC_CLK_DISABLE();
|
|
|
|
/** FMC GPIO Configuration
|
|
PF0 ------> FMC_A0
|
|
PF1 ------> FMC_A1
|
|
PF2 ------> FMC_A2
|
|
PF3 ------> FMC_A3
|
|
PF4 ------> FMC_A4
|
|
PF5 ------> FMC_A5
|
|
PC0 ------> FMC_SDNWE
|
|
PH2 ------> FMC_SDCKE0
|
|
PH3 ------> FMC_SDNE0
|
|
PF11 ------> FMC_SDNRAS
|
|
PF12 ------> FMC_A6
|
|
PF13 ------> FMC_A7
|
|
PF14 ------> FMC_A8
|
|
PF15 ------> FMC_A9
|
|
PG0 ------> FMC_A10
|
|
PG1 ------> FMC_A11
|
|
PE7 ------> FMC_D4
|
|
PE8 ------> FMC_D5
|
|
PE9 ------> FMC_D6
|
|
PE10 ------> FMC_D7
|
|
PE11 ------> FMC_D8
|
|
PE12 ------> FMC_D9
|
|
PE13 ------> FMC_D10
|
|
PE14 ------> FMC_D11
|
|
PE15 ------> FMC_D12
|
|
PD8 ------> FMC_D13
|
|
PD9 ------> FMC_D14
|
|
PD10 ------> FMC_D15
|
|
PD14 ------> FMC_D0
|
|
PD15 ------> FMC_D1
|
|
PG2 ------> FMC_A12
|
|
PG4 ------> FMC_BA0
|
|
PG5 ------> FMC_BA1
|
|
PG8 ------> FMC_SDCLK
|
|
PD0 ------> FMC_D2
|
|
PD1 ------> FMC_D3
|
|
PG15 ------> FMC_SDNCAS
|
|
PE0 ------> FMC_NBL0
|
|
PE1 ------> FMC_NBL1
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|
|
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_11|GPIO_PIN_12
|
|
|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
|
|
|
|
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0);
|
|
|
|
HAL_GPIO_DeInit(GPIOH, GPIO_PIN_2|GPIO_PIN_3);
|
|
|
|
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_4
|
|
|GPIO_PIN_5|GPIO_PIN_8|GPIO_PIN_15);
|
|
|
|
HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
|
|
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|
|
|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
|
|
|
|
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
|
|
|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
|
|
|
|
/* USER CODE BEGIN FMC_MspDeInit 1 */
|
|
|
|
/* USER CODE END FMC_MspDeInit 1 */
|
|
}
|
|
|
|
void HAL_SDRAM_MspDeInit(SDRAM_HandleTypeDef* hsdram){
|
|
/* USER CODE BEGIN SDRAM_MspDeInit 0 */
|
|
|
|
/* USER CODE END SDRAM_MspDeInit 0 */
|
|
HAL_FMC_MspDeInit();
|
|
/* USER CODE BEGIN SDRAM_MspDeInit 1 */
|
|
|
|
/* USER CODE END SDRAM_MspDeInit 1 */
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|