找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32以太网lwip服务器实现程序

[复制链接]
ID:576178 发表于 2019-7-2 10:16 | 显示全部楼层 |阅读模式
更具lwip移植到stm32上实现以太网服务器

单片机源程序如下:
  1. #include "led.h"
  2. #include "lcd.h"
  3. #include "key.h"

  4. #include "stm32f4x7_eth.h"
  5. #include "stm32f4x7_eth_bsp.h"
  6. #include "netconf.h"
  7. #include "tcp.h"
  8. #include "udp.h"
  9. #include "string.h"

  10. #include "TCP_SERVER.h"

  11. #define SYSTEMTICK_PERIOD_MS  10
  12.        
  13. /* Private macro -------------------------------------------------------------*/
  14. /* Private variables ---------------------------------------------------------*/
  15. __IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
  16. uint32_t timingdelay;

  17. int main(void)
  18. {       
  19.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
  20.         delay_init();         //初始化延时函数
  21.         LED_Init();                                          //初始化LED
  22.         //LCD_Init();                                          //初始化LCD
  23.         KEY_Init();           //初始化KEY
  24.        
  25. //        BRUSH_COLOR=RED;
  26. //        LCD_DisplayString(10,10,24,"Illuminati STM32F4");       
  27. //  LCD_DisplayString(10,40,16,"Author:Clever");
  28. //        LCD_DisplayString(20,70,24,"23 TCP_Server ");
  29. //       
  30. //        BRUSH_COLOR=BLUE;
  31. //        LCD_DisplayString(20,110,16,"IMT407G_IP:192.168.1.240");  //开发板作为服务器时的IP
  32. //        LCD_DisplayString(20,130,16,"TCP_Server_PORT:2040 ");     //开发板作为服务器时的端口号
  33.   
  34.         ETH_BSP_Config();     //DP83848相关IO初始化与ETH相关初始化
  35.         LwIP_Init();          //LWIP初始化
  36.         TCP_server_init();    //初始化开发板为服务器

  37.         while (1)
  38.         {  
  39.      LwIP_Periodic_Handle(LocalTime);                   /* handle periodic timers for LwIP */
  40.   }               
  41. }

  42. /**
  43.   * @brief  Inserts a delay time.
  44.   * @param  nCount: number of 10ms periods to wait for.
  45.   * @retval None
  46.   */
  47. void Delay(uint32_t nCount)
  48. {
  49.   /* Capture the current local time */
  50.   timingdelay = LocalTime + nCount;  

  51.   /* wait until the desired delay finish */  
  52.   while(timingdelay > LocalTime)
  53.   {     
  54.   }
  55. }

  56. /**
  57.   * @brief  Updates the system local time
  58.   * @param  None
  59.   * @retval None
  60.   */
  61. void Time_Update(void)
  62. {
  63.   LocalTime += SYSTEMTICK_PERIOD_MS;
  64. }

  65. #ifdef  USE_FULL_ASSERT

  66. /**
  67.   * @brief  Reports the name of the source file and the source line number
  68.   *   where the assert_param error has occurred.
  69.   * @param  file: pointer to the source file name
  70.   * @param  line: assert_param error line source number
  71.   * @retval None
  72.   */
  73. void assert_failed(uint8_t* file, uint32_t line)
  74. {
  75.   /* User can add his own implementation to report the file name and line number,
  76.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  77.   /* Infinite loop */
  78.   while (1)
  79.   {}
  80. }
  81. #endif
复制代码

所有资料51hei提供下载:
TCP服务器数据收发实验.7z (613.2 KB, 下载次数: 43)
回复

使用道具 举报

ID:529603 发表于 2019-7-30 09:10 | 显示全部楼层
为什么PC无法连接上啊?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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