Advertisement
Guest User

Untitled

a guest
Aug 18th, 2021
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 43.83 KB
  1. /* USER CODE END Header */
  2. /* Includes ------------------------------------------------------------------*/
  3. #include "main.h"
  4. #include "fatfs.h"
  5. #include "usb_device.h"
  6.  
  7. /* Private includes ----------------------------------------------------------*/
  8. /* USER CODE BEGIN Includes */
  9. #include "STM32 PLC/Functions.h"
  10. /* USER CODE END Includes */
  11.  
  12. /* Private typedef -----------------------------------------------------------*/
  13. /* USER CODE BEGIN PTD */
  14.  
  15. /* USER CODE END PTD */
  16.  
  17. /* Private define ------------------------------------------------------------*/
  18. /* USER CODE BEGIN PD */
  19. /* USER CODE END PD */
  20.  
  21. /* Private macro -------------------------------------------------------------*/
  22. /* USER CODE BEGIN PM */
  23.  
  24. /* USER CODE END PM */
  25.  
  26. /* Private variables ---------------------------------------------------------*/
  27. CAN_HandleTypeDef hcan;
  28.  
  29. DAC_HandleTypeDef hdac1;
  30. DAC_HandleTypeDef hdac2;
  31.  
  32. RTC_HandleTypeDef hrtc;
  33.  
  34. SDADC_HandleTypeDef hsdadc1;
  35. SDADC_HandleTypeDef hsdadc2;
  36. SDADC_HandleTypeDef hsdadc3;
  37. DMA_HandleTypeDef hdma_sdadc1;
  38. DMA_HandleTypeDef hdma_sdadc2;
  39. DMA_HandleTypeDef hdma_sdadc3;
  40.  
  41. SPI_HandleTypeDef hspi1;
  42. SPI_HandleTypeDef hspi2;
  43.  
  44. TIM_HandleTypeDef htim2;
  45. TIM_HandleTypeDef htim4;
  46. TIM_HandleTypeDef htim5;
  47. TIM_HandleTypeDef htim6;
  48. TIM_HandleTypeDef htim12;
  49. TIM_HandleTypeDef htim13;
  50. TIM_HandleTypeDef htim16;
  51. TIM_HandleTypeDef htim17;
  52. TIM_HandleTypeDef htim19;
  53. DMA_HandleTypeDef hdma_tim16_ch1_up;
  54. DMA_HandleTypeDef hdma_tim17_ch1_up;
  55.  
  56. UART_HandleTypeDef huart1;
  57.  
  58. /* USER CODE BEGIN PV */
  59.  
  60. /* USER CODE END PV */
  61.  
  62. /* Private function prototypes -----------------------------------------------*/
  63. void SystemClock_Config(void);
  64. static void MX_GPIO_Init(void);
  65. static void MX_DAC1_Init(void);
  66. static void MX_DAC2_Init(void);
  67. static void MX_RTC_Init(void);
  68. static void MX_SPI2_Init(void);
  69. static void MX_TIM2_Init(void);
  70. static void MX_TIM5_Init(void);
  71. static void MX_SPI1_Init(void);
  72. static void MX_TIM4_Init(void);
  73. static void MX_SDADC1_Init(void);
  74. static void MX_SDADC2_Init(void);
  75. static void MX_SDADC3_Init(void);
  76. static void MX_CAN_Init(void);
  77. static void MX_USART1_UART_Init(void);
  78. static void MX_TIM6_Init(void);
  79. static void MX_TIM12_Init(void);
  80. static void MX_TIM13_Init(void);
  81. static void MX_TIM16_Init(void);
  82. static void MX_TIM17_Init(void);
  83. static void MX_DMA_Init(void);
  84. static void MX_TIM19_Init(void);
  85. /* USER CODE BEGIN PFP */
  86.  
  87. /* USER CODE END PFP */
  88.  
  89. /* Private user code ---------------------------------------------------------*/
  90. /* USER CODE BEGIN 0 */
  91.  
  92. /* USER CODE END 0 */
  93.  
  94. /**
  95.   * @brief  The application entry point.
  96.   * @retval int
  97.   */
  98. int main(void)
  99. {
  100.   /* USER CODE BEGIN 1 */
  101.  
  102.   /* USER CODE END 1 */
  103.  
  104.   /* MCU Configuration--------------------------------------------------------*/
  105.  
  106.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  107.   HAL_Init();
  108.  
  109.   /* USER CODE BEGIN Init */
  110.  
  111.   /* USER CODE END Init */
  112.  
  113.   /* Configure the system clock */
  114.   SystemClock_Config();
  115.  
  116.   /* USER CODE BEGIN SysInit */
  117.  
  118.   /* USER CODE END SysInit */
  119.  
  120.   /* Initialize all configured peripherals */
  121.   MX_GPIO_Init();
  122.   MX_DAC1_Init();
  123.   MX_DAC2_Init();
  124.   MX_RTC_Init();
  125.   MX_SPI2_Init();
  126.   MX_TIM2_Init();
  127.   MX_TIM5_Init();
  128.   MX_SPI1_Init();
  129.   MX_TIM4_Init();
  130.   MX_SDADC1_Init();
  131.   MX_SDADC2_Init();
  132.   MX_SDADC3_Init();
  133.   MX_CAN_Init();
  134.   MX_USART1_UART_Init();
  135.   MX_TIM6_Init();
  136.   MX_TIM12_Init();
  137.   MX_TIM13_Init();
  138.   MX_TIM16_Init();
  139.   MX_USB_DEVICE_Init();
  140.   MX_FATFS_Init();
  141.   MX_TIM17_Init();
  142.   MX_DMA_Init();
  143.   MX_TIM19_Init();
  144.   /* USER CODE BEGIN 2 */
  145.  
  146.   /* SAE J1939 */
  147.   J1939 j1939 = {0};
  148.   for(uint8_t i = 0; i < 0xFF; i++)
  149.       j1939.ECU_address[i] = 0xFF;
  150.  
  151.   /* Start */
  152.   STM32_PLC_Start_Analog_Input(&htim12, &htim13, &hsdadc1, &hsdadc2, &hsdadc3);
  153.   STM32_PLC_Start_Analog_Output(&hdac1, &hdac2, &htim6);
  154.   STM32_PLC_Start_Encoder(&htim4, &htim19);
  155.   STM32_PLC_Start_Input_Capture(&htim17, &htim16);
  156.   STM32_PLC_Start_PWM(&htim2, &htim5);
  157.   STM32_PLC_Start_SD(&hspi2, SD_CS_GPIO_Port, SD_CS_Pin);
  158.   STM32_PLC_Start_RTC(&hrtc);
  159.   STM32_PLC_Start_CAN(&hcan, &j1939);
  160.   STM32_PLC_Start_LCD(&hspi1, &hspi2, LCD_CS_GPIO_Port, LCD_CS_Pin, LCD_DC_GPIO_Port, LCD_DC_Pin, LCD_RST_GPIO_Port, LCD_RST_Pin, TS_CS_GPIO_Port, TS_CS_Pin);
  161.  
  162.   /* Reset outputs */
  163.   STM32_PLC_PWM_Reset();
  164.   STM32_PLC_Analog_Output_Reset();
  165.  
  166.   /* If we are going to send and receive the ECU identification and component identification, we need to specify the size of them */
  167.   j1939.this_identifications.ecu_identification.length_of_each_field = 30;
  168.   j1939.this_identifications.component_identification.length_of_each_field = 30;
  169.   j1939.from_other_ecu_identifications.ecu_identification.length_of_each_field = 30;
  170.   j1939.from_other_ecu_identifications.component_identification.length_of_each_field = 30;
  171.  
  172.   /* LCD */
  173.   //STM32_PLC_LCD_Show_Intro_Frame();
  174.   uint8_t frame_id = 0;
  175.   STM32_PLC_LCD_Show_Main_Frame(&frame_id, false);
  176.  
  177.   /* Mount SD card and read initial start up */
  178.   STM32_PLC_Initial_Startup(&j1939);
  179.  
  180.   /* USER CODE END 2 */
  181.  
  182.   /* Infinite loop */
  183.   /* USER CODE BEGIN WHILE */
  184.   while (1)
  185.   {
  186.     /* USER CODE END WHILE */
  187.  
  188.     /* USER CODE BEGIN 3 */
  189.  
  190.       /* Listen for frame changes */
  191.       STM32_PLC_LCD_Call_Main_Logic(&frame_id, &j1939);
  192.       /* Perform control program */
  193.       STM32_PLC_LCD_Execute_Control_Program(&j1939);
  194.  
  195.   }
  196.   /* USER CODE END 3 */
  197. }
  198.  
  199. /**
  200.   * @brief System Clock Configuration
  201.   * @retval None
  202.   */
  203. void SystemClock_Config(void)
  204. {
  205.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  206.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  207.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  208.  
  209.   /** Initializes the RCC Oscillators according to the specified parameters
  210.   * in the RCC_OscInitTypeDef structure.
  211.   */
  212.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  213.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  214.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  215.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  216.   RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  217.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  218.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  219.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  220.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  221.   {
  222.     Error_Handler();
  223.   }
  224.   /** Initializes the CPU, AHB and APB buses clocks
  225.   */
  226.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  227.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  228.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  229.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  230.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  231.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  232.  
  233.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  234.   {
  235.     Error_Handler();
  236.   }
  237.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_USART1
  238.                               |RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_SDADC;
  239.   PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  240.   PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  241.   PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL;
  242.   PeriphClkInit.SdadcClockSelection = RCC_SDADCSYSCLK_DIV8;
  243.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  244.   {
  245.     Error_Handler();
  246.   }
  247.   HAL_PWREx_EnableSDADC(PWR_SDADC_ANALOG1);
  248.   HAL_PWREx_EnableSDADC(PWR_SDADC_ANALOG2);
  249.   HAL_PWREx_EnableSDADC(PWR_SDADC_ANALOG3);
  250. }
  251.  
  252. /**
  253.   * @brief CAN Initialization Function
  254.   * @param None
  255.   * @retval None
  256.   */
  257. static void MX_CAN_Init(void)
  258. {
  259.  
  260.   /* USER CODE BEGIN CAN_Init 0 */
  261.  
  262.   /* USER CODE END CAN_Init 0 */
  263.  
  264.   /* USER CODE BEGIN CAN_Init 1 */
  265.  
  266.   /* USER CODE END CAN_Init 1 */
  267.   hcan.Instance = CAN;
  268.   hcan.Init.Prescaler = 16;
  269.   hcan.Init.Mode = CAN_MODE_NORMAL;
  270.   hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
  271.   hcan.Init.TimeSeg1 = CAN_BS1_3TQ;
  272.   hcan.Init.TimeSeg2 = CAN_BS2_2TQ;
  273.   hcan.Init.TimeTriggeredMode = DISABLE;
  274.   hcan.Init.AutoBusOff = DISABLE;
  275.   hcan.Init.AutoWakeUp = DISABLE;
  276.   hcan.Init.AutoRetransmission = DISABLE;
  277.   hcan.Init.ReceiveFifoLocked = DISABLE;
  278.   hcan.Init.TransmitFifoPriority = DISABLE;
  279.   if (HAL_CAN_Init(&hcan) != HAL_OK)
  280.   {
  281.     Error_Handler();
  282.   }
  283.   /* USER CODE BEGIN CAN_Init 2 */
  284.  
  285.   /* USER CODE END CAN_Init 2 */
  286.  
  287. }
  288.  
  289. /**
  290.   * @brief DAC1 Initialization Function
  291.   * @param None
  292.   * @retval None
  293.   */
  294. static void MX_DAC1_Init(void)
  295. {
  296.  
  297.   /* USER CODE BEGIN DAC1_Init 0 */
  298.  
  299.   /* USER CODE END DAC1_Init 0 */
  300.  
  301.   DAC_ChannelConfTypeDef sConfig = {0};
  302.  
  303.   /* USER CODE BEGIN DAC1_Init 1 */
  304.  
  305.   /* USER CODE END DAC1_Init 1 */
  306.   /** DAC Initialization
  307.   */
  308.   hdac1.Instance = DAC1;
  309.   if (HAL_DAC_Init(&hdac1) != HAL_OK)
  310.   {
  311.     Error_Handler();
  312.   }
  313.   /** DAC channel OUT1 config
  314.   */
  315.   sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
  316.   sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  317.   if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
  318.   {
  319.     Error_Handler();
  320.   }
  321.   /** DAC channel OUT2 config
  322.   */
  323.   if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
  324.   {
  325.     Error_Handler();
  326.   }
  327.   /* USER CODE BEGIN DAC1_Init 2 */
  328.  
  329.   /* USER CODE END DAC1_Init 2 */
  330.  
  331. }
  332.  
  333. /**
  334.   * @brief DAC2 Initialization Function
  335.   * @param None
  336.   * @retval None
  337.   */
  338. static void MX_DAC2_Init(void)
  339. {
  340.  
  341.   /* USER CODE BEGIN DAC2_Init 0 */
  342.  
  343.   /* USER CODE END DAC2_Init 0 */
  344.  
  345.   DAC_ChannelConfTypeDef sConfig = {0};
  346.  
  347.   /* USER CODE BEGIN DAC2_Init 1 */
  348.  
  349.   /* USER CODE END DAC2_Init 1 */
  350.   /** DAC Initialization
  351.   */
  352.   hdac2.Instance = DAC2;
  353.   if (HAL_DAC_Init(&hdac2) != HAL_OK)
  354.   {
  355.     Error_Handler();
  356.   }
  357.   /** DAC channel OUT1 config
  358.   */
  359.   sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
  360.   sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  361.   if (HAL_DAC_ConfigChannel(&hdac2, &sConfig, DAC_CHANNEL_1) != HAL_OK)
  362.   {
  363.     Error_Handler();
  364.   }
  365.   /* USER CODE BEGIN DAC2_Init 2 */
  366.  
  367.   /* USER CODE END DAC2_Init 2 */
  368.  
  369. }
  370.  
  371. /**
  372.   * @brief RTC Initialization Function
  373.   * @param None
  374.   * @retval None
  375.   */
  376. static void MX_RTC_Init(void)
  377. {
  378.  
  379.   /* USER CODE BEGIN RTC_Init 0 */
  380.  
  381.   /* USER CODE END RTC_Init 0 */
  382.  
  383.   RTC_TimeTypeDef sTime = {0};
  384.   RTC_DateTypeDef sDate = {0};
  385.   RTC_AlarmTypeDef sAlarm = {0};
  386.  
  387.   /* USER CODE BEGIN RTC_Init 1 */
  388.  
  389.   /* USER CODE END RTC_Init 1 */
  390.   /** Initialize RTC Only
  391.   */
  392.   hrtc.Instance = RTC;
  393.   hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  394.   hrtc.Init.AsynchPrediv = 127;
  395.   hrtc.Init.SynchPrediv = 255;
  396.   hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  397.   hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  398.   hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  399.   if (HAL_RTC_Init(&hrtc) != HAL_OK)
  400.   {
  401.     Error_Handler();
  402.   }
  403.  
  404.   /* USER CODE BEGIN Check_RTC_BKUP */
  405.  
  406.   /* USER CODE END Check_RTC_BKUP */
  407.  
  408.   /** Initialize RTC and set the Time and Date
  409.   */
  410.   sTime.Hours = 0;
  411.   sTime.Minutes = 0;
  412.   sTime.Seconds = 0;
  413.   sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  414.   sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  415.   if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  416.   {
  417.     Error_Handler();
  418.   }
  419.   sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  420.   sDate.Month = RTC_MONTH_JANUARY;
  421.   sDate.Date = 1;
  422.   sDate.Year = 0;
  423.  
  424.   if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
  425.   {
  426.     Error_Handler();
  427.   }
  428.   /** Enable the Alarm A
  429.   */
  430.   sAlarm.AlarmTime.Hours = 0;
  431.   sAlarm.AlarmTime.Minutes = 0;
  432.   sAlarm.AlarmTime.Seconds = 0;
  433.   sAlarm.AlarmTime.SubSeconds = 0;
  434.   sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  435.   sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
  436.   sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
  437.   sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
  438.   sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
  439.   sAlarm.AlarmDateWeekDay = 1;
  440.   sAlarm.Alarm = RTC_ALARM_A;
  441.   if (HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
  442.   {
  443.     Error_Handler();
  444.   }
  445.   /** Enable the Alarm B
  446.   */
  447.   sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
  448.   sAlarm.Alarm = RTC_ALARM_B;
  449.   /* USER CODE BEGIN RTC_Init 2 */
  450.  
  451.   /* USER CODE END RTC_Init 2 */
  452.  
  453. }
  454.  
  455. /**
  456.   * @brief SDADC1 Initialization Function
  457.   * @param None
  458.   * @retval None
  459.   */
  460. static void MX_SDADC1_Init(void)
  461. {
  462.  
  463.   /* USER CODE BEGIN SDADC1_Init 0 */
  464.  
  465.   /* USER CODE END SDADC1_Init 0 */
  466.  
  467.   SDADC_ConfParamTypeDef ConfParamStruct = {0};
  468.  
  469.   /* USER CODE BEGIN SDADC1_Init 1 */
  470.  
  471.   /* USER CODE END SDADC1_Init 1 */
  472.   /** Configure the SDADC low power mode, fast conversion mode,
  473.   slow clock mode and SDADC1 reference voltage
  474.   */
  475.   hsdadc1.Instance = SDADC1;
  476.   hsdadc1.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
  477.   hsdadc1.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
  478.   hsdadc1.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
  479.   hsdadc1.Init.ReferenceVoltage = SDADC_VREF_EXT;
  480.   hsdadc1.InjectedTrigger = SDADC_EXTERNAL_TRIGGER;
  481.   hsdadc1.ExtTriggerEdge = SDADC_EXT_TRIG_RISING_EDGE;
  482.   if (HAL_SDADC_Init(&hsdadc1) != HAL_OK)
  483.   {
  484.     Error_Handler();
  485.   }
  486.   /** Configure the Injected Mode
  487.   */
  488.   if (HAL_SDADC_SelectInjectedDelay(&hsdadc1, SDADC_INJECTED_DELAY_NONE) != HAL_OK)
  489.   {
  490.     Error_Handler();
  491.   }
  492.   if (HAL_SDADC_SelectInjectedExtTrigger(&hsdadc1, SDADC_EXT_TRIG_TIM13_CC1, SDADC_EXT_TRIG_RISING_EDGE) != HAL_OK)
  493.   {
  494.     Error_Handler();
  495.   }
  496.   if (HAL_SDADC_SelectInjectedTrigger(&hsdadc1, SDADC_EXTERNAL_TRIGGER) != HAL_OK)
  497.   {
  498.     Error_Handler();
  499.   }
  500.   if (HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_0|SDADC_CHANNEL_1
  501.                               |SDADC_CHANNEL_2|SDADC_CHANNEL_3
  502.                               |SDADC_CHANNEL_4|SDADC_CHANNEL_5
  503.                               |SDADC_CHANNEL_6|SDADC_CHANNEL_7
  504.                               |SDADC_CHANNEL_8, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
  505.   {
  506.     Error_Handler();
  507.   }
  508.   /** Set parameters for SDADC configuration 0 Register
  509.   */
  510.   ConfParamStruct.InputMode = SDADC_INPUT_MODE_SE_ZERO_REFERENCE;
  511.   ConfParamStruct.Gain = SDADC_GAIN_1;
  512.   ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
  513.   ConfParamStruct.Offset = 0;
  514.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK)
  515.   {
  516.     Error_Handler();
  517.   }
  518.   /** Set parameters for SDADC configuration 1 Register
  519.   */
  520.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_1, &ConfParamStruct) != HAL_OK)
  521.   {
  522.     Error_Handler();
  523.   }
  524.   /** Set parameters for SDADC configuration 2 Register
  525.   */
  526.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_2, &ConfParamStruct) != HAL_OK)
  527.   {
  528.     Error_Handler();
  529.   }
  530.   /** Configure the Injected Channel
  531.   */
  532.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_0, SDADC_CONF_INDEX_0) != HAL_OK)
  533.   {
  534.     Error_Handler();
  535.   }
  536.   /** Configure the Injected Channel
  537.   */
  538.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_1, SDADC_CONF_INDEX_0) != HAL_OK)
  539.   {
  540.     Error_Handler();
  541.   }
  542.   /** Configure the Injected Channel
  543.   */
  544.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_2, SDADC_CONF_INDEX_0) != HAL_OK)
  545.   {
  546.     Error_Handler();
  547.   }
  548.   /** Configure the Injected Channel
  549.   */
  550.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_3, SDADC_CONF_INDEX_1) != HAL_OK)
  551.   {
  552.     Error_Handler();
  553.   }
  554.   /** Configure the Injected Channel
  555.   */
  556.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_4, SDADC_CONF_INDEX_1) != HAL_OK)
  557.   {
  558.     Error_Handler();
  559.   }
  560.   /** Configure the Injected Channel
  561.   */
  562.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_5, SDADC_CONF_INDEX_1) != HAL_OK)
  563.   {
  564.     Error_Handler();
  565.   }
  566.   /** Configure the Injected Channel
  567.   */
  568.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_6, SDADC_CONF_INDEX_2) != HAL_OK)
  569.   {
  570.     Error_Handler();
  571.   }
  572.   /** Configure the Injected Channel
  573.   */
  574.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_7, SDADC_CONF_INDEX_2) != HAL_OK)
  575.   {
  576.     Error_Handler();
  577.   }
  578.   /** Configure the Injected Channel
  579.   */
  580.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_8, SDADC_CONF_INDEX_2) != HAL_OK)
  581.   {
  582.     Error_Handler();
  583.   }
  584.   /* USER CODE BEGIN SDADC1_Init 2 */
  585.  
  586.   /* USER CODE END SDADC1_Init 2 */
  587.  
  588. }
  589.  
  590. /**
  591.   * @brief SDADC2 Initialization Function
  592.   * @param None
  593.   * @retval None
  594.   */
  595. static void MX_SDADC2_Init(void)
  596. {
  597.  
  598.   /* USER CODE BEGIN SDADC2_Init 0 */
  599.  
  600.   /* USER CODE END SDADC2_Init 0 */
  601.  
  602.   SDADC_ConfParamTypeDef ConfParamStruct = {0};
  603.  
  604.   /* USER CODE BEGIN SDADC2_Init 1 */
  605.  
  606.   /* USER CODE END SDADC2_Init 1 */
  607.   /** Configure the SDADC low power mode, fast conversion mode,
  608.   slow clock mode and SDADC1 reference voltage
  609.   */
  610.   hsdadc2.Instance = SDADC2;
  611.   hsdadc2.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
  612.   hsdadc2.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
  613.   hsdadc2.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
  614.   hsdadc2.Init.ReferenceVoltage = SDADC_VREF_EXT;
  615.   hsdadc2.InjectedTrigger = SDADC_EXTERNAL_TRIGGER;
  616.   hsdadc2.ExtTriggerEdge = SDADC_EXT_TRIG_RISING_EDGE;
  617.   if (HAL_SDADC_Init(&hsdadc2) != HAL_OK)
  618.   {
  619.     Error_Handler();
  620.   }
  621.   /** Configure the Injected Mode
  622.   */
  623.   if (HAL_SDADC_SelectInjectedDelay(&hsdadc2, SDADC_INJECTED_DELAY_NONE) != HAL_OK)
  624.   {
  625.     Error_Handler();
  626.   }
  627.   if (HAL_SDADC_SelectInjectedExtTrigger(&hsdadc2, SDADC_EXT_TRIG_TIM12_CC1, SDADC_EXT_TRIG_RISING_EDGE) != HAL_OK)
  628.   {
  629.     Error_Handler();
  630.   }
  631.   if (HAL_SDADC_SelectInjectedTrigger(&hsdadc2, SDADC_EXTERNAL_TRIGGER) != HAL_OK)
  632.   {
  633.     Error_Handler();
  634.   }
  635.   if (HAL_SDADC_InjectedConfigChannel(&hsdadc2, SDADC_CHANNEL_0|SDADC_CHANNEL_1
  636.                               |SDADC_CHANNEL_2, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
  637.   {
  638.     Error_Handler();
  639.   }
  640.   /** Set parameters for SDADC configuration 0 Register
  641.   */
  642.   ConfParamStruct.InputMode = SDADC_INPUT_MODE_SE_ZERO_REFERENCE;
  643.   ConfParamStruct.Gain = SDADC_GAIN_1;
  644.   ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
  645.   ConfParamStruct.Offset = 0;
  646.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc2, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK)
  647.   {
  648.     Error_Handler();
  649.   }
  650.   /** Set parameters for SDADC configuration 1 Register
  651.   */
  652.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc2, SDADC_CONF_INDEX_1, &ConfParamStruct) != HAL_OK)
  653.   {
  654.     Error_Handler();
  655.   }
  656.   /** Set parameters for SDADC configuration 2 Register
  657.   */
  658.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc2, SDADC_CONF_INDEX_2, &ConfParamStruct) != HAL_OK)
  659.   {
  660.     Error_Handler();
  661.   }
  662.   /** Configure the Injected Channel
  663.   */
  664.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc2, SDADC_CHANNEL_0, SDADC_CONF_INDEX_0) != HAL_OK)
  665.   {
  666.     Error_Handler();
  667.   }
  668.   /** Configure the Injected Channel
  669.   */
  670.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc2, SDADC_CHANNEL_1, SDADC_CONF_INDEX_1) != HAL_OK)
  671.   {
  672.     Error_Handler();
  673.   }
  674.   /** Configure the Injected Channel
  675.   */
  676.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc2, SDADC_CHANNEL_2, SDADC_CONF_INDEX_2) != HAL_OK)
  677.   {
  678.     Error_Handler();
  679.   }
  680.   /* USER CODE BEGIN SDADC2_Init 2 */
  681.  
  682.   /* USER CODE END SDADC2_Init 2 */
  683.  
  684. }
  685.  
  686. /**
  687.   * @brief SDADC3 Initialization Function
  688.   * @param None
  689.   * @retval None
  690.   */
  691. static void MX_SDADC3_Init(void)
  692. {
  693.  
  694.   /* USER CODE BEGIN SDADC3_Init 0 */
  695.  
  696.   /* USER CODE END SDADC3_Init 0 */
  697.  
  698.   SDADC_ConfParamTypeDef ConfParamStruct = {0};
  699.  
  700.   /* USER CODE BEGIN SDADC3_Init 1 */
  701.  
  702.   /* USER CODE END SDADC3_Init 1 */
  703.   /** Configure the SDADC low power mode, fast conversion mode,
  704.   slow clock mode and SDADC1 reference voltage
  705.   */
  706.   hsdadc3.Instance = SDADC3;
  707.   hsdadc3.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
  708.   hsdadc3.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
  709.   hsdadc3.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
  710.   hsdadc3.Init.ReferenceVoltage = SDADC_VREF_EXT;
  711.   hsdadc3.InjectedTrigger = SDADC_EXTERNAL_TRIGGER;
  712.   hsdadc3.ExtTriggerEdge = SDADC_EXT_TRIG_RISING_EDGE;
  713.   if (HAL_SDADC_Init(&hsdadc3) != HAL_OK)
  714.   {
  715.     Error_Handler();
  716.   }
  717.   /** Configure the Injected Mode
  718.   */
  719.   if (HAL_SDADC_SelectInjectedDelay(&hsdadc3, SDADC_INJECTED_DELAY_NONE) != HAL_OK)
  720.   {
  721.     Error_Handler();
  722.   }
  723.   if (HAL_SDADC_SelectInjectedExtTrigger(&hsdadc3, SDADC_EXT_TRIG_TIM12_CC2, SDADC_EXT_TRIG_RISING_EDGE) != HAL_OK)
  724.   {
  725.     Error_Handler();
  726.   }
  727.   if (HAL_SDADC_SelectInjectedTrigger(&hsdadc3, SDADC_EXTERNAL_TRIGGER) != HAL_OK)
  728.   {
  729.     Error_Handler();
  730.   }
  731.   if (HAL_SDADC_InjectedConfigChannel(&hsdadc3, SDADC_CHANNEL_0|SDADC_CHANNEL_2
  732.                               |SDADC_CHANNEL_4|SDADC_CHANNEL_6
  733.                               |SDADC_CHANNEL_8, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
  734.   {
  735.     Error_Handler();
  736.   }
  737.   /** Set parameters for SDADC configuration 0 Register
  738.   */
  739.   ConfParamStruct.InputMode = SDADC_INPUT_MODE_DIFF;
  740.   ConfParamStruct.Gain = SDADC_GAIN_1;
  741.   ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
  742.   ConfParamStruct.Offset = 0;
  743.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc3, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK)
  744.   {
  745.     Error_Handler();
  746.   }
  747.   /** Set parameters for SDADC configuration 1 Register
  748.   */
  749.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc3, SDADC_CONF_INDEX_1, &ConfParamStruct) != HAL_OK)
  750.   {
  751.     Error_Handler();
  752.   }
  753.   /** Set parameters for SDADC configuration 2 Register
  754.   */
  755.   if (HAL_SDADC_PrepareChannelConfig(&hsdadc3, SDADC_CONF_INDEX_2, &ConfParamStruct) != HAL_OK)
  756.   {
  757.     Error_Handler();
  758.   }
  759.   /** Configure the Injected Channel
  760.   */
  761.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc3, SDADC_CHANNEL_0, SDADC_CONF_INDEX_0) != HAL_OK)
  762.   {
  763.     Error_Handler();
  764.   }
  765.   /** Configure the Injected Channel
  766.   */
  767.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc3, SDADC_CHANNEL_2, SDADC_CONF_INDEX_0) != HAL_OK)
  768.   {
  769.     Error_Handler();
  770.   }
  771.   /** Configure the Injected Channel
  772.   */
  773.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc3, SDADC_CHANNEL_4, SDADC_CONF_INDEX_1) != HAL_OK)
  774.   {
  775.     Error_Handler();
  776.   }
  777.   /** Configure the Injected Channel
  778.   */
  779.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc3, SDADC_CHANNEL_6, SDADC_CONF_INDEX_1) != HAL_OK)
  780.   {
  781.     Error_Handler();
  782.   }
  783.   /** Configure the Injected Channel
  784.   */
  785.   if (HAL_SDADC_AssociateChannelConfig(&hsdadc3, SDADC_CHANNEL_8, SDADC_CONF_INDEX_2) != HAL_OK)
  786.   {
  787.     Error_Handler();
  788.   }
  789.   /* USER CODE BEGIN SDADC3_Init 2 */
  790.  
  791.   /* USER CODE END SDADC3_Init 2 */
  792.  
  793. }
  794.  
  795. /**
  796.   * @brief SPI1 Initialization Function
  797.   * @param None
  798.   * @retval None
  799.   */
  800. static void MX_SPI1_Init(void)
  801. {
  802.  
  803.   /* USER CODE BEGIN SPI1_Init 0 */
  804.  
  805.   /* USER CODE END SPI1_Init 0 */
  806.  
  807.   /* USER CODE BEGIN SPI1_Init 1 */
  808.  
  809.   /* USER CODE END SPI1_Init 1 */
  810.   /* SPI1 parameter configuration*/
  811.   hspi1.Instance = SPI1;
  812.   hspi1.Init.Mode = SPI_MODE_MASTER;
  813.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  814.   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  815.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  816.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  817.   hspi1.Init.NSS = SPI_NSS_SOFT;
  818.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  819.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  820.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  821.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  822.   hspi1.Init.CRCPolynomial = 7;
  823.   hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  824.   hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  825.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  826.   {
  827.     Error_Handler();
  828.   }
  829.   /* USER CODE BEGIN SPI1_Init 2 */
  830.  
  831.   /* USER CODE END SPI1_Init 2 */
  832.  
  833. }
  834.  
  835. /**
  836.   * @brief SPI2 Initialization Function
  837.   * @param None
  838.   * @retval None
  839.   */
  840. static void MX_SPI2_Init(void)
  841. {
  842.  
  843.   /* USER CODE BEGIN SPI2_Init 0 */
  844.  
  845.   /* USER CODE END SPI2_Init 0 */
  846.  
  847.   /* USER CODE BEGIN SPI2_Init 1 */
  848.  
  849.   /* USER CODE END SPI2_Init 1 */
  850.   /* SPI2 parameter configuration*/
  851.   hspi2.Instance = SPI2;
  852.   hspi2.Init.Mode = SPI_MODE_MASTER;
  853.   hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  854.   hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  855.   hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  856.   hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  857.   hspi2.Init.NSS = SPI_NSS_SOFT;
  858.   hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
  859.   hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  860.   hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  861.   hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  862.   hspi2.Init.CRCPolynomial = 7;
  863.   hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  864.   hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  865.   if (HAL_SPI_Init(&hspi2) != HAL_OK)
  866.   {
  867.     Error_Handler();
  868.   }
  869.   /* USER CODE BEGIN SPI2_Init 2 */
  870.  
  871.   /* USER CODE END SPI2_Init 2 */
  872.  
  873. }
  874.  
  875. /**
  876.   * @brief TIM2 Initialization Function
  877.   * @param None
  878.   * @retval None
  879.   */
  880. static void MX_TIM2_Init(void)
  881. {
  882.  
  883.   /* USER CODE BEGIN TIM2_Init 0 */
  884.  
  885.   /* USER CODE END TIM2_Init 0 */
  886.  
  887.   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  888.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  889.   TIM_OC_InitTypeDef sConfigOC = {0};
  890.  
  891.   /* USER CODE BEGIN TIM2_Init 1 */
  892.  
  893.   /* USER CODE END TIM2_Init 1 */
  894.   htim2.Instance = TIM2;
  895.   htim2.Init.Prescaler = 0;
  896.   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  897.   htim2.Init.Period = 0xffff;
  898.   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  899.   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  900.   if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  901.   {
  902.     Error_Handler();
  903.   }
  904.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  905.   if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  906.   {
  907.     Error_Handler();
  908.   }
  909.   if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
  910.   {
  911.     Error_Handler();
  912.   }
  913.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  914.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  915.   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  916.   {
  917.     Error_Handler();
  918.   }
  919.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  920.   sConfigOC.Pulse = 0;
  921.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  922.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  923.   if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  924.   {
  925.     Error_Handler();
  926.   }
  927.   if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
  928.   {
  929.     Error_Handler();
  930.   }
  931.   if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
  932.   {
  933.     Error_Handler();
  934.   }
  935.   if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
  936.   {
  937.     Error_Handler();
  938.   }
  939.   /* USER CODE BEGIN TIM2_Init 2 */
  940.  
  941.   /* USER CODE END TIM2_Init 2 */
  942.   HAL_TIM_MspPostInit(&htim2);
  943.  
  944. }
  945.  
  946. /**
  947.   * @brief TIM4 Initialization Function
  948.   * @param None
  949.   * @retval None
  950.   */
  951. static void MX_TIM4_Init(void)
  952. {
  953.  
  954.   /* USER CODE BEGIN TIM4_Init 0 */
  955.  
  956.   /* USER CODE END TIM4_Init 0 */
  957.  
  958.   TIM_Encoder_InitTypeDef sConfig = {0};
  959.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  960.  
  961.   /* USER CODE BEGIN TIM4_Init 1 */
  962.  
  963.   /* USER CODE END TIM4_Init 1 */
  964.   htim4.Instance = TIM4;
  965.   htim4.Init.Prescaler = 0;
  966.   htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  967.   htim4.Init.Period = 65535;
  968.   htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  969.   htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  970.   sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
  971.   sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  972.   sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  973.   sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
  974.   sConfig.IC1Filter = 0;
  975.   sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  976.   sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  977.   sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
  978.   sConfig.IC2Filter = 0;
  979.   if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK)
  980.   {
  981.     Error_Handler();
  982.   }
  983.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  984.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  985.   if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
  986.   {
  987.     Error_Handler();
  988.   }
  989.   /* USER CODE BEGIN TIM4_Init 2 */
  990.  
  991.   /* USER CODE END TIM4_Init 2 */
  992.  
  993. }
  994.  
  995. /**
  996.   * @brief TIM5 Initialization Function
  997.   * @param None
  998.   * @retval None
  999.   */
  1000. static void MX_TIM5_Init(void)
  1001. {
  1002.  
  1003.   /* USER CODE BEGIN TIM5_Init 0 */
  1004.  
  1005.   /* USER CODE END TIM5_Init 0 */
  1006.  
  1007.   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  1008.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  1009.   TIM_OC_InitTypeDef sConfigOC = {0};
  1010.  
  1011.   /* USER CODE BEGIN TIM5_Init 1 */
  1012.  
  1013.   /* USER CODE END TIM5_Init 1 */
  1014.   htim5.Instance = TIM5;
  1015.   htim5.Init.Prescaler = 0;
  1016.   htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
  1017.   htim5.Init.Period = 0xffff;
  1018.   htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1019.   htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1020.   if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
  1021.   {
  1022.     Error_Handler();
  1023.   }
  1024.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1025.   if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
  1026.   {
  1027.     Error_Handler();
  1028.   }
  1029.   if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
  1030.   {
  1031.     Error_Handler();
  1032.   }
  1033.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1034.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1035.   if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
  1036.   {
  1037.     Error_Handler();
  1038.   }
  1039.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  1040.   sConfigOC.Pulse = 0;
  1041.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1042.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1043.   if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  1044.   {
  1045.     Error_Handler();
  1046.   }
  1047.   if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
  1048.   {
  1049.     Error_Handler();
  1050.   }
  1051.   if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
  1052.   {
  1053.     Error_Handler();
  1054.   }
  1055.   if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
  1056.   {
  1057.     Error_Handler();
  1058.   }
  1059.   /* USER CODE BEGIN TIM5_Init 2 */
  1060.  
  1061.   /* USER CODE END TIM5_Init 2 */
  1062.   HAL_TIM_MspPostInit(&htim5);
  1063.  
  1064. }
  1065.  
  1066. /**
  1067.   * @brief TIM6 Initialization Function
  1068.   * @param None
  1069.   * @retval None
  1070.   */
  1071. static void MX_TIM6_Init(void)
  1072. {
  1073.  
  1074.   /* USER CODE BEGIN TIM6_Init 0 */
  1075.  
  1076.   /* USER CODE END TIM6_Init 0 */
  1077.  
  1078.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  1079.  
  1080.   /* USER CODE BEGIN TIM6_Init 1 */
  1081.  
  1082.   /* USER CODE END TIM6_Init 1 */
  1083.   htim6.Instance = TIM6;
  1084.   htim6.Init.Prescaler = 99;
  1085.   htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  1086.   htim6.Init.Period = 0xbb80;
  1087.   htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1088.   if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  1089.   {
  1090.     Error_Handler();
  1091.   }
  1092.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
  1093.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1094.   if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  1095.   {
  1096.     Error_Handler();
  1097.   }
  1098.   /* USER CODE BEGIN TIM6_Init 2 */
  1099.  
  1100.   /* USER CODE END TIM6_Init 2 */
  1101.  
  1102. }
  1103.  
  1104. /**
  1105.   * @brief TIM12 Initialization Function
  1106.   * @param None
  1107.   * @retval None
  1108.   */
  1109. static void MX_TIM12_Init(void)
  1110. {
  1111.  
  1112.   /* USER CODE BEGIN TIM12_Init 0 */
  1113.  
  1114.   /* USER CODE END TIM12_Init 0 */
  1115.  
  1116.   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  1117.   TIM_OC_InitTypeDef sConfigOC = {0};
  1118.  
  1119.   /* USER CODE BEGIN TIM12_Init 1 */
  1120.  
  1121.   /* USER CODE END TIM12_Init 1 */
  1122.   htim12.Instance = TIM12;
  1123.   htim12.Init.Prescaler = 0;
  1124.   htim12.Init.CounterMode = TIM_COUNTERMODE_UP;
  1125.   htim12.Init.Period = 0xbb80;
  1126.   htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1127.   htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1128.   if (HAL_TIM_Base_Init(&htim12) != HAL_OK)
  1129.   {
  1130.     Error_Handler();
  1131.   }
  1132.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1133.   if (HAL_TIM_ConfigClockSource(&htim12, &sClockSourceConfig) != HAL_OK)
  1134.   {
  1135.     Error_Handler();
  1136.   }
  1137.   if (HAL_TIM_OC_Init(&htim12) != HAL_OK)
  1138.   {
  1139.     Error_Handler();
  1140.   }
  1141.   sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
  1142.   sConfigOC.Pulse = 0;
  1143.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1144.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1145.   if (HAL_TIM_OC_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  1146.   {
  1147.     Error_Handler();
  1148.   }
  1149.   sConfigOC.OCMode = TIM_OCMODE_TIMING;
  1150.   if (HAL_TIM_OC_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
  1151.   {
  1152.     Error_Handler();
  1153.   }
  1154.   /* USER CODE BEGIN TIM12_Init 2 */
  1155.  
  1156.   /* USER CODE END TIM12_Init 2 */
  1157.  
  1158. }
  1159.  
  1160. /**
  1161.   * @brief TIM13 Initialization Function
  1162.   * @param None
  1163.   * @retval None
  1164.   */
  1165. static void MX_TIM13_Init(void)
  1166. {
  1167.  
  1168.   /* USER CODE BEGIN TIM13_Init 0 */
  1169.  
  1170.   /* USER CODE END TIM13_Init 0 */
  1171.  
  1172.   TIM_OC_InitTypeDef sConfigOC = {0};
  1173.  
  1174.   /* USER CODE BEGIN TIM13_Init 1 */
  1175.  
  1176.   /* USER CODE END TIM13_Init 1 */
  1177.   htim13.Instance = TIM13;
  1178.   htim13.Init.Prescaler = 0;
  1179.   htim13.Init.CounterMode = TIM_COUNTERMODE_UP;
  1180.   htim13.Init.Period = 0xbb80;
  1181.   htim13.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1182.   htim13.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1183.   if (HAL_TIM_Base_Init(&htim13) != HAL_OK)
  1184.   {
  1185.     Error_Handler();
  1186.   }
  1187.   if (HAL_TIM_OC_Init(&htim13) != HAL_OK)
  1188.   {
  1189.     Error_Handler();
  1190.   }
  1191.   sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
  1192.   sConfigOC.Pulse = 0;
  1193.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1194.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1195.   if (HAL_TIM_OC_ConfigChannel(&htim13, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  1196.   {
  1197.     Error_Handler();
  1198.   }
  1199.   /* USER CODE BEGIN TIM13_Init 2 */
  1200.  
  1201.   /* USER CODE END TIM13_Init 2 */
  1202.  
  1203. }
  1204.  
  1205. /**
  1206.   * @brief TIM16 Initialization Function
  1207.   * @param None
  1208.   * @retval None
  1209.   */
  1210. static void MX_TIM16_Init(void)
  1211. {
  1212.  
  1213.   /* USER CODE BEGIN TIM16_Init 0 */
  1214.  
  1215.   /* USER CODE END TIM16_Init 0 */
  1216.  
  1217.   TIM_IC_InitTypeDef sConfigIC = {0};
  1218.  
  1219.   /* USER CODE BEGIN TIM16_Init 1 */
  1220.  
  1221.   /* USER CODE END TIM16_Init 1 */
  1222.   htim16.Instance = TIM16;
  1223.   htim16.Init.Prescaler = 4799;
  1224.   htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
  1225.   htim16.Init.Period = 0xffff;
  1226.   htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1227.   htim16.Init.RepetitionCounter = 0;
  1228.   htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1229.   if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
  1230.   {
  1231.     Error_Handler();
  1232.   }
  1233.   if (HAL_TIM_IC_Init(&htim16) != HAL_OK)
  1234.   {
  1235.     Error_Handler();
  1236.   }
  1237.   sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
  1238.   sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  1239.   sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
  1240.   sConfigIC.ICFilter = 0;
  1241.   if (HAL_TIM_IC_ConfigChannel(&htim16, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
  1242.   {
  1243.     Error_Handler();
  1244.   }
  1245.   /* USER CODE BEGIN TIM16_Init 2 */
  1246.  
  1247.   /* USER CODE END TIM16_Init 2 */
  1248.  
  1249. }
  1250.  
  1251. /**
  1252.   * @brief TIM17 Initialization Function
  1253.   * @param None
  1254.   * @retval None
  1255.   */
  1256. static void MX_TIM17_Init(void)
  1257. {
  1258.  
  1259.   /* USER CODE BEGIN TIM17_Init 0 */
  1260.  
  1261.   /* USER CODE END TIM17_Init 0 */
  1262.  
  1263.   TIM_IC_InitTypeDef sConfigIC = {0};
  1264.  
  1265.   /* USER CODE BEGIN TIM17_Init 1 */
  1266.  
  1267.   /* USER CODE END TIM17_Init 1 */
  1268.   htim17.Instance = TIM17;
  1269.   htim17.Init.Prescaler = 4799;
  1270.   htim17.Init.CounterMode = TIM_COUNTERMODE_UP;
  1271.   htim17.Init.Period = 0xffff;
  1272.   htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1273.   htim17.Init.RepetitionCounter = 0;
  1274.   htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1275.   if (HAL_TIM_Base_Init(&htim17) != HAL_OK)
  1276.   {
  1277.     Error_Handler();
  1278.   }
  1279.   if (HAL_TIM_IC_Init(&htim17) != HAL_OK)
  1280.   {
  1281.     Error_Handler();
  1282.   }
  1283.   sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
  1284.   sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  1285.   sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
  1286.   sConfigIC.ICFilter = 0;
  1287.   if (HAL_TIM_IC_ConfigChannel(&htim17, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
  1288.   {
  1289.     Error_Handler();
  1290.   }
  1291.   /* USER CODE BEGIN TIM17_Init 2 */
  1292.  
  1293.   /* USER CODE END TIM17_Init 2 */
  1294.  
  1295. }
  1296.  
  1297. /**
  1298.   * @brief TIM19 Initialization Function
  1299.   * @param None
  1300.   * @retval None
  1301.   */
  1302. static void MX_TIM19_Init(void)
  1303. {
  1304.  
  1305.   /* USER CODE BEGIN TIM19_Init 0 */
  1306.  
  1307.   /* USER CODE END TIM19_Init 0 */
  1308.  
  1309.   TIM_Encoder_InitTypeDef sConfig = {0};
  1310.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  1311.  
  1312.   /* USER CODE BEGIN TIM19_Init 1 */
  1313.  
  1314.   /* USER CODE END TIM19_Init 1 */
  1315.   htim19.Instance = TIM19;
  1316.   htim19.Init.Prescaler = 0;
  1317.   htim19.Init.CounterMode = TIM_COUNTERMODE_UP;
  1318.   htim19.Init.Period = 65535;
  1319.   htim19.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1320.   htim19.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1321.   sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
  1322.   sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  1323.   sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  1324.   sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
  1325.   sConfig.IC1Filter = 0;
  1326.   sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  1327.   sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  1328.   sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
  1329.   sConfig.IC2Filter = 0;
  1330.   if (HAL_TIM_Encoder_Init(&htim19, &sConfig) != HAL_OK)
  1331.   {
  1332.     Error_Handler();
  1333.   }
  1334.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1335.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1336.   if (HAL_TIMEx_MasterConfigSynchronization(&htim19, &sMasterConfig) != HAL_OK)
  1337.   {
  1338.     Error_Handler();
  1339.   }
  1340.   /* USER CODE BEGIN TIM19_Init 2 */
  1341.  
  1342.   /* USER CODE END TIM19_Init 2 */
  1343.  
  1344. }
  1345.  
  1346. /**
  1347.   * @brief USART1 Initialization Function
  1348.   * @param None
  1349.   * @retval None
  1350.   */
  1351. static void MX_USART1_UART_Init(void)
  1352. {
  1353.  
  1354.   /* USER CODE BEGIN USART1_Init 0 */
  1355.  
  1356.   /* USER CODE END USART1_Init 0 */
  1357.  
  1358.   /* USER CODE BEGIN USART1_Init 1 */
  1359.  
  1360.   /* USER CODE END USART1_Init 1 */
  1361.   huart1.Instance = USART1;
  1362.   huart1.Init.BaudRate = 38400;
  1363.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  1364.   huart1.Init.StopBits = UART_STOPBITS_1;
  1365.   huart1.Init.Parity = UART_PARITY_NONE;
  1366.   huart1.Init.Mode = UART_MODE_TX_RX;
  1367.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1368.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  1369.   huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  1370.   huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  1371.   if (HAL_UART_Init(&huart1) != HAL_OK)
  1372.   {
  1373.     Error_Handler();
  1374.   }
  1375.   /* USER CODE BEGIN USART1_Init 2 */
  1376.  
  1377.   /* USER CODE END USART1_Init 2 */
  1378.  
  1379. }
  1380.  
  1381. /**
  1382.   * Enable DMA controller clock
  1383.   */
  1384. static void MX_DMA_Init(void)
  1385. {
  1386.  
  1387.   /* DMA controller clock enable */
  1388.   __HAL_RCC_DMA1_CLK_ENABLE();
  1389.   __HAL_RCC_DMA2_CLK_ENABLE();
  1390.  
  1391.   /* DMA interrupt init */
  1392.   /* DMA1_Channel1_IRQn interrupt configuration */
  1393.   HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  1394.   HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  1395.   /* DMA1_Channel3_IRQn interrupt configuration */
  1396.   HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0);
  1397.   HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
  1398.   /* DMA2_Channel3_IRQn interrupt configuration */
  1399.   HAL_NVIC_SetPriority(DMA2_Channel3_IRQn, 0, 0);
  1400.   HAL_NVIC_EnableIRQ(DMA2_Channel3_IRQn);
  1401.   /* DMA2_Channel4_IRQn interrupt configuration */
  1402.   HAL_NVIC_SetPriority(DMA2_Channel4_IRQn, 0, 0);
  1403.   HAL_NVIC_EnableIRQ(DMA2_Channel4_IRQn);
  1404.   /* DMA2_Channel5_IRQn interrupt configuration */
  1405.   HAL_NVIC_SetPriority(DMA2_Channel5_IRQn, 0, 0);
  1406.   HAL_NVIC_EnableIRQ(DMA2_Channel5_IRQn);
  1407.  
  1408. }
  1409.  
  1410. /**
  1411.   * @brief GPIO Initialization Function
  1412.   * @param None
  1413.   * @retval None
  1414.   */
  1415. static void MX_GPIO_Init(void)
  1416. {
  1417.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  1418.  
  1419.   /* GPIO Ports Clock Enable */
  1420.   __HAL_RCC_GPIOE_CLK_ENABLE();
  1421.   __HAL_RCC_GPIOC_CLK_ENABLE();
  1422.   __HAL_RCC_GPIOF_CLK_ENABLE();
  1423.   __HAL_RCC_GPIOA_CLK_ENABLE();
  1424.   __HAL_RCC_GPIOB_CLK_ENABLE();
  1425.   __HAL_RCC_GPIOD_CLK_ENABLE();
  1426.  
  1427.   /*Configure GPIO pin Output Level */
  1428.   HAL_GPIO_WritePin(CS4_GPIO_Port, CS4_Pin, GPIO_PIN_SET);
  1429.  
  1430.   /*Configure GPIO pin Output Level */
  1431.   HAL_GPIO_WritePin(GPIOF, CS3_Pin|LCD_RST_Pin, GPIO_PIN_RESET);
  1432.  
  1433.   /*Configure GPIO pin Output Level */
  1434.   HAL_GPIO_WritePin(CS0_GPIO_Port, CS0_Pin, GPIO_PIN_SET);
  1435.  
  1436.   /*Configure GPIO pin Output Level */
  1437.   HAL_GPIO_WritePin(GPIOC, CS1_Pin|CS2_Pin|TS_CS_Pin, GPIO_PIN_SET);
  1438.  
  1439.   /*Configure GPIO pin Output Level */
  1440.   HAL_GPIO_WritePin(CS5_GPIO_Port, CS5_Pin, GPIO_PIN_SET);
  1441.  
  1442.   /*Configure GPIO pin Output Level */
  1443.   HAL_GPIO_WritePin(LCD_DC_GPIO_Port, LCD_DC_Pin, GPIO_PIN_RESET);
  1444.  
  1445.   /*Configure GPIO pin Output Level */
  1446.   HAL_GPIO_WritePin(GPIOD, LCD_CS_Pin|SD_CS_Pin, GPIO_PIN_SET);
  1447.  
  1448.   /*Configure GPIO pin Output Level */
  1449.   HAL_GPIO_WritePin(GPIOD, LED0_Pin|LED1_Pin|LED2_Pin, GPIO_PIN_RESET);
  1450.  
  1451.   /*Configure GPIO pin Output Level */
  1452.   HAL_GPIO_WritePin(GPIOB, LED3_Pin|LED4_Pin, GPIO_PIN_RESET);
  1453.  
  1454.   /*Configure GPIO pins : DI0_Pin DI1_Pin DI2_Pin DI3_Pin
  1455.                            DI4_Pin */
  1456.   GPIO_InitStruct.Pin = DI0_Pin|DI1_Pin|DI2_Pin|DI3_Pin
  1457.                           |DI4_Pin;
  1458.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1459.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1460.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  1461.  
  1462.   /*Configure GPIO pins : DI5_Pin STOP_LOGGING_CONTROL_Pin */
  1463.   GPIO_InitStruct.Pin = DI5_Pin|STOP_LOGGING_CONTROL_Pin;
  1464.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1465.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1466.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1467.  
  1468.   /*Configure GPIO pins : DI6_Pin DI7_Pin */
  1469.   GPIO_InitStruct.Pin = DI6_Pin|DI7_Pin;
  1470.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1471.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1472.   HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  1473.  
  1474.   /*Configure GPIO pin : CS4_Pin */
  1475.   GPIO_InitStruct.Pin = CS4_Pin;
  1476.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1477.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1478.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1479.   HAL_GPIO_Init(CS4_GPIO_Port, &GPIO_InitStruct);
  1480.  
  1481.   /*Configure GPIO pins : CS3_Pin LCD_RST_Pin */
  1482.   GPIO_InitStruct.Pin = CS3_Pin|LCD_RST_Pin;
  1483.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1484.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1485.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1486.   HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  1487.  
  1488.   /*Configure GPIO pin : CS0_Pin */
  1489.   GPIO_InitStruct.Pin = CS0_Pin;
  1490.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1491.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1492.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1493.   HAL_GPIO_Init(CS0_GPIO_Port, &GPIO_InitStruct);
  1494.  
  1495.   /*Configure GPIO pins : CS1_Pin CS2_Pin TS_CS_Pin */
  1496.   GPIO_InitStruct.Pin = CS1_Pin|CS2_Pin|TS_CS_Pin;
  1497.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1498.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1499.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1500.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1501.  
  1502.   /*Configure GPIO pin : CS5_Pin */
  1503.   GPIO_InitStruct.Pin = CS5_Pin;
  1504.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1505.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1506.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1507.   HAL_GPIO_Init(CS5_GPIO_Port, &GPIO_InitStruct);
  1508.  
  1509.   /*Configure GPIO pin : LCD_DC_Pin */
  1510.   GPIO_InitStruct.Pin = LCD_DC_Pin;
  1511.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1512.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1513.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1514.   HAL_GPIO_Init(LCD_DC_GPIO_Port, &GPIO_InitStruct);
  1515.  
  1516.   /*Configure GPIO pins : LCD_CS_Pin SD_CS_Pin */
  1517.   GPIO_InitStruct.Pin = LCD_CS_Pin|SD_CS_Pin;
  1518.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1519.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1520.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1521.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  1522.  
  1523.   /*Configure GPIO pin : TS_IRQ_Pin */
  1524.   GPIO_InitStruct.Pin = TS_IRQ_Pin;
  1525.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1526.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1527.   HAL_GPIO_Init(TS_IRQ_GPIO_Port, &GPIO_InitStruct);
  1528.  
  1529.   /*Configure GPIO pins : LED0_Pin LED1_Pin LED2_Pin */
  1530.   GPIO_InitStruct.Pin = LED0_Pin|LED1_Pin|LED2_Pin;
  1531.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1532.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1533.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1534.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  1535.  
  1536.   /*Configure GPIO pins : LED3_Pin LED4_Pin */
  1537.   GPIO_InitStruct.Pin = LED3_Pin|LED4_Pin;
  1538.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1539.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1540.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1541.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1542.  
  1543. }
  1544.  
  1545. /* USER CODE BEGIN 4 */
  1546.  
  1547. /* USER CODE END 4 */
  1548.  
  1549. /**
  1550.   * @brief  This function is executed in case of error occurrence.
  1551.   * @retval None
  1552.   */
  1553. void Error_Handler(void)
  1554. {
  1555.   /* USER CODE BEGIN Error_Handler_Debug */
  1556.   /* User can add his own implementation to report the HAL error return state */
  1557.   __disable_irq();
  1558.   while (1)
  1559.   {
  1560.   }
  1561.   /* USER CODE END Error_Handler_Debug */
  1562. }
  1563.  
  1564. #ifdef  USE_FULL_ASSERT
  1565. /**
  1566.   * @brief  Reports the name of the source file and the source line number
  1567.   *         where the assert_param error has occurred.
  1568.   * @param  file: pointer to the source file name
  1569.   * @param  line: assert_param error line source number
  1570.   * @retval None
  1571.   */
  1572. void assert_failed(uint8_t *file, uint32_t line)
  1573. {
  1574.   /* USER CODE BEGIN 6 */
  1575.   /* User can add his own implementation to report the file name and line number,
  1576.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1577.   /* USER CODE END 6 */
  1578. }
  1579. #endif /* USE_FULL_ASSERT */
  1580.  
  1581.  
Advertisement
RAW Paste Data Copied
Advertisement