STM32F4使用lwip无法发送udp包
lwip debug日志如下:udp_sendpbuf_header: old 20006da8 new 20006da0 (8)
udp_send: added header in given pbuf 20003058
udp_send: sending datagram of length 19
udp_send: UDP packet length 19
udp_send: UDP checksum 0x0000
udp_send: ip_output_if (,,,,0x11,)
pbuf_header: old 20006da0 new 20006d8c (20)
ip4_output_if: st0
IP header:
+-------------------------------+
| 4 | 5 |0x00 | 39 | (v, hl, tos, len)
+-------------------------------+
| 1 |000| 0 | (id, flags, offset)
+-------------------------------+
|255| 17| 0x0000 | (ttl, proto, chksum)
+-------------------------------+
|192|168|137| 1| (src)
+-------------------------------+
|192|168|137| 2| (dest)
+-------------------------------+
ip4_output_if: call netif->output()
pbuf_header: old 20006d8c new 20006d7e (14)
ethernet_output: sending packet 20003058把ethernet_output执行完后,返回程序,一直返回到发送函数,然后直接hardfault。所以无法定位到错误的程序在哪里。
我的project配置是:
1. STM32F407ZG
2. lwip是用stm32cubemx自动生成的
3. 这个项目可以接收tcp,可以发送tcp,可以收到udp包,就是不能发送。
4. 核心函数如下:
while (1)
{
MX_LWIP_Process();
if(isStart==1)udp_send(udp_pcb,udp_p);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}这里是先建立tcp连接,另外一个pc发送start命令,板子收到start,令isStart=1,然后就发送udp包。
5. udp client初始化如下:
void UDP_client_init()
{
udp_p = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM);
udp_p -> payload = (void*)UDPData;
Set_IP4_ADDR(&ipaddr2,UDP_REMOTE_IP);
udp_pcb = udp_new();
udp_bind(udp_pcb,IP_ADDR_ANY,UDP_Client_PORT);
udp_connect(udp_pcb,&ipaddr2,UDP_REMOTE_PORT);
}
NOTE:
为什么加TCP连接?
1. 因为直接发udp也是不行的。
2. 我的这个是程序查询接收以太网包的,没有用中断。所以怀疑是arp没有解析到的原因。结果并不是。
已经解决,是pbuf为的type为PBUF_RAM,改成PBUF_ROM。或者,将udp_p -> payload = (void*)UDPData;改成memcpy或者pbuf_take。 不是在config文件里面要开启UDP的功能么? xiaoshen-372360 发表于 2018-8-24 09:04
不是在config文件里面要开启UDP的功能么?
不是这个原因 配置和自己移植Lwip,发送udp数据,或者是帧的时间不对。如果采用中断方式接收会不会就行了呢,实在不行,在网上找找类似的例子参考下。。。
页:
[1]