Subversion Repositories DashDisplay

Rev

Rev 79 | 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.  
  22. #include "main.h"
  23.  
  24. /* Private includes ----------------------------------------------------------*/
  25. /* USER CODE BEGIN Includes */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28.  
  29. #include "libPLX/plx.h"
  30. #include "libPLX/displayinfo.h"
  31. #include "libPLX/commsLib.h"
  32. #include "libSerial/serialUtils.H"
  33.  
  34. #include "libSmallPrintf/small_printf.h"
  35. #include "libNMEA/nmea.h"
  36. #include "switches.h"
  37. #include <string.h>
  38.  
  39. /* USER CODE END Includes */
  40.  
  41. /* Private typedef -----------------------------------------------------------*/
  42. /* USER CODE BEGIN PTD */
  43.  
  44. /* USER CODE END PTD */
  45.  
  46. /* Private define ------------------------------------------------------------*/
  47. /* USER CODE BEGIN PD */
  48. /* USER CODE END PD */
  49.  
  50. /* Private macro -------------------------------------------------------------*/
  51. /* USER CODE BEGIN PM */
  52.  
  53. /* USER CODE END PM */
  54.  
  55. /* Private variables ---------------------------------------------------------*/
  56. I2C_HandleTypeDef hi2c1;
  57.  
  58. SPI_HandleTypeDef hspi1;
  59.  
  60. TIM_HandleTypeDef htim2;
  61. TIM_HandleTypeDef htim3;
  62. TIM_HandleTypeDef htim9;
  63.  
  64. UART_HandleTypeDef huart4;
  65. UART_HandleTypeDef huart1;
  66. UART_HandleTypeDef huart2;
  67. UART_HandleTypeDef huart3;
  68.  
  69. /* USER CODE BEGIN PV */
  70. /* Private variables ---------------------------------------------------------*/
  71.  
  72. ///@brief  timeout when the ignition is switched off
  73. uint32_t const IGNITION_OFF_TIMEOUT = 30000UL;
  74.  
  75. /// @brief 1000mS per logger period, print average per period
  76. uint32_t const LOGGER_INTERVAL = 250UL;
  77.  
  78. /// @brief  about 2 seconds after twiddle, save the dial position.
  79. const int DialTimeout = 2000;
  80.  
  81. /// @brief Observations are stale if not seen for 1 second  
  82. const int MAX_OBS_AGE = 1000;
  83.  
  84. /// @brief Unused Observation
  85. uniqueObs_t const nullObs = {PLX_MAX_OBS,
  86.                              PLX_MAX_INST};
  87.  
  88. /// @brief Null context
  89. context_t const nullContext = {.knobPos = -1,
  90.                                .dial_timer = 0,
  91.                                .dial0 = -1,
  92.                                .dial1 = -1,
  93.                                .OldObservation = nullObs};
  94.  
  95. /// @brief Define a null item
  96. info_t const nullInfo = {.Max = 0,
  97.                          .Min = 0xFFF,
  98.                          .sum = 0,
  99.                          .count = 0,
  100.                          .updated = 0,
  101.                          .lastUpdated = 0,
  102.                          .observation = nullObs};
  103.  
  104. context_t contexts[MAX_DISPLAYS];
  105.  
  106. /// @brief Data storage for readings
  107. info_t Info[INFO_SIZE];
  108.  
  109. uint32_t Latch_Timer = 0 ;
  110.  
  111. // location for GPS data
  112. Location loc = {};
  113.  
  114. /// @brief Time when the logged data will be sent
  115. uint32_t nextTickReload = 0;
  116.  
  117. // data timeout
  118. uint32_t dataTimeout = 0; //
  119.  
  120. // USART buffers
  121. uint8_t uc1_tx_buffer[TX_USART_BUFF_SIZ];
  122. uint8_t uc1_rx_buffer[RX_USART_BUFF_SIZ];
  123.  
  124. uint8_t uc2_tx_buffer[TX_USART_BUFF_SIZ];
  125. uint8_t uc2_rx_buffer[RX_USART_BUFF_SIZ];
  126.  
  127. uint8_t uc3_tx_buffer[TX_USART_BUFF_SIZ];
  128. uint8_t uc3_rx_buffer[RX_USART_BUFF_SIZ];
  129.  
  130. uint8_t uc4_tx_buffer[TX_USART_BUFF_SIZ];
  131. uint8_t uc4_rx_buffer[RX_USART_BUFF_SIZ];
  132.  
  133. /* USER CODE END PV */
  134.  
  135. /* Private function prototypes -----------------------------------------------*/
  136. void SystemClock_Config(void);
  137. static void MX_GPIO_Init(void);
  138. static void MX_SPI1_Init(void);
  139. static void MX_USART1_UART_Init(void);
  140. static void MX_USART2_UART_Init(void);
  141. static void MX_USART3_UART_Init(void);
  142. static void MX_TIM3_Init(void);
  143. static void MX_TIM9_Init(void);
  144. static void MX_TIM2_Init(void);
  145. static void MX_UART4_Init(void);
  146. static void MX_I2C1_Init(void);
  147. /* USER CODE BEGIN PFP */
  148.  
  149. // the dial is the switch number we are using.
  150. // suppress is the ItemIndex we wish to suppress on this display
  151. int DisplayCurrent(int dial, int suppress)
  152. {
  153.   return cc_display(dial, suppress);
  154. }
  155.  
  156. /// \note  HC-05 only accepts : 9600,19200,38400,57600,115200,230400,460800 baud
  157. /// \brief Setup Bluetooth module
  158. void initModule(struct usart_ctl *ctl, uint32_t baudRate)
  159. {
  160.   char initBuf[60];
  161.   // switch to command mode
  162.   HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_SET);
  163.   HAL_Delay(500);
  164.   // clear the button press
  165.   HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_RESET);
  166.   HAL_Delay(500);
  167.   setBaud(ctl, 38400);
  168.   int initLen = small_sprintf(initBuf, "AT\nAT+UART?\nAT+UART=%ld,0,0\n", baudRate);
  169.   const char buf[] = "AT+RESET\n";
  170.   sendString(ctl, initBuf, initLen);
  171.   HAL_Delay(500);
  172.   initLen = small_sprintf(initBuf, buf);
  173.   sendString(ctl, initBuf, initLen);
  174.  
  175.   TxWaitEmpty(ctl);
  176.  
  177.   // switch back to normal comms at new baud rate
  178.   setBaud(ctl, baudRate);
  179.   HAL_Delay(100);
  180. }
  181.  
  182. // workspace for RMC data read from GPS module.
  183. volatile uint16_t rmc_length;
  184.  
  185. uint8_t rmc_callback(uint8_t *data, uint16_t length)
  186. {
  187.   // send it back out
  188.   rmc_length = length;
  189.  
  190.   sendString(&uc3, (const char *)data, length);
  191.  
  192.   nextTickReload = HAL_GetTick() + LOGGER_INTERVAL;
  193.  
  194.   return 0;
  195. }
  196.  
  197. // check if bluetooth connected
  198. uint8_t btConnected()
  199. {
  200.   return HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET;
  201. }
  202.  
  203. /// @brief return true if this slot is unused
  204. /// @param ptr pointer to the slot to
  205. uint8_t isUnused(int index)
  206. {
  207.   if (index < 0 || index > PLX_MAX_OBS)
  208.     return false;
  209.   return Info[index].observation.Instance == PLX_MAX_INST && Info[index].observation.Obs == PLX_MAX_OBS;
  210. }
  211.  
  212. /// @brief Determine if an entry is currently valid
  213. /// @param index the number of the array entry to display
  214. /// @return true if the entry contains data which is fresh
  215. uint8_t isValid(int index)
  216. {
  217.   if (index < 0 || index > INFO_SIZE)
  218.     return false;
  219.   if (isUnused(index))
  220.     return false;
  221.  
  222.   uint32_t age = HAL_GetTick() - Info[index].lastUpdated;
  223.  
  224.   if (age > MAX_OBS_AGE )
  225.     return false;
  226.  
  227.   return true;
  228. }
  229.  
  230. /* USER CODE END PFP */
  231.  
  232. /* Private user code ---------------------------------------------------------*/
  233. /* USER CODE BEGIN 0 */
  234.  
  235. unsigned mapToIndex(unsigned instance, unsigned item)
  236. {
  237.   return instance + item * PLX_MAX_INST_LIMIT;
  238. }
  239.  
  240. void libPLXcallbackSendUserData(struct usart_ctl *instance)
  241. {
  242.   (void)instance;
  243. }
  244.  
  245. void libPLXcallbackRecievedData(PLX_SensorInfo *info)
  246. {
  247.   // received some data , timeout is reset
  248.   dataTimeout = 0;
  249.  
  250.   // search to see if the item already has a slot in the Info[] array
  251.   // match the observation and instance: if found, update entry
  252.   enum PLX_Observations observation = ConvPLX(info->AddrH,
  253.                                               info->AddrL);
  254.  
  255.   char instance = info->Instance;
  256.  
  257.   // validate the current item, discard out of range
  258.   if ((instance > PLX_MAX_INST_LIMIT) || (observation > PLX_MAX_OBS))
  259.     return;
  260.  
  261.   unsigned currentSlot = mapToIndex(instance, observation);
  262.  
  263.   int16_t data = ConvPLX(info->ReadingH,
  264.                          info->ReadingL);
  265.  
  266.   Info[currentSlot].observation.Obs = observation;
  267.  
  268.   Info[currentSlot].observation.Instance = instance;
  269.   Info[currentSlot].data = data;
  270.   if (data > Info[currentSlot].Max)
  271.   {
  272.     Info[currentSlot].Max = data;
  273.   }
  274.   if (data < Info[currentSlot].Min)
  275.   {
  276.     Info[currentSlot].Min = data;
  277.   }
  278.   // take an average
  279.   Info[currentSlot].sum += data;
  280.   Info[currentSlot].count++;
  281.   // note the last update time
  282.   Info[currentSlot].lastUpdated = HAL_GetTick();
  283.   Info[currentSlot].updated = 1; // it has been updated
  284. }
  285.  
  286. // move to the next valid item if the current is not valid
  287. int nextItem(int pos, int delta)
  288. {
  289.   int start = pos;
  290.   // move in positive direction
  291.   while (delta > 0)
  292.   {
  293.     // skip invalid items, dont count
  294.     if (pos < INFO_SIZE - 1)
  295.       pos++;
  296.     else
  297.       pos = 0;
  298.  
  299.     if (isValid(pos))
  300.       delta--; // count a valid item
  301.  
  302.     // wrap
  303.     if (pos == start)
  304.       break;
  305.   }
  306.  
  307.   // move in negative direction
  308.   while (delta < 0)
  309.   {
  310.     // skip invalid items, dont count
  311.     if (pos > 0)
  312.       pos--;
  313.     else
  314.       pos = INFO_SIZE - 1;
  315.  
  316.     if (isValid(pos))
  317.       delta++; // count a valid item
  318.  
  319.     // wrap
  320.     if (pos == start)
  321.       break;
  322.   }
  323.   return pos;
  324. }
  325.  
  326. /// @brief Log data to bluetooth as a sort of NMEA0183
  327. /// @param offsetTicks fraction of a second offset
  328. /// @return new offsetTicks value
  329. uint32_t logBt( uint32_t offsetTicks)
  330. {
  331.   // Send items  to BT if it is in connected state
  332.   // print timestamp as a $PLTIM record.
  333.   char linebuff[20];
  334.   strftime(linebuff, sizeof(linebuff), "%H%M%S", &loc.tv);
  335.  
  336.   char outbuff[100];
  337.   int cnt = small_sprintf(outbuff, "$PLTIM,%s.%03lu\n", linebuff, offsetTicks);
  338.   sendString(&uc3, outbuff, cnt);
  339.   offsetTicks += LOGGER_INTERVAL;
  340.  
  341.   // increment timer
  342.   if (offsetTicks >= (1000))
  343.   {
  344.     offsetTicks -= 1000;
  345.     loc.tv.tm_sec++;
  346.     if (loc.tv.tm_sec >= 60)
  347.     {
  348.       loc.tv.tm_sec = 0;
  349.       loc.tv.tm_min++;
  350.       if (loc.tv.tm_min >= 60)
  351.       {
  352.         loc.tv.tm_hour++;
  353.         if (loc.tv.tm_hour >= 24)
  354.           loc.tv.tm_hour = 0;
  355.       }
  356.     }
  357.   }
  358.  
  359.   for (int i = 0; i < INFO_SIZE; ++i)
  360.   {
  361.     if (!isValid(i))
  362.       continue;
  363.     // format output
  364.     // avoid division by zero for items with no sample data this iteration
  365.     if (Info[i].count == 0)
  366.       continue;
  367.     double average = (double)Info[i].sum / Info[i].count;
  368.     enum PLX_Observations Observation = Info[i].observation.Obs;
  369.  
  370.     double cur_rdg = ConveriMFDRaw2Data((enum PLX_Observations)Observation, DisplayInfo[Observation].Units,
  371.                                         average);
  372.     int cnt;
  373.     int intPart;
  374.     // depending on digits after the decimal point,
  375.     // choose how to format data
  376.     switch (DisplayInfo[Observation].DP)
  377.     {
  378.     default:
  379.     case 0:
  380.       cnt = small_sprintf(outbuff,
  381.                           "$PLLOG,%s,%d,%d",
  382.                           DisplayInfo[Info[i].observation.Obs].name,
  383.                           Info[i].observation.Instance,
  384.                           (int)cur_rdg);
  385.  
  386.       break;
  387.     case 1:
  388.       intPart = (int)(cur_rdg * 10);
  389.       cnt = small_sprintf(outbuff,
  390.                           "$PLLOG,%s,%d,%d.%1d",
  391.                           DisplayInfo[Info[i].observation.Obs].name,
  392.                           Info[i].observation.Instance,
  393.                           intPart / 10, abs(intPart) % 10);
  394.  
  395.       break;
  396.     case 2:
  397.       intPart = (int)(cur_rdg * 100);
  398.       cnt = small_sprintf(outbuff,
  399.                           "$PLLOG,%s,%d,%d.%02d",
  400.                           DisplayInfo[Info[i].observation.Obs].name,
  401.                           Info[i].observation.Instance,
  402.                           intPart / 100, abs(intPart) % 100);
  403.  
  404.       break;
  405.     }
  406.  
  407.     Info[i].count = 0;
  408.     Info[i].sum = 0;
  409.  
  410.     // NMEA style checksum
  411.     int ck;
  412.     int sum = 0;
  413.     for (ck = 1; ck < cnt; ck++)
  414.       sum += outbuff[ck];
  415.     cnt += small_sprintf(outbuff + cnt, "*%02X\n",
  416.                          sum & 0xFF);
  417.     sendString(&uc3, outbuff, cnt);
  418.   }
  419. return offsetTicks;
  420. }
  421.  
  422.  
  423. void resetDialTimer(int index)
  424. {
  425.   contexts[index].dial_timer =  HAL_GetTick() + DialTimeout;
  426. }
  427.  
  428. /* USER CODE END 0 */
  429.  
  430. /**
  431.  * @brief  The application entry point.
  432.  * @retval int
  433.  */
  434. int main(void)
  435. {
  436.  
  437.   /* USER CODE BEGIN 1 */
  438. #if defined SEMIHOSTING
  439.   initialise_monitor_handles();
  440.   #endif
  441.   __HAL_RCC_SPI1_CLK_ENABLE();
  442.   __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port
  443.   __HAL_RCC_USART2_CLK_ENABLE(); // debug port
  444.   __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port
  445.   __HAL_RCC_UART4_CLK_ENABLE();  // NMEA0183 port
  446.  
  447.   __HAL_RCC_TIM3_CLK_ENABLE();
  448.  
  449.   __HAL_RCC_TIM9_CLK_ENABLE();
  450.  
  451.   /* USER CODE END 1 */
  452.  
  453.   /* MCU Configuration--------------------------------------------------------*/
  454.  
  455.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  456.   HAL_Init();
  457.  
  458.   /* USER CODE BEGIN Init */
  459.  
  460.   /* USER CODE END Init */
  461.  
  462.   /* Configure the system clock */
  463.   SystemClock_Config();
  464.  
  465.   /* USER CODE BEGIN SysInit */
  466.   // Switch handler called on sysTick interrupt.
  467.   InitSwitches();
  468.  
  469.   /* USER CODE END SysInit */
  470.  
  471.   /* Initialize all configured peripherals */
  472.   MX_GPIO_Init();
  473.   MX_SPI1_Init();
  474.   MX_USART1_UART_Init();
  475.   MX_USART2_UART_Init();
  476.   MX_USART3_UART_Init();
  477.   MX_TIM3_Init();
  478.   MX_TIM9_Init();
  479.   MX_TIM2_Init();
  480.   MX_UART4_Init();
  481.   MX_I2C1_Init();
  482.   /* USER CODE BEGIN 2 */
  483.  
  484.   /* Turn on USART1 IRQ */
  485.   HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
  486.   HAL_NVIC_EnableIRQ(USART1_IRQn);
  487.  
  488.   /* Turn on USART2 IRQ  */
  489.   HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
  490.   HAL_NVIC_EnableIRQ(USART2_IRQn);
  491.  
  492.   /* turn on USART3 IRQ */
  493.   HAL_NVIC_SetPriority(USART3_IRQn, 4, 0);
  494.   HAL_NVIC_EnableIRQ(USART3_IRQn);
  495.  
  496.   /* turn on UART4 IRQ */
  497.   HAL_NVIC_SetPriority(UART4_IRQn, 4, 0);
  498.   HAL_NVIC_EnableIRQ(UART4_IRQn);
  499.  
  500.   /* setup the USART control blocks */
  501.   init_usart_ctl(&uc1, &huart1, uc1_tx_buffer,
  502.                  uc1_rx_buffer,
  503.                  TX_USART_BUFF_SIZ,
  504.                  TX_USART_BUFF_SIZ);
  505.   init_usart_ctl(&uc2, &huart2, uc2_tx_buffer,
  506.                  uc2_rx_buffer,
  507.                  TX_USART_BUFF_SIZ,
  508.                  TX_USART_BUFF_SIZ);
  509.   init_usart_ctl(&uc3, &huart3, uc3_tx_buffer,
  510.                  uc3_rx_buffer,
  511.                  TX_USART_BUFF_SIZ,
  512.                  TX_USART_BUFF_SIZ);
  513.   init_usart_ctl(&uc4, &huart4, uc4_tx_buffer,
  514.                  uc4_rx_buffer,
  515.                  TX_USART_BUFF_SIZ,
  516.                  TX_USART_BUFF_SIZ);
  517.  
  518.   EnableSerialRxInterrupt(&uc1);
  519.   EnableSerialRxInterrupt(&uc2);
  520.   EnableSerialRxInterrupt(&uc3);
  521.   EnableSerialRxInterrupt(&uc4);
  522.  
  523.   HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
  524.  
  525.   HAL_TIM_Encoder_Start(&htim9, TIM_CHANNEL_ALL);
  526.  
  527.   initModule(&uc3, 38400);
  528.  
  529.   // Initialise UART for 4800 baud NMEA
  530.   setBaud(&uc2, 4800);
  531.  
  532.   // Initialuse UART4 for 4800 baud NMEA.
  533.   setBaud(&uc4, 4800);
  534.  
  535.   cc_init();
  536.  
  537.   for (int i = 0; i < MAX_DISPLAYS; ++i)
  538.   {
  539.     contexts[i] = nullContext; // set the knob position
  540.     resetDialTimer(i);
  541.   }
  542.  
  543.   /* reset the display timeout, latch on power from accessories */
  544.   Latch_Timer = IGNITION_OFF_TIMEOUT;
  545.   HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
  546.  
  547.   /// @brief Time when the logged data will be sent
  548.  
  549.   setRmcCallback(&rmc_callback);
  550.  
  551.   // used in NMEA style logging
  552.   uint32_t nextTick = 0; ///< time to send next
  553.   nextTickReload = 0;
  554.   uint32_t offsetTicks = 0; ///< time to print as offset in mS for each loop
  555.  
  556.   for (int i = 0; i < INFO_SIZE; ++i)
  557.   {
  558.     Info[i] = nullInfo;
  559.   }
  560.  
  561.   uint32_t resetCounter = 0; // record time at which both reset buttons were first pressed.
  562.  
  563.   resetPLX();
  564.  
  565.   /* USER CODE END 2 */
  566.  
  567.   /* Infinite loop */
  568.   /* USER CODE BEGIN WHILE */
  569.   while (1)
  570.   {
  571.  
  572.     /* while ignition is on, keep resetting power latch timer */
  573.     if (HAL_GPIO_ReadPin(IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET)
  574.     {
  575.       Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT;
  576.     }
  577.     else
  578.     {
  579.       /* if the ignition has been off for a while, then turn off power */
  580.       if (HAL_GetTick() > Latch_Timer)
  581.       {
  582.         HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin,
  583.                           GPIO_PIN_RESET);
  584.       }
  585.     }
  586.  
  587.     // Handle the bluetooth pairing / reset function by pressing both buttons.
  588.     if ((push_pos[0] == 1) && (push_pos[1] == 1))
  589.     {
  590.       HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin,
  591.                         GPIO_PIN_RESET);
  592.       if (resetCounter == 0)
  593.         resetCounter = HAL_GetTick();
  594.     }
  595.     else
  596.     {
  597.       HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin,
  598.                         GPIO_PIN_SET);
  599.  
  600.       if (resetCounter != 0)
  601.       {
  602.         // Held down reset button for 10 seconds, clear NVRAM.
  603.         if ((HAL_GetTick() - resetCounter) > 10000)
  604.         {
  605.           for (int i = 0; i < MAX_DISPLAYS; i++)
  606.           {
  607.             contexts[i] = nullContext;
  608.             contexts[i].dial_timer = HAL_GetTick(); // timeout immediately when decremented
  609.           }
  610.           erase_nvram();
  611.         }
  612.         resetCounter = 0;
  613.       }
  614.     }
  615.  
  616.     // poll GPS Position/time on UART4
  617.     (void)updateLocation(&loc, &uc4);
  618.     if (loc.valid == 'V')
  619.       memset(loc.time, '-', 6);
  620.  
  621.     // if permitted, log data from RMC packet
  622.     if (btConnected())
  623.     {
  624.  
  625.       // Timeout for data logging regularly
  626.       if (HAL_GetTick() > nextTick)
  627.       {
  628.         nextTick = nextTickReload;
  629.         nextTickReload += LOGGER_INTERVAL;
  630.         offsetTicks = logBt(offsetTicks);
  631.       }
  632.     }
  633.  
  634.     // poll data into libPLX
  635.     libPLXpollData(&uc1);
  636.  
  637.     // determine if we are getting any data from the interface
  638.  
  639.     dataTimeout++;
  640.     if (btConnected() && (dataTimeout % 1000 == 0))
  641.     {
  642.       const char msg[] = "Timeout\r\n";
  643.       sendString(&uc3, msg, sizeof(msg));
  644.     }
  645.  
  646.     if (dataTimeout > 60000)
  647.     {
  648.       // do turn off screen
  649.     }
  650.  
  651.     // handle switch rotation
  652.     for (int i = 0; i < MAX_DIALS; ++i)
  653.     {
  654.       int pos = contexts[i].knobPos;
  655.       if (pos < 0)
  656.         break; // dont process until we have read NVRAM for the first time .
  657.       int start = pos;
  658.       pos = nextItem(pos, get_dial_diff(i));
  659.  
  660.       contexts[i].knobPos = pos;
  661.       if (pos != start)
  662.        resetDialTimer(i);
  663.     }
  664.  
  665.     int suppress = -1;
  666.     for (int i = 0; i < MAX_DISPLAYS; ++i)
  667.     { // now to display the information
  668.       suppress = DisplayCurrent(i, suppress);
  669.  
  670.       cc_check_nvram(i);
  671.     }
  672.     HAL_Delay(1);
  673.     /* USER CODE END WHILE */
  674.   }
  675.   /* USER CODE BEGIN 3 */
  676.  
  677.   /* USER CODE END 3 */
  678. }
  679.  
  680. /**
  681.  * @brief System Clock Configuration
  682.  * @retval None
  683.  */
  684. void SystemClock_Config(void)
  685. {
  686.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  687.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  688.  
  689.   /** Configure the main internal regulator output voltage
  690.    */
  691.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  692.  
  693.   /** Initializes the RCC Oscillators according to the specified parameters
  694.    * in the RCC_OscInitTypeDef structure.
  695.    */
  696.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  697.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  698.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  699.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  700.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  701.   RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
  702.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  703.   {
  704.     Error_Handler();
  705.   }
  706.  
  707.   /** Initializes the CPU, AHB and APB buses clocks
  708.    */
  709.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  710.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  711.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  712.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  713.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  714.  
  715.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  716.   {
  717.     Error_Handler();
  718.   }
  719. }
  720.  
  721. /**
  722.  * @brief I2C1 Initialization Function
  723.  * @param None
  724.  * @retval None
  725.  */
  726. static void MX_I2C1_Init(void)
  727. {
  728.  
  729.   /* USER CODE BEGIN I2C1_Init 0 */
  730.  
  731.   /* USER CODE END I2C1_Init 0 */
  732.  
  733.   /* USER CODE BEGIN I2C1_Init 1 */
  734.  
  735.   /* USER CODE END I2C1_Init 1 */
  736.   hi2c1.Instance = I2C1;
  737.   hi2c1.Init.ClockSpeed = 100000;
  738.   hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  739.   hi2c1.Init.OwnAddress1 = 0;
  740.   hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  741.   hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  742.   hi2c1.Init.OwnAddress2 = 0;
  743.   hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  744.   hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  745.   if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  746.   {
  747.     Error_Handler();
  748.   }
  749.   /* USER CODE BEGIN I2C1_Init 2 */
  750.  
  751.   /* USER CODE END I2C1_Init 2 */
  752. }
  753.  
  754. /**
  755.  * @brief SPI1 Initialization Function
  756.  * @param None
  757.  * @retval None
  758.  */
  759. static void MX_SPI1_Init(void)
  760. {
  761.  
  762.   /* USER CODE BEGIN SPI1_Init 0 */
  763.  
  764.   /* USER CODE END SPI1_Init 0 */
  765.  
  766.   /* USER CODE BEGIN SPI1_Init 1 */
  767.  
  768.   /* USER CODE END SPI1_Init 1 */
  769.   /* SPI1 parameter configuration*/
  770.   hspi1.Instance = SPI1;
  771.   hspi1.Init.Mode = SPI_MODE_MASTER;
  772.   hspi1.Init.Direction = SPI_DIRECTION_1LINE;
  773.   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  774.   hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
  775.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  776.   hspi1.Init.NSS = SPI_NSS_SOFT;
  777.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  778.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  779.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  780.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  781.   hspi1.Init.CRCPolynomial = 10;
  782.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  783.   {
  784.     Error_Handler();
  785.   }
  786.   /* USER CODE BEGIN SPI1_Init 2 */
  787.  
  788.   /* USER CODE END SPI1_Init 2 */
  789. }
  790.  
  791. /**
  792.  * @brief TIM2 Initialization Function
  793.  * @param None
  794.  * @retval None
  795.  */
  796. static void MX_TIM2_Init(void)
  797. {
  798.  
  799.   /* USER CODE BEGIN TIM2_Init 0 */
  800.  
  801.   /* USER CODE END TIM2_Init 0 */
  802.  
  803.   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  804.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  805.  
  806.   /* USER CODE BEGIN TIM2_Init 1 */
  807.  
  808.   /* USER CODE END TIM2_Init 1 */
  809.   htim2.Instance = TIM2;
  810.   htim2.Init.Prescaler = 0;
  811.   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  812.   htim2.Init.Period = 65535;
  813.   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  814.   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  815.   if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  816.   {
  817.     Error_Handler();
  818.   }
  819.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  820.   if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  821.   {
  822.     Error_Handler();
  823.   }
  824.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  825.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  826.   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  827.   {
  828.     Error_Handler();
  829.   }
  830.   /* USER CODE BEGIN TIM2_Init 2 */
  831.  
  832.   /* USER CODE END TIM2_Init 2 */
  833. }
  834.  
  835. /**
  836.  * @brief TIM3 Initialization Function
  837.  * @param None
  838.  * @retval None
  839.  */
  840. static void MX_TIM3_Init(void)
  841. {
  842.  
  843.   /* USER CODE BEGIN TIM3_Init 0 */
  844.  
  845.   /* USER CODE END TIM3_Init 0 */
  846.  
  847.   TIM_Encoder_InitTypeDef sConfig = {0};
  848.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  849.  
  850.   /* USER CODE BEGIN TIM3_Init 1 */
  851.  
  852.   /* USER CODE END TIM3_Init 1 */
  853.   htim3.Instance = TIM3;
  854.   htim3.Init.Prescaler = 0;
  855.   htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  856.   htim3.Init.Period = 65535;
  857.   htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  858.   htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  859.   sConfig.EncoderMode = TIM_ENCODERMODE_TI1;
  860.   sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  861.   sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  862.   sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
  863.   sConfig.IC1Filter = 15;
  864.   sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  865.   sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  866.   sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
  867.   sConfig.IC2Filter = 15;
  868.   if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK)
  869.   {
  870.     Error_Handler();
  871.   }
  872.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  873.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  874.   if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  875.   {
  876.     Error_Handler();
  877.   }
  878.   /* USER CODE BEGIN TIM3_Init 2 */
  879.  
  880.   /* USER CODE END TIM3_Init 2 */
  881. }
  882.  
  883. /**
  884.  * @brief TIM9 Initialization Function
  885.  * @param None
  886.  * @retval None
  887.  */
  888. static void MX_TIM9_Init(void)
  889. {
  890.  
  891.   /* USER CODE BEGIN TIM9_Init 0 */
  892.  
  893.   /* USER CODE END TIM9_Init 0 */
  894.  
  895.   TIM_Encoder_InitTypeDef sConfig = {0};
  896.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  897.  
  898.   /* USER CODE BEGIN TIM9_Init 1 */
  899.  
  900.   /* USER CODE END TIM9_Init 1 */
  901.   htim9.Instance = TIM9;
  902.   htim9.Init.Prescaler = 0;
  903.   htim9.Init.CounterMode = TIM_COUNTERMODE_UP;
  904.   htim9.Init.Period = 65535;
  905.   htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  906.   htim9.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  907.   sConfig.EncoderMode = TIM_ENCODERMODE_TI1;
  908.   sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  909.   sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  910.   sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
  911.   sConfig.IC1Filter = 15;
  912.   sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  913.   sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  914.   sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
  915.   sConfig.IC2Filter = 0;
  916.   if (HAL_TIM_Encoder_Init(&htim9, &sConfig) != HAL_OK)
  917.   {
  918.     Error_Handler();
  919.   }
  920.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  921.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  922.   if (HAL_TIMEx_MasterConfigSynchronization(&htim9, &sMasterConfig) != HAL_OK)
  923.   {
  924.     Error_Handler();
  925.   }
  926.   /* USER CODE BEGIN TIM9_Init 2 */
  927.  
  928.   /* USER CODE END TIM9_Init 2 */
  929. }
  930.  
  931. /**
  932.  * @brief UART4 Initialization Function
  933.  * @param None
  934.  * @retval None
  935.  */
  936. static void MX_UART4_Init(void)
  937. {
  938.  
  939.   /* USER CODE BEGIN UART4_Init 0 */
  940.  
  941.   /* USER CODE END UART4_Init 0 */
  942.  
  943.   /* USER CODE BEGIN UART4_Init 1 */
  944.  
  945.   /* USER CODE END UART4_Init 1 */
  946.   huart4.Instance = UART4;
  947.   huart4.Init.BaudRate = 4800;
  948.   huart4.Init.WordLength = UART_WORDLENGTH_8B;
  949.   huart4.Init.StopBits = UART_STOPBITS_1;
  950.   huart4.Init.Parity = UART_PARITY_NONE;
  951.   huart4.Init.Mode = UART_MODE_TX_RX;
  952.   huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  953.   huart4.Init.OverSampling = UART_OVERSAMPLING_16;
  954.   if (HAL_UART_Init(&huart4) != HAL_OK)
  955.   {
  956.     Error_Handler();
  957.   }
  958.   /* USER CODE BEGIN UART4_Init 2 */
  959.  
  960.   /* USER CODE END UART4_Init 2 */
  961. }
  962.  
  963. /**
  964.  * @brief USART1 Initialization Function
  965.  * @param None
  966.  * @retval None
  967.  */
  968. static void MX_USART1_UART_Init(void)
  969. {
  970.  
  971.   /* USER CODE BEGIN USART1_Init 0 */
  972.  
  973.   /* USER CODE END USART1_Init 0 */
  974.  
  975.   /* USER CODE BEGIN USART1_Init 1 */
  976.  
  977.   /* USER CODE END USART1_Init 1 */
  978.   huart1.Instance = USART1;
  979.   huart1.Init.BaudRate = 19200;
  980.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  981.   huart1.Init.StopBits = UART_STOPBITS_1;
  982.   huart1.Init.Parity = UART_PARITY_NONE;
  983.   huart1.Init.Mode = UART_MODE_TX_RX;
  984.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  985.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  986.   if (HAL_UART_Init(&huart1) != HAL_OK)
  987.   {
  988.     Error_Handler();
  989.   }
  990.   /* USER CODE BEGIN USART1_Init 2 */
  991.  
  992.   /* USER CODE END USART1_Init 2 */
  993. }
  994.  
  995. /**
  996.  * @brief USART2 Initialization Function
  997.  * @param None
  998.  * @retval None
  999.  */
  1000. static void MX_USART2_UART_Init(void)
  1001. {
  1002.  
  1003.   /* USER CODE BEGIN USART2_Init 0 */
  1004.  
  1005.   /* USER CODE END USART2_Init 0 */
  1006.  
  1007.   /* USER CODE BEGIN USART2_Init 1 */
  1008.  
  1009.   /* USER CODE END USART2_Init 1 */
  1010.   huart2.Instance = USART2;
  1011.   huart2.Init.BaudRate = 115200;
  1012.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  1013.   huart2.Init.StopBits = UART_STOPBITS_1;
  1014.   huart2.Init.Parity = UART_PARITY_NONE;
  1015.   huart2.Init.Mode = UART_MODE_TX_RX;
  1016.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1017.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  1018.   if (HAL_UART_Init(&huart2) != HAL_OK)
  1019.   {
  1020.     Error_Handler();
  1021.   }
  1022.   /* USER CODE BEGIN USART2_Init 2 */
  1023.  
  1024.   /* USER CODE END USART2_Init 2 */
  1025. }
  1026.  
  1027. /**
  1028.  * @brief USART3 Initialization Function
  1029.  * @param None
  1030.  * @retval None
  1031.  */
  1032. static void MX_USART3_UART_Init(void)
  1033. {
  1034.  
  1035.   /* USER CODE BEGIN USART3_Init 0 */
  1036.  
  1037.   /* USER CODE END USART3_Init 0 */
  1038.  
  1039.   /* USER CODE BEGIN USART3_Init 1 */
  1040.  
  1041.   /* USER CODE END USART3_Init 1 */
  1042.   huart3.Instance = USART3;
  1043.   huart3.Init.BaudRate = 19200;
  1044.   huart3.Init.WordLength = UART_WORDLENGTH_8B;
  1045.   huart3.Init.StopBits = UART_STOPBITS_1;
  1046.   huart3.Init.Parity = UART_PARITY_NONE;
  1047.   huart3.Init.Mode = UART_MODE_TX_RX;
  1048.   huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1049.   huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  1050.   if (HAL_UART_Init(&huart3) != HAL_OK)
  1051.   {
  1052.     Error_Handler();
  1053.   }
  1054.   /* USER CODE BEGIN USART3_Init 2 */
  1055.  
  1056.   /* USER CODE END USART3_Init 2 */
  1057. }
  1058.  
  1059. /**
  1060.  * @brief GPIO Initialization Function
  1061.  * @param None
  1062.  * @retval None
  1063.  */
  1064. static void MX_GPIO_Init(void)
  1065. {
  1066.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  1067.   /* USER CODE BEGIN MX_GPIO_Init_1 */
  1068.   /* USER CODE END MX_GPIO_Init_1 */
  1069.  
  1070.   /* GPIO Ports Clock Enable */
  1071.   __HAL_RCC_GPIOH_CLK_ENABLE();
  1072.   __HAL_RCC_GPIOA_CLK_ENABLE();
  1073.   __HAL_RCC_GPIOC_CLK_ENABLE();
  1074.   __HAL_RCC_GPIOB_CLK_ENABLE();
  1075.  
  1076.   /*Configure GPIO pin Output Level */
  1077.   HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | BT_BUTTON_Pin | BT_RESET_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(GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin, GPIO_PIN_RESET);
  1084.  
  1085.   /*Configure GPIO pin Output Level */
  1086.   HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
  1087.  
  1088.   /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */
  1089.   GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_CD_Pin;
  1090.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1091.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1092.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1093.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1094.  
  1095.   /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */
  1096.   GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | POWER_LATCH_Pin | USB_PWR_Pin;
  1097.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1098.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1099.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1100.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1101.  
  1102.   /*Configure GPIO pins : BT_STATE_Pin SW1_PUSH_Pin SW2_PUSH_Pin */
  1103.   GPIO_InitStruct.Pin = BT_STATE_Pin | SW1_PUSH_Pin | SW2_PUSH_Pin;
  1104.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1105.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1106.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1107.  
  1108.   /*Configure GPIO pin : IGNITION_Pin */
  1109.   GPIO_InitStruct.Pin = IGNITION_Pin;
  1110.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1111.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1112.   HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct);
  1113.  
  1114.   /*Configure GPIO pin : BT_BUTTON_Pin */
  1115.   GPIO_InitStruct.Pin = BT_BUTTON_Pin;
  1116.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  1117.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  1118.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1119.   HAL_GPIO_Init(BT_BUTTON_GPIO_Port, &GPIO_InitStruct);
  1120.  
  1121.   /*Configure GPIO pin : BT_RESET_Pin */
  1122.   GPIO_InitStruct.Pin = BT_RESET_Pin;
  1123.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1124.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1125.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  1126.   HAL_GPIO_Init(BT_RESET_GPIO_Port, &GPIO_InitStruct);
  1127.  
  1128.   /* USER CODE BEGIN MX_GPIO_Init_2 */
  1129.   /* USER CODE END MX_GPIO_Init_2 */
  1130. }
  1131.  
  1132. /* USER CODE BEGIN 4 */
  1133.  
  1134. /* USER CODE END 4 */
  1135.  
  1136. /**
  1137.  * @brief  This function is executed in case of error occurrence.
  1138.  * @retval None
  1139.  */
  1140. void Error_Handler(void)
  1141. {
  1142.   /* USER CODE BEGIN Error_Handler_Debug */
  1143.   /* User can add his own implementation to report the HAL error return state */
  1144.  
  1145.   /* USER CODE END Error_Handler_Debug */
  1146. }
  1147.  
  1148. #ifdef USE_FULL_ASSERT
  1149. /**
  1150.  * @brief  Reports the name of the source file and the source line number
  1151.  *         where the assert_param error has occurred.
  1152.  * @param  file: pointer to the source file name
  1153.  * @param  line: assert_param error line source number
  1154.  * @retval None
  1155.  */
  1156. void assert_failed(uint8_t *file, uint32_t line)
  1157. {
  1158.   /* USER CODE BEGIN 6 */
  1159.   /* User can add his own implementation to report the file name and line number,
  1160.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1161.   /* USER CODE END 6 */
  1162. }
  1163. #endif /* USE_FULL_ASSERT */
  1164.