找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4120|回复: 1
收起左侧

lwip+freertos stm32源程序 能ping通,测试通过

[复制链接]
ID:222629 发表于 2017-7-26 21:03 | 显示全部楼层 |阅读模式
lwip+freertos 能ping通,测试过
0.png
stm32主程序源码如下:
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   *
  7.   * Copyright (c) 2017 STMicroelectronics International N.V.
  8.   * All rights reserved.
  9.   *
  10.   * Redistribution and use in source and binary forms, with or without
  11.   * modification, are permitted, provided that the following conditions are met:
  12.   *
  13.   * 1. Redistribution of source code must retain the above copyright notice,
  14.   *    this list of conditions and the following disclaimer.
  15.   * 2. Redistributions in binary form must reproduce the above copyright notice,
  16.   *    this list of conditions and the following disclaimer in the documentation
  17.   *    and/or other materials provided with the distribution.
  18.   * 3. Neither the name of STMicroelectronics nor the names of other
  19.   *    contributors to this software may be used to endorse or promote products
  20.   *    derived from this software without specific written permission.
  21.   * 4. This software, including modifications and/or derivative works of this
  22.   *    software, must execute solely and exclusively on microcontroller or
  23.   *    microprocessor devices manufactured by or for STMicroelectronics.
  24.   * 5. Redistribution and use of this software other than as permitted under
  25.   *    this license is void and will automatically terminate your rights under
  26.   *    this license.
  27.   *
  28.   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  29.   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  30.   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  31.   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  32.   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  33.   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  34.   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35.   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  36.   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  37.   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38.   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  39.   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40.   *
  41.   ******************************************************************************
  42.   */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "main.h"
  45. #include "stm32f7xx_hal.h"
  46. #include "cmsis_os.h"
  47. #include "lwip.h"

  48. /* USER CODE BEGIN Includes */

  49. /* USER CODE END Includes */

  50. /* Private variables ---------------------------------------------------------*/

  51. osThreadId defaultTaskHandle;

  52. /* USER CODE BEGIN PV */
  53. /* Private variables ---------------------------------------------------------*/

  54. /* USER CODE END PV */

  55. /* Private function prototypes -----------------------------------------------*/
  56. void SystemClock_Config(void);
  57. void Error_Handler(void);
  58. static void MX_GPIO_Init(void);
  59. void StartDefaultTask(void const * argument);

  60. /* USER CODE BEGIN PFP */
  61. /* Private function prototypes -----------------------------------------------*/

  62. /* USER CODE END PFP */

  63. /* USER CODE BEGIN 0 */

  64. /* USER CODE END 0 */

  65. int main(void)
  66. {

  67.   /* USER CODE BEGIN 1 */

  68.   /* USER CODE END 1 */

  69.   /* MCU Configuration----------------------------------------------------------*/

  70.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  71.   HAL_Init();

  72.   /* Configure the system clock */
  73.   SystemClock_Config();

  74.   /* Initialize all configured peripherals */
  75.   MX_GPIO_Init();

  76.   /* USER CODE BEGIN 2 */

  77.   /* USER CODE END 2 */

  78.   /* USER CODE BEGIN RTOS_MUTEX */
  79.   /* add mutexes, ... */
  80.   /* USER CODE END RTOS_MUTEX */

  81.   /* USER CODE BEGIN RTOS_SEMAPHORES */
  82.   /* add semaphores, ... */
  83.   /* USER CODE END RTOS_SEMAPHORES */

  84.   /* USER CODE BEGIN RTOS_TIMERS */
  85.   /* start timers, add new ones, ... */
  86.   /* USER CODE END RTOS_TIMERS */

  87.   /* Create the thread(s) */
  88.   /* definition and creation of defaultTask */
  89.   osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  90.   defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  91.   /* USER CODE BEGIN RTOS_THREADS */
  92.   /* add threads, ... */
  93.   /* USER CODE END RTOS_THREADS */

  94.   /* USER CODE BEGIN RTOS_QUEUES */
  95.   /* add queues, ... */
  96.   /* USER CODE END RTOS_QUEUES */


  97.   /* Start scheduler */
  98.   osKernelStart();
  99.   
  100.   /* We should never get here as control is now taken by the scheduler */

  101.   /* Infinite loop */
  102.   /* USER CODE BEGIN WHILE */
  103.   while (1)
  104.   {
  105.   /* USER CODE END WHILE */

  106.   /* USER CODE BEGIN 3 */

  107.   }
  108.   /* USER CODE END 3 */

  109. }

  110. /** System Clock Configuration
  111. */
  112. void SystemClock_Config(void)
  113. {

  114.   RCC_OscInitTypeDef RCC_OscInitStruct;
  115.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  116.     /**Configure the main internal regulator output voltage
  117.     */
  118.   __HAL_RCC_PWR_CLK_ENABLE();

  119.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  120.     /**Initializes the CPU, AHB and APB busses clocks
  121.     */
  122.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  123.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  124.   RCC_OscInitStruct.HSICalibrationValue = 16;
  125.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  126.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  127.   RCC_OscInitStruct.PLL.PLLM = 8;
  128.   RCC_OscInitStruct.PLL.PLLN = 216;
  129.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  130.   RCC_OscInitStruct.PLL.PLLQ = 2;
  131.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  132.   {
  133.     Error_Handler();
  134.   }

  135.     /**Activate the Over-Drive mode
  136.     */
  137.   if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  138.   {
  139.     Error_Handler();
  140.   }

  141.     /**Initializes the CPU, AHB and APB busses clocks
  142.     */
  143.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  144.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  145.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  146.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  147.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  148.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  149.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
  150.   {
  151.     Error_Handler();
  152.   }

  153.     /**Configure the Systick interrupt time
  154.     */
  155.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  156.     /**Configure the Systick
  157.     */
  158.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  159.   /* SysTick_IRQn interrupt configuration */
  160.   HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
  161. }

  162. /** Configure pins as
  163.         * Analog
  164.         * Input
  165.         * Output
  166.         * EVENT_OUT
  167.         * EXTI
  168. */
  169. static void MX_GPIO_Init(void)
  170. {

  171.   GPIO_InitTypeDef GPIO_InitStruct;

  172.   /* GPIO Ports Clock Enable */
  173.   __HAL_RCC_GPIOG_CLK_ENABLE();
  174.   __HAL_RCC_GPIOJ_CLK_ENABLE();
  175.   __HAL_RCC_GPIOC_CLK_ENABLE();
  176.   __HAL_RCC_GPIOA_CLK_ENABLE();

  177.   /*Configure GPIO pin Output Level */
  178.   HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_13|GPIO_PIN_5, GPIO_PIN_RESET);

  179.   /*Configure GPIO pins : PJ13 PJ5 */
  180.   GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_5;
  181.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  182.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  183.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  184.   HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct);

  185. }

  186. /* USER CODE BEGIN 4 */

  187. /* USER CODE END 4 */

  188. /* StartDefaultTask function */
  189. void StartDefaultTask(void const * argument)
  190. {
  191.   /* init code for LWIP */
  192.   MX_LWIP_Init();

  193.   /* USER CODE BEGIN 5 */
  194.   /* Infinite loop */
  195.   for(;;)
  196.   {
  197.     osDelay(1);
  198.   }
  199.   /* USER CODE END 5 */
  200. }

  201. /**
  202.   * @brief  This function is executed in case of error occurrence.
  203.   * @param  None
  204.   * @retval None
  205.   */
  206. void Error_Handler(void)
  207. {
  208.   /* USER CODE BEGIN Error_Handler */
  209.   /* User can add his own implementation to report the HAL error return state */
  210.   while(1)
  211.   {
  212.   }
  213. ……………………

  214. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码


lwip_test5.7z

2.05 MB, 下载次数: 43, 下载积分: 黑币 -5

回复

使用道具 举报

ID:250480 发表于 2017-11-22 10:39 | 显示全部楼层
你好,我按照您的方法lwip+freertos  stm32f429  ping不通   但是不加freertos时可以ping通,这是什么原因呢?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表