[STM32F4] STM32F407的以太网接口,有人做过这吗?

[复制链接]
11388|10
 楼主| 1255875047 发表于 2014-11-13 15:27 | 显示全部楼层 |阅读模式
我是用的ST的官方例程。UDP客户端的那个。
ETH_CheckFrameReceived()检测到有数据包的时候,就会调用这个函数LwIP_Pkt_Handle()。然后进入到ethernetif_input(&netif);这个函数里面,进行处理,
在ethernetif_input(&netif);这个函数里面,看到有low_level_input(netif);把网卡的帧拷贝出来,然后再ethernet_input(struct pbuf *p, struct netif *netif)这个函数里面进行了处理。
但是在处理完了之后,我怎么去获取到处理出来的数据呢?这个有人教我吗?
mmuuss586 发表于 2014-11-13 18:24 | 显示全部楼层

应该有吧,不过我没做过;
这方面不熟悉,帮不了你;
YDMCP 发表于 2014-11-13 19:01 | 显示全部楼层
参考原子的吧
song19881218 发表于 2014-11-14 09:18 | 显示全部楼层
数据会一层层向上递交,你要TCP数据,会递交到TCP层,UDP递交到UDP,不是让你处理底层的以太网帧
 楼主| 1255875047 发表于 2014-11-18 17:30 | 显示全部楼层
YDMCP 发表于 2014-11-13 19:01
参考原子的吧

你好,有源代码吗?能不能提供一个给我,具体的操作收发的
 楼主| 1255875047 发表于 2014-11-18 17:31 | 显示全部楼层
song19881218 发表于 2014-11-14 09:18
数据会一层层向上递交,你要TCP数据,会递交到TCP层,UDP递交到UDP,不是让你处理底层的以太网帧
...

你好,能提供一个示例吗?比如一个可用的函数来实现这个,怎么去获取数据。
song19881218 发表于 2014-11-21 17:26 | 显示全部楼层
  1. static err_t telnet_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
  2. {
  3. //  char *rq;

  4.   /* We perform here any necessary processing on the pbuf */
  5.   if (p != NULL)
  6.   {  
  7.          u16_t len;
  8.          u8_t *datab;
  9.          u16_t strlen;      
  10.         /* We call this function to tell the LwIp that we have processed the data */
  11.         /* This lets the stack advertise a larger window, so more data can be received*/
  12.         tcp_recved(pcb, p->tot_len);
  13.         //do
  14.         {
  15.                 //data=p->payload;
  16.                 len=p->len;
  17.                 datab = (unsigned char *)p->payload;
  18.                 if((len == 2) && (*datab == 0x0d) && (*(datab+1) == 0x0a))
  19.                 {       
  20.                         if(cmd_flag > 0)
  21.                         {
  22.                           cmdbuf[cmd_flag] = 0x00;
  23.                           if(strcmp(cmdbuf,"date")==0)
  24.                           {
  25.                                 strlen = sprintf(sndbuf, "Now, It is 2011-xx-xx!\r\n");
  26.                                 tcp_write(pcb,sndbuf,strlen, 1);
  27.                           }
  28.                           else if(strcmp(cmdbuf, "hello")==0)
  29.                           {
  30.                                 strlen = sprintf(sndbuf, "Hello, Nice to see you!\r\n");
  31.                                 tcp_write(pcb,sndbuf,strlen, 1);
  32.                           }
  33.                           else if(strcmp(cmdbuf, "more")==0)
  34.                           {
  35.                                 strlen = sprintf(sndbuf, "Add whatever you need in this way!\r\n");
  36.                                 tcp_write(pcb,sndbuf,strlen, 1);
  37.                           }
  38.                           else if(strcmp(cmdbuf, "help")==0)
  39.                           {
  40.                                 strlen = sprintf(sndbuf, "Suppprted Command£ºdate  hello  more  help  quit\r\n");
  41.                                 tcp_write(pcb,sndbuf,strlen, 1);
  42.                           }
  43.                           else if(strcmp(cmdbuf, "quit")==0)
  44.                           {
  45.                                 cmd_flag=0;
  46.                                 pbuf_free(p);
  47.                                 return tcp_close(pcb);
  48.                           }
  49.                          else
  50.                           {
  51.                            strlen = sprintf(sndbuf, "Unkonwn Command: %s.\r\n", cmdbuf);
  52.                            tcp_write(pcb,sndbuf,strlen, 1);
  53.                          }
  54.                           cmd_flag = 0;
  55.                         }
  56.                         strlen = sprintf(sndbuf,"\r\nForrest_Shell>>");
  57.                         tcp_write(pcb,sndbuf,strlen, 1);
  58.                  }
  59.                  else if((len == 1) && (*datab >= 0x20) && (*datab <= 0x7e) && (cmd_flag < 19))
  60.                  {
  61.                         cmdbuf[cmd_flag] = *datab;
  62.                         cmd_flag++;
  63.                  }
  64.                 else if((len == 1) && (*datab == 0x08) && (cmd_flag >0))
  65.                 {
  66.                         cmd_flag--;
  67.                         strlen = sprintf(sndbuf," \b \b");
  68.                         tcp_write(pcb,sndbuf,strlen, 1);
  69.                 }
  70.                 else if((len == 1) && (*datab == 0x08))
  71.                 {
  72.                         cmd_flag=0;
  73.                         strlen = sprintf(sndbuf,">");
  74.                         tcp_write(pcb,sndbuf,strlen, 1);
  75.                 }
  76.                 else
  77.                 {
  78.                                        
  79.                 }
  80.         }
  81. //        while(netbuf_next(buf) >= 0);
  82.      pbuf_free(p);
  83.     }
  84.   else if (err == ERR_OK)
  85.   {
  86.     /* When the pbuf is NULL and the err is ERR_OK, the remote end is closing the connection. */
  87.     /* We free the allocated memory and we close the connection */
  88.     return tcp_close(pcb);
  89.   }
  90.   return ERR_OK;
  91. }
这个是收到数据后的回调函数,你可以看看数据怎么提取以及处理的,这是个talent的例子

一般首席 发表于 2015-6-20 16:51 | 显示全部楼层
学习中
chenci2013 发表于 2015-6-21 10:38 | 显示全部楼层
进来学习一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

45

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部