Subversion Repositories EngineBay2

Rev

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