Subversion Repositories EngineBay2

Rev

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