976 lines
23 KiB
C
976 lines
23 KiB
C
|
/* USER CODE BEGIN Header */
|
||
|
/**
|
||
|
******************************************************************************
|
||
|
* @file : main.c
|
||
|
* @brief : Main program body
|
||
|
******************************************************************************
|
||
|
* @attention
|
||
|
*
|
||
|
* Copyright (c) 2023 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"
|
||
|
#include "string.h"
|
||
|
|
||
|
/* Private includes ----------------------------------------------------------*/
|
||
|
/* USER CODE BEGIN Includes */
|
||
|
|
||
|
/* USER CODE END Includes */
|
||
|
|
||
|
/* Private typedef -----------------------------------------------------------*/
|
||
|
/* USER CODE BEGIN PTD */
|
||
|
|
||
|
/* USER CODE END PTD */
|
||
|
|
||
|
/* Private define ------------------------------------------------------------*/
|
||
|
/* USER CODE BEGIN PD */
|
||
|
|
||
|
/* USER CODE END PD */
|
||
|
|
||
|
/* Private macro -------------------------------------------------------------*/
|
||
|
/* USER CODE BEGIN PM */
|
||
|
|
||
|
/* USER CODE END PM */
|
||
|
|
||
|
/* Private variables ---------------------------------------------------------*/
|
||
|
|
||
|
ETH_TxPacketConfig TxConfig;
|
||
|
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
|
||
|
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
|
||
|
|
||
|
DAC_HandleTypeDef hdac;
|
||
|
|
||
|
ETH_HandleTypeDef heth;
|
||
|
|
||
|
IWDG_HandleTypeDef hiwdg;
|
||
|
|
||
|
RTC_HandleTypeDef hrtc;
|
||
|
|
||
|
SD_HandleTypeDef hsd;
|
||
|
|
||
|
SPI_HandleTypeDef hspi1;
|
||
|
SPI_HandleTypeDef hspi2;
|
||
|
|
||
|
TIM_HandleTypeDef htim2;
|
||
|
TIM_HandleTypeDef htim3;
|
||
|
TIM_HandleTypeDef htim4;
|
||
|
TIM_HandleTypeDef htim11;
|
||
|
TIM_HandleTypeDef htim13;
|
||
|
TIM_HandleTypeDef htim14;
|
||
|
|
||
|
UART_HandleTypeDef huart1;
|
||
|
UART_HandleTypeDef huart3;
|
||
|
|
||
|
PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||
|
|
||
|
SRAM_HandleTypeDef hsram1;
|
||
|
|
||
|
/* USER CODE BEGIN PV */
|
||
|
|
||
|
/* USER CODE END PV */
|
||
|
|
||
|
/* Private function prototypes -----------------------------------------------*/
|
||
|
void SystemClock_Config(void);
|
||
|
static void MX_GPIO_Init(void);
|
||
|
static void MX_USART1_UART_Init(void);
|
||
|
static void MX_SPI1_Init(void);
|
||
|
static void MX_ETH_Init(void);
|
||
|
static void MX_USART3_UART_Init(void);
|
||
|
static void MX_RTC_Init(void);
|
||
|
static void MX_IWDG_Init(void);
|
||
|
static void MX_TIM14_Init(void);
|
||
|
static void MX_TIM13_Init(void);
|
||
|
static void MX_TIM11_Init(void);
|
||
|
static void MX_SDIO_SD_Init(void);
|
||
|
static void MX_TIM2_Init(void);
|
||
|
static void MX_SPI2_Init(void);
|
||
|
static void MX_TIM4_Init(void);
|
||
|
static void MX_USB_OTG_FS_PCD_Init(void);
|
||
|
static void MX_FSMC_Init(void);
|
||
|
static void MX_DAC_Init(void);
|
||
|
static void MX_TIM3_Init(void);
|
||
|
/* USER CODE BEGIN PFP */
|
||
|
|
||
|
/* USER CODE END PFP */
|
||
|
|
||
|
/* Private user code ---------------------------------------------------------*/
|
||
|
/* USER CODE BEGIN 0 */
|
||
|
|
||
|
/* USER CODE END 0 */
|
||
|
|
||
|
/**
|
||
|
* @brief The application entry point.
|
||
|
* @retval int
|
||
|
*/
|
||
|
int main(void)
|
||
|
{
|
||
|
/* USER CODE BEGIN 1 */
|
||
|
|
||
|
/* USER CODE END 1 */
|
||
|
|
||
|
/* MCU Configuration--------------------------------------------------------*/
|
||
|
|
||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||
|
HAL_Init();
|
||
|
|
||
|
/* USER CODE BEGIN Init */
|
||
|
|
||
|
/* USER CODE END Init */
|
||
|
|
||
|
/* Configure the system clock */
|
||
|
SystemClock_Config();
|
||
|
|
||
|
/* USER CODE BEGIN SysInit */
|
||
|
|
||
|
/* USER CODE END SysInit */
|
||
|
|
||
|
/* Initialize all configured peripherals */
|
||
|
MX_GPIO_Init();
|
||
|
MX_USART1_UART_Init();
|
||
|
MX_SPI1_Init();
|
||
|
MX_ETH_Init();
|
||
|
MX_USART3_UART_Init();
|
||
|
MX_RTC_Init();
|
||
|
MX_IWDG_Init();
|
||
|
MX_TIM14_Init();
|
||
|
MX_TIM13_Init();
|
||
|
MX_TIM11_Init();
|
||
|
MX_SDIO_SD_Init();
|
||
|
MX_TIM2_Init();
|
||
|
MX_SPI2_Init();
|
||
|
MX_TIM4_Init();
|
||
|
MX_USB_OTG_FS_PCD_Init();
|
||
|
MX_FSMC_Init();
|
||
|
MX_DAC_Init();
|
||
|
MX_TIM3_Init();
|
||
|
/* USER CODE BEGIN 2 */
|
||
|
|
||
|
/* USER CODE END 2 */
|
||
|
|
||
|
/* Infinite loop */
|
||
|
/* USER CODE BEGIN WHILE */
|
||
|
while (1)
|
||
|
{
|
||
|
/* USER CODE END WHILE */
|
||
|
|
||
|
/* USER CODE BEGIN 3 */
|
||
|
}
|
||
|
/* USER CODE END 3 */
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief System Clock Configuration
|
||
|
* @retval None
|
||
|
*/
|
||
|
void SystemClock_Config(void)
|
||
|
{
|
||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||
|
|
||
|
/** Configure the main internal regulator output voltage
|
||
|
*/
|
||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||
|
|
||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||
|
* in the RCC_OscInitTypeDef structure.
|
||
|
*/
|
||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE
|
||
|
|RCC_OSCILLATORTYPE_LSE;
|
||
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||
|
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||
|
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||
|
RCC_OscInitStruct.PLL.PLLM = 4;
|
||
|
RCC_OscInitStruct.PLL.PLLN = 168;
|
||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||
|
*/
|
||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||
|
|
||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief DAC Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_DAC_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN DAC_Init 0 */
|
||
|
|
||
|
/* USER CODE END DAC_Init 0 */
|
||
|
|
||
|
DAC_ChannelConfTypeDef sConfig = {0};
|
||
|
|
||
|
/* USER CODE BEGIN DAC_Init 1 */
|
||
|
|
||
|
/* USER CODE END DAC_Init 1 */
|
||
|
|
||
|
/** DAC Initialization
|
||
|
*/
|
||
|
hdac.Instance = DAC;
|
||
|
if (HAL_DAC_Init(&hdac) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
/** DAC channel OUT1 config
|
||
|
*/
|
||
|
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
|
||
|
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
|
||
|
if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
/** DAC channel OUT2 config
|
||
|
*/
|
||
|
if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN DAC_Init 2 */
|
||
|
|
||
|
/* USER CODE END DAC_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief ETH Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_ETH_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN ETH_Init 0 */
|
||
|
|
||
|
/* USER CODE END ETH_Init 0 */
|
||
|
|
||
|
static uint8_t MACAddr[6];
|
||
|
|
||
|
/* USER CODE BEGIN ETH_Init 1 */
|
||
|
|
||
|
/* USER CODE END ETH_Init 1 */
|
||
|
heth.Instance = ETH;
|
||
|
MACAddr[0] = 0x00;
|
||
|
MACAddr[1] = 0x80;
|
||
|
MACAddr[2] = 0xE1;
|
||
|
MACAddr[3] = 0x00;
|
||
|
MACAddr[4] = 0x00;
|
||
|
MACAddr[5] = 0x00;
|
||
|
heth.Init.MACAddr = &MACAddr[0];
|
||
|
heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
|
||
|
heth.Init.TxDesc = DMATxDscrTab;
|
||
|
heth.Init.RxDesc = DMARxDscrTab;
|
||
|
heth.Init.RxBuffLen = 1524;
|
||
|
|
||
|
/* USER CODE BEGIN MACADDRESS */
|
||
|
|
||
|
/* USER CODE END MACADDRESS */
|
||
|
|
||
|
if (HAL_ETH_Init(&heth) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig));
|
||
|
TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;
|
||
|
TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
|
||
|
TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
|
||
|
/* USER CODE BEGIN ETH_Init 2 */
|
||
|
|
||
|
/* USER CODE END ETH_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief IWDG Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_IWDG_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN IWDG_Init 0 */
|
||
|
|
||
|
/* USER CODE END IWDG_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN IWDG_Init 1 */
|
||
|
|
||
|
/* USER CODE END IWDG_Init 1 */
|
||
|
hiwdg.Instance = IWDG;
|
||
|
hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
|
||
|
hiwdg.Init.Reload = 4095;
|
||
|
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN IWDG_Init 2 */
|
||
|
|
||
|
/* USER CODE END IWDG_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief RTC Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_RTC_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN RTC_Init 0 */
|
||
|
|
||
|
/* USER CODE END RTC_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN RTC_Init 1 */
|
||
|
|
||
|
/* USER CODE END RTC_Init 1 */
|
||
|
|
||
|
/** Initialize RTC Only
|
||
|
*/
|
||
|
hrtc.Instance = RTC;
|
||
|
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
||
|
hrtc.Init.AsynchPrediv = 127;
|
||
|
hrtc.Init.SynchPrediv = 255;
|
||
|
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||
|
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||
|
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||
|
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN RTC_Init 2 */
|
||
|
|
||
|
/* USER CODE END RTC_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief SDIO Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_SDIO_SD_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN SDIO_Init 0 */
|
||
|
|
||
|
/* USER CODE END SDIO_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN SDIO_Init 1 */
|
||
|
|
||
|
/* USER CODE END SDIO_Init 1 */
|
||
|
hsd.Instance = SDIO;
|
||
|
hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
||
|
hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
|
||
|
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||
|
hsd.Init.BusWide = SDIO_BUS_WIDE_4B;
|
||
|
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
|
||
|
hsd.Init.ClockDiv = 0;
|
||
|
if (HAL_SD_Init(&hsd) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN SDIO_Init 2 */
|
||
|
|
||
|
/* USER CODE END SDIO_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief SPI1 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_SPI1_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN SPI1_Init 0 */
|
||
|
|
||
|
/* USER CODE END SPI1_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN SPI1_Init 1 */
|
||
|
|
||
|
/* USER CODE END SPI1_Init 1 */
|
||
|
/* SPI1 parameter configuration*/
|
||
|
hspi1.Instance = SPI1;
|
||
|
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||
|
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||
|
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||
|
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||
|
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||
|
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||
|
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||
|
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||
|
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||
|
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||
|
hspi1.Init.CRCPolynomial = 10;
|
||
|
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN SPI1_Init 2 */
|
||
|
|
||
|
/* USER CODE END SPI1_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief SPI2 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_SPI2_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN SPI2_Init 0 */
|
||
|
|
||
|
/* USER CODE END SPI2_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN SPI2_Init 1 */
|
||
|
|
||
|
/* USER CODE END SPI2_Init 1 */
|
||
|
/* SPI2 parameter configuration*/
|
||
|
hspi2.Instance = SPI2;
|
||
|
hspi2.Init.Mode = SPI_MODE_MASTER;
|
||
|
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
|
||
|
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
|
||
|
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||
|
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||
|
hspi2.Init.NSS = SPI_NSS_SOFT;
|
||
|
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||
|
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||
|
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
||
|
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||
|
hspi2.Init.CRCPolynomial = 10;
|
||
|
if (HAL_SPI_Init(&hspi2) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN SPI2_Init 2 */
|
||
|
|
||
|
/* USER CODE END SPI2_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief TIM2 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_TIM2_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM2_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM2_Init 0 */
|
||
|
|
||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||
|
TIM_OC_InitTypeDef sConfigOC = {0};
|
||
|
|
||
|
/* USER CODE BEGIN TIM2_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM2_Init 1 */
|
||
|
htim2.Instance = TIM2;
|
||
|
htim2.Init.Prescaler = 0;
|
||
|
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||
|
htim2.Init.Period = 4294967295;
|
||
|
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||
|
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||
|
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||
|
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||
|
sConfigOC.Pulse = 0;
|
||
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||
|
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN TIM2_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM2_Init 2 */
|
||
|
HAL_TIM_MspPostInit(&htim2);
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief TIM3 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_TIM3_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM3_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM3_Init 0 */
|
||
|
|
||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||
|
TIM_OC_InitTypeDef sConfigOC = {0};
|
||
|
|
||
|
/* USER CODE BEGIN TIM3_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM3_Init 1 */
|
||
|
htim3.Instance = TIM3;
|
||
|
htim3.Init.Prescaler = 0;
|
||
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||
|
htim3.Init.Period = 65535;
|
||
|
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||
|
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||
|
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||
|
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||
|
sConfigOC.Pulse = 0;
|
||
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||
|
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN TIM3_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM3_Init 2 */
|
||
|
HAL_TIM_MspPostInit(&htim3);
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief TIM4 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_TIM4_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM4_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM4_Init 0 */
|
||
|
|
||
|
TIM_Encoder_InitTypeDef sConfig = {0};
|
||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||
|
|
||
|
/* USER CODE BEGIN TIM4_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM4_Init 1 */
|
||
|
htim4.Instance = TIM4;
|
||
|
htim4.Init.Prescaler = 0;
|
||
|
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||
|
htim4.Init.Period = 65535;
|
||
|
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||
|
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||
|
sConfig.EncoderMode = TIM_ENCODERMODE_TI1;
|
||
|
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
|
||
|
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
|
||
|
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
|
||
|
sConfig.IC1Filter = 0;
|
||
|
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
|
||
|
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
|
||
|
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
|
||
|
sConfig.IC2Filter = 0;
|
||
|
if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN TIM4_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM4_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief TIM11 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_TIM11_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM11_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM11_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN TIM11_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM11_Init 1 */
|
||
|
htim11.Instance = TIM11;
|
||
|
htim11.Init.Prescaler = 0;
|
||
|
htim11.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||
|
htim11.Init.Period = 65535;
|
||
|
htim11.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||
|
htim11.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||
|
if (HAL_TIM_Base_Init(&htim11) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN TIM11_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM11_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief TIM13 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_TIM13_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM13_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM13_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN TIM13_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM13_Init 1 */
|
||
|
htim13.Instance = TIM13;
|
||
|
htim13.Init.Prescaler = 0;
|
||
|
htim13.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||
|
htim13.Init.Period = 65535;
|
||
|
htim13.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||
|
htim13.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||
|
if (HAL_TIM_Base_Init(&htim13) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN TIM13_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM13_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief TIM14 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_TIM14_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM14_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM14_Init 0 */
|
||
|
|
||
|
TIM_OC_InitTypeDef sConfigOC = {0};
|
||
|
|
||
|
/* USER CODE BEGIN TIM14_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM14_Init 1 */
|
||
|
htim14.Instance = TIM14;
|
||
|
htim14.Init.Prescaler = 0;
|
||
|
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||
|
htim14.Init.Period = 65535;
|
||
|
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||
|
htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||
|
if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
if (HAL_TIM_PWM_Init(&htim14) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||
|
sConfigOC.Pulse = 0;
|
||
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||
|
if (HAL_TIM_PWM_ConfigChannel(&htim14, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN TIM14_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM14_Init 2 */
|
||
|
HAL_TIM_MspPostInit(&htim14);
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief USART1 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_USART1_UART_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN USART1_Init 0 */
|
||
|
|
||
|
/* USER CODE END USART1_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN USART1_Init 1 */
|
||
|
|
||
|
/* USER CODE END USART1_Init 1 */
|
||
|
huart1.Instance = USART1;
|
||
|
huart1.Init.BaudRate = 115200;
|
||
|
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||
|
huart1.Init.StopBits = UART_STOPBITS_1;
|
||
|
huart1.Init.Parity = UART_PARITY_NONE;
|
||
|
huart1.Init.Mode = UART_MODE_TX_RX;
|
||
|
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||
|
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||
|
if (HAL_UART_Init(&huart1) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN USART1_Init 2 */
|
||
|
|
||
|
/* USER CODE END USART1_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief USART3 Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_USART3_UART_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN USART3_Init 0 */
|
||
|
|
||
|
/* USER CODE END USART3_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN USART3_Init 1 */
|
||
|
|
||
|
/* USER CODE END USART3_Init 1 */
|
||
|
huart3.Instance = USART3;
|
||
|
huart3.Init.BaudRate = 115200;
|
||
|
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||
|
huart3.Init.StopBits = UART_STOPBITS_1;
|
||
|
huart3.Init.Parity = UART_PARITY_NONE;
|
||
|
huart3.Init.Mode = UART_MODE_TX_RX;
|
||
|
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||
|
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
|
||
|
if (HAL_UART_Init(&huart3) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN USART3_Init 2 */
|
||
|
|
||
|
/* USER CODE END USART3_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief USB_OTG_FS Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_USB_OTG_FS_PCD_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN USB_OTG_FS_Init 0 */
|
||
|
|
||
|
/* USER CODE END USB_OTG_FS_Init 0 */
|
||
|
|
||
|
/* USER CODE BEGIN USB_OTG_FS_Init 1 */
|
||
|
|
||
|
/* USER CODE END USB_OTG_FS_Init 1 */
|
||
|
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
|
||
|
hpcd_USB_OTG_FS.Init.dev_endpoints = 4;
|
||
|
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
|
||
|
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
|
||
|
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||
|
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
|
||
|
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
|
||
|
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
|
||
|
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
|
||
|
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
|
||
|
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
/* USER CODE BEGIN USB_OTG_FS_Init 2 */
|
||
|
|
||
|
/* USER CODE END USB_OTG_FS_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief GPIO Initialization Function
|
||
|
* @param None
|
||
|
* @retval None
|
||
|
*/
|
||
|
static void MX_GPIO_Init(void)
|
||
|
{
|
||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||
|
|
||
|
/* GPIO Ports Clock Enable */
|
||
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||
|
|
||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||
|
}
|
||
|
|
||
|
/* FSMC initialization function */
|
||
|
static void MX_FSMC_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN FSMC_Init 0 */
|
||
|
|
||
|
/* USER CODE END FSMC_Init 0 */
|
||
|
|
||
|
FSMC_NORSRAM_TimingTypeDef Timing = {0};
|
||
|
|
||
|
/* USER CODE BEGIN FSMC_Init 1 */
|
||
|
|
||
|
/* USER CODE END FSMC_Init 1 */
|
||
|
|
||
|
/** Perform the SRAM1 memory initialization sequence
|
||
|
*/
|
||
|
hsram1.Instance = FSMC_NORSRAM_DEVICE;
|
||
|
hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
|
||
|
/* hsram1.Init */
|
||
|
hsram1.Init.NSBank = FSMC_NORSRAM_BANK3;
|
||
|
hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
|
||
|
hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
|
||
|
hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_8;
|
||
|
hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
|
||
|
hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
|
||
|
hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
|
||
|
hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
|
||
|
hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
|
||
|
hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
|
||
|
hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
|
||
|
hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
|
||
|
hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
|
||
|
hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE;
|
||
|
/* Timing */
|
||
|
Timing.AddressSetupTime = 15;
|
||
|
Timing.AddressHoldTime = 15;
|
||
|
Timing.DataSetupTime = 255;
|
||
|
Timing.BusTurnAroundDuration = 15;
|
||
|
Timing.CLKDivision = 16;
|
||
|
Timing.DataLatency = 17;
|
||
|
Timing.AccessMode = FSMC_ACCESS_MODE_A;
|
||
|
/* ExtTiming */
|
||
|
|
||
|
if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler( );
|
||
|
}
|
||
|
|
||
|
/* USER CODE BEGIN FSMC_Init 2 */
|
||
|
|
||
|
/* USER CODE END FSMC_Init 2 */
|
||
|
}
|
||
|
|
||
|
/* USER CODE BEGIN 4 */
|
||
|
|
||
|
/* USER CODE END 4 */
|
||
|
|
||
|
/**
|
||
|
* @brief This function is executed in case of error occurrence.
|
||
|
* @retval None
|
||
|
*/
|
||
|
void Error_Handler(void)
|
||
|
{
|
||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||
|
/* User can add his own implementation to report the HAL error return state */
|
||
|
__disable_irq();
|
||
|
while (1)
|
||
|
{
|
||
|
}
|
||
|
/* USER CODE END Error_Handler_Debug */
|
||
|
}
|
||
|
|
||
|
#ifdef USE_FULL_ASSERT
|
||
|
/**
|
||
|
* @brief Reports the name of the source file and the source line number
|
||
|
* where the assert_param error has occurred.
|
||
|
* @param file: pointer to the source file name
|
||
|
* @param line: assert_param error line source number
|
||
|
* @retval None
|
||
|
*/
|
||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||
|
{
|
||
|
/* USER CODE BEGIN 6 */
|
||
|
/* User can add his own implementation to report the file name and line number,
|
||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||
|
/* USER CODE END 6 */
|
||
|
}
|
||
|
#endif /* USE_FULL_ASSERT */
|