Subversion Repositories EngineBay2

Rev

Rev 31 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* USER CODE BEGIN Header */
  2. /**
  3.  ******************************************************************************
  4.  * @file           : main.c
  5.  * @brief          : Main program body
  6.  ******************************************************************************
  7.  * @attention
  8.  *
  9.  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10.  * All rights reserved.</center></h2>
  11.  *
  12.  * This software component is licensed by ST under BSD 3-Clause license,
  13.  * the "License"; You may not use this file except in compliance with the
  14.  * License. You may obtain a copy of the License at:
  15.  *                        opensource.org/licenses/BSD-3-Clause
  16.  *
  17.  ******************************************************************************
  18.  */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22.  
  23. /* Private includes ----------------------------------------------------------*/
  24. /* USER CODE BEGIN Includes */
  25. #include "libSerial/serial.h"
  26. #include "libPLX/plx.h"
  27. #include "misc.h"
  28. /* USER CODE END Includes */
  29.  
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* USER CODE BEGIN PTD */
  32.  
  33. /* USER CODE END PTD */
  34.  
  35. /* Private define ------------------------------------------------------------*/
  36. /* USER CODE BEGIN PD */
  37. /* USER CODE END PD */
  38.  
  39. /* Private macro -------------------------------------------------------------*/
  40. /* USER CODE BEGIN PM */
  41.  
  42. /* USER CODE END PM */
  43.  
  44. /* Private variables ---------------------------------------------------------*/
  45. ADC_HandleTypeDef hadc;
  46. DMA_HandleTypeDef hdma_adc;
  47.  
  48. SPI_HandleTypeDef hspi1;
  49.  
  50. TIM_HandleTypeDef htim2;
  51. TIM_HandleTypeDef htim3;
  52. TIM_HandleTypeDef htim6;
  53.  
  54. UART_HandleTypeDef huart1;
  55. UART_HandleTypeDef huart2;
  56.  
  57. /* USER CODE BEGIN PV */
  58. /* Private variables ---------------------------------------------------------*/
  59.  
  60. // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000
  61. // freq = 5000/60 * 2 = 166Hz.
  62. // the TIM2 counter counts in 10uS increments,
  63. // TODO this is wrong algo. Accept FIRST pulse, skip shorter pulses
  64. // Accept the first pulse with over 1mS duration as the closure
  65. #define BREAKER_MIN (RPM_COUNT_RATE/1000)
  66.  
  67. #define RPM_AVERAGE 4
  68.  
  69. // wait for about 1 second to decide whether or not starter is on
  70.  
  71. #define STARTER_LIMIT 10
  72.  
  73. volatile char TimerFlag = 0;
  74.  
  75. volatile char NoSerialInCTR = 0; // Missing characters coming in on USART1
  76. volatile char NoSerialIn = 0;
  77.  
  78. // storage for ADC
  79. uint16_t ADC_Samples[6];
  80.  
  81. #define Scale 1024.0
  82. const float ADC_Scale = 3.3 / (Scale * 4096.0); // convert to a voltage
  83.  
  84. uint32_t FILT_Samples[6]; // filtered ADC samples * 1024
  85. // Rev counter processing from original RevCounter Project
  86. uint16_t RPM_Diff = 0;
  87. uint16_t RPM_Count_Latch = 0;
  88. // accumulators
  89. uint16_t RPM_Pulsecount = 0;
  90. unsigned int RPM_FilteredWidth = 0;
  91.  
  92. // last time we detected end of dwell i.e. ignition pulse
  93. uint16_t last_dwell_end = 0;
  94. uint16_t RPM_Period[RPM_AVERAGE];
  95. unsigned int RPM_Period_Ptr = 0;
  96.  
  97. unsigned int Coded_RPM = 0;
  98. unsigned int Coded_CHT = 0;
  99.  
  100. uint32_t Power_CHT_Timer;
  101.  
  102. uint16_t Starter_Debounce = 0;
  103.  
  104. /* USER CODE END PV */
  105.  
  106. /* Private function prototypes -----------------------------------------------*/
  107. void SystemClock_Config(void);
  108. static void MX_GPIO_Init(void);
  109. static void MX_DMA_Init(void);
  110. static void MX_ADC_Init(void);
  111. static void MX_SPI1_Init(void);
  112. static void MX_TIM2_Init(void);
  113. static void MX_TIM6_Init(void);
  114. static void MX_USART1_UART_Init(void);
  115. static void MX_USART2_UART_Init(void);
  116. static void MX_TIM3_Init(void);
  117. /* USER CODE BEGIN PFP */
  118. /* Private function prototypes -----------------------------------------------*/
  119.  
  120. /* USER CODE END PFP */
  121.  
  122. /* Private user code ---------------------------------------------------------*/
  123. /* USER CODE BEGIN 0 */
  124.  
  125. void
  126. plx_sendword (int x)
  127. {
  128.   PutCharSerial (&uc1, ((x) >> 6) & 0x3F);
  129.   PutCharSerial (&uc1, (x) & 0x3F);
  130. }
  131.  
  132. void
  133. init_ADC_filter ()
  134. {
  135.   int i;
  136.   for (i = 0; i < 6; i++)
  137.     {
  138.       FILT_Samples[i] = 0;
  139.     }
  140. }
  141.  
  142. void
  143. filter_ADC_samples ()
  144. {
  145.   int i;
  146.   for (i = 0; i < 6; i++)
  147.     {
  148.       FILT_Samples[i] += (ADC_Samples[i] * Scale - FILT_Samples[i]) / 2;
  149.     }
  150. }
  151.  
  152. void
  153. ProcessRPM (int instance)
  154. {
  155. // compute the timer values
  156. // snapshot timers
  157.   unsigned long RPM_Pulsewidth;
  158.   // current RPM pulse next slot index
  159.   unsigned long RPM_Count_Val;
  160.   __disable_irq (); // copy the counter value
  161.   RPM_Count_Val = RPM_Count;
  162.   __enable_irq ();
  163. // do calculations
  164. // if there is only one entry, cannot get difference
  165.   if (RPM_Count_Latch != RPM_Count_Val)
  166.     {
  167.       while (1)
  168.         {
  169.           unsigned int base_time;
  170.           unsigned int new_time;
  171.           // if we are at N-1, stop.
  172.           unsigned int next_count = (RPM_Count_Latch + 1) % RPM_SAMPLES;
  173.           if (next_count == RPM_Count_Val)
  174.             {
  175.               break; // completed loop
  176.             }
  177.           char pulse_level = RPM_Level[RPM_Count_Latch];
  178.           base_time = RPM_Time[RPM_Count_Latch];
  179.           new_time = RPM_Time[next_count];
  180.           RPM_Count_Latch = next_count;
  181.  
  182.           RPM_Pulsewidth = new_time - base_time; // not wrapped
  183.  
  184.           // if the pulse was low,
  185.           if (pulse_level == 0 && RPM_Pulsewidth > BREAKER_MIN)
  186.             {
  187.  
  188.               RPM_Diff = new_time - last_dwell_end;
  189.  
  190.               RPM_Period[RPM_Period_Ptr] = RPM_Diff;
  191.               RPM_Period_Ptr = (RPM_Period_Ptr + 1) % RPM_AVERAGE;
  192.               if (RPM_Pulsecount < RPM_AVERAGE)
  193.                 RPM_Pulsecount++; // count one pulse
  194.               last_dwell_end = new_time;
  195.  
  196.             }
  197.         }
  198.  
  199.     }
  200.  
  201.   if (RPM_Pulsecount == RPM_AVERAGE)
  202.     {
  203.       // now have time for N pulses in clocks
  204.       // need to scale by 19.55: one unit is 19.55 RPM
  205.       // 1Hz is 30 RPM
  206.       int i;
  207.       RPM_FilteredWidth = 0;
  208.       for (i = 0; i < RPM_AVERAGE; i++)
  209.         RPM_FilteredWidth += RPM_Period[i];
  210.  
  211.       Coded_RPM = (Scale * 30.0 * RPM_AVERAGE * RPM_COUNT_RATE)
  212.           / (19.55 * RPM_FilteredWidth);
  213.  
  214. #if !defined MY_DEBUG
  215.       // reset here unless we want to debug
  216.       RPM_Pulsecount = 0;
  217.       RPM_FilteredWidth = 0;
  218. #endif
  219.     }
  220.  
  221. // send the current RPM *calculation
  222.   plx_sendword (PLX_RPM);
  223.   PutCharSerial (&uc1, instance);
  224.   plx_sendword (Coded_RPM / Scale);
  225. }
  226.  
  227. // this uses a MAX6675 which is a simple 16 bit read
  228. // SPI is configured for 8 bits so I can use an OLED display if I need it
  229. // must wait > 0.22 seconds between conversion attempts as this is the measurement time
  230. //
  231.  
  232. FunctionalState CHT_Enable = ENABLE;
  233.  
  234. #define CORR 3
  235.  
  236.  
  237. uint16_t CHT_Observations[2] =
  238.   { 0, 0 };
  239.  
  240. // look for the trigger pin being high then low - the points
  241. // are opening, and skip the reading
  242.  
  243. void
  244. ProcessCHT (int instance)
  245. {
  246.   plx_sendword (PLX_X_CHT);
  247.   PutCharSerial (&uc1, instance);
  248.   plx_sendword (CHT_Observations[instance]);
  249.  
  250. }
  251.  
  252. void
  253. EnableCHT (FunctionalState state)
  254.  
  255. {
  256.   GPIO_InitTypeDef GPIO_InitStruct;
  257.  
  258.   CHT_Enable = state;
  259.  
  260.   /* enable SPI in live mode : assume it and its GPIOs are already initialised in SPI mode */
  261.   if (state == ENABLE)
  262.     {
  263.       HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_SET);
  264.       HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET);
  265.       HAL_GPIO_WritePin (SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin,
  266.                          GPIO_PIN_SET);
  267.  
  268.       /* put the SPI pins back into SPI AF mode */
  269.       GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin;
  270.       GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  271.       GPIO_InitStruct.Pull = GPIO_NOPULL;
  272.       GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  273.       GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  274.       HAL_GPIO_Init (SPI1_SCK_GPIO_Port, &GPIO_InitStruct);
  275.  
  276.     }
  277.   else
  278.     {
  279.       /*  Power down the SPI interface taking signals all low */
  280.       HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_RESET);
  281.       HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin,
  282.                          GPIO_PIN_RESET);
  283.       HAL_GPIO_WritePin (SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin,
  284.                          GPIO_PIN_RESET);
  285.  
  286.       HAL_GPIO_WritePin (SPI1_SCK_GPIO_Port,
  287.       SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin,
  288.                          GPIO_PIN_RESET);
  289.  
  290.       /* put the SPI pins back into GPIO mode */
  291.       GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin;
  292.       GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  293.       GPIO_InitStruct.Pull = GPIO_NOPULL;
  294.       GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  295.       HAL_GPIO_Init (SPI1_SCK_GPIO_Port, &GPIO_InitStruct);
  296.  
  297.     }
  298.  
  299. }
  300.  
  301. // 1023 is 20.00 volts.
  302. void
  303. ProcessBatteryVoltage (int instance)
  304. {
  305.   float reading = FILT_Samples[instance] * ADC_Scale;
  306.   reading = reading * 7.8125; // real voltage
  307.   reading = reading * 51.15; // 1023/20
  308.  
  309.   plx_sendword (PLX_Volts);
  310.   PutCharSerial (&uc1, instance);
  311.   plx_sendword ((uint16_t) reading);
  312.  
  313. }
  314.  
  315. /****!
  316.  * @brief this reads the reference voltage within the STM32L151
  317.  * Powers up reference voltage and temperature sensor, waits 3mS  and takes reading
  318.  * Requires that the ADC be powered up
  319.  */
  320.  
  321. uint32_t ADC_VREF_MV = 3300;           // 3.300V typical
  322. const uint16_t STM32REF_MV = 1224;           // 1.224V typical
  323.  
  324. void
  325. CalibrateADC (void)
  326. {
  327.   uint32_t adc_val = FILT_Samples[5];       // as set up in device config
  328.   ADC_VREF_MV = (STM32REF_MV * 4096) / adc_val;
  329. }
  330.  
  331. void
  332. ProcessCPUTemperature (int instance)
  333. {
  334.   int32_t temp_val;
  335.  
  336.   uint16_t TS_CAL30 = *(uint16_t*) (0x1FF8007AUL); /* ADC reading for temperature sensor at 30 degrees C with Vref = 3000mV */
  337.   uint16_t TS_CAL110 = *(uint16_t*) (0x1FF8007EUL); /* ADC reading for temperature sensor at 110 degrees C with Vref = 3000mV */
  338.   /* get the ADC reading corresponding to ADC channel 16 after turning on the ADC */
  339.  
  340.   temp_val = FILT_Samples[5];
  341.  
  342.   /* renormalise temperature value to account for different ADC Vref  : normalise to that which we would get for a 3000mV reference */
  343.   temp_val = temp_val * ADC_VREF_MV / (Scale * 3000UL);
  344.  
  345.   int32_t result = 800 * ((int32_t) temp_val - TS_CAL30);
  346.   result = result / (TS_CAL110 - TS_CAL30) + 300;
  347.  
  348.   if (result < 0)
  349.     {
  350.       result = 0;
  351.     }
  352.   plx_sendword (PLX_FluidTemp);
  353.   PutCharSerial (&uc1, instance);
  354.   plx_sendword (result / 10);
  355.  
  356. }
  357.  
  358. // the MAP sensor is giving us a reading of
  359. // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016)
  360. // I believe the sensor reads  4.5V at 1000kPa and 0.5V at  0kPa
  361. // Calibration is a bit off
  362. // Real   Displayed
  363. // 989    968
  364. // 994.1    986
  365. // 992.3  984
  366.  
  367. void
  368. ProcessMAP (int instance)
  369. {
  370. // Using ADC_Samples[3] as the MAP input
  371.   float reading = FILT_Samples[3] * ADC_Scale;
  372.   reading = reading * 2.016;      // real voltage
  373.   // values computed from slope / intercept of map.ods
  374.   //reading = (reading) * 56.23 + 743.2; // do not assume 0.5 volt offset : reading from 0 to 4.5 instead of 0.5 to 4.5
  375.   // using a pressure gauge.
  376.   reading = (reading) * 150 + 326;
  377.  
  378.   plx_sendword (PLX_MAP);
  379.   PutCharSerial (&uc1, instance);
  380.   plx_sendword ((uint16_t) reading);
  381.  
  382. }
  383.  
  384. // the Oil pressi sensor is giving us a reading of
  385. // 4.5 volts for 100 PSI or  2.25 volts at the ADC input (resistive divider by 2.016)
  386. // I believe the sensor reads  4.5V at 100PSI and 0.5V at  0PSI
  387. // an observation of 1024 is 200PSI, so observation of 512 is 100 PSI.
  388.  
  389. void
  390. ProcessOilPress (int instance)
  391. {
  392. // Using ADC_Samples[2] as the MAP input
  393.   float reading = FILT_Samples[2] * ADC_Scale;
  394.   reading = reading * 2.00; // real voltage
  395.   reading = (reading - 0.5) * 512 / 4;  // this is 1023 * 100/200
  396.  
  397.   plx_sendword (PLX_FluidPressure);
  398.   PutCharSerial (&uc1, instance);
  399.   plx_sendword ((uint16_t) reading);
  400.  
  401. }
  402.  
  403. void
  404. ProcessTiming (int instance)
  405. {
  406.   plx_sendword (PLX_Timing);
  407.   PutCharSerial (&uc1, instance);
  408.   plx_sendword (64 - 15); // make it negative
  409. }
  410.  
  411. /* USER CODE END 0 */
  412.  
  413. /**
  414.   * @brief  The application entry point.
  415.   * @retval int
  416.   */
  417. int main(void)
  418. {
  419.   /* USER CODE BEGIN 1 */
  420.  
  421.   /* USER CODE END 1 */
  422.  
  423.   /* MCU Configuration--------------------------------------------------------*/
  424.  
  425.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  426.   HAL_Init();
  427.  
  428.   /* USER CODE BEGIN Init */
  429.  
  430.   /* USER CODE END Init */
  431.  
  432.   /* Configure the system clock */
  433.   SystemClock_Config();
  434.  
  435.   /* USER CODE BEGIN SysInit */
  436.  
  437.   /* USER CODE END SysInit */
  438.  
  439.   /* Initialize all configured peripherals */
  440.   MX_GPIO_Init();
  441.   MX_DMA_Init();
  442.   MX_ADC_Init();
  443.   MX_SPI1_Init();
  444.   MX_TIM2_Init();
  445.   MX_TIM6_Init();
  446.   MX_USART1_UART_Init();
  447.   MX_USART2_UART_Init();
  448.   MX_TIM3_Init();
  449.   /* USER CODE BEGIN 2 */
  450.   HAL_MspInit ();
  451.  
  452. // Not using HAL USART code
  453.   __HAL_RCC_USART1_CLK_ENABLE()
  454.   ; // PLX comms port
  455.   __HAL_RCC_USART2_CLK_ENABLE()
  456.   ;  // Debug comms port
  457.   /* setup the USART control blocks */
  458.   init_usart_ctl (&uc1, huart1.Instance);
  459.   init_usart_ctl (&uc2, huart2.Instance);
  460.  
  461.   EnableSerialRxInterrupt (&uc1);
  462.   EnableSerialRxInterrupt (&uc2);
  463.  
  464.   HAL_SPI_MspInit (&hspi1);
  465.  
  466.   HAL_ADC_MspInit (&hadc);
  467.  
  468.   HAL_ADC_Start_DMA (&hadc, ADC_Samples, 6);
  469.  
  470.   HAL_ADC_Start_IT (&hadc);
  471.  
  472.   HAL_TIM_Base_MspInit (&htim6);
  473.   HAL_TIM_Base_Start_IT (&htim6);
  474.  
  475. // initialise all the STMCubeMX stuff
  476.   HAL_TIM_Base_MspInit (&htim2);
  477. // Start the counter
  478.   HAL_TIM_Base_Start (&htim2);
  479. // Start the input capture and the interrupt
  480.   HAL_TIM_IC_Start_IT (&htim2, TIM_CHANNEL_1);
  481.  
  482.   HAL_TIM_Base_MspInit (&htim3);
  483.   __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);
  484.   uint32_t Ticks = HAL_GetTick () + 100;
  485.   int CalCounter = 0;
  486.  
  487.   Power_CHT_Timer = HAL_GetTick () + 1000; /* wait 10 seconds before powering up the CHT sensor */
  488.  
  489.   /* USER CODE END 2 */
  490.  
  491.   /* Infinite loop */
  492.   /* USER CODE BEGIN WHILE */
  493.   while (1)
  494.     {
  495.     /* USER CODE END WHILE */
  496.  
  497.     /* USER CODE BEGIN 3 */
  498.  
  499.       if (HAL_GetTick () > Ticks)
  500.         {
  501.           Ticks += 100;
  502.           filter_ADC_samples ();
  503.           // delay to calibrate ADC
  504.           if (CalCounter < 1000)
  505.             {
  506.               CalCounter += 100;
  507.             }
  508.  
  509.           if (CalCounter == 900)
  510.             {
  511.               CalibrateADC ();
  512.             }
  513.         }
  514.       /* when the starter motor is on then power down the CHT sensors as they seem to fail */
  515.  
  516.       if (HAL_GPIO_ReadPin (STARTER_ON_GPIO_Port, STARTER_ON_Pin)
  517.           == GPIO_PIN_RESET)
  518.         {
  519.           if (Starter_Debounce < STARTER_LIMIT)
  520.             {
  521.               Starter_Debounce++;
  522.             }
  523.         }
  524.       else
  525.         {
  526.           if (Starter_Debounce > 0)
  527.             {
  528.               Starter_Debounce--;
  529.             }
  530.         }
  531.  
  532.       if (Starter_Debounce == STARTER_LIMIT)
  533.         {
  534.           EnableCHT (DISABLE);
  535.           Power_CHT_Timer = HAL_GetTick () + 1000;
  536.         }
  537.       else
  538.       /* if the Power_CHT_Timer is set then wait for it to timeout, then power up CHT */
  539.         {
  540.           if ((Power_CHT_Timer > 0) && (HAL_GetTick () > Power_CHT_Timer))
  541.             {
  542.               EnableCHT (ENABLE);
  543.               Power_CHT_Timer = 0;
  544.             }
  545.         }
  546.  
  547.       // check to see if we have any incoming data, copy and append if so, if no data then create our own frames.
  548.       int c;
  549.       char send = 0;
  550.  
  551.       // poll the  input for a stop bit or timeout
  552.       if (PollSerial (&uc1))
  553.         {
  554.           resetSerialTimeout ();
  555.           c = GetCharSerial (&uc1);
  556.           if (c != PLX_Stop)
  557.             {
  558.               PutCharSerial (&uc1, c); // echo all but the stop bit
  559.             }
  560.           else
  561.             { // must be a stop character
  562.               send = 1; // start our sending process.
  563.             }
  564.         }
  565.  
  566.       // sort out auto-sending
  567.       if (TimerFlag)
  568.         {
  569.           TimerFlag = 0;
  570.           if (NoSerialIn)
  571.             {
  572.               PutCharSerial (&uc1, PLX_Start);
  573.               send = 1;
  574.             }
  575.         }
  576.       if (send)
  577.         {
  578.           send = 0;
  579.  
  580.           uint16_t val;
  581.           val = __HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1);
  582.           PutCharSerial (&uc2, (val & 31) + 32);
  583.  
  584.           // send the observations
  585.           ProcessRPM (0);
  586.           ProcessCHT (0);
  587.           ProcessCHT (1);
  588.           ProcessBatteryVoltage (0); // Batt 1
  589.           ProcessBatteryVoltage (1); // Batt 2
  590.           ProcessCPUTemperature (0); //  built in temperature sensor
  591.  
  592.           ProcessMAP (0);
  593.           ProcessOilPress (0);
  594.  
  595.           PutCharSerial (&uc1, PLX_Stop);
  596.         }
  597.     }
  598.   /* USER CODE END 3 */
  599. }
  600.  
  601. /**
  602.   * @brief System Clock Configuration
  603.   * @retval None
  604.   */
  605. void SystemClock_Config(void)
  606. {
  607.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  608.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  609.  
  610.   /** Configure the main internal regulator output voltage
  611.   */
  612.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  613.   /** Initializes the RCC Oscillators according to the specified parameters
  614.   * in the RCC_OscInitTypeDef structure.
  615.   */
  616.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  617.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  618.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  619.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  620.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  621.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  622.   RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
  623.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  624.   {
  625.     Error_Handler();
  626.   }
  627.   /** Initializes the CPU, AHB and APB buses clocks
  628.   */
  629.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  630.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  631.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  632.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  633.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  634.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  635.  
  636.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  637.   {
  638.     Error_Handler();
  639.   }
  640. }
  641.  
  642. /**
  643.   * @brief ADC Initialization Function
  644.   * @param None
  645.   * @retval None
  646.   */
  647. static void MX_ADC_Init(void)
  648. {
  649.  
  650.   /* USER CODE BEGIN ADC_Init 0 */
  651.  
  652.   /* USER CODE END ADC_Init 0 */
  653.  
  654.   ADC_ChannelConfTypeDef sConfig = {0};
  655.  
  656.   /* USER CODE BEGIN ADC_Init 1 */
  657.  
  658.   /* USER CODE END ADC_Init 1 */
  659.   /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  660.   */
  661.   hadc.Instance = ADC1;
  662.   hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  663.   hadc.Init.Resolution = ADC_RESOLUTION_12B;
  664.   hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  665.   hadc.Init.ScanConvMode = ADC_SCAN_ENABLE;
  666.   hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  667.   hadc.Init.LowPowerAutoWait = ADC_AUTOWAIT_DISABLE;
  668.   hadc.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE;
  669.   hadc.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
  670.   hadc.Init.ContinuousConvMode = DISABLE;
  671.   hadc.Init.NbrOfConversion = 6;
  672.   hadc.Init.DiscontinuousConvMode = DISABLE;
  673.   hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO;
  674.   hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
  675.   hadc.Init.DMAContinuousRequests = ENABLE;
  676.   if (HAL_ADC_Init(&hadc) != HAL_OK)
  677.   {
  678.     Error_Handler();
  679.   }
  680.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  681.   */
  682.   sConfig.Channel = ADC_CHANNEL_10;
  683.   sConfig.Rank = ADC_REGULAR_RANK_1;
  684.   sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES;
  685.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  686.   {
  687.     Error_Handler();
  688.   }
  689.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  690.   */
  691.   sConfig.Channel = ADC_CHANNEL_11;
  692.   sConfig.Rank = ADC_REGULAR_RANK_2;
  693.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  694.   {
  695.     Error_Handler();
  696.   }
  697.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  698.   */
  699.   sConfig.Channel = ADC_CHANNEL_12;
  700.   sConfig.Rank = ADC_REGULAR_RANK_3;
  701.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  702.   {
  703.     Error_Handler();
  704.   }
  705.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  706.   */
  707.   sConfig.Channel = ADC_CHANNEL_13;
  708.   sConfig.Rank = ADC_REGULAR_RANK_4;
  709.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  710.   {
  711.     Error_Handler();
  712.   }
  713.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  714.   */
  715.   sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
  716.   sConfig.Rank = ADC_REGULAR_RANK_5;
  717.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  718.   {
  719.     Error_Handler();
  720.   }
  721.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  722.   */
  723.   sConfig.Channel = ADC_CHANNEL_VREFINT;
  724.   sConfig.Rank = ADC_REGULAR_RANK_6;
  725.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  726.   {
  727.     Error_Handler();
  728.   }
  729.   /* USER CODE BEGIN ADC_Init 2 */
  730.  
  731.   /* USER CODE END ADC_Init 2 */
  732.  
  733. }
  734.  
  735. /**
  736.   * @brief SPI1 Initialization Function
  737.   * @param None
  738.   * @retval None
  739.   */
  740. static void MX_SPI1_Init(void)
  741. {
  742.  
  743.   /* USER CODE BEGIN SPI1_Init 0 */
  744.  
  745.   /* USER CODE END SPI1_Init 0 */
  746.  
  747.   /* USER CODE BEGIN SPI1_Init 1 */
  748.  
  749.   /* USER CODE END SPI1_Init 1 */
  750.   /* SPI1 parameter configuration*/
  751.   hspi1.Instance = SPI1;
  752.   hspi1.Init.Mode = SPI_MODE_MASTER;
  753.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  754.   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  755.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  756.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  757.   hspi1.Init.NSS = SPI_NSS_SOFT;
  758.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
  759.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  760.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  761.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  762.   hspi1.Init.CRCPolynomial = 10;
  763.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  764.   {
  765.     Error_Handler();
  766.   }
  767.   /* USER CODE BEGIN SPI1_Init 2 */
  768.  
  769.   /* USER CODE END SPI1_Init 2 */
  770.  
  771. }
  772.  
  773. /**
  774.   * @brief TIM2 Initialization Function
  775.   * @param None
  776.   * @retval None
  777.   */
  778. static void MX_TIM2_Init(void)
  779. {
  780.  
  781.   /* USER CODE BEGIN TIM2_Init 0 */
  782.  
  783.   /* USER CODE END TIM2_Init 0 */
  784.  
  785.   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  786.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  787.   TIM_IC_InitTypeDef sConfigIC = {0};
  788.  
  789.   /* USER CODE BEGIN TIM2_Init 1 */
  790.  
  791.   /* USER CODE END TIM2_Init 1 */
  792.   htim2.Instance = TIM2;
  793.   htim2.Init.Prescaler = 320;
  794.   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  795.   htim2.Init.Period = 65535;
  796.   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  797.   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  798.   if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  799.   {
  800.     Error_Handler();
  801.   }
  802.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  803.   if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  804.   {
  805.     Error_Handler();
  806.   }
  807.   if (HAL_TIM_IC_Init(&htim2) != HAL_OK)
  808.   {
  809.     Error_Handler();
  810.   }
  811.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
  812.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  813.   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  814.   {
  815.     Error_Handler();
  816.   }
  817.   sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
  818.   sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  819.   sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
  820.   sConfigIC.ICFilter = 15;
  821.   if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
  822.   {
  823.     Error_Handler();
  824.   }
  825.   /* USER CODE BEGIN TIM2_Init 2 */
  826.  
  827.   /* USER CODE END TIM2_Init 2 */
  828.  
  829. }
  830.  
  831. /**
  832.   * @brief TIM3 Initialization Function
  833.   * @param None
  834.   * @retval None
  835.   */
  836. static void MX_TIM3_Init(void)
  837. {
  838.  
  839.   /* USER CODE BEGIN TIM3_Init 0 */
  840.  
  841.   /* USER CODE END TIM3_Init 0 */
  842.  
  843.   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  844.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  845.   TIM_OC_InitTypeDef sConfigOC = {0};
  846.  
  847.   /* USER CODE BEGIN TIM3_Init 1 */
  848.  
  849.   /* USER CODE END TIM3_Init 1 */
  850.   htim3.Instance = TIM3;
  851.   htim3.Init.Prescaler = 320;
  852.   htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  853.   htim3.Init.Period = 100;
  854.   htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  855.   htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  856.   if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
  857.   {
  858.     Error_Handler();
  859.   }
  860.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  861.   if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
  862.   {
  863.     Error_Handler();
  864.   }
  865.   if (HAL_TIM_OC_Init(&htim3) != HAL_OK)
  866.   {
  867.     Error_Handler();
  868.   }
  869.   if (HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE) != HAL_OK)
  870.   {
  871.     Error_Handler();
  872.   }
  873.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1;
  874.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  875.   if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  876.   {
  877.     Error_Handler();
  878.   }
  879.   sConfigOC.OCMode = TIM_OCMODE_TIMING;
  880.   sConfigOC.Pulse = 99;
  881.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  882.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  883.   if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  884.   {
  885.     Error_Handler();
  886.   }
  887.   /* USER CODE BEGIN TIM3_Init 2 */
  888.  
  889.   /* USER CODE END TIM3_Init 2 */
  890.  
  891. }
  892.  
  893. /**
  894.   * @brief TIM6 Initialization Function
  895.   * @param None
  896.   * @retval None
  897.   */
  898. static void MX_TIM6_Init(void)
  899. {
  900.  
  901.   /* USER CODE BEGIN TIM6_Init 0 */
  902.  
  903.   /* USER CODE END TIM6_Init 0 */
  904.  
  905.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  906.  
  907.   /* USER CODE BEGIN TIM6_Init 1 */
  908.  
  909.   /* USER CODE END TIM6_Init 1 */
  910.   htim6.Instance = TIM6;
  911.   htim6.Init.Prescaler = 320;
  912.   htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  913.   htim6.Init.Period = 9999;
  914.   htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  915.   if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  916.   {
  917.     Error_Handler();
  918.   }
  919.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
  920.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  921.   if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  922.   {
  923.     Error_Handler();
  924.   }
  925.   /* USER CODE BEGIN TIM6_Init 2 */
  926.  
  927.   /* USER CODE END TIM6_Init 2 */
  928.  
  929. }
  930.  
  931. /**
  932.   * @brief USART1 Initialization Function
  933.   * @param None
  934.   * @retval None
  935.   */
  936. static void MX_USART1_UART_Init(void)
  937. {
  938.  
  939.   /* USER CODE BEGIN USART1_Init 0 */
  940.  
  941.   /* USER CODE END USART1_Init 0 */
  942.  
  943.   /* USER CODE BEGIN USART1_Init 1 */
  944.  
  945.   /* USER CODE END USART1_Init 1 */
  946.   huart1.Instance = USART1;
  947.   huart1.Init.BaudRate = 19200;
  948.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  949.   huart1.Init.StopBits = UART_STOPBITS_1;
  950.   huart1.Init.Parity = UART_PARITY_NONE;
  951.   huart1.Init.Mode = UART_MODE_TX_RX;
  952.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  953.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  954.   if (HAL_UART_Init(&huart1) != HAL_OK)
  955.   {
  956.     Error_Handler();
  957.   }
  958.   /* USER CODE BEGIN USART1_Init 2 */
  959.  
  960.   /* USER CODE END USART1_Init 2 */
  961.  
  962. }
  963.  
  964. /**
  965.   * @brief USART2 Initialization Function
  966.   * @param None
  967.   * @retval None
  968.   */
  969. static void MX_USART2_UART_Init(void)
  970. {
  971.  
  972.   /* USER CODE BEGIN USART2_Init 0 */
  973.  
  974.   /* USER CODE END USART2_Init 0 */
  975.  
  976.   /* USER CODE BEGIN USART2_Init 1 */
  977.  
  978.   /* USER CODE END USART2_Init 1 */
  979.   huart2.Instance = USART2;
  980.   huart2.Init.BaudRate = 115200;
  981.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  982.   huart2.Init.StopBits = UART_STOPBITS_1;
  983.   huart2.Init.Parity = UART_PARITY_NONE;
  984.   huart2.Init.Mode = UART_MODE_TX_RX;
  985.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  986.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  987.   if (HAL_UART_Init(&huart2) != HAL_OK)
  988.   {
  989.     Error_Handler();
  990.   }
  991.   /* USER CODE BEGIN USART2_Init 2 */
  992.  
  993.   /* USER CODE END USART2_Init 2 */
  994.  
  995. }
  996.  
  997. /**
  998.   * Enable DMA controller clock
  999.   */
  1000. static void MX_DMA_Init(void)
  1001. {
  1002.  
  1003.   /* DMA controller clock enable */
  1004.   __HAL_RCC_DMA1_CLK_ENABLE();
  1005.  
  1006.   /* DMA interrupt init */
  1007.   /* DMA1_Channel1_IRQn interrupt configuration */
  1008.   HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  1009.   HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  1010.  
  1011. }
  1012.  
  1013. /**
  1014.   * @brief GPIO Initialization Function
  1015.   * @param None
  1016.   * @retval None
  1017.   */
  1018. static void MX_GPIO_Init(void)
  1019. {
  1020.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  1021.  
  1022.   /* GPIO Ports Clock Enable */
  1023.   __HAL_RCC_GPIOC_CLK_ENABLE();
  1024.   __HAL_RCC_GPIOH_CLK_ENABLE();
  1025.   __HAL_RCC_GPIOA_CLK_ENABLE();
  1026.   __HAL_RCC_GPIOB_CLK_ENABLE();
  1027.   __HAL_RCC_GPIOD_CLK_ENABLE();
  1028.  
  1029.   /*Configure GPIO pin Output Level */
  1030.   HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET);
  1031.  
  1032.   /*Configure GPIO pin Output Level */
  1033.   HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
  1034.  
  1035.   /*Configure GPIO pin Output Level */
  1036.   HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
  1037.  
  1038.   /*Configure GPIO pin Output Level */
  1039.   HAL_GPIO_WritePin(GPIOB, SPI_RESET_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET);
  1040.  
  1041.   /*Configure GPIO pin Output Level */
  1042.   HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET);
  1043.  
  1044.   /*Configure GPIO pins : PC13 PC14 PC15 PC6
  1045.                            PC7 PC8 PC9 PC11
  1046.                            PC12 */
  1047.   GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_6
  1048.                           |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11
  1049.                           |GPIO_PIN_12;
  1050.   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  1051.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1052.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1053.  
  1054.   /*Configure GPIO pins : PH0 PH1 */
  1055.   GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  1056.   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  1057.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1058.   HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
  1059.  
  1060.   /*Configure GPIO pins : PA0 PA1 PA8 PA11
  1061.                            PA12 */
  1062.   GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11
  1063.                           |GPIO_PIN_12;
  1064.   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  1065.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1066.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1067.  
  1068.   /*Configure GPIO pin : LED_Blink_Pin */
  1069.   GPIO_InitStruct.Pin = LED_Blink_Pin;
  1070.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1071.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1072.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1073.   HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct);
  1074.  
  1075.   /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */
  1076.   GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_CD_Pin;
  1077.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1078.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1079.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1080.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1081.  
  1082.   /*Configure GPIO pins : SPI_RESET_Pin SPI_NS_Temp_Pin SPI_NS_Temp2_Pin ENA_AUX_5V_Pin */
  1083.   GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NS_Temp_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin;
  1084.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1085.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1086.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1087.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1088.  
  1089.   /*Configure GPIO pins : PB11 PB12 PB13 PB14
  1090.                            PB15 PB3 PB4 PB5
  1091.                            PB6 PB7 PB8 PB9 */
  1092.   GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  1093.                           |GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  1094.                           |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
  1095.   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  1096.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1097.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1098.  
  1099.   /*Configure GPIO pin : STARTER_ON_Pin */
  1100.   GPIO_InitStruct.Pin = STARTER_ON_Pin;
  1101.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1102.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1103.   HAL_GPIO_Init(STARTER_ON_GPIO_Port, &GPIO_InitStruct);
  1104.  
  1105.   /*Configure GPIO pin : PD2 */
  1106.   GPIO_InitStruct.Pin = GPIO_PIN_2;
  1107.   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  1108.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1109.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  1110.  
  1111. }
  1112.  
  1113. /* USER CODE BEGIN 4 */
  1114.  
  1115. /* USER CODE END 4 */
  1116.  
  1117. /**
  1118.   * @brief  This function is executed in case of error occurrence.
  1119.   * @retval None
  1120.   */
  1121. void Error_Handler(void)
  1122. {
  1123.   /* USER CODE BEGIN Error_Handler_Debug */
  1124.   /* User can add his own implementation to report the HAL error return state */
  1125.  
  1126.   /* USER CODE END Error_Handler_Debug */
  1127. }
  1128.  
  1129. #ifdef  USE_FULL_ASSERT
  1130. /**
  1131.   * @brief  Reports the name of the source file and the source line number
  1132.   *         where the assert_param error has occurred.
  1133.   * @param  file: pointer to the source file name
  1134.   * @param  line: assert_param error line source number
  1135.   * @retval None
  1136.   */
  1137. void assert_failed(uint8_t *file, uint32_t line)
  1138. {
  1139.   /* USER CODE BEGIN 6 */
  1140.         /* User can add his own implementation to report the file name and line number,
  1141.          ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1142.   /* USER CODE END 6 */
  1143. }
  1144. #endif /* USE_FULL_ASSERT */
  1145.  
  1146. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  1147.