Advertisement
Guest User

LwIP-Init

a guest
Jul 17th, 2021
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 17.19 KB | None | 0 0
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "cmsis_os.h"
  23. #include "lwip.h"
  24.  
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27. //#include "sockets.h"
  28. #include "lwip/api.h"
  29. #include "VNI8200XP.h"
  30. #include "CLT01-38SQ7.h"
  31. /* USER CODE END Includes */
  32.  
  33. /* Private typedef -----------------------------------------------------------*/
  34. /* USER CODE BEGIN PTD */
  35.  
  36. /* USER CODE END PTD */
  37.  
  38. /* Private define ------------------------------------------------------------*/
  39. /* USER CODE BEGIN PD */
  40. #ifdef DEBUG
  41. #define DEBUG_UART
  42. #endif
  43.  
  44. #ifdef DEBUG_UART
  45. #include "serialDebug.h"
  46. #endif
  47. /* USER CODE END PD */
  48.  
  49. /* Private macro -------------------------------------------------------------*/
  50. /* USER CODE BEGIN PM */
  51.  
  52. /* USER CODE END PM */
  53.  
  54. /* Private variables ---------------------------------------------------------*/
  55. SPI_HandleTypeDef hspi1;
  56.  
  57. UART_HandleTypeDef huart3;
  58.  
  59. PCD_HandleTypeDef hpcd_USB_OTG_FS;
  60.  
  61. /* Definitions for defaultTask */
  62. osThreadId_t defaultTaskHandle;
  63.  
  64. const osThreadAttr_t defaultTask_attributes = {
  65.   .name = "defaultTask",
  66.   .stack_size = 128 * 32,
  67.   .priority = (osPriority_t) osPriorityNormal,
  68. };
  69.  
  70. /* USER CODE BEGIN PV */
  71. uint8_t DIGITAL_INPUTS[8] = {0x0};
  72. uint8_t DIGITAL_OUTPUTS[8] = {0x0};
  73.  
  74. osMutexId_t digital_inputs_mutex;
  75. osMutexId_t digital_outputs_mutex;
  76.  
  77. #ifdef DEBUG_UART
  78. osMutexId_t serial_mutex;
  79. #endif
  80.  
  81. const osMutexAttr_t IO_Mutex_attr = {
  82.   "IO_mutex",     // human readable mutex name
  83.   osMutexPrioInherit,  // attr_bits
  84.   NULL,                // memory for control block
  85.   0U                   // size for control block
  86. };
  87.  
  88. osThreadId_t ServerTaskHandle;
  89. osThreadId_t ClientTaskHandle;
  90. osThreadId_t IOTaskHandle;
  91.  
  92. const osThreadAttr_t ServerTask_attributes = {
  93.   .name = "Server",
  94.   .stack_size = 128 * 4,
  95.   .priority = (osPriority_t) osPriorityNormal,
  96. };
  97.  
  98. const osThreadAttr_t ServiceTask_attributes = {
  99.   .name = "NetworkTask",
  100.   .stack_size = 128 * 4,
  101.   .priority = (osPriority_t) osPriorityNormal,
  102. };
  103.  
  104. const osThreadAttr_t IOTask_attributes = {
  105.   .name = "IOTask",
  106.   .stack_size = 128 * 4,
  107.   .priority = (osPriority_t) osPriorityRealtime7,
  108. };
  109. /* USER CODE END PV */
  110.  
  111. /* Private function prototypes -----------------------------------------------*/
  112. void SystemClock_Config(void);
  113. static void MX_GPIO_Init(void);
  114. static void MX_USART3_UART_Init(void);
  115. static void MX_USB_OTG_FS_PCD_Init(void);
  116. static void MX_SPI1_Init(void);
  117. void StartDefaultTask(void *argument);
  118.  
  119. /* USER CODE BEGIN PFP */
  120. static void ServerTask( void *argument );
  121. static void ServiceTask( void *argument );
  122. static void IOTask( void *argument );
  123. /* USER CODE END PFP */
  124.  
  125. /* Private user code ---------------------------------------------------------*/
  126. /* USER CODE BEGIN 0 */
  127.  
  128. /* USER CODE END 0 */
  129.  
  130. /**
  131.   * @brief  The application entry point.
  132.   * @retval int
  133.   */
  134. int main(void)
  135. {
  136.   /* USER CODE BEGIN 1 */
  137.  
  138.   /* USER CODE END 1 */
  139.  
  140.   /* MCU Configuration--------------------------------------------------------*/
  141.  
  142.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  143.   HAL_Init();
  144.  
  145.   /* USER CODE BEGIN Init */
  146.  
  147.   /* USER CODE END Init */
  148.  
  149.   /* Configure the system clock */
  150.   SystemClock_Config();
  151.  
  152.   /* USER CODE BEGIN SysInit */
  153.  
  154.   /* USER CODE END SysInit */
  155.  
  156.   /* Initialize all configured peripherals */
  157.   MX_GPIO_Init();
  158.   MX_USART3_UART_Init();
  159.   MX_USB_OTG_FS_PCD_Init();
  160.   MX_SPI1_Init();
  161.   /* USER CODE BEGIN 2 */
  162. #ifdef DEBUG_UART
  163.   serial_init( &huart3 );
  164. #endif
  165.   /* USER CODE END 2 */
  166.  
  167.   /* Init scheduler */
  168.   osKernelInitialize();
  169.  
  170.   /* USER CODE BEGIN RTOS_MUTEX */
  171.   digital_inputs_mutex = osMutexNew(&IO_Mutex_attr);
  172.   digital_outputs_mutex = osMutexNew(&IO_Mutex_attr);
  173.  
  174. #ifdef DEBUG_UART
  175.   serial_mutex = osMutexNew(&IO_Mutex_attr);
  176. #endif
  177.   /* USER CODE END RTOS_MUTEX */
  178.  
  179.   /* USER CODE BEGIN RTOS_SEMAPHORES */
  180.   /* add semaphores, ... */
  181.   /* USER CODE END RTOS_SEMAPHORES */
  182.  
  183.   /* USER CODE BEGIN RTOS_TIMERS */
  184.   /* start timers, add new ones, ... */
  185.   /* USER CODE END RTOS_TIMERS */
  186.  
  187.   /* USER CODE BEGIN RTOS_QUEUES */
  188.   /* add queues, ... */
  189.   /* USER CODE END RTOS_QUEUES */
  190.  
  191.   /* Create the thread(s) */
  192.   /* creation of defaultTask */
  193.   defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  194.   IOTaskHandle = osThreadNew( IOTask, NULL, &IOTask_attributes );
  195.   /* USER CODE BEGIN RTOS_THREADS */
  196.  
  197.   /* USER CODE END RTOS_THREADS */
  198.  
  199.   /* USER CODE BEGIN RTOS_EVENTS */
  200.   /* add events, ... */
  201.   /* USER CODE END RTOS_EVENTS */
  202.  
  203.   /* Start scheduler */
  204.   osKernelStart();
  205.  
  206.   /* We should never get here as control is now taken by the scheduler */
  207.   /* Infinite loop */
  208.   /* USER CODE BEGIN WHILE */
  209.   while (1)
  210.   {
  211.     /* USER CODE END WHILE */
  212.  
  213.     /* USER CODE BEGIN 3 */
  214.   }
  215.   /* USER CODE END 3 */
  216. }
  217.  
  218. /**
  219.   * @brief System Clock Configuration
  220.   * @retval None
  221.   */
  222. void SystemClock_Config(void)
  223. {
  224.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  225.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  226.  
  227.   /** Configure the main internal regulator output voltage
  228.   */
  229.   __HAL_RCC_PWR_CLK_ENABLE();
  230.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  231.   /** Initializes the RCC Oscillators according to the specified parameters
  232.   * in the RCC_OscInitTypeDef structure.
  233.   */
  234.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  235.   RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  236.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  237.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  238.   RCC_OscInitStruct.PLL.PLLM = 4;
  239.   RCC_OscInitStruct.PLL.PLLN = 168;
  240.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  241.   RCC_OscInitStruct.PLL.PLLQ = 7;
  242.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  243.   {
  244.     Error_Handler();
  245.   }
  246.   /** Initializes the CPU, AHB and APB buses clocks
  247.   */
  248.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  249.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  250.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  251.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  252.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  253.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  254.  
  255.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  256.   {
  257.     Error_Handler();
  258.   }
  259. }
  260.  
  261. /**
  262.   * @brief SPI1 Initialization Function
  263.   * @param None
  264.   * @retval None
  265.   */
  266. static void MX_SPI1_Init(void)
  267. {
  268.  
  269.   /* USER CODE BEGIN SPI1_Init 0 */
  270.  
  271.   /* USER CODE END SPI1_Init 0 */
  272.  
  273.   /* USER CODE BEGIN SPI1_Init 1 */
  274.  
  275.   /* USER CODE END SPI1_Init 1 */
  276.   /* SPI1 parameter configuration*/
  277.   hspi1.Instance = SPI1;
  278.   hspi1.Init.Mode = SPI_MODE_MASTER;
  279.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  280.   hspi1.Init.DataSize = SPI_DATASIZE_16BIT;
  281.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  282.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  283.   hspi1.Init.NSS = SPI_NSS_SOFT;
  284.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
  285.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  286.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  287.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  288.   hspi1.Init.CRCPolynomial = 10;
  289.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  290.   {
  291.     Error_Handler();
  292.   }
  293.   /* USER CODE BEGIN SPI1_Init 2 */
  294.  
  295.   /* USER CODE END SPI1_Init 2 */
  296.  
  297. }
  298.  
  299. /**
  300.   * @brief USART3 Initialization Function
  301.   * @param None
  302.   * @retval None
  303.   */
  304. static void MX_USART3_UART_Init(void)
  305. {
  306.  
  307.   /* USER CODE BEGIN USART3_Init 0 */
  308.  
  309.   /* USER CODE END USART3_Init 0 */
  310.  
  311.   /* USER CODE BEGIN USART3_Init 1 */
  312.  
  313.   /* USER CODE END USART3_Init 1 */
  314.   huart3.Instance = USART3;
  315.   huart3.Init.BaudRate = 115200;
  316.   huart3.Init.WordLength = UART_WORDLENGTH_8B;
  317.   huart3.Init.StopBits = UART_STOPBITS_1;
  318.   huart3.Init.Parity = UART_PARITY_NONE;
  319.   huart3.Init.Mode = UART_MODE_TX_RX;
  320.   huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  321.   huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  322.   if (HAL_UART_Init(&huart3) != HAL_OK)
  323.   {
  324.     Error_Handler();
  325.   }
  326.   /* USER CODE BEGIN USART3_Init 2 */
  327.  
  328.   /* USER CODE END USART3_Init 2 */
  329.  
  330. }
  331.  
  332. /**
  333.   * @brief USB_OTG_FS Initialization Function
  334.   * @param None
  335.   * @retval None
  336.   */
  337. static void MX_USB_OTG_FS_PCD_Init(void)
  338. {
  339.  
  340.   /* USER CODE BEGIN USB_OTG_FS_Init 0 */
  341.  
  342.   /* USER CODE END USB_OTG_FS_Init 0 */
  343.  
  344.   /* USER CODE BEGIN USB_OTG_FS_Init 1 */
  345.  
  346.   /* USER CODE END USB_OTG_FS_Init 1 */
  347.   hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  348.   hpcd_USB_OTG_FS.Init.dev_endpoints = 4;
  349.   hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  350.   hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  351.   hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  352.   hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE;
  353.   hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  354.   hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  355.   hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
  356.   hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  357.   if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
  358.   {
  359.     Error_Handler();
  360.   }
  361.   /* USER CODE BEGIN USB_OTG_FS_Init 2 */
  362.  
  363.   /* USER CODE END USB_OTG_FS_Init 2 */
  364.  
  365. }
  366.  
  367. /**
  368.   * @brief GPIO Initialization Function
  369.   * @param None
  370.   * @retval None
  371.   */
  372. static void MX_GPIO_Init(void)
  373. {
  374.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  375.  
  376.   /* GPIO Ports Clock Enable */
  377.   __HAL_RCC_GPIOC_CLK_ENABLE();
  378.   __HAL_RCC_GPIOH_CLK_ENABLE();
  379.   __HAL_RCC_GPIOA_CLK_ENABLE();
  380.   __HAL_RCC_GPIOE_CLK_ENABLE();
  381.   __HAL_RCC_GPIOB_CLK_ENABLE();
  382.   __HAL_RCC_GPIOD_CLK_ENABLE();
  383.   __HAL_RCC_GPIOG_CLK_ENABLE();
  384.  
  385.   /*Configure GPIO pin Output Level */
  386.   HAL_GPIO_WritePin(GPIOE, GPIO_PIN_9, GPIO_PIN_RESET);
  387.  
  388.   /*Configure GPIO pin Output Level */
  389.   HAL_GPIO_WritePin(GPIOB, LD3_Pin|LD2_Pin, GPIO_PIN_RESET);
  390.  
  391.   /*Configure GPIO pin Output Level */
  392.   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
  393.  
  394.   /*Configure GPIO pin Output Level */
  395.   HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET);
  396.  
  397.   /*Configure GPIO pin : USER_Btn_Pin */
  398.   GPIO_InitStruct.Pin = USER_Btn_Pin;
  399.   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  400.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  401.   HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct);
  402.  
  403.   /*Configure GPIO pin : PE9 */
  404.   GPIO_InitStruct.Pin = GPIO_PIN_9;
  405.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  406.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  407.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  408.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  409.  
  410.   /*Configure GPIO pins : LD3_Pin LD2_Pin */
  411.   GPIO_InitStruct.Pin = LD3_Pin|LD2_Pin;
  412.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  413.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  414.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  415.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  416.  
  417.   /*Configure GPIO pins : PD14 PD15 */
  418.   GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  419.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  420.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  421.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  422.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  423.  
  424.   /*Configure GPIO pin : USB_PowerSwitchOn_Pin */
  425.   GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin;
  426.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  427.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  428.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  429.   HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
  430.  
  431.   /*Configure GPIO pin : USB_OverCurrent_Pin */
  432.   GPIO_InitStruct.Pin = USB_OverCurrent_Pin;
  433.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  434.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  435.   HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  436.  
  437. }
  438.  
  439. /* USER CODE BEGIN 4 */
  440. static void IOTask( void *argument )
  441. {
  442.  
  443.     VNI8200XP_Init(&hspi1);
  444.     CLT01_38SQ7_Init(&hspi1);
  445.  
  446.     while(1)
  447.     {
  448.         VNI8200XP_WD_Reset();
  449.  
  450.         osMutexAcquire(digital_inputs_mutex, osWaitForever);
  451.         ReadDigitalInputs( DIGITAL_INPUTS );
  452.         osMutexRelease(digital_inputs_mutex);
  453.  
  454. //      for( uint8_t i=0; i<8; ++i )
  455. //      {
  456. //          DIGITAL_OUTPUTS[i] = DIGITAL_INPUTS[i];
  457. //      }
  458.  
  459.         osMutexAcquire(digital_outputs_mutex, osWaitForever);
  460.         WriteDigitalOutputs(DIGITAL_OUTPUTS);
  461.         osMutexRelease(digital_outputs_mutex);
  462.  
  463.         osDelay(20);
  464.     }
  465. }
  466.  
  467.  
  468. static void ServiceTask( void * argument )
  469. {
  470.  
  471.     /*
  472.      * MEM_SIZE
  473.      * MEMP_NUM_NETCONN
  474.      * THREAD_STACK_SIZE
  475.      * */
  476.  
  477.     struct netbuf * inbuf;
  478.     char * buf;
  479.     err_t err;
  480.     uint16_t buflen;
  481.  
  482.     struct netconn * newconn = (struct netconn *)argument;
  483.  
  484.     err = netconn_recv( newconn, &inbuf );
  485.  
  486.     if( err == ERR_OK )
  487.     {
  488.         netbuf_data(inbuf, (void**)&buf, &buflen);
  489.  
  490.         if( buflen >= 12 &&
  491.             buf[0] == 'S' &&
  492.             buf[1] == 'E' &&
  493.             buf[2] == 'T')
  494.         {
  495.  
  496.             osMutexAcquire(digital_outputs_mutex, osWaitForever);
  497.             for( uint8_t i=0; i<8; ++i )
  498.             {
  499.                 if( buf[i+4] == '1' )
  500.                 {
  501.                     DIGITAL_OUTPUTS[i] = 0x01;
  502.                 }
  503.                 else if( buf[i+4] == '0' )
  504.                 {
  505.                     DIGITAL_OUTPUTS[i] = 0x00;
  506.                 }
  507.             }
  508.             osMutexRelease(digital_outputs_mutex);
  509.         }
  510.         else if( buflen >= 3 &&
  511.                  buf[0] == 'G' &&
  512.                  buf[1] == 'E' &&
  513.                  buf[2] == 'T' )
  514.         {
  515.             char reply[] = "########\r\n";
  516.  
  517.             osMutexAcquire(digital_inputs_mutex, osWaitForever);
  518.             for( uint8_t i=0; i<8; ++i )
  519.             {
  520.                 if( DIGITAL_INPUTS[i] == 0x00 )
  521.                 {
  522.                     reply[i] = '0';
  523.                 }
  524.                 else
  525.                 {
  526.                     reply[i] = '1';
  527.                 }
  528.             }
  529.             osMutexRelease(digital_inputs_mutex);
  530.  
  531.             netconn_write(newconn, reply, 10, NETCONN_NOCOPY);
  532.         }
  533.  
  534.         netconn_write(newconn, "OK\r\n", sizeof("OK\r\n")-1, NETCONN_NOCOPY);
  535.         netconn_close(newconn);
  536.         netbuf_delete(inbuf);
  537.     }
  538.     else
  539.     {
  540. #ifdef DEBUG_UART
  541.         osMutexAcquire(serial_mutex, osWaitForever);
  542.         serial_print("Error en recepción de cliente");
  543.         osMutexRelease(serial_mutex);
  544. #endif
  545.     }
  546.     netconn_delete(newconn);
  547.  
  548. //  osThreadExit();
  549. }
  550.  
  551. static void ServerTask( void *argument )
  552. {
  553.     err_t err;
  554.     struct netconn *conn, *newconn;
  555.     osThreadId_t client_thread;
  556.  
  557.     conn = netconn_new(NETCONN_TCP);
  558.  
  559.     netconn_bind(conn, NULL, 503);
  560.  
  561.     while(1)
  562.     {
  563.         netconn_listen(conn);
  564.  
  565.         err = netconn_accept(conn,&newconn);
  566.  
  567.         if( err == ERR_OK )
  568.         {
  569. //          client_thread = sys_thread_new( "ServiceTask", ServiceTask, (void *)newconn, ServiceTask_attributes.stack_size, ServiceTask_attributes.priority );
  570.             ServiceTask((void*)newconn);
  571.         }
  572.         else
  573.         {
  574. #ifdef DEBUG_UART
  575.             osMutexAcquire(serial_mutex, osWaitForever);
  576.             serial_print("Error de conexión");
  577.             osMutexRelease(serial_mutex);
  578. #endif
  579.         }
  580.     }
  581.  
  582.     netconn_close(conn);
  583.     netconn_delete(conn);
  584.  
  585.     osThreadExit();
  586. }
  587.  
  588. /* USER CODE END 4 */
  589.  
  590. /* USER CODE BEGIN Header_StartDefaultTask */
  591.  
  592. /**
  593.   * @brief  Function implementing the defaultTask thread.
  594.   * @param  argument: Not used
  595.   * @retval None
  596.   */
  597. /* USER CODE END Header_StartDefaultTask */
  598. void StartDefaultTask(void *argument)
  599. {
  600.   /* init code for LWIP */
  601.   MX_LWIP_Init();
  602.   /* USER CODE BEGIN 5 */
  603. //  ServerTaskHandle = osThreadNew(ServerTask, NULL, &ServerTask_attributes);
  604.   /* Infinite loop */
  605.   for(;;)
  606.   {
  607.     osDelay(1);
  608.   }
  609.   /* USER CODE END 5 */
  610. }
  611.  
  612.  /**
  613.   * @brief  Period elapsed callback in non blocking mode
  614.   * @note   This function is called  when TIM1 interrupt took place, inside
  615.   * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  616.   * a global variable "uwTick" used as application time base.
  617.   * @param  htim : TIM handle
  618.   * @retval None
  619.   */
  620. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  621. {
  622.   /* USER CODE BEGIN Callback 0 */
  623.  
  624.   /* USER CODE END Callback 0 */
  625.   if (htim->Instance == TIM1) {
  626.     HAL_IncTick();
  627.   }
  628.   /* USER CODE BEGIN Callback 1 */
  629.  
  630.   /* USER CODE END Callback 1 */
  631. }
  632.  
  633. /**
  634.   * @brief  This function is executed in case of error occurrence.
  635.   * @retval None
  636.   */
  637. void Error_Handler(void)
  638. {
  639.   /* USER CODE BEGIN Error_Handler_Debug */
  640.   /* User can add his own implementation to report the HAL error return state */
  641.   __disable_irq();
  642.   while (1)
  643.   {
  644.       HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
  645.   }
  646.   /* USER CODE END Error_Handler_Debug */
  647. }
  648.  
  649. #ifdef  USE_FULL_ASSERT
  650. /**
  651.   * @brief  Reports the name of the source file and the source line number
  652.   *         where the assert_param error has occurred.
  653.   * @param  file: pointer to the source file name
  654.   * @param  line: assert_param error line source number
  655.   * @retval None
  656.   */
  657. void assert_failed(uint8_t *file, uint32_t line)
  658. {
  659.   /* USER CODE BEGIN 6 */
  660.   /* User can add his own implementation to report the file name and line number,
  661.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  662.   /* USER CODE END 6 */
  663. }
  664. #endif /* USE_FULL_ASSERT */
  665.  
  666. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  667.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement