找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6765|回复: 0
打印 上一主题 下一主题
收起左侧

STM32 LwIP用TCP连接方式在数据量比较大协议栈(4k缓冲区调试通过)

[复制链接]
跳转到指定楼层
楼主


这段时间用STM32移植LwIP做语音传输。但是遇到一个问题困扰许久,在使用TCP方式做一个client去连接server,由于数据量比较大经常在连接一个多小时候就出现断线而

也ping不通。接下来我们看一下这个问题是怎么出现的和他的决绝方法(小白一枚,说错的地方还望指正哈 。。。。共同学习 。嘻嘻 ^_^  )。

额,还没有学操作系统,还生活在裸奔的年代。。。 client和server采用LwIP的Raw函数编写。连接过程采用短连接,即发送一次数据就请求断开。

我们先看一个client端的程序。

/**************************************/
以太网实验,步骤

///
1.把M3接入路由。

///
2.ping实验。在接入相同路由的PC中,运行CMD,输入命令: ping 192.168.1.18
  看是否能ping通,只有ping通后才能进行后续的实验。

*********ping通的实验现象如下(时间可能稍有区别)***********


    C:\Documents and Settings\>ping 192.168.1.18
   
    Pinging 192.168.1.18 with 32 bytes of data:
   
    Reply from 192.168.1.18: bytes=32 time=1ms TTL=255
    Reply from 192.168.1.18: bytes=32 time=2ms TTL=255
    Reply from 192.168.1.18: bytes=32 time<1ms TTL=255
    Reply from 192.168.1.18: bytes=32 time=1ms TTL=255
   
    Ping statistics for 192.168.1.18:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 2ms, Average = 1ms

******************************************************************
    若不能ping通,可能是路由的限制:
      可尝试把M3与PC直接用网线相连, 再 ping 192.168.1.18  ,
    如果还不通,排除网线及接触问题后,可能是代码被修改或板子故障。

///
3.telnet实验。ping通后,输入命令: telnet 192.168.1.18

使用用户名:wildfire 密码:123456  登录。
登录成功后可选两条指令:LED1_ON 和 LED1_OFF 用于远程控制。

***************正常实验现象如下****************************************
屏幕输出        Please enter your username:

键盘输入        wildfire

屏幕输出        Please enter your password:

键盘输入        123456

屏幕输出        Please enter command:

键盘输入        LED1_ON
        
屏幕输出         Success,LED1 status is ON!
        
屏幕输出        Please enter command:

键盘输入        LED1_OFF
        
屏幕输出         Success,LED1 status is OFF!
        
屏幕输出        Please enter command:


************输入命令LED1_ON后,板上的LED1会点亮,输入LED1_OFF后,LED1熄灭****************
(win7系统没有telnet,需要在网上下载该程序进行实验)



////
4.浏览器实验。打开浏览器,在地址栏输入 http://192.168.1.18
  
  连接成功后,可看到登录界面。输入:
*****************************************************  
用户名:wildfire
密码  :123456
*****************************************************
登录成功后,可点击LED控制界面对M3板上的LED1进行控制。
(如果不是原版代码,该网页上的野火旗舰店网址链接可能会被恶意篡改。)

单片机源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  fire
  5.   * @version V1.0
  6.   * @date    2013-xx-xx
  7.   * @brief   enc28j60+lwip测试,具体测试步骤参考工程里面的文件readme.txt

  8.   */

  9. /* Includes ------------------------------------------------------------------*/
  10. #include <stdio.h>
  11. #include "stm32f10x.h"
  12. #include "stm32f10x_usart.h"

  13. #include "err.h"
  14. #include "etharp.h"
  15.         
  16. #include "netconfig.h"
  17. #include "bsp_usart1.h"
  18. #include "bsp_SysTick.h"
  19. #include "spi.h"
  20. #include "bsp_led.h"

  21. #include "cmd.h"
  22. #include "httpd.h"


  23. #include "DAC.h"
  24. #include "TIM2delay.h"
  25. #include "edcode.h"
  26. #include "ADPCM.h"
  27. #include "ADC.h"

  28. /*****************************************************************************************************************************/




  29. __IO uint32_t LocalTime = 0;
  30. /* this variable is used to create a time reference incremented by 10ms */
  31.         
  32. /*
  33. * 函数名:main
  34. * 描述  :主函数
  35. * 输入  :无
  36. * 输出  : 无
  37. * 调用  :
  38. */
  39. int main(void)
  40. {
  41.         /*初始化串口*/
  42.   USART1_Config();         

  43.         /*初始化 以太网SPI接口*/
  44.         ENC_SPI_Init();                 

  45.         /*初始化systick,用于定时轮询输入或给LWIP提供定时*/
  46.         SysTick_Init();               

  47.     ADC1_Init();//ADC 初始化 采用DMA方式
  48.          
  49.         printf("\r\n************************\r\n");
  50.          
  51.           /* 初始化LWIP协议栈*/
  52.         LwIP_Init(); //192.168.1.18

  53.         /*初始化web server 显示网页程序*/
  54.         httpd_init();


  55.         DAC_init(); //DAC初始化
  56.         

  57.         
  58.         timer_init(32);//定时器初始化 开始播放

  59.   /* Infinite loop */  
  60.     while ( 1 )
  61.     {        
  62.         /*轮询*/  
  63.         LwIP_Periodic_Handle(LocalTime);

  64.         decoding( );  //解码
  65.         
  66.         encoding( );
  67.         

  68.         
  69.      
  70.     }
  71. }
复制代码

所有资料51hei提供下载:
LwIP client server.7z (630.54 KB, 下载次数: 60)


此商品已被删除
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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