Facebook
From Sweet Gibbon, 2 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 224
  1.  
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * This notice applies to any and all portions of this file
  8.   * that are not between comment pairs USER CODE BEGIN and
  9.   * USER CODE END. Other portions of this file, whether
  10.   * inserted by the user or by software development tools
  11.   * are owned by their respective copyright owners.
  12.   *
  13.   * Copyright (c) 2018 STMicroelectronics International N.V.
  14.   * All rights reserved.
  15.   *
  16.   * Redistribution and use in source and binary forms, with or without
  17.   * modification, are permitted, provided that the following conditions are met:
  18.   *
  19.   * 1. Redistribution of source code must retain the above copyright notice,
  20.   *    this list of conditions and the following disclaimer.
  21.   * 2. Redistributions in binary form must reproduce the above copyright notice,
  22.   *    this list of conditions and the following disclaimer in the documentation
  23.   *    and/or other materials provided with the distribution.
  24.   * 3. Neither the name of STMicroelectronics nor the names of other
  25.   *    contributors to this software may be used to endorse or promote products
  26.   *    derived from this software without specific written permission.
  27.   * 4. This software, including modifications and/or derivative works of this
  28.   *    software, must execute solely and exclusively on microcontroller or
  29.   *    microprocessor devices manufactured by or for STMicroelectronics.
  30.   * 5. Redistribution and use of this software other than as permitted under
  31.   *    this license is void and will automatically terminate your rights under
  32.   *    this license.
  33.   *
  34.   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35.   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36.   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37.   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38.   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39.   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40.   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42.   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43.   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44.   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45.   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.   *
  47.   ******************************************************************************
  48.   */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "main.h"
  51. #include "stm32f7xx_hal.h"
  52. #include "cmsis_os.h"
  53. #include "fatfs.h"
  54. #include "lwip.h"
  55. #include "usb_host.h"
  56.  
  57. /* USER CODE BEGIN Includes */
  58. #include  <errno.h>
  59. #include  <sys/unistd.h>
  60.  
  61. #include "stm32746g_discovery_lcd.h"
  62. #include "Utilities/Fonts/fonts.h"
  63. #include "stm32746g_discovery_ts.h"
  64. #include "stm32746g_discovery_audio.h"
  65. #include "term_io.h"
  66. #include "dbgu.h"
  67. #include "ansi.h"
  68.  
  69. #include "FreeRTOS.h"
  70. #include "task.h"
  71. #include "queue.h"
  72.  
  73. #include "lwip/opt.h"
  74. #include "lwip/api.h"
  75. #include "lwip/apps/fs.h"
  76. #include "lwip/dhcp.h"
  77. #include "lwip/tcpip.h"
  78. #include "lwip/netdb.h"
  79. #include "lwip/sockets.h"
  80.  
  81. #include "lwip.h"
  82.  
  83. #include "wm8994/wm8994.h"
  84.  
  85.  
  86.  
  87.  
  88. /* USER CODE END Includes */
  89.  
  90. /* Private variables ---------------------------------------------------------*/
  91. ADC_HandleTypeDef hadc3;
  92.  
  93. CRC_HandleTypeDef hcrc;
  94.  
  95. DCMI_HandleTypeDef hdcmi;
  96.  
  97. DMA2D_HandleTypeDef hdma2d;
  98.  
  99. I2C_HandleTypeDef hi2c1;
  100. I2C_HandleTypeDef hi2c3;
  101.  
  102. LTDC_HandleTypeDef hltdc;
  103.  
  104. QSPI_HandleTypeDef hqspi;
  105.  
  106. RTC_HandleTypeDef hrtc;
  107.  
  108. SAI_HandleTypeDef hsai_BlockA2;
  109. SAI_HandleTypeDef hsai_BlockB2;
  110.  
  111. SD_HandleTypeDef hsd1;
  112.  
  113. SPDIFRX_HandleTypeDef hspdif;
  114.  
  115. SPI_HandleTypeDef hspi2;
  116.  
  117. TIM_HandleTypeDef htim1;
  118. TIM_HandleTypeDef htim2;
  119. TIM_HandleTypeDef htim3;
  120. TIM_HandleTypeDef htim5;
  121. TIM_HandleTypeDef htim7;
  122. TIM_HandleTypeDef htim8;
  123. TIM_HandleTypeDef htim12;
  124.  
  125. UART_HandleTypeDef huart1;
  126. UART_HandleTypeDef huart6;
  127.  
  128. SDRAM_HandleTypeDef hsdram1;
  129.  
  130. osThreadId defaultTaskHandle;
  131.  
  132. /* USER CODE BEGIN PV */
  133. /* Private variables ---------------------------------------------------------*/
  134.  
  135. /* USER CODE END PV */
  136.  
  137. /* Private function prototypes -----------------------------------------------*/
  138. void SystemClock_Config(void);
  139. static void MX_GPIO_Init(void);
  140. static void MX_ADC3_Init(void);
  141. static void MX_CRC_Init(void);
  142. static void MX_DCMI_Init(void);
  143. static void MX_DMA2D_Init(void);
  144. static void MX_FMC_Init(void);
  145. static void MX_I2C1_Init(void);
  146. static void MX_I2C3_Init(void);
  147. static void MX_LTDC_Init(void);
  148. static void MX_QUADSPI_Init(void);
  149. static void MX_RTC_Init(void);
  150. static void MX_SAI2_Init(void);
  151. static void MX_SDMMC1_SD_Init(void);
  152. static void MX_SPDIFRX_Init(void);
  153. static void MX_SPI2_Init(void);
  154. static void MX_TIM1_Init(void);
  155. static void MX_TIM2_Init(void);
  156. static void MX_TIM3_Init(void);
  157. static void MX_TIM5_Init(void);
  158. static void MX_TIM8_Init(void);
  159. static void MX_TIM12_Init(void);
  160. static void MX_USART1_UART_Init(void);
  161. static void MX_USART6_UART_Init(void);
  162. static void MX_TIM7_Init(void);
  163. void StartDefaultTask(void const * argument);
  164.  
  165. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  166.  
  167.  
  168.  
  169.  
  170.  
  171. /* USER CODE BEGIN PFP */
  172. /* Private function prototypes -----------------------------------------------*/
  173.  
  174. /* USER CODE END PFP */
  175.  
  176. /* USER CODE BEGIN 0 */
  177. void mainTask(void* p);
  178.  
  179. osThreadId netconn_thread_handle;
  180.  
  181. #define LCD_X_SIZE                      RK043FN48H_WIDTH
  182. #define LCD_Y_SIZE                      RK043FN48H_HEIGHT
  183.  
  184. #define PRINTF_USES_HAL_TX              0
  185.  
  186. int __io_putchar(int ch)
  187. {
  188.         uint8_t data = ch;
  189.         #if PRINTF_USES_HAL_TX
  190.                 HAL_StatusTypeDef status = HAL_UART_Transmit(&huart1, (uint8_t*)&data, len, 100);
  191.         #else
  192.                 while(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) == RESET) { ; }
  193.                 huart1.Instance->TDR = (uint16_t)data;
  194.         #endif
  195.         return 0;
  196. }
  197.  
  198. char inkey(void)
  199. {
  200.         uint32_t flags = huart1.Instance->ISR;
  201.  
  202.         if((flags & UART_FLAG_RXNE) || (flags & UART_FLAG_ORE))
  203.         {
  204.                 __HAL_UART_CLEAR_OREFLAG(&huart1);
  205.                 return (huart1.Instance->RDR);
  206.         }
  207.         else
  208.                 return 0;
  209. }
  210.  
  211. //partially based on available code examples
  212. static void lcd_start(void)
  213. {
  214.   /* LCD Initialization */
  215.   BSP_LCD_Init();
  216.  
  217.   /* LCD Initialization */
  218.   BSP_LCD_LayerDefaultInit(0, (unsigned int)0xC0000000);
  219.   //BSP_LCD_LayerDefaultInit(1, (unsigned int)lcd_image_bg+(LCD_X_SIZE*LCD_Y_SIZE*4));
  220.   BSP_LCD_LayerDefaultInit(1, (unsigned int)0xC0000000+(LCD_X_SIZE*LCD_Y_SIZE*4));
  221.  
  222.   /* Enable the LCD */
  223.   BSP_LCD_DisplayOn();
  224.  
  225.   /* Select the LCD Background Layer  */
  226.   BSP_LCD_SelectLayer(0);
  227.  
  228.   /* Clear the Background Layer */
  229.   BSP_LCD_Clear(LCD_COLOR_WHITE);
  230.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  231.  
  232.   BSP_LCD_SetColorKeying(1,LCD_COLOR_WHITE);
  233.  
  234.   /* Select the LCD Foreground Layer  */
  235.   BSP_LCD_SelectLayer(1);
  236.  
  237.   /* Clear the Foreground Layer */
  238.   BSP_LCD_Clear(LCD_COLOR_WHITE);
  239.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  240.  
  241.   /* Configure the transparency for foreground and background :
  242.      Increase the transparency */
  243.   BSP_LCD_SetTransparency(0, 255);
  244.   BSP_LCD_SetTransparency(1, 255);
  245. }
  246.  
  247. //[rmv]
  248. void draw_background(void)
  249. {
  250.         /* Select the LCD Background Layer  */
  251.         BSP_LCD_SelectLayer(0);
  252.         BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  253.         BSP_LCD_FillRect(0.4*LCD_X_SIZE,0.2*LCD_Y_SIZE,150,130);
  254.  
  255.         //select Foreground Layer
  256.         BSP_LCD_SelectLayer(1);
  257. }
  258.  
  259. static TS_StateTypeDef  TS_State;
  260.  
  261.  
  262. int initialize_touchscreen(void)
  263. {
  264.         uint8_t  status = 0;
  265.         status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  266.         if(status != TS_OK) return -1;
  267.         return 0;
  268. }
  269.  
  270.  
  271.  
  272. /* USER CODE END 0 */
  273.  
  274. /**
  275.   * @brief  The application entry point.
  276.   *
  277.   * @retval None
  278.   */
  279. int main(void)
  280. {
  281.   /* USER CODE BEGIN 1 */
  282.  
  283.   /* USER CODE END 1 */
  284.  
  285.   /* MCU Configuration----------------------------------------------------------*/
  286.  
  287.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  288.   HAL_Init();
  289.  
  290.   /* USER CODE BEGIN Init */
  291.  
  292.   /* USER CODE END Init */
  293.  
  294.   /* Configure the system clock */
  295.   SystemClock_Config();
  296.  
  297.   /* USER CODE BEGIN SysInit */
  298.  
  299.   /* USER CODE END SysInit */
  300.  
  301.   /* Initialize all configured peripherals */
  302.   MX_GPIO_Init();
  303.   MX_ADC3_Init();
  304.   MX_CRC_Init();
  305.   MX_DCMI_Init();
  306.   MX_DMA2D_Init();
  307.   MX_FMC_Init();
  308.   MX_I2C1_Init();
  309.   MX_I2C3_Init();
  310.   MX_LTDC_Init();
  311.   MX_QUADSPI_Init();
  312.   MX_RTC_Init();
  313.   MX_SAI2_Init();
  314.   MX_SDMMC1_SD_Init();
  315.   MX_SPDIFRX_Init();
  316.   MX_SPI2_Init();
  317.   MX_TIM1_Init();
  318.   MX_TIM2_Init();
  319.   MX_TIM3_Init();
  320.   MX_TIM5_Init();
  321.   MX_TIM8_Init();
  322.   MX_TIM12_Init();
  323.   MX_USART1_UART_Init();
  324.   MX_USART6_UART_Init();
  325.   MX_TIM7_Init();
  326.   /* USER CODE BEGIN 2 */
  327.   debug_init(&huart1);
  328.  
  329.   xprintf(ANSI_FG_GREEN "STM32F746 Discovery Project" ANSI_FG_DEFAULT "\n");
  330.  
  331.   printf("Regular printf\n");
  332.  
  333. lcd_start();
  334. draw_background();
  335. initialize_touchscreen();
  336.  
  337.   /* USER CODE END 2 */
  338.  
  339.   /* USER CODE BEGIN RTOS_MUTEX */
  340.   /* add mutexes, ... */
  341.   /* USER CODE END RTOS_MUTEX */
  342.  
  343.   /* USER CODE BEGIN RTOS_SEMAPHORES */
  344.   /* add semaphores, ... */
  345.   /* USER CODE END RTOS_SEMAPHORES */
  346.  
  347.   /* USER CODE BEGIN RTOS_TIMERS */
  348.   /* start timers, add new ones, ... */
  349.   /* USER CODE END RTOS_TIMERS */
  350.  
  351.   /* Create the thread(s) */
  352.   /* definition and creation of defaultTask */
  353.   osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
  354.   defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  355.  
  356.   /* USER CODE BEGIN RTOS_THREADS */
  357.   /* add threads, ... */
  358.   /* USER CODE END RTOS_THREADS */
  359.  
  360.   /* USER CODE BEGIN RTOS_QUEUES */
  361.   /* add queues, ... */
  362.   /* USER CODE END RTOS_QUEUES */
  363.  
  364.  
  365.   /* Start scheduler */
  366.   osKernelStart();
  367.  
  368.   /* We should never get here as control is now taken by the scheduler */
  369.  
  370.   /* Infinite loop */
  371.   /* USER CODE BEGIN WHILE */
  372.   while (1)
  373.   {
  374.  
  375.   /* USER CODE END WHILE */
  376.  
  377.   /* USER CODE BEGIN 3 */
  378.  
  379.   }
  380.   /* USER CODE END 3 */
  381.  
  382. }
  383.  
  384. /**
  385.   * @brief System Clock Configuration
  386.   * @retval None
  387.   */
  388. void SystemClock_Config(void)
  389. {
  390.  
  391.   RCC_OscInitTypeDef RCC_OscInitStruct;
  392.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  393.   RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  394.  
  395.     /**Configure the main internal regulator output voltage
  396.     */
  397.   __HAL_RCC_PWR_CLK_ENABLE();
  398.  
  399.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  400.  
  401.     /**Initializes the CPU, AHB and APB busses clocks
  402.     */
  403.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  404.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  405.   RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  406.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  407.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  408.   RCC_OscInitStruct.PLL.PLLM = 25;
  409.   RCC_OscInitStruct.PLL.PLLN = 400;
  410.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  411.   RCC_OscInitStruct.PLL.PLLQ = 8;
  412.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  413.   {
  414.     _Error_Handler(__FILE__, __LINE__);
  415.   }
  416.  
  417.     /**Activate the Over-Drive mode
  418.     */
  419.   if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  420.   {
  421.     _Error_Handler(__FILE__, __LINE__);
  422.   }
  423.  
  424.     /**Initializes the CPU, AHB and APB busses clocks
  425.     */
  426.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  427.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  428.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  429.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  430.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  431.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  432.  
  433.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK)
  434.   {
  435.     _Error_Handler(__FILE__, __LINE__);
  436.   }
  437.  
  438.   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPDIFRX|RCC_PERIPHCLK_LTDC
  439.                               |RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART1
  440.                               |RCC_PERIPHCLK_USART6|RCC_PERIPHCLK_SAI2
  441.                               |RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_I2C3
  442.                               |RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_CLK48;
  443.   PeriphClkInitStruct.PLLI2S.PLLI2SN = 100;
  444.   PeriphClkInitStruct.PLLI2S.PLLI2SP = RCC_PLLP_DIV2;
  445.   PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
  446.   PeriphClkInitStruct.PLLI2S.PLLI2SQ = 2;
  447.   PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
  448.   PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
  449.   PeriphClkInitStruct.PLLSAI.PLLSAIQ = 4;
  450.   PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
  451.   PeriphClkInitStruct.PLLI2SDivQ = 1;
  452.   PeriphClkInitStruct.PLLSAIDivQ = 1;
  453.   PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
  454.   PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  455.   PeriphClkInitStruct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLSAI;
  456.   PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  457.   PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
  458.   PeriphClkInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
  459.   PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
  460.   PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLLSAIP;
  461.   PeriphClkInitStruct.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_CLK48;
  462.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  463.   {
  464.     _Error_Handler(__FILE__, __LINE__);
  465.   }
  466.  
  467.     /**Configure the Systick interrupt time
  468.     */
  469.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  470.  
  471.     /**Configure the Systick
  472.     */
  473.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  474.  
  475.   /* SysTick_IRQn interrupt configuration */
  476.   HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
  477. }
  478.  
  479. /* ADC3 init function */
  480. static void MX_ADC3_Init(void)
  481. {
  482.  
  483.   ADC_ChannelConfTypeDef sConfig;
  484.  
  485.     /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  486.     */
  487.   hadc3.Instance = ADC3;
  488.   hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  489.   hadc3.Init.Resolution = ADC_RESOLUTION_12B;
  490.   hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
  491.   hadc3.Init.ContinuousConvMode = DISABLE;
  492.   hadc3.Init.DiscontinuousConvMode = DISABLE;
  493.   hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  494.   hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  495.   hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  496.   hadc3.Init.NbrOfConversion = 1;
  497.   hadc3.Init.DMAContinuousRequests = DISABLE;
  498.   hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  499.   if (HAL_ADC_Init(&hadc3) != HAL_OK)
  500.   {
  501.     _Error_Handler(__FILE__, __LINE__);
  502.   }
  503.  
  504.     /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  505.     */
  506.   sConfig.Channel = ADC_CHANNEL_4;
  507.   sConfig.Rank = ADC_REGULAR_RANK_1;
  508.   sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  509.   if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  510.   {
  511.     _Error_Handler(__FILE__, __LINE__);
  512.   }
  513.  
  514. }
  515.  
  516. /* CRC init function */
  517. static void MX_CRC_Init(void)
  518. {
  519.  
  520.   hcrc.Instance = CRC;
  521.   hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
  522.   hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
  523.   hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
  524.   hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
  525.   hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
  526.   if (HAL_CRC_Init(&hcrc) != HAL_OK)
  527.   {
  528.     _Error_Handler(__FILE__, __LINE__);
  529.   }
  530.  
  531. }
  532.  
  533. /* DCMI init function */
  534. static void MX_DCMI_Init(void)
  535. {
  536.  
  537.   hdcmi.Instance = DCMI;
  538.   hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
  539.   hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
  540.   hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
  541.   hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
  542.   hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
  543.   hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
  544.   hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
  545.   hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
  546.   hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
  547.   hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
  548.   hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
  549.   if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
  550.   {
  551.     _Error_Handler(__FILE__, __LINE__);
  552.   }
  553.  
  554. }
  555.  
  556. /* DMA2D init function */
  557. static void MX_DMA2D_Init(void)
  558. {
  559.  
  560.   hdma2d.Instance = DMA2D;
  561.   hdma2d.Init.Mode = DMA2D_M2M;
  562.   hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
  563.   hdma2d.Init.OutputOffset = 0;
  564.   hdma2d.LayerCfg[1].InputOffset = 0;
  565.   hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
  566.   hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
  567.   hdma2d.LayerCfg[1].InputAlpha = 0;
  568.   if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
  569.   {
  570.     _Error_Handler(__FILE__, __LINE__);
  571.   }
  572.  
  573.   if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
  574.   {
  575.     _Error_Handler(__FILE__, __LINE__);
  576.   }
  577.  
  578. }
  579.  
  580. /* I2C1 init function */
  581. static void MX_I2C1_Init(void)
  582. {
  583.  
  584.   hi2c1.Instance = I2C1;
  585.   hi2c1.Init.Timing = 0x00C0EAFF;
  586.   hi2c1.Init.OwnAddress1 = 0;
  587.   hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  588.   hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  589.   hi2c1.Init.OwnAddress2 = 0;
  590.   hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  591.   hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  592.   hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  593.   if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  594.   {
  595.     _Error_Handler(__FILE__, __LINE__);
  596.   }
  597.  
  598.     /**Configure Analogue filter
  599.     */
  600.   if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  601.   {
  602.     _Error_Handler(__FILE__, __LINE__);
  603.   }
  604.  
  605.     /**Configure Digital filter
  606.     */
  607.   if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
  608.   {
  609.     _Error_Handler(__FILE__, __LINE__);
  610.   }
  611.  
  612. }
  613.  
  614. /* I2C3 init function */
  615. static void MX_I2C3_Init(void)
  616. {
  617.  
  618.   hi2c3.Instance = I2C3;
  619.   hi2c3.Init.Timing = 0x00C0EAFF;
  620.   hi2c3.Init.OwnAddress1 = 0;
  621.   hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  622.   hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  623.   hi2c3.Init.OwnAddress2 = 0;
  624.   hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  625.   hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  626.   hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  627.   if (HAL_I2C_Init(&hi2c3) != HAL_OK)
  628.   {
  629.     _Error_Handler(__FILE__, __LINE__);
  630.   }
  631.  
  632.     /**Configure Analogue filter
  633.     */
  634.   if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  635.   {
  636.     _Error_Handler(__FILE__, __LINE__);
  637.   }
  638.  
  639.     /**Configure Digital filter
  640.     */
  641.   if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
  642.   {
  643.     _Error_Handler(__FILE__, __LINE__);
  644.   }
  645.  
  646. }
  647.  
  648. /* LTDC init function */
  649. static void MX_LTDC_Init(void)
  650. {
  651.  
  652.   LTDC_LayerCfgTypeDef pLayerCfg;
  653.  
  654.   hltdc.Instance = LTDC;
  655.   hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
  656.   hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
  657.   hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
  658.   hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
  659.   hltdc.Init.HorizontalSync = 40;
  660.   hltdc.Init.VerticalSync = 9;
  661.   hltdc.Init.AccumulatedHBP = 53;
  662.   hltdc.Init.AccumulatedVBP = 11;
  663.   hltdc.Init.AccumulatedActiveW = 533;
  664.   hltdc.Init.AccumulatedActiveH = 283;
  665.   hltdc.Init.TotalWidth = 565;
  666.   hltdc.Init.TotalHeigh = 285;
  667.   hltdc.Init.Backcolor.Blue = 0;
  668.   hltdc.Init.Backcolor.Green = 0;
  669.   hltdc.Init.Backcolor.Red = 0;
  670.   if (HAL_LTDC_Init(&hltdc) != HAL_OK)
  671.   {
  672.     _Error_Handler(__FILE__, __LINE__);
  673.   }
  674.  
  675.   pLayerCfg.WindowX0 = 0;
  676.   pLayerCfg.WindowX1 = 480;
  677.   pLayerCfg.WindowY0 = 0;
  678.   pLayerCfg.WindowY1 = 272;
  679.   pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
  680.   pLayerCfg.Alpha = 255;
  681.   pLayerCfg.Alpha0 = 0;
  682.   pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  683.   pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
  684.   pLayerCfg.FBStartAdress = 0xC0000000;
  685.   pLayerCfg.ImageWidth = 480;
  686.   pLayerCfg.ImageHeight = 272;
  687.   pLayerCfg.Backcolor.Blue = 0;
  688.   pLayerCfg.Backcolor.Green = 0;
  689.   pLayerCfg.Backcolor.Red = 0;
  690.   if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
  691.   {
  692.     _Error_Handler(__FILE__, __LINE__);
  693.   }
  694.  
  695. }
  696.  
  697. /* QUADSPI init function */
  698. static void MX_QUADSPI_Init(void)
  699. {
  700.  
  701.   /* QUADSPI parameter configuration*/
  702.   hqspi.Instance = QUADSPI;
  703.   hqspi.Init.ClockPrescaler = 255;
  704.   hqspi.Init.FifoThreshold = 1;
  705.   hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
  706.   hqspi.Init.FlashSize = 1;
  707.   hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
  708.   hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
  709.   hqspi.Init.FlashID = QSPI_FLASH_ID_1;
  710.   hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
  711.   if (HAL_QSPI_Init(&hqspi) != HAL_OK)
  712.   {
  713.     _Error_Handler(__FILE__, __LINE__);
  714.   }
  715.  
  716. }
  717.  
  718. /* RTC init function */
  719. static void MX_RTC_Init(void)
  720. {
  721.  
  722.   /* USER CODE BEGIN RTC_Init 0 */
  723.  
  724.   /* USER CODE END RTC_Init 0 */
  725.  
  726.   RTC_TimeTypeDef sTime;
  727.   RTC_DateTypeDef sDate;
  728.   RTC_AlarmTypeDef sAlarm;
  729.  
  730.   /* USER CODE BEGIN RTC_Init 1 */
  731.  
  732.   /* USER CODE END RTC_Init 1 */
  733.  
  734.     /**Initialize RTC Only
  735.     */
  736.   hrtc.Instance = RTC;
  737.   hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  738.   hrtc.Init.AsynchPrediv = 127;
  739.   hrtc.Init.SynchPrediv = 255;
  740.   hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  741.   hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  742.   hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  743.   if (HAL_RTC_Init(&hrtc) != HAL_OK)
  744.   {
  745.     _Error_Handler(__FILE__, __LINE__);
  746.   }
  747.  
  748.     /**Initialize RTC and set the Time and Date
  749.     */
  750.   sTime.Hours = 0x0;
  751.   sTime.Minutes = 0x0;
  752.   sTime.Seconds = 0x0;
  753.   sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  754.   sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  755.   if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
  756.   {
  757.     _Error_Handler(__FILE__, __LINE__);
  758.   }
  759.  
  760.   sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  761.   sDate.Month = RTC_MONTH_JANUARY;
  762.   sDate.Date = 0x1;
  763.   sDate.Year = 0x0;
  764.  
  765.   if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
  766.   {
  767.     _Error_Handler(__FILE__, __LINE__);
  768.   }
  769.  
  770.     /**Enable the Alarm A
  771.     */
  772.   sAlarm.AlarmTime.Hours = 0x0;
  773.   sAlarm.AlarmTime.Minutes = 0x0;
  774.   sAlarm.AlarmTime.Seconds = 0x0;
  775.   sAlarm.AlarmTime.SubSeconds = 0x0;
  776.   sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  777.   sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
  778.   sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
  779.   sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
  780.   sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
  781.   sAlarm.AlarmDateWeekDay = 0x1;
  782.   sAlarm.Alarm = RTC_ALARM_A;
  783.   if (HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
  784.   {
  785.     _Error_Handler(__FILE__, __LINE__);
  786.   }
  787.  
  788.     /**Enable the Alarm B
  789.     */
  790.   sAlarm.AlarmDateWeekDay = 0x1;
  791.   sAlarm.Alarm = RTC_ALARM_B;
  792.   if (HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
  793.   {
  794.     _Error_Handler(__FILE__, __LINE__);
  795.   }
  796.  
  797.     /**Enable the TimeStamp
  798.     */
  799.   if (HAL_RTCEx_SetTimeStamp(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_POS1) != HAL_OK)
  800.   {
  801.     _Error_Handler(__FILE__, __LINE__);
  802.   }
  803.  
  804. }
  805.  
  806. /* SAI2 init function */
  807. static void MX_SAI2_Init(void)
  808. {
  809.  
  810.   hsai_BlockA2.Instance = SAI2_Block_A;
  811.   hsai_BlockA2.Init.Protocol = SAI_FREE_PROTOCOL;
  812.   hsai_BlockA2.Init.AudioMode = SAI_MODEMASTER_TX;
  813.   hsai_BlockA2.Init.DataSize = SAI_DATASIZE_24;
  814.   hsai_BlockA2.Init.FirstBit = SAI_FIRSTBIT_MSB;
  815.   hsai_BlockA2.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
  816.   hsai_BlockA2.Init.Synchro = SAI_ASYNCHRONOUS;
  817.   hsai_BlockA2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
  818.   hsai_BlockA2.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
  819.   hsai_BlockA2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
  820.   hsai_BlockA2.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_192K;
  821.   hsai_BlockA2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
  822.   hsai_BlockA2.Init.MonoStereoMode = SAI_STEREOMODE;
  823.   hsai_BlockA2.Init.CompandingMode = SAI_NOCOMPANDING;
  824.   hsai_BlockA2.Init.TriState = SAI_OUTPUT_NOTRELEASED;
  825.   hsai_BlockA2.FrameInit.FrameLength = 8;
  826.   hsai_BlockA2.FrameInit.ActiveFrameLength = 1;
  827.   hsai_BlockA2.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
  828.   hsai_BlockA2.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
  829.   hsai_BlockA2.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
  830.   hsai_BlockA2.SlotInit.FirstBitOffset = 0;
  831.   hsai_BlockA2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
  832.   hsai_BlockA2.SlotInit.SlotNumber = 1;
  833.   hsai_BlockA2.SlotInit.SlotActive = 0x00000000;
  834.   if (HAL_SAI_Init(&hsai_BlockA2) != HAL_OK)
  835.   {
  836.     _Error_Handler(__FILE__, __LINE__);
  837.   }
  838.  
  839.   hsai_BlockB2.Instance = SAI2_Block_B;
  840.   hsai_BlockB2.Init.Protocol = SAI_FREE_PROTOCOL;
  841.   hsai_BlockB2.Init.AudioMode = SAI_MODESLAVE_RX;
  842.   hsai_BlockB2.Init.DataSize = SAI_DATASIZE_24;
  843.   hsai_BlockB2.Init.FirstBit = SAI_FIRSTBIT_MSB;
  844.   hsai_BlockB2.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
  845.   hsai_BlockB2.Init.Synchro = SAI_SYNCHRONOUS;
  846.   hsai_BlockB2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
  847.   hsai_BlockB2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
  848.   hsai_BlockB2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
  849.   hsai_BlockB2.Init.MonoStereoMode = SAI_STEREOMODE;
  850.   hsai_BlockB2.Init.CompandingMode = SAI_NOCOMPANDING;
  851.   hsai_BlockB2.Init.TriState = SAI_OUTPUT_NOTRELEASED;
  852.   hsai_BlockB2.FrameInit.FrameLength = 8;
  853.   hsai_BlockB2.FrameInit.ActiveFrameLength = 1;
  854.   hsai_BlockB2.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
  855.   hsai_BlockB2.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
  856.   hsai_BlockB2.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
  857.   hsai_BlockB2.SlotInit.FirstBitOffset = 0;
  858.   hsai_BlockB2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
  859.   hsai_BlockB2.SlotInit.SlotNumber = 1;
  860.   hsai_BlockB2.SlotInit.SlotActive = 0x00000000;
  861.   if (HAL_SAI_Init(&hsai_BlockB2) != HAL_OK)
  862.   {
  863.     _Error_Handler(__FILE__, __LINE__);
  864.   }
  865.  
  866. }
  867.  
  868. /* SDMMC1 init function */
  869. static void MX_SDMMC1_SD_Init(void)
  870. {
  871.  
  872.   hsd1.Instance = SDMMC1;
  873.   hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
  874.   hsd1.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;
  875.   hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
  876.   hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
  877.   hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
  878.   hsd1.Init.ClockDiv = 0;
  879.  
  880. }
  881.  
  882. /* SPDIFRX init function */
  883. static void MX_SPDIFRX_Init(void)
  884. {
  885.  
  886.   hspdif.Instance = SPDIFRX;
  887.   hspdif.Init.InputSelection = SPDIFRX_INPUT_IN0;
  888.   hspdif.Init.Retries = SPDIFRX_MAXRETRIES_NONE;
  889.   hspdif.Init.WaitForActivity = SPDIFRX_WAITFORACTIVITY_OFF;
  890.   hspdif.Init.ChannelSelection = SPDIFRX_CHANNEL_A;
  891.   hspdif.Init.DataFormat = SPDIFRX_DATAFORMAT_LSB;
  892.   hspdif.Init.StereoMode = SPDIFRX_STEREOMODE_DISABLE;
  893.   hspdif.Init.PreambleTypeMask = SPDIFRX_PREAMBLETYPEMASK_OFF;
  894.   hspdif.Init.ChannelStatusMask = SPDIFRX_CHANNELSTATUS_OFF;
  895.   hspdif.Init.ValidityBitMask = SPDIFRX_VALIDITYMASK_OFF;
  896.   hspdif.Init.ParityErrorMask = SPDIFRX_PARITYERRORMASK_OFF;
  897.   if (HAL_SPDIFRX_Init(&hspdif) != HAL_OK)
  898.   {
  899.     _Error_Handler(__FILE__, __LINE__);
  900.   }
  901.  
  902. }
  903.  
  904. /* SPI2 init function */
  905. static void MX_SPI2_Init(void)
  906. {
  907.  
  908.   /* SPI2 parameter configuration*/
  909.   hspi2.Instance = SPI2;
  910.   hspi2.Init.Mode = SPI_MODE_MASTER;
  911.   hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  912.   hspi2.Init.DataSize = SPI_DATASIZE_4BIT;
  913.   hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  914.   hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  915.   hspi2.Init.NSS = SPI_NSS_SOFT;
  916.   hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  917.   hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  918.   hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  919.   hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  920.   hspi2.Init.CRCPolynomial = 7;
  921.   hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  922.   hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  923.   if (HAL_SPI_Init(&hspi2) != HAL_OK)
  924.   {
  925.     _Error_Handler(__FILE__, __LINE__);
  926.   }
  927.  
  928. }
  929.  
  930. /* TIM1 init function */
  931. static void MX_TIM1_Init(void)
  932. {
  933.  
  934.   TIM_ClockConfigTypeDef sClockSourceConfig;
  935.   TIM_MasterConfigTypeDef sMasterConfig;
  936.   TIM_OC_InitTypeDef sConfigOC;
  937.   TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
  938.  
  939.   htim1.Instance = TIM1;
  940.   htim1.Init.Prescaler = 0;
  941.   htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  942.   htim1.Init.Period = 0;
  943.   htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  944.   htim1.Init.RepetitionCounter = 0;
  945.   htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  946.   if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  947.   {
  948.     _Error_Handler(__FILE__, __LINE__);
  949.   }
  950.  
  951.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  952.   if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  953.   {
  954.     _Error_Handler(__FILE__, __LINE__);
  955.   }
  956.  
  957.   if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
  958.   {
  959.     _Error_Handler(__FILE__, __LINE__);
  960.   }
  961.  
  962.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  963.   sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
  964.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  965.   if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  966.   {
  967.     _Error_Handler(__FILE__, __LINE__);
  968.   }
  969.  
  970.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  971.   sConfigOC.Pulse = 0;
  972.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  973.   sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
  974.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  975.   sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
  976.   sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
  977.   if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  978.   {
  979.     _Error_Handler(__FILE__, __LINE__);
  980.   }
  981.  
  982.   sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
  983.   sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
  984.   sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
  985.   sBreakDeadTimeConfig.DeadTime = 0;
  986.   sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
  987.   sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
  988.   sBreakDeadTimeConfig.BreakFilter = 0;
  989.   sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
  990.   sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
  991.   sBreakDeadTimeConfig.Break2Filter = 0;
  992.   sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
  993.   if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
  994.   {
  995.     _Error_Handler(__FILE__, __LINE__);
  996.   }
  997.  
  998.   HAL_TIM_MspPostInit(&htim1);
  999.  
  1000. }
  1001.  
  1002. /* TIM2 init function */
  1003. static void MX_TIM2_Init(void)
  1004. {
  1005.  
  1006.   TIM_ClockConfigTypeDef sClockSourceConfig;
  1007.   TIM_MasterConfigTypeDef sMasterConfig;
  1008.   TIM_OC_InitTypeDef sConfigOC;
  1009.  
  1010.   htim2.Instance = TIM2;
  1011.   htim2.Init.Prescaler = 0;
  1012.   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  1013.   htim2.Init.Period = 0;
  1014.   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1015.   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1016.   if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  1017.   {
  1018.     _Error_Handler(__FILE__, __LINE__);
  1019.   }
  1020.  
  1021.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1022.   if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  1023.   {
  1024.     _Error_Handler(__FILE__, __LINE__);
  1025.   }
  1026.  
  1027.   if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
  1028.   {
  1029.     _Error_Handler(__FILE__, __LINE__);
  1030.   }
  1031.  
  1032.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1033.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1034.   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  1035.   {
  1036.     _Error_Handler(__FILE__, __LINE__);
  1037.   }
  1038.  
  1039.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  1040.   sConfigOC.Pulse = 0;
  1041.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1042.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1043.   if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  1044.   {
  1045.     _Error_Handler(__FILE__, __LINE__);
  1046.   }
  1047.  
  1048.   HAL_TIM_MspPostInit(&htim2);
  1049.  
  1050. }
  1051.  
  1052. /* TIM3 init function */
  1053. static void MX_TIM3_Init(void)
  1054. {
  1055.  
  1056.   TIM_ClockConfigTypeDef sClockSourceConfig;
  1057.   TIM_MasterConfigTypeDef sMasterConfig;
  1058.   TIM_OC_InitTypeDef sConfigOC;
  1059.  
  1060.   htim3.Instance = TIM3;
  1061.   htim3.Init.Prescaler = 0;
  1062.   htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  1063.   htim3.Init.Period = 0;
  1064.   htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1065.   htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1066.   if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
  1067.   {
  1068.     _Error_Handler(__FILE__, __LINE__);
  1069.   }
  1070.  
  1071.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1072.   if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
  1073.   {
  1074.     _Error_Handler(__FILE__, __LINE__);
  1075.   }
  1076.  
  1077.   if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
  1078.   {
  1079.     _Error_Handler(__FILE__, __LINE__);
  1080.   }
  1081.  
  1082.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1083.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1084.   if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  1085.   {
  1086.     _Error_Handler(__FILE__, __LINE__);
  1087.   }
  1088.  
  1089.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  1090.   sConfigOC.Pulse = 0;
  1091.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1092.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1093.   if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  1094.   {
  1095.     _Error_Handler(__FILE__, __LINE__);
  1096.   }
  1097.  
  1098.   HAL_TIM_MspPostInit(&htim3);
  1099.  
  1100. }
  1101.  
  1102. /* TIM5 init function */
  1103. static void MX_TIM5_Init(void)
  1104. {
  1105.  
  1106.   TIM_ClockConfigTypeDef sClockSourceConfig;
  1107.   TIM_MasterConfigTypeDef sMasterConfig;
  1108.   TIM_OC_InitTypeDef sConfigOC;
  1109.  
  1110.   htim5.Instance = TIM5;
  1111.   htim5.Init.Prescaler = 0;
  1112.   htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
  1113.   htim5.Init.Period = 0;
  1114.   htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1115.   htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1116.   if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
  1117.   {
  1118.     _Error_Handler(__FILE__, __LINE__);
  1119.   }
  1120.  
  1121.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1122.   if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
  1123.   {
  1124.     _Error_Handler(__FILE__, __LINE__);
  1125.   }
  1126.  
  1127.   if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
  1128.   {
  1129.     _Error_Handler(__FILE__, __LINE__);
  1130.   }
  1131.  
  1132.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1133.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1134.   if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
  1135.   {
  1136.     _Error_Handler(__FILE__, __LINE__);
  1137.   }
  1138.  
  1139.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  1140.   sConfigOC.Pulse = 0;
  1141.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1142.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1143.   if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
  1144.   {
  1145.     _Error_Handler(__FILE__, __LINE__);
  1146.   }
  1147.  
  1148.   HAL_TIM_MspPostInit(&htim5);
  1149.  
  1150. }
  1151.  
  1152. /* TIM7 init function */
  1153. static void MX_TIM7_Init(void)
  1154. {
  1155.  
  1156.   TIM_MasterConfigTypeDef sMasterConfig;
  1157.  
  1158.   htim7.Instance = TIM7;
  1159.   htim7.Init.Prescaler = 0;
  1160.   htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
  1161.   htim7.Init.Period = 0;
  1162.   htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1163.   if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
  1164.   {
  1165.     _Error_Handler(__FILE__, __LINE__);
  1166.   }
  1167.  
  1168.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1169.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1170.   if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
  1171.   {
  1172.     _Error_Handler(__FILE__, __LINE__);
  1173.   }
  1174.  
  1175. }
  1176.  
  1177. /* TIM8 init function */
  1178. static void MX_TIM8_Init(void)
  1179. {
  1180.  
  1181.   TIM_ClockConfigTypeDef sClockSourceConfig;
  1182.   TIM_MasterConfigTypeDef sMasterConfig;
  1183.  
  1184.   htim8.Instance = TIM8;
  1185.   htim8.Init.Prescaler = 0;
  1186.   htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
  1187.   htim8.Init.Period = 0;
  1188.   htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1189.   htim8.Init.RepetitionCounter = 0;
  1190.   htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1191.   if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
  1192.   {
  1193.     _Error_Handler(__FILE__, __LINE__);
  1194.   }
  1195.  
  1196.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1197.   if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
  1198.   {
  1199.     _Error_Handler(__FILE__, __LINE__);
  1200.   }
  1201.  
  1202.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1203.   sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
  1204.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1205.   if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
  1206.   {
  1207.     _Error_Handler(__FILE__, __LINE__);
  1208.   }
  1209.  
  1210. }
  1211.  
  1212. /* TIM12 init function */
  1213. static void MX_TIM12_Init(void)
  1214. {
  1215.  
  1216.   TIM_OC_InitTypeDef sConfigOC;
  1217.  
  1218.   htim12.Instance = TIM12;
  1219.   htim12.Init.Prescaler = 0;
  1220.   htim12.Init.CounterMode = TIM_COUNTERMODE_UP;
  1221.   htim12.Init.Period = 0;
  1222.   htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1223.   htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1224.   if (HAL_TIM_PWM_Init(&htim12) != HAL_OK)
  1225.   {
  1226.     _Error_Handler(__FILE__, __LINE__);
  1227.   }
  1228.  
  1229.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  1230.   sConfigOC.Pulse = 0;
  1231.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  1232.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  1233.   if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  1234.   {
  1235.     _Error_Handler(__FILE__, __LINE__);
  1236.   }
  1237.  
  1238.   HAL_TIM_MspPostInit(&htim12);
  1239.  
  1240. }
  1241.  
  1242. /* USART1 init function */
  1243. static void MX_USART1_UART_Init(void)
  1244. {
  1245.  
  1246.   huart1.Instance = USART1;
  1247.   huart1.Init.BaudRate = 115200;
  1248.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  1249.   huart1.Init.StopBits = UART_STOPBITS_1;
  1250.   huart1.Init.Parity = UART_PARITY_NONE;
  1251.   huart1.Init.Mode = UART_MODE_TX_RX;
  1252.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1253.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  1254.   huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  1255.   huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  1256.   if (HAL_UART_Init(&huart1) != HAL_OK)
  1257.   {
  1258.     _Error_Handler(__FILE__, __LINE__);
  1259.   }
  1260.  
  1261. }
  1262.  
  1263. /* USART6 init function */
  1264. static void MX_USART6_UART_Init(void)
  1265. {
  1266.  
  1267.   huart6.Instance = USART6;
  1268.   huart6.Init.BaudRate = 115200;
  1269.   huart6.Init.WordLength = UART_WORDLENGTH_8B;
  1270.   huart6.Init.StopBits = UART_STOPBITS_1;
  1271.   huart6.Init.Parity = UART_PARITY_NONE;
  1272.   huart6.Init.Mode = UART_MODE_TX_RX;
  1273.   huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1274.   huart6.Init.OverSampling = UART_OVERSAMPLING_16;
  1275.   huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  1276.   huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  1277.   if (HAL_UART_Init(&huart6) != HAL_OK)
  1278.   {
  1279.     _Error_Handler(__FILE__, __LINE__);
  1280.   }
  1281.  
  1282. }
  1283.  
  1284. /* FMC initialization function */
  1285. static void MX_FMC_Init(void)
  1286. {
  1287.   FMC_SDRAM_TimingTypeDef SdramTiming;
  1288.  
  1289.   /** Perform the SDRAM1 memory initialization sequence
  1290.   */
  1291.   hsdram1.Instance = FMC_SDRAM_DEVICE;
  1292.   /* hsdram1.Init */
  1293.   hsdram1.Init.SDBank = FMC_SDRAM_BANK1;
  1294.   hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
  1295.   hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
  1296.   hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
  1297.   hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
  1298.   hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
  1299.   hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
  1300.   hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
  1301.   hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
  1302.   hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
  1303.   /* SdramTiming */
  1304.   SdramTiming.LoadToActiveDelay = 2;
  1305.   SdramTiming.ExitSelfRefreshDelay = 7;
  1306.   SdramTiming.SelfRefreshTime = 4;
  1307.   SdramTiming.RowCycleDelay = 7;
  1308.   SdramTiming.WriteRecoveryTime = 3;
  1309.   SdramTiming.RPDelay = 2;
  1310.   SdramTiming.RCDDelay = 2;
  1311.  
  1312.   if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
  1313.   {
  1314.     _Error_Handler(__FILE__, __LINE__);
  1315.   }
  1316.  
  1317. }
  1318.  
  1319. /** Configure pins as
  1320.         * Analog
  1321.         * Input
  1322.         * Output
  1323.         * EVENT_OUT
  1324.         * EXTI
  1325.      PB5   ------> USB_OTG_HS_ULPI_D7
  1326.      PH4   ------> USB_OTG_HS_ULPI_NXT
  1327.      PB13   ------> USB_OTG_HS_ULPI_D6
  1328.      PB12   ------> USB_OTG_HS_ULPI_D5
  1329.      PC0   ------> USB_OTG_HS_ULPI_STP
  1330.      PC2   ------> USB_OTG_HS_ULPI_DIR
  1331.      PA5   ------> USB_OTG_HS_ULPI_CK
  1332.      PB10   ------> USB_OTG_HS_ULPI_D3
  1333.      PA3   ------> USB_OTG_HS_ULPI_D0
  1334.      PB1   ------> USB_OTG_HS_ULPI_D2
  1335.      PB0   ------> USB_OTG_HS_ULPI_D1
  1336.      PB11   ------> USB_OTG_HS_ULPI_D4
  1337. */
  1338. static void MX_GPIO_Init(void)
  1339. {
  1340.  
  1341.   GPIO_InitTypeDef GPIO_InitStruct;
  1342.  
  1343.   /* GPIO Ports Clock Enable */
  1344.   __HAL_RCC_GPIOE_CLK_ENABLE();
  1345.   __HAL_RCC_GPIOG_CLK_ENABLE();
  1346.   __HAL_RCC_GPIOB_CLK_ENABLE();
  1347.   __HAL_RCC_GPIOD_CLK_ENABLE();
  1348.   __HAL_RCC_GPIOC_CLK_ENABLE();
  1349.   __HAL_RCC_GPIOA_CLK_ENABLE();
  1350.   __HAL_RCC_GPIOJ_CLK_ENABLE();
  1351.   __HAL_RCC_GPIOI_CLK_ENABLE();
  1352.   __HAL_RCC_GPIOK_CLK_ENABLE();
  1353.   __HAL_RCC_GPIOF_CLK_ENABLE();
  1354.   __HAL_RCC_GPIOH_CLK_ENABLE();
  1355.  
  1356.   /*Configure GPIO pin Output Level */
  1357.   HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);
  1358.  
  1359.   /*Configure GPIO pin Output Level */
  1360.   HAL_GPIO_WritePin(GPIOI, ARDUINO_D7_Pin|ARDUINO_D8_Pin, GPIO_PIN_RESET);
  1361.  
  1362.   /*Configure GPIO pin Output Level */
  1363.   HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_SET);
  1364.  
  1365.   /*Configure GPIO pin Output Level */
  1366.   HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET);
  1367.  
  1368.   /*Configure GPIO pin Output Level */
  1369.   HAL_GPIO_WritePin(DCMI_PWR_EN_GPIO_Port, DCMI_PWR_EN_Pin, GPIO_PIN_RESET);
  1370.  
  1371.   /*Configure GPIO pin Output Level */
  1372.   HAL_GPIO_WritePin(GPIOG, ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin, GPIO_PIN_RESET);
  1373.  
  1374.   /*Configure GPIO pin : OTG_HS_OverCurrent_Pin */
  1375.   GPIO_InitStruct.Pin = OTG_HS_OverCurrent_Pin;
  1376.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1377.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1378.   HAL_GPIO_Init(OTG_HS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  1379.  
  1380.   /*Configure GPIO pins : ULPI_D7_Pin ULPI_D6_Pin ULPI_D5_Pin ULPI_D3_Pin
  1381.                            ULPI_D2_Pin ULPI_D1_Pin ULPI_D4_Pin */
  1382.   GPIO_InitStruct.Pin = ULPI_D7_Pin|ULPI_D6_Pin|ULPI_D5_Pin|ULPI_D3_Pin
  1383.                           |ULPI_D2_Pin|ULPI_D1_Pin|ULPI_D4_Pin;
  1384.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1385.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1386.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1387.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  1388.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1389.  
  1390.   /*Configure GPIO pin : OTG_FS_VBUS_Pin */
  1391.   GPIO_InitStruct.Pin = OTG_FS_VBUS_Pin;
  1392.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1393.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1394.   HAL_GPIO_Init(OTG_FS_VBUS_GPIO_Port, &GPIO_InitStruct);
  1395.  
  1396.   /*Configure GPIO pin : Audio_INT_Pin */
  1397.   GPIO_InitStruct.Pin = Audio_INT_Pin;
  1398.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  1399.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1400.   HAL_GPIO_Init(Audio_INT_GPIO_Port, &GPIO_InitStruct);
  1401.  
  1402.   /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  1403.   GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  1404.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1405.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1406.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1407.   HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
  1408.  
  1409.   /*Configure GPIO pins : ARDUINO_D7_Pin ARDUINO_D8_Pin LCD_DISP_Pin */
  1410.   GPIO_InitStruct.Pin = ARDUINO_D7_Pin|ARDUINO_D8_Pin|LCD_DISP_Pin;
  1411.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1412.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1413.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1414.   HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
  1415.  
  1416.   /*Configure GPIO pin : uSD_Detect_Pin */
  1417.   GPIO_InitStruct.Pin = uSD_Detect_Pin;
  1418.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1419.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1420.   HAL_GPIO_Init(uSD_Detect_GPIO_Port, &GPIO_InitStruct);
  1421.  
  1422.   /*Configure GPIO pin : LCD_BL_CTRL_Pin */
  1423.   GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin;
  1424.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1425.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1426.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1427.   HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct);
  1428.  
  1429.   /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  1430.   GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  1431.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1432.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1433.   HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  1434.  
  1435.   /*Configure GPIO pins : TP3_Pin NC2_Pin */
  1436.   GPIO_InitStruct.Pin = TP3_Pin|NC2_Pin;
  1437.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1438.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1439.   HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
  1440.  
  1441.   /*Configure GPIO pin : DCMI_PWR_EN_Pin */
  1442.   GPIO_InitStruct.Pin = DCMI_PWR_EN_Pin;
  1443.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1444.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1445.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1446.   HAL_GPIO_Init(DCMI_PWR_EN_GPIO_Port, &GPIO_InitStruct);
  1447.  
  1448.   /*Configure GPIO pin : LCD_INT_Pin */
  1449.   GPIO_InitStruct.Pin = LCD_INT_Pin;
  1450.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  1451.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1452.   HAL_GPIO_Init(LCD_INT_GPIO_Port, &GPIO_InitStruct);
  1453.  
  1454.   /*Configure GPIO pin : ULPI_NXT_Pin */
  1455.   GPIO_InitStruct.Pin = ULPI_NXT_Pin;
  1456.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1457.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1458.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1459.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  1460.   HAL_GPIO_Init(ULPI_NXT_GPIO_Port, &GPIO_InitStruct);
  1461.  
  1462.   /*Configure GPIO pins : ARDUINO_D4_Pin ARDUINO_D2_Pin EXT_RST_Pin */
  1463.   GPIO_InitStruct.Pin = ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin;
  1464.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1465.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1466.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1467.   HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  1468.  
  1469.   /*Configure GPIO pins : ULPI_STP_Pin ULPI_DIR_Pin */
  1470.   GPIO_InitStruct.Pin = ULPI_STP_Pin|ULPI_DIR_Pin;
  1471.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1472.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1473.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1474.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  1475.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1476.  
  1477.   /*Configure GPIO pin : RMII_RXER_Pin */
  1478.   GPIO_InitStruct.Pin = RMII_RXER_Pin;
  1479.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1480.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1481.   HAL_GPIO_Init(RMII_RXER_GPIO_Port, &GPIO_InitStruct);
  1482.  
  1483.   /*Configure GPIO pins : ULPI_CLK_Pin ULPI_D0_Pin */
  1484.   GPIO_InitStruct.Pin = ULPI_CLK_Pin|ULPI_D0_Pin;
  1485.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1486.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  1487.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1488.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  1489.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1490.  
  1491. }
  1492.  
  1493. /* USER CODE BEGIN 4 */
  1494. static char response[500];
  1495.  
  1496. //based on available code examples
  1497. static void http_server_serve(struct netconn *conn)
  1498. {
  1499.  
  1500.   xprintf("\n still running http server function! \n")
  1501.   struct netbuf *inbuf;
  1502.   err_t recv_err;
  1503.   char* buf;
  1504.   u16_t buflen;
  1505.  
  1506.   /* Read the data from the port, blocking if nothing yet there.
  1507.    We assume the request (the part we care about) is in one netbuf */
  1508.   recv_err = netconn_recv(conn, &inbuf);
  1509.  
  1510.   if (recv_err == ERR_OK)
  1511.   {
  1512.     if (netconn_err(conn) == ERR_OK)
  1513.     {
  1514.       netbuf_data(inbuf, (void**)&buf, &buflen);
  1515.  
  1516.       /* Is this an HTTP GET command? (only check the first 5 chars, since
  1517.       there are other formats for GET, and we're keeping it very simple )*/
  1518.       if ((buflen >=5) && (strncmp(buf, "GET /", 5) == 0))
  1519.       {
  1520.                         response[0] = 0;
  1521.  
  1522.                         strcpy(response, "HTTP/1.1 200 OK\r\n\
  1523.                                 Content-Type: text/html\r\n\
  1524.                                 Connnection: close\r\n\r\n\
  1525.                                 <!DOCTYPE HTML>\r\n");
  1526.  
  1527.                         #if 0
  1528.                         strcat(response,"<html>\r\n\
  1529.                         <meta http-equiv=\"refresh\" content=\"10\">");
  1530.                         #endif
  1531.  
  1532.                         strcat(response,"<title>Prosta strona WWW</title>");
  1533.                         strcat(response,"<h1>H1 Header</h1>");
  1534.  
  1535.                         strcat(response,"A to jest tekst na stronie");
  1536.           netconn_write(conn, response, sizeof(response), NETCONN_NOCOPY);
  1537.       }
  1538.     }
  1539.   }
  1540.   /* Close the connection (server closes in HTTP) */
  1541.   netconn_close(conn);
  1542.  
  1543.   /* Delete the buffer (netconn_recv gives us ownership,
  1544.    so we have to make sure to deallocate the buffer) */
  1545.   netbuf_delete(inbuf);
  1546. }
  1547.  
  1548.  
  1549. //based on available code examples
  1550. static void http_server_netconn_thread(void const *arg)
  1551. {
  1552.   struct netconn *conn, *newconn;
  1553.   err_t err, accept_err;
  1554.  
  1555.   xprintf("http_server_netconn_thread\n");
  1556.  
  1557.   /* Create a new TCP connection handle */
  1558.   conn = netconn_new(NETCONN_TCP);
  1559.  
  1560.   if (conn!= NULL)
  1561.   {
  1562.     /* Bind to port 80 (HTTP) with default IP address */
  1563.     err = netconn_bind(conn, NULL, 80);
  1564.  
  1565.     if (err == ERR_OK)
  1566.     {
  1567.       /* Put the connection into LISTEN state */
  1568.       //netconn_listen(conn);
  1569.       xprintf("TCP connection is set!\n");
  1570.  
  1571.       ip_addr_t* addr;
  1572.       u16_t* port;
  1573.       netconn_getaddr(conn,addr,port,1); // 1 -> local IP address, 0 -> remote
  1574.       mqtt_client_t mqtt_client;
  1575.     //  mqtt_do_connect(&mqtt_client);
  1576.       xprint("Start of new mqqt connection\n");
  1577.  
  1578.  
  1579.       ip4_addr_t broker_ipaddr;
  1580.       struct mqtt_connect_client_info_t ci;
  1581.       err_t err;
  1582.  
  1583.       IP4_ADDR(&broker_ipaddr, configBroker_ADDR0, configBroker_ADDR1, configBroker_ADDR2, configBroker_ADDR3);
  1584.  
  1585.       /* Setup an empty client info structure */
  1586.       memset(&ci, 0, sizeof(ci));
  1587.  
  1588.       /* Minimal amount of information required is client identifier, so set it here */
  1589.       ci.client_id = "lwip_test";
  1590.       //ci.client_user = configMQTT_CLIENT_USER;
  1591.       //ci.client_pass = configMQTT_CLIENT_PWD;
  1592.  
  1593.       /* Initiate client and connect to server, if this fails immediately an error code is returned
  1594.         otherwise mqtt_connection_cb will be called with connection result after attempting
  1595.         to establish a connection with the server.
  1596.         For now MQTT version 3.1.1 is always used */
  1597.       err = mqtt_client_connect(client, &broker_ipaddr, MQTT_PORT, mqtt_connection_cb, 0, &ci);
  1598.  
  1599.       /* For now just print the result code if something goes wrong */
  1600.       if(err != ERR_OK) {
  1601.         printf("mqtt_connect return %d\n", err);
  1602.       }
  1603. /*
  1604.  
  1605.       while(1)
  1606.       {
  1607.  
  1608.  
  1609.         // accept any icoming connection
  1610.         accept_err = netconn_accept(conn, &newconn);
  1611.         if(accept_err == ERR_OK)
  1612.         {
  1613.           // serve connection
  1614.           //http_server_serve(newconn);
  1615.  
  1616.           // delete connection
  1617.           //netconn_delete(newconn);
  1618.           // mqtt broker connection
  1619.           mqtt_client_t mqtt_client;
  1620.           mqtt_do_connect(&mqtt_client);
  1621.         }
  1622.  
  1623.       }
  1624. */
  1625.     }
  1626.   }
  1627. }
  1628.  
  1629. static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) {
  1630.  err_t err;
  1631.  
  1632.  if(status == MQTT_CONNECT_ACCEPTED) {
  1633.    xprintf("Mqtt_connection_cb: Successfully connected\n");
  1634.   else{
  1635.     xprintf("Mqtt_connection_cb: Not connected\n");
  1636.   }
  1637.    /* Setup callback for incoming publish requests */
  1638.    mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
  1639.  
  1640.    /* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */
  1641.    err = mqtt_subscribe(client, "subtopic", 1, mqtt_sub_request_cb, arg);
  1642.  
  1643.    if(err != ERR_OK) {
  1644.      xprintf("mqtt_subscribe return: %d\n", err);
  1645.    }
  1646.  } else {
  1647.    xprintf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
  1648.  
  1649.    /* Its more nice to be connected, so try to reconnect */
  1650.    mqtt_do_connect(client);
  1651.  }
  1652. }
  1653. static int inpub_id;
  1654. static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) {
  1655.  printf("Incoming publish at topic %s with total length %u\n", topic, (unsigned int)tot_len);
  1656.  
  1657.  /* Decode topic string into a user defined reference */
  1658.  if(strcmp(topic, "print_payload") == 0) {
  1659.    inpub_id = 0;
  1660.  } else if(topic[0] == 'A') {
  1661.    /* All topics starting with 'A' might be handled at the same way */
  1662.    inpub_id = 1;
  1663.  } else {
  1664.    /* For all other topics */
  1665.    inpub_id = 2;
  1666.  }
  1667. }
  1668.  
  1669. static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) {
  1670.  printf("Incoming publish payload with length %d, flags %u\n", len, (unsigned int)flags);
  1671.  
  1672.  if(flags & MQTT_DATA_FLAG_LAST) {
  1673.    /* Last fragment of payload received (or whole part if payload fits receive buffer
  1674.    See MQTT_VAR_HEADER_BUFFER_LEN) */
  1675.  
  1676.    /* Call function or do action depending on reference, in this case inpub_id */
  1677.    if(inpub_id == 0) {
  1678.      /* Don't trust the publisher, check zero termination */
  1679.      if(data[len-1] == 0) {
  1680.        printf("mqtt_incoming_data_cb: %s\n", (const char *)data);
  1681.      }
  1682.    } else if(inpub_id == 1) {
  1683.      /* Call an 'A' function... */
  1684.    } else {
  1685.      printf("mqtt_incoming_data_cb: Ignoring payload...\n");
  1686.    }
  1687.  } else {
  1688.    /* Handle fragmented payload, store in buffer, write to file or whatever */
  1689.  }
  1690. }
  1691.  
  1692. static void my_mqtt_publish(mqtt_client_t *client, void *arg) {
  1693.  const char *pub_payload= "abcd";
  1694.  err_t err;
  1695.  u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
  1696.  u8_t retain = 0; /* No don't retain such crappy payload... */
  1697.  err = mqtt_publish(client, "erichs/f/test", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg);
  1698.  if(err != ERR_OK) {
  1699.    printf("Publish err: %d\n", err);
  1700.  }
  1701. }
  1702.  
  1703. static void mqtt_pub_request_cb(void *arg, err_t result) {
  1704.  if(result != ERR_OK) {
  1705.    printf("Publish result: %d\n", result);
  1706.  }
  1707. }
  1708.  
  1709. static void mqtt_sub_request_cb(void *arg, err_t result) {
  1710.  /* Just print the result code here for simplicity,
  1711.  normal behaviour would be to take some action if subscribe fails like
  1712.  notifying user, retry subscribe or disconnect from server */
  1713.  printf("Subscribe result: %d\n", result);
  1714. }
  1715.  
  1716.  
  1717. #define AUDIO_OUT_BUFFER_SIZE                      8192
  1718. enum {
  1719.   BUFFER_OFFSET_NONE = 0,
  1720.   BUFFER_OFFSET_HALF,
  1721.   BUFFER_OFFSET_FULL,
  1722. };
  1723.  
  1724. uint8_t buff[AUDIO_OUT_BUFFER_SIZE];
  1725. static FIL file;
  1726. extern ApplicationTypeDef Appli_state;
  1727. static uint8_t player_state = 0;
  1728. static uint8_t buf_offs = BUFFER_OFFSET_NONE;
  1729. static uint32_t fpos = 0;
  1730.  
  1731.  
  1732. void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
  1733. {
  1734.     buf_offs = BUFFER_OFFSET_FULL;
  1735. }
  1736.  
  1737. void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
  1738. {
  1739.     buf_offs = BUFFER_OFFSET_HALF;
  1740. }
  1741.  
  1742.  
  1743.  
  1744.  
  1745. /* USER CODE END 4 */
  1746.  
  1747. /* USER CODE BEGIN Header_StartDefaultTask */
  1748. /**
  1749.   * @brief  Function implementing the defaultTask thread.
  1750.   * @param  argument: Not used
  1751.   * @retval None
  1752.   */
  1753. /* USER CODE END Header_StartDefaultTask */
  1754. void StartDefaultTask(void const * argument)
  1755. {
  1756.   /* init code for FATFS */
  1757.   //MX_FATFS_Init();
  1758.  
  1759.   /* init code for USB_HOST */
  1760.   //MX_USB_HOST_Init();
  1761.  
  1762.   /* init code for LWIP */
  1763.   MX_LWIP_Init();
  1764.  
  1765.   /* USER CODE BEGIN 5 */
  1766.   osThreadDef(netconn_thread, http_server_netconn_thread, osPriorityNormal, 0, 1024);
  1767.   netconn_thread_handle = osThreadCreate(osThread(netconn_thread), NULL);
  1768. /*
  1769.   vTaskDelay(1000);
  1770.  
  1771.   xprintf("waiting for USB mass storage\n");
  1772.  
  1773.   do
  1774.   {
  1775.           xprintf(".");
  1776.           vTaskDelay(250);
  1777.   }while(Appli_state != APPLICATION_READY);
  1778.  
  1779.   FRESULT res;
  1780.  
  1781.   res = f_open(&file,"1:/test_1k.wav",FA_READ);
  1782.  
  1783.   if(res==FR_OK)
  1784.   {
  1785.           xprintf("wave file open OK\n");
  1786.   }
  1787.   else
  1788.   {
  1789.           xprintf("wave file open ERROR, res = %d\n",res);
  1790.           while(1);
  1791.   }
  1792.  
  1793.   //workaround: use 22K to play 44K
  1794.   if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE1, 60, AUDIO_FREQUENCY_22K) == 0)
  1795.   {
  1796.           xprintf("audio init OK\n");
  1797.   }
  1798.   else
  1799.   {
  1800.           xprintf("audio init ERROR\n");
  1801.   }
  1802.  
  1803. */
  1804.   /* Infinite loop */
  1805.   for(;;)
  1806.   {
  1807. /*
  1808.         BSP_TS_GetState(&TS_State);
  1809.         if(TS_State.touchDetected)
  1810.         {
  1811.                 BSP_LCD_Clear(LCD_COLOR_WHITE);
  1812.                 BSP_LCD_SetTextColor(0x40FF00FF);
  1813.                 BSP_LCD_FillCircle(TS_State.touchX[0],TS_State.touchY[0],40);
  1814.         }
  1815.  
  1816.         char key = inkey();
  1817.  
  1818.         switch(key)
  1819.         {
  1820.                 case 'p':
  1821.                 {
  1822.                         xprintf("play command...\n");
  1823.                         if(player_state) {xprintf("already playing\n"); break;}
  1824.                         player_state = 1;
  1825.                         BSP_AUDIO_OUT_Play((uint16_t*)&buff[0],AUDIO_OUT_BUFFER_SIZE);
  1826.                         fpos = 0;
  1827.                         buf_offs = BUFFER_OFFSET_NONE;
  1828.                         break;
  1829.                 }
  1830.         }
  1831.  
  1832.         if(player_state)
  1833.         {
  1834.                 uint32_t br;
  1835.  
  1836.                 if(buf_offs == BUFFER_OFFSET_HALF)
  1837.                 {
  1838.                   if(f_read(&file,
  1839.                                         &buff[0],
  1840.                                         AUDIO_OUT_BUFFER_SIZE/2,
  1841.                                         (void *)&br) != FR_OK)
  1842.                   {
  1843.                         BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
  1844.                         xprintf("f_read error on half\n");
  1845.                   }
  1846.                   buf_offs = BUFFER_OFFSET_NONE;
  1847.                   fpos += br;
  1848.  
  1849.                 }
  1850.  
  1851.                 if(buf_offs == BUFFER_OFFSET_FULL)
  1852.                 {
  1853.                         if(f_read(&file,
  1854.                                         &buff[AUDIO_OUT_BUFFER_SIZE /2],
  1855.                                         AUDIO_OUT_BUFFER_SIZE/2,
  1856.                                         (void *)&br) != FR_OK)
  1857.                         {
  1858.                                 BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
  1859.                                 xprintf("f_read error on full\n");
  1860.                         }
  1861.  
  1862.                         buf_offs = BUFFER_OFFSET_NONE;
  1863.                         fpos += br;
  1864.                 }
  1865.  
  1866.                 if( br < AUDIO_OUT_BUFFER_SIZE/2 )
  1867.                 {
  1868.                         xprintf("stop at eof\n");
  1869.                         BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
  1870.                         player_state = 0;
  1871.                 }
  1872.         }  //if(player_state)
  1873.  
  1874. */
  1875.         vTaskDelay(2);
  1876.  
  1877.   }
  1878.   /* USER CODE END 5 */
  1879. }
  1880.  
  1881. /**
  1882.   * @brief  Period elapsed callback in non blocking mode
  1883.   * @note   This function is called  when TIM6 interrupt took place, inside
  1884.   * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  1885.   * a global variable "uwTick" used as application time base.
  1886.   * @param  htim : TIM handle
  1887.   * @retval None
  1888.   */
  1889. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  1890. {
  1891.   /* USER CODE BEGIN Callback 0 */
  1892.  
  1893.   /* USER CODE END Callback 0 */
  1894.   if (htim->Instance == TIM6) {
  1895.     HAL_IncTick();
  1896.   }
  1897.   /* USER CODE BEGIN Callback 1 */
  1898.  
  1899.   /* USER CODE END Callback 1 */
  1900. }
  1901.  
  1902. /**
  1903.   * @brief  This function is executed in case of error occurrence.
  1904.   * @param  file: The file name as string.
  1905.   * @param  line: The line in file as a number.
  1906.   * @retval None
  1907.   */
  1908. void _Error_Handler(char *file, int line)
  1909. {
  1910.   /* USER CODE BEGIN Error_Handler_Debug */
  1911.   /* User can add his own implementation to report the HAL error return state */
  1912.   while(1)
  1913.   {
  1914.   }
  1915.   /* USER CODE END Error_Handler_Debug */
  1916. }
  1917.  
  1918. #ifdef  USE_FULL_ASSERT
  1919. /**
  1920.   * @brief  Reports the name of the source file and the source line number
  1921.   *         where the assert_param error has occurred.
  1922.   * @param  file: pointer to the source file name
  1923.   * @param  line: assert_param error line source number
  1924.   * @retval None
  1925.   */
  1926. void assert_failed(uint8_t* file, uint32_t line)
  1927. {
  1928.   /* USER CODE BEGIN 6 */
  1929.   /* User can add his own implementation to report the file name and line number,
  1930.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1931.   /* USER CODE END 6 */
  1932. }
  1933. #endif /* USE_FULL_ASSERT */
  1934.  
  1935.  
  1936. ///////////////////////   my_mqqt connection
  1937. static void mqtt_do_connect(mqtt_client_t *client) {
  1938.  
  1939.  xprint("Start of new mqqt connection\n");
  1940.  ip4_addr_t broker_ipaddr;
  1941.  struct mqtt_connect_client_info_t ci;
  1942.  err_t err;
  1943.  
  1944.  IP4_ADDR(&broker_ipaddr, configBroker_ADDR0, configBroker_ADDR1, configBroker_ADDR2, configBroker_ADDR3);
  1945.  
  1946.  /* Setup an empty client info structure */
  1947.  memset(&ci, 0, sizeof(ci));
  1948.  
  1949.  /* Minimal amount of information required is client identifier, so set it here */
  1950.  ci.client_id = configMQTT_CLIENT_NAME;
  1951.  ci.client_user = configMQTT_CLIENT_USER;
  1952.  ci.client_pass = configMQTT_CLIENT_PWD;
  1953.  
  1954.  /* Initiate client and connect to server, if this fails immediately an error code is returned
  1955.    otherwise mqtt_connection_cb will be called with connection result after attempting
  1956.    to establish a connection with the server.
  1957.    For now MQTT version 3.1.1 is always used */
  1958.  err = mqtt_client_connect(client, &broker_ipaddr, MQTT_PORT, mqtt_connection_cb, 0, &ci);
  1959.  
  1960.  /* For now just print the result code if something goes wrong */
  1961.  if(err != ERR_OK) {
  1962.    printf("mqtt_connect return %d\n", err);
  1963.  }
  1964. }
  1965.  
  1966.  
  1967. /**
  1968.   * @}
  1969.   */
  1970.  
  1971. /**
  1972.   * @}
  1973.   */
  1974.  
  1975. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  1976.