Facebook
From Red Marten, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 187
  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 "lwip.h"
  54.  
  55. /* USER CODE BEGIN Includes */
  56. #include  <errno.h>
  57. #include  <sys/unistd.h>
  58.  
  59. #include "stm32746g_discovery_lcd.h"
  60. #include "Utilities/Fonts/fonts.h"
  61. #include "stm32746g_discovery_ts.h"
  62. #include "term_io.h"
  63. #include "dbgu.h"
  64. #include "ansi.h"
  65.  
  66. #include "FreeRTOS.h"
  67. #include "task.h"
  68. #include "queue.h"
  69.  
  70. #include "lwip/opt.h"
  71. #include "lwip/api.h"
  72. #include "lwip/apps/fs.h"
  73. #include "lwip/dhcp.h"
  74. #include "lwip/tcpip.h"
  75. #include "lwip/netdb.h"
  76. #include "lwip/sockets.h"
  77.  
  78. #include "lwip.h"
  79.  
  80. #include "wm8994/wm8994.h"
  81.  
  82. //
  83. #include "lwip/apps/mqtt.h"
  84.  
  85.  
  86. /* USER CODE END Includes */
  87.  
  88. /* Private variables ---------------------------------------------------------*/
  89. ADC_HandleTypeDef hadc3;
  90.  
  91. CRC_HandleTypeDef hcrc;
  92.  
  93. DCMI_HandleTypeDef hdcmi;
  94.  
  95. DMA2D_HandleTypeDef hdma2d;
  96.  
  97. I2C_HandleTypeDef hi2c1;
  98. I2C_HandleTypeDef hi2c3;
  99.  
  100. LTDC_HandleTypeDef hltdc;
  101.  
  102. QSPI_HandleTypeDef hqspi;
  103.  
  104. RTC_HandleTypeDef hrtc;
  105.  
  106. SAI_HandleTypeDef hsai_BlockA2;
  107. SAI_HandleTypeDef hsai_BlockB2;
  108.  
  109. SD_HandleTypeDef hsd1;
  110.  
  111. SPDIFRX_HandleTypeDef hspdif;
  112.  
  113. SPI_HandleTypeDef hspi2;
  114.  
  115. TIM_HandleTypeDef htim1;
  116. TIM_HandleTypeDef htim2;
  117. TIM_HandleTypeDef htim3;
  118. TIM_HandleTypeDef htim5;
  119. TIM_HandleTypeDef htim7;
  120. TIM_HandleTypeDef htim8;
  121. TIM_HandleTypeDef htim12;
  122.  
  123. UART_HandleTypeDef huart1;
  124. UART_HandleTypeDef huart6;
  125.  
  126. SDRAM_HandleTypeDef hsdram1;
  127.  
  128. osThreadId defaultTaskHandle;
  129.  
  130. /* USER CODE BEGIN PV */
  131. /* Private variables ---------------------------------------------------------*/
  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_I2C1_Init(void);
  139. static void MX_USART1_UART_Init(void);
  140. static void MX_USART6_UART_Init(void);
  141. void StartDefaultTask(void const * argument);
  142.  
  143. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  144.  
  145.  
  146.  
  147.  
  148.  
  149. /* USER CODE BEGIN PFP */
  150. /* Private function prototypes -----------------------------------------------*/
  151.  
  152. /* USER CODE END PFP */
  153.  
  154. /* USER CODE BEGIN 0 */
  155. void mainTask(void* p);
  156.  
  157. osThreadId netconn_thread_handle;
  158.  
  159. #define LCD_X_SIZE                      RK043FN48H_WIDTH
  160. #define LCD_Y_SIZE                      RK043FN48H_HEIGHT
  161.  
  162. #define PRINTF_USES_HAL_TX              0
  163.  
  164. int __io_putchar(int ch)
  165. {
  166.         uint8_t data = ch;
  167.         #if PRINTF_USES_HAL_TX
  168.                 HAL_StatusTypeDef status = HAL_UART_Transmit(&huart1, (uint8_t*)&data, len, 100);
  169.         #else
  170.                 while(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) == RESET) { ; }
  171.                 huart1.Instance->TDR = (uint16_t)data;
  172.         #endif
  173.         return 0;
  174. }
  175.  
  176. char inkey(void)
  177. {
  178.         uint32_t flags = huart1.Instance->ISR;
  179.  
  180.         if((flags & UART_FLAG_RXNE) || (flags & UART_FLAG_ORE))
  181.         {
  182.                 __HAL_UART_CLEAR_OREFLAG(&huart1);
  183.                 return (huart1.Instance->RDR);
  184.         }
  185.         else
  186.                 return 0;
  187. }
  188.  
  189. //partially based on available code examples
  190. static void lcd_start(void)
  191. {
  192.   /* LCD Initialization */
  193.   BSP_LCD_Init();
  194.  
  195.   /* LCD Initialization */
  196.   BSP_LCD_LayerDefaultInit(0, (unsigned int)0xC0000000);
  197.   //BSP_LCD_LayerDefaultInit(1, (unsigned int)lcd_image_bg+(LCD_X_SIZE*LCD_Y_SIZE*4));
  198.   BSP_LCD_LayerDefaultInit(1, (unsigned int)0xC0000000+(LCD_X_SIZE*LCD_Y_SIZE*4));
  199.  
  200.   /* Enable the LCD */
  201.   BSP_LCD_DisplayOn();
  202.  
  203.   /* Select the LCD Background Layer  */
  204.   BSP_LCD_SelectLayer(0);
  205.  
  206.   /* Clear the Background Layer */
  207.   BSP_LCD_Clear(LCD_COLOR_WHITE);
  208.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  209.  
  210.   BSP_LCD_SetColorKeying(1,LCD_COLOR_WHITE);
  211.  
  212.   /* Select the LCD Foreground Layer  */
  213.   BSP_LCD_SelectLayer(1);
  214.  
  215.   /* Clear the Foreground Layer */
  216.   BSP_LCD_Clear(LCD_COLOR_WHITE);
  217.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  218.  
  219.   /* Configure the transparency for foreground and background :
  220.      Increase the transparency */
  221.   BSP_LCD_SetTransparency(0, 255);
  222.   BSP_LCD_SetTransparency(1, 255);
  223. }
  224.  
  225. //[rmv]
  226. void draw_button(int xPos, int yPos, int width, int height, uint32_t color, uint8_t* text);
  227. void draw_background(void)
  228. {
  229.         /* Select the LCD Background Layer  */
  230.         BSP_LCD_SelectLayer(0);
  231.         BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  232.         BSP_LCD_FillRect(0,0,LCD_X_SIZE,LCD_Y_SIZE);
  233.  
  234.         //select Foreground Layer
  235.         BSP_LCD_SelectLayer(1);
  236.         char greeting[] = "Hello";
  237.         draw_button(50,50,100,100,LCD_COLOR_MAGENTA,&greeting);
  238. }
  239.  
  240. void draw_button(int xPos, int yPos, int width, int height, uint32_t color, uint8_t* text){
  241.  
  242.         BSP_LCD_SelectLayer(0);
  243.         BSP_LCD_SetTextColor(color);
  244.         BSP_LCD_FillRect(xPos,yPos,width,height);
  245.         BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  246.         BSP_LCD_DisplayStringAt(xPos+5, yPos+5, text, 0);
  247.  
  248. }
  249.  
  250. void draw_chart(float* data){
  251.  
  252.     int chart_height = 200;
  253.     int chart_length = 250;
  254.     int chart_y_pos = 20;
  255.     int chart_x_pos = 20
  256.  
  257. //drawing coordinates system
  258.     BSP_LCD_SelectLayer(0);
  259.     BSP_LCD_Clear(LCD_COLOR_WHITE);
  260.     BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  261.     BSP_LCD_DrawHLine(chart_x_pos,chart_y_pos,chart_length);
  262.     BSP_LCD_DrawVLine(chart_x_pos,chart_y_pos,chart_height);
  263.     BSP_LCD_FillTriangle(chart_length-10,chart_length-10,chart_length,chart_y_pos+5,chart_y_pos-5,chart_y_pos);
  264.     BSP_LCD_FillTriangle(chart_x_pos-5,chart_x_pos,chart_x_pos+5,chart_height-10,chart_height,chart_height-10);
  265.  
  266.     int n = sizeof(data)/sizeof(data[0]);
  267.     float max = data[0];
  268.     float min = data[0];
  269.  
  270.     for(int i=1; i<n; i++){
  271.       if(data[i] < min)
  272.           min = data[i];
  273.       if(data[i] > max)
  274.           max = data[i]
  275.     }
  276.     int min_i = min;
  277.     int max_i = max;
  278.     float coordinates_scale = chart_height/(max_i - min_i);
  279.     float amplitude = max - min; // ?
  280.     float scale = chart_height/amplitude; // ?
  281.  
  282. // draw scale
  283.     int y = chart_y_pos;
  284.     BSP_LCD_SetTextColor(LCD_COLOR_MAGENTA);
  285.     for(int i=1;i<amplitude;i++){
  286.       BSP_LCD_DrawHLine(chart_x_pos,chart_y_pos+i*coordinates_scale,chart_length);
  287.     }
  288.  
  289. // draw data
  290.   BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  291.  
  292.   int sample_len = chart_length/n;
  293.   for(int i=0; i<n-1; i++){
  294.     int x1,y1,x2,y2;
  295.     x1 = chart_x_pos + i * sample_len;
  296.     x2 = chart_x_pos + (i+1) * sample_len;
  297.     y1 = chart_y_pos + (data[i] - min_i)*coordinates_scale;
  298.     y2 = chart_y_pos + (data[i+1] - min_i)*coordinates_scale;
  299.  
  300.     BSP_LCD_DrawLine(x1,y1,x2,y2);
  301.  
  302.   }
  303.  
  304. }
  305.  
  306. static TS_StateTypeDef  TS_State;
  307.  
  308.  
  309. int initialize_touchscreen(void)
  310. {
  311.         uint8_t  status = 0;
  312.         status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  313.         if(status != TS_OK) return -1;
  314.         return 0;
  315. }
  316.  
  317.  int print_data(char* data, int client_id, int len){
  318.         BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
  319.         BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  320.         BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  321.         if(client_id == 1){
  322.                 printf("%s\n",data);
  323.                 int i;
  324.                 for(i = 10; i < 70;i++)
  325.                         BSP_LCD_ClearStringLine(i);
  326.                 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  327.                 BSP_LCD_FillRect(0.3*LCD_X_SIZE,0.1*LCD_Y_SIZE,10,50);
  328.                 BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  329.                 BSP_LCD_ClearStringLine(10);
  330.                 BSP_LCD_ClearStringLine(50);
  331.                 char target[100];
  332.  
  333.                 strncpy(target, data, len);
  334.                 target[len] = '\0';
  335.                 BSP_LCD_DisplayStringAt(0, 10, (uint8_t*)"Temperature1 is:", CENTER_MODE);
  336.                 BSP_LCD_DisplayStringAt(0, 50, (uint8_t*)target, CENTER_MODE);
  337.         }
  338.         else{
  339.         printf("%s\n",data);
  340.         char target[100];
  341.         BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  342.                 BSP_LCD_FillRect(0.3*LCD_X_SIZE,0.1*LCD_Y_SIZE,10,50);
  343.                 BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  344.         strncpy(target, data, len);
  345.         target[len] = '\0';
  346.         BSP_LCD_DisplayStringAt(0, 70, (uint8_t*)"Temperature2 is:", CENTER_MODE);
  347.         BSP_LCD_DisplayStringAt(0, 110, (uint8_t*)target, CENTER_MODE);
  348.         }
  349. }
  350.  
  351.  
  352. /* USER CODE END 0 */
  353.  
  354. /**
  355.   * @brief  The application entry point.
  356.   *
  357.   * @retval None
  358.   */
  359. int main(void)
  360. {
  361.  
  362.  
  363.   float data[10] = {20.34,21.39,22.05,25.07,26.97,24.27,26.34,26.39,26.32,22.01}
  364.  
  365.   /* USER CODE BEGIN 1 */
  366.  
  367.   /* USER CODE END 1 */
  368.  
  369.   /* MCU Configuration----------------------------------------------------------*/
  370.  
  371.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  372.   HAL_Init();
  373.  
  374.   /* USER CODE BEGIN Init */
  375.  
  376.   /* USER CODE END Init */
  377.  
  378.   /* Configure the system clock */
  379.   SystemClock_Config();
  380.  
  381.   /* USER CODE BEGIN SysInit */
  382.  
  383.   /* USER CODE END SysInit */
  384.  
  385.   /* Initialize all configured peripherals */
  386.   MX_GPIO_Init();
  387.   MX_USART1_UART_Init();
  388.   MX_USART6_UART_Init();
  389.   /* USER CODE BEGIN 2 */
  390.   debug_init(&huart1);
  391.  
  392.   xprintf(ANSI_FG_GREEN "STM32F746 Discovery Project" ANSI_FG_DEFAULT "\n");
  393.  
  394.   printf("Regular printf\n");
  395.  
  396. lcd_start();
  397. draw_background();
  398. initialize_touchscreen();
  399. draw_chart(data);
  400.  
  401.   /* Create the thread(s) */
  402.   /* definition and creation of defaultTask */
  403.   osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
  404.   defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  405.  
  406.  
  407.   /* Start scheduler */
  408.   osKernelStart();
  409.  
  410.   /* We should never get here as control is now taken by the scheduler */
  411.  
  412.   /* Infinite loop */
  413.   /* USER CODE BEGIN WHILE */
  414.   while (1)
  415.   {
  416.  
  417.   }
  418.  
  419. }
  420.  
  421. /**
  422.   * @brief System Clock Configuration
  423.   * @retval None
  424.   */
  425. void SystemClock_Config(void)
  426. {
  427.  
  428.   RCC_OscInitTypeDef RCC_OscInitStruct;
  429.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  430.   RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  431.  
  432.     /**Configure the main internal regulator output voltage
  433.     */
  434.   __HAL_RCC_PWR_CLK_ENABLE();
  435.  
  436.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  437.  
  438.     /**Initializes the CPU, AHB and APB busses clocks
  439.     */
  440.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  441.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  442.   RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  443.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  444.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  445.   RCC_OscInitStruct.PLL.PLLM = 25;
  446.   RCC_OscInitStruct.PLL.PLLN = 400;
  447.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  448.   RCC_OscInitStruct.PLL.PLLQ = 8;
  449.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  450.   {
  451.     _Error_Handler(__FILE__, __LINE__);
  452.   }
  453.  
  454.     /**Activate the Over-Drive mode
  455.     */
  456.   if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  457.   {
  458.     _Error_Handler(__FILE__, __LINE__);
  459.   }
  460.  
  461.     /**Initializes the CPU, AHB and APB busses clocks
  462.     */
  463.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  464.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  465.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  466.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  467.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  468.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  469.  
  470.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK)
  471.   {
  472.     _Error_Handler(__FILE__, __LINE__);
  473.   }
  474.  
  475.   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPDIFRX|RCC_PERIPHCLK_LTDC
  476.                               |RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART1
  477.                               |RCC_PERIPHCLK_USART6|RCC_PERIPHCLK_SAI2
  478.                               |RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_I2C3
  479.                               |RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_CLK48;
  480.   PeriphClkInitStruct.PLLI2S.PLLI2SN = 100;
  481.   PeriphClkInitStruct.PLLI2S.PLLI2SP = RCC_PLLP_DIV2;
  482.   PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
  483.   PeriphClkInitStruct.PLLI2S.PLLI2SQ = 2;
  484.   PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
  485.   PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
  486.   PeriphClkInitStruct.PLLSAI.PLLSAIQ = 4;
  487.   PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
  488.   PeriphClkInitStruct.PLLI2SDivQ = 1;
  489.   PeriphClkInitStruct.PLLSAIDivQ = 1;
  490.   PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
  491.   PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  492.   PeriphClkInitStruct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLSAI;
  493.   PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  494.   PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
  495.   PeriphClkInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
  496.   PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
  497.   PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLLSAIP;
  498.   PeriphClkInitStruct.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_CLK48;
  499.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  500.   {
  501.     _Error_Handler(__FILE__, __LINE__);
  502.   }
  503.  
  504.     /**Configure the Systick interrupt time
  505.     */
  506.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  507.  
  508.     /**Configure the Systick
  509.     */
  510.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  511.  
  512.   /* SysTick_IRQn interrupt configuration */
  513.   HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
  514. }
  515.  
  516.  
  517.  
  518.  
  519. /* USART1 init function */
  520. static void MX_USART1_UART_Init(void)
  521. {
  522.  
  523.   huart1.Instance = USART1;
  524.   huart1.Init.BaudRate = 115200;
  525.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  526.   huart1.Init.StopBits = UART_STOPBITS_1;
  527.   huart1.Init.Parity = UART_PARITY_NONE;
  528.   huart1.Init.Mode = UART_MODE_TX_RX;
  529.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  530.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  531.   huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  532.   huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  533.   if (HAL_UART_Init(&huart1) != HAL_OK)
  534.   {
  535.     _Error_Handler(__FILE__, __LINE__);
  536.   }
  537.  
  538. }
  539.  
  540. /* USART6 init function */
  541. static void MX_USART6_UART_Init(void)
  542. {
  543.  
  544.   huart6.Instance = USART6;
  545.   huart6.Init.BaudRate = 115200;
  546.   huart6.Init.WordLength = UART_WORDLENGTH_8B;
  547.   huart6.Init.StopBits = UART_STOPBITS_1;
  548.   huart6.Init.Parity = UART_PARITY_NONE;
  549.   huart6.Init.Mode = UART_MODE_TX_RX;
  550.   huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  551.   huart6.Init.OverSampling = UART_OVERSAMPLING_16;
  552.   huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  553.   huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  554.   if (HAL_UART_Init(&huart6) != HAL_OK)
  555.   {
  556.     _Error_Handler(__FILE__, __LINE__);
  557.   }
  558.  
  559. }
  560.  
  561.  
  562.  
  563. /** Configure pins as
  564.         * Analog
  565.         * Input
  566.         * Output
  567.         * EVENT_OUT
  568.         * EXTI
  569.      PB5   ------> USB_OTG_HS_ULPI_D7
  570.      PH4   ------> USB_OTG_HS_ULPI_NXT
  571.      PB13   ------> USB_OTG_HS_ULPI_D6
  572.      PB12   ------> USB_OTG_HS_ULPI_D5
  573.      PC0   ------> USB_OTG_HS_ULPI_STP
  574.      PC2   ------> USB_OTG_HS_ULPI_DIR
  575.      PA5   ------> USB_OTG_HS_ULPI_CK
  576.      PB10   ------> USB_OTG_HS_ULPI_D3
  577.      PA3   ------> USB_OTG_HS_ULPI_D0
  578.      PB1   ------> USB_OTG_HS_ULPI_D2
  579.      PB0   ------> USB_OTG_HS_ULPI_D1
  580.      PB11   ------> USB_OTG_HS_ULPI_D4
  581. */
  582. static void MX_GPIO_Init(void)
  583. {
  584.  
  585.   GPIO_InitTypeDef GPIO_InitStruct;
  586.  
  587.   /* GPIO Ports Clock Enable */
  588.   __HAL_RCC_GPIOE_CLK_ENABLE();
  589.   __HAL_RCC_GPIOG_CLK_ENABLE();
  590.   __HAL_RCC_GPIOB_CLK_ENABLE();
  591.   __HAL_RCC_GPIOD_CLK_ENABLE();
  592.   __HAL_RCC_GPIOC_CLK_ENABLE();
  593.   __HAL_RCC_GPIOA_CLK_ENABLE();
  594.   __HAL_RCC_GPIOJ_CLK_ENABLE();
  595.   __HAL_RCC_GPIOI_CLK_ENABLE();
  596.   __HAL_RCC_GPIOK_CLK_ENABLE();
  597.   __HAL_RCC_GPIOF_CLK_ENABLE();
  598.   __HAL_RCC_GPIOH_CLK_ENABLE();
  599.  
  600.   /*Configure GPIO pin Output Level */
  601.   HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);
  602.  
  603.   /*Configure GPIO pin Output Level */
  604.   HAL_GPIO_WritePin(GPIOI, ARDUINO_D7_Pin|ARDUINO_D8_Pin, GPIO_PIN_RESET);
  605.  
  606.   /*Configure GPIO pin Output Level */
  607.   HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_SET);
  608.  
  609.   /*Configure GPIO pin Output Level */
  610.   HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET);
  611.  
  612.   /*Configure GPIO pin Output Level */
  613.   HAL_GPIO_WritePin(DCMI_PWR_EN_GPIO_Port, DCMI_PWR_EN_Pin, GPIO_PIN_RESET);
  614.  
  615.   /*Configure GPIO pin Output Level */
  616.   HAL_GPIO_WritePin(GPIOG, ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin, GPIO_PIN_RESET);
  617.  
  618.   /*Configure GPIO pin : OTG_HS_OverCurrent_Pin */
  619.   GPIO_InitStruct.Pin = OTG_HS_OverCurrent_Pin;
  620.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  621.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  622.   HAL_GPIO_Init(OTG_HS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  623.  
  624.   /*Configure GPIO pins : ULPI_D7_Pin ULPI_D6_Pin ULPI_D5_Pin ULPI_D3_Pin
  625.                            ULPI_D2_Pin ULPI_D1_Pin ULPI_D4_Pin */
  626.   GPIO_InitStruct.Pin = ULPI_D7_Pin|ULPI_D6_Pin|ULPI_D5_Pin|ULPI_D3_Pin
  627.                           |ULPI_D2_Pin|ULPI_D1_Pin|ULPI_D4_Pin;
  628.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  629.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  630.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  631.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  632.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  633.  
  634.   /*Configure GPIO pin : OTG_FS_VBUS_Pin */
  635.   GPIO_InitStruct.Pin = OTG_FS_VBUS_Pin;
  636.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  637.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  638.   HAL_GPIO_Init(OTG_FS_VBUS_GPIO_Port, &GPIO_InitStruct);
  639.  
  640.   /*Configure GPIO pin : Audio_INT_Pin */
  641.   /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  642.   GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  643.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  644.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  645.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  646.   HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
  647.  
  648.   /*Configure GPIO pins : ARDUINO_D7_Pin ARDUINO_D8_Pin LCD_DISP_Pin */
  649.   GPIO_InitStruct.Pin = ARDUINO_D7_Pin|ARDUINO_D8_Pin|LCD_DISP_Pin;
  650.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  651.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  652.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  653.   HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
  654.  
  655.   /*Configure GPIO pin : uSD_Detect_Pin */
  656.   GPIO_InitStruct.Pin = uSD_Detect_Pin;
  657.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  658.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  659.   HAL_GPIO_Init(uSD_Detect_GPIO_Port, &GPIO_InitStruct);
  660.  
  661.   /*Configure GPIO pin : LCD_BL_CTRL_Pin */
  662.   GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin;
  663.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  664.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  665.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  666.   HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct);
  667.  
  668.   /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  669.   GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  670.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  671.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  672.   HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  673.  
  674.   /*Configure GPIO pins : TP3_Pin NC2_Pin */
  675.   GPIO_InitStruct.Pin = TP3_Pin|NC2_Pin;
  676.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  677.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  678.   HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
  679.  
  680.   /*Configure GPIO pin : DCMI_PWR_EN_Pin */
  681.   GPIO_InitStruct.Pin = DCMI_PWR_EN_Pin;
  682.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  683.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  684.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  685.   HAL_GPIO_Init(DCMI_PWR_EN_GPIO_Port, &GPIO_InitStruct);
  686.  
  687.   /*Configure GPIO pin : LCD_INT_Pin */
  688.   GPIO_InitStruct.Pin = LCD_INT_Pin;
  689.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  690.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  691.   HAL_GPIO_Init(LCD_INT_GPIO_Port, &GPIO_InitStruct);
  692.  
  693.   /*Configure GPIO pin : ULPI_NXT_Pin */
  694.   GPIO_InitStruct.Pin = ULPI_NXT_Pin;
  695.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  696.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  697.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  698.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  699.   HAL_GPIO_Init(ULPI_NXT_GPIO_Port, &GPIO_InitStruct);
  700.  
  701.   /*Configure GPIO pins : ARDUINO_D4_Pin ARDUINO_D2_Pin EXT_RST_Pin */
  702.   GPIO_InitStruct.Pin = ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin;
  703.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  704.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  705.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  706.   HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  707.  
  708.   /*Configure GPIO pins : ULPI_STP_Pin ULPI_DIR_Pin */
  709.   GPIO_InitStruct.Pin = ULPI_STP_Pin|ULPI_DIR_Pin;
  710.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  711.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  712.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  713.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  714.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  715.  
  716.   /*Configure GPIO pin : RMII_RXER_Pin */
  717.   GPIO_InitStruct.Pin = RMII_RXER_Pin;
  718.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  719.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  720.   HAL_GPIO_Init(RMII_RXER_GPIO_Port, &GPIO_InitStruct);
  721.  
  722.   /*Configure GPIO pins : ULPI_CLK_Pin ULPI_D0_Pin */
  723.   GPIO_InitStruct.Pin = ULPI_CLK_Pin|ULPI_D0_Pin;
  724.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  725.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  726.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  727.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  728.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  729.  
  730. }
  731.  
  732.  
  733.  
  734. /* USER CODE END 4 */
  735.  
  736. /* USER CODE BEGIN Header_StartDefaultTask */
  737. /**
  738.   * @brief  Function implementing the defaultTask thread.
  739.   * @param  argument: Not used
  740.   * @retval None
  741.   */
  742. /* USER CODE END Header_StartDefaultTask */
  743. static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status);
  744. static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len);
  745. static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags);
  746. static void mqtt_sub_request_cb(void *arg, err_t result);
  747. static void mqtt_pub_request_cb(void *arg, err_t result);
  748. int example_do_connect(mqtt_client_t *client)
  749. {
  750.   struct mqtt_connect_client_info_t ci;
  751.   err_t err;
  752.  
  753.   /* Setup an empty client info structure */
  754.   memset(&ci, 0, sizeof(ci));
  755.  
  756.   /* Minimal amount of information required is client identifier, so set it here */
  757.   ci.client_id = "lwip_test";
  758.  
  759.   /* Initiate client and connect to server, if this fails immediately an error code is returned
  760.      otherwise mqtt_connection_cb will be called with connection result after attempting
  761.      to establish a connection with the server.
  762.      For now MQTT version 3.1.1 is always used */
  763.   ip_addr_t ip_addr;
  764.   if(1 == ipaddr_aton( "192.168.0.101",&ip_addr)){
  765.         printf("Created ip");
  766.   }
  767.   err = mqtt_client_connect(client, &ip_addr, 1883, mqtt_connection_cb, 0, &ci);
  768.  
  769.   /* For now just print the result code if something goes wrong */
  770.   if(err != ERR_OK) {
  771.     printf("mqtt_connect return tutaj %d\n", err);
  772.         return 1;
  773.  
  774.   }
  775.   else{
  776.         printf("mqtt_connectbvgfdbgfdgfd\n");
  777.         return 0;
  778.   }
  779. }
  780.  
  781. static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status)
  782. {
  783.  
  784.   err_t err;
  785.   err_t err2;
  786.   if(status == MQTT_CONNECT_ACCEPTED) {
  787.     printf("mqtt_connection_cb: Successfully connected\n");
  788.  
  789.     /* Setup callback for incoming publish requests */
  790.     mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
  791.  
  792.     /* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */
  793.     err = mqtt_subscribe(client, "esp/temperature/client2", 1, mqtt_sub_request_cb, arg);
  794.         err2 = mqtt_subscribe(client, "esp/temperature/client1", 1, mqtt_sub_request_cb, arg);
  795.  
  796.     if(err != ERR_OK || err2 != ERR_OK) {
  797.       printf("mqtt_subscribe return: %d\n", err);
  798.     }
  799.   } else {
  800.     printf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
  801.     /* Its more nice to be connected, so try to reconnect */
  802.     example_do_connect(client);
  803.   }
  804.  
  805. }
  806.  
  807. static void mqtt_sub_request_cb(void *arg, err_t result)
  808. {
  809.   /* Just print the result code here for simplicity,
  810.      normal behaviour would be to take some action if subscribe fails like
  811.      notifying user, retry subscribe or disconnect from server */
  812.   printf("Subscribe result: %d\n", result);
  813.   if(result == ERR_OK){
  814.   printf("Subscribe result is OK!\n");
  815.   }
  816. }
  817.  
  818. //-----------------------------------------------------------------
  819. //3. Implementing callbacks for incoming publish and data
  820.  
  821. /* The idea is to demultiplex topic and create some reference to be used in data callbacks
  822.    Example here uses a global variable, better would be to use a member in arg
  823.    If RAM and CPU budget allows it, the easiest implementation might be to just take a copy of
  824.    the topic string and use it in mqtt_incoming_data_cb
  825. */
  826. static int inpub_id;
  827. static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) // callback invoked when publish starts, contain topic and total length of payload
  828. {
  829.   printf("Incoming publish at topic %s with total length %u\n", topic, (unsigned int)tot_len);
  830.  
  831.   /* Decode topic string into a user defined reference */
  832.   if(strcmp(topic, "print_payload") == 0) {
  833.     inpub_id = 0;
  834.   } else if(topic[0] == 'A') {
  835.     /* All topics starting with 'A' might be handled at the same way */
  836.     inpub_id = 1;
  837.   } else if(strcmp(topic,"esp/temperature/client1") == 0){
  838.         inpub_id = 2;
  839.   }
  840.   else {
  841.     /* For all other topics */
  842.     inpub_id = 3;
  843.   }
  844. }
  845.  
  846. static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) // callback for each fragment of payload that arrives
  847. {
  848.   printf("Incoming publish payload with length %d, flags %u\n", len, (unsigned int)flags);
  849.  
  850.   if(flags & MQTT_DATA_FLAG_LAST) {
  851.     /* Last fragment of payload received (or whole part if payload fits receive buffer
  852.        See MQTT_VAR_HEADER_BUFFER_LEN)  */
  853.  
  854.     /* Call function or do action depending on reference, in this case inpub_id */
  855.     if(inpub_id == 0) {
  856.       /* Don't trust the publisher, check zero termination */
  857.       if(data[len-1] == 0) {
  858.         printf("mqtt_incoming_data_cb: %s\n", (const char *)data);
  859.       }
  860.     } else if(inpub_id == 1) {
  861.       /* Call an 'A' function... */
  862.  
  863.           xprintf("Call an A function ...\n");
  864.  
  865.     } else if(inpub_id == 2){
  866.                 print_data((const char *)data, 1,len);
  867.         }
  868.         else {
  869.       //printf("mqtt_incoming_data_cb: Ignoring payload...\n");
  870.           printf("mqtt_incoming_data_cb: %s\n", (const char *)data);
  871.           print_data((const char *)data,2,len);
  872.     }
  873.   } else {
  874.     /* Handle fragmented payload, store in buffer, write to file or whatever */
  875.   }
  876.   //data = NULL;
  877. }
  878.  
  879. //-----------------------------------------------------------------
  880. //4. Using outgoing publish
  881.  static void mqtt_pub_request_cb(void *arg, err_t result)
  882. {
  883.   if(result != ERR_OK) {
  884.     printf("Publish result: %d\n", result);
  885.   }
  886. }
  887.  
  888. void example_publish(mqtt_client_t *client, void *arg)
  889. {
  890.   const char *pub_payload= "give_temperature";
  891.   err_t err;
  892.   u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
  893.   u8_t retain = 0; /* No don't retain such crappy payload... */
  894.   err = mqtt_publish(client, "esp/temperature", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg);
  895.   if(err != ERR_OK) {
  896.     printf("Publish err: %d\n", err);
  897.   }
  898. }
  899.  
  900. void create_menu(){
  901.  
  902.  
  903. }
  904. void StartDefaultTask(void const * argument)
  905. {
  906.   MX_LWIP_Init();
  907.  
  908.   /*MQTT */
  909.  
  910.   int tmp = 1;
  911.   mqtt_client_t static_client;
  912.   while(tmp == 1){
  913.         xprintf("Trying to connect\n");
  914.         vTaskDelay(1000);
  915.         tmp = example_do_connect(&static_client);
  916.         vTaskDelay(1000);
  917.   //xprintf("tutaj koniecx");
  918.   }
  919.  
  920.   for(;;)
  921.   {
  922.  
  923.         BSP_TS_GetState(&TS_State);
  924.         if(TS_State.touchDetected)
  925.         {
  926.                 BSP_LCD_Clear(LCD_COLOR_WHITE);
  927.                 BSP_LCD_SelectLayer(0);
  928.                 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  929.                 BSP_LCD_FillRect(0,0,LCD_X_SIZE,LCD_Y_SIZE);
  930.  
  931.                 //select Foreground Layer
  932.                 BSP_LCD_SelectLayer(1);
  933.                 char greeting[] = "Hello";
  934.                 draw_button(50,50,100,100,LCD_COLOR_MAGENTA,&greeting);
  935.  
  936.         }
  937.  
  938.         char key = inkey();
  939.         if(key == 'p'){
  940.                 xprintf("Send message \n");
  941.                 example_publish(&static_client,2);
  942.         }
  943.  
  944.  
  945.         vTaskDelay(2);
  946.  
  947.   }
  948.   /* USER CODE END 5 */
  949. }
  950.  
  951. /**
  952.   * @brief  Period elapsed callback in non blocking mode
  953.   * @note   This function is called  when TIM6 interrupt took place, inside
  954.   * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  955.   * a global variable "uwTick" used as application time base.
  956.   * @param  htim : TIM handle
  957.   * @retval None
  958.   */
  959. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  960. {
  961.   /* USER CODE BEGIN Callback 0 */
  962.  
  963.   /* USER CODE END Callback 0 */
  964.   if (htim->Instance == TIM6) {
  965.     HAL_IncTick();
  966.   }
  967.   /* USER CODE BEGIN Callback 1 */
  968.  
  969.   /* USER CODE END Callback 1 */
  970. }
  971.  
  972. /**
  973.   * @brief  This function is executed in case of error occurrence.
  974.   * @param  file: The file name as string.
  975.   * @param  line: The line in file as a number.
  976.   * @retval None
  977.   */
  978. void _Error_Handler(char *file, int line)
  979. {
  980.   /* USER CODE BEGIN Error_Handler_Debug */
  981.   /* User can add his own implementation to report the HAL error return state */
  982.   while(1)
  983.   {
  984.   }
  985.   /* USER CODE END Error_Handler_Debug */
  986. }
  987.  
  988. #ifdef  USE_FULL_ASSERT
  989. /**
  990.   * @brief  Reports the name of the source file and the source line number
  991.   *         where the assert_param error has occurred.
  992.   * @param  file: pointer to the source file name
  993.   * @param  line: assert_param error line source number
  994.   * @retval None
  995.   */
  996. void assert_failed(uint8_t* file, uint32_t line)
  997. {
  998.   /* USER CODE BEGIN 6 */
  999.   /* User can add his own implementation to report the file name and line number,
  1000.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1001.   /* USER CODE END 6 */
  1002. }
  1003. #endif /* USE_FULL_ASSERT */
  1004.  
  1005. /**
  1006.   * @}
  1007.   */
  1008.  
  1009. /**
  1010.   * @}
  1011.   */
  1012.  
  1013. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  1014.