sdsffghgfdfg 发表于 2018-6-6 16:00:31

STM32CUBEMX为STM32F407ZG创建lwip,使用udp发送数据失败

问题描述:用买开发板淘宝送的程序源码在我的电脑是可以通过udp接收到发过来的数据。但是,我自己分别stm32cubemx配置和自己移植Lwip,发送udp数据,我的PC都无法接收到。

一、用的是STM32CUBEMX4.25.1版本,lwip是2.0.3版本。下面是我的操作步骤:1. cube里面配置ETH、RCC、SYS、USART1这几个,然后使能lwip。
2. 更改了middlerwares lwip的dhcp选项使不能,以及PHY改成user phy。
3. 开启lwip debug。

二、下面是(STM32CUBEMX配置的)lwip debug打印的信息

udp_send
pbuf_header: failed as 0800c754 < 20003340 (not enough space for new header size)
pbuf_alloc(length=8)
pbuf_alloc(length=8) == 2000334c
pbuf_chain: 2000334c references 20003330
udp_send: added header pbuf 2000334c before given pbuf 20003330
udp_send: sending datagram of length 12
udp_send: UDP packet length 12
udp_send: UDP checksum 0x0000
udp_send: ip_output_if (,,,,0x11,)
pbuf_header: old 20003380 new 2000336c (20)
ip4_output_if: st0
IP header:
+-------------------------------+
| 4 | 5 |0x00 |      32   | (v, hl, tos, len)
+-------------------------------+
|       89      |000|       0   | (id, flags, offset)
+-------------------------------+
|255|   17|    0x0000   | (ttl, proto, chksum)
+-------------------------------+
|192|168|    1|240| (src)
+-------------------------------+
|192|168|    1|   68| (dest)
+-------------------------------+
ip4_output_if: call netif->output()
etharp_find_entry: found matching entry 0
pbuf_alloc(length=32)
pbuf_alloc(length=32) == 200033d8
pbuf_copy(200033d8, 2000334c)
pbuf_copy: end of chain reached.
etharp_query: dropped previously queued packet 2000334c for ARP entry 0
pbuf_free(20003390)
pbuf_free: deallocating 20003390
etharp_query: queued packet 2000334c on ARP entry 0
pbuf_free(2000334c)
pbuf_free: deallocating 2000334c
pbuf_free: 20003330 has ref 1, ending here.

三、 下面是淘宝(可以正常运行)送的程序打印的信息
udp_send
pbuf_header: failed as 0800d822 < 20000898 (not enough space for new header size)
pbuf_alloc(length=8)
pbuf_alloc(length=8) == 200008b8
pbuf_chain: 200008b8 references 20000888
udp_send: added header pbuf 200008b8 before given pbuf 20000888
udp_send: sending datagram of length 29
udp_send: UDP packet length 29
udp_send: UDP checksum 0x0000
udp_send: ip_output_if (,,,,IP_PROTO_UDP,)
pbuf_header: old 200008ec new 200008d8 (20)
ip_output_if: st0
IP header:
+-------------------------------+
| 4 | 5 |0x00 |      49   | (v, hl, tos, len)
+-------------------------------+
|       15      |000|       0   | (id, flags, offset)
+-------------------------------+
|255|   17|    0x0000   | (ttl, proto, chksum)
+-------------------------------+
|192|168|    1|240| (src)
+-------------------------------+
|192|168|    1|   68| (dest)
+-------------------------------+
netif->output()pbuf_header: old 200008d8 new 200008ca (14)
etharp_send_ip: sending packet 200008b8
pbuf_free(200008b8)
pbuf_free: deallocating 200008b8
pbuf_free: 20000888 has ref 1, ending here.


四、自己分析了一下,差别就在于etharp这里。有大佬给指点一下吗?跪求了。。。

sdsffghgfdfg 发表于 2018-6-6 17:07:06

补充一点:我跑TCP是没有问题的,可以ping通。板子当服务器,可以收到PC发来的包,并发回去。

sdsffghgfdfg 发表于 2018-6-7 09:14:36

解决了。主要是中断服务程序的问题,导致ethernet的arp包收不到。

sdsffghgfdfg 发表于 2018-6-7 16:13:52

这下应该彻底解决了。
1. 之前解决的是自己移植的Lwip,自己没有加ETH_IRQHandler。主要不是ETH_IRQHandler,主要是ethernet_input。参考stm32cubemx没有ETH_IRQHandler也可以正常使用。
2. stn32cubemx给我生产的lwip解决方案是,引脚的问题。我看了淘宝那个程序源码给的初始化的引脚和stm32cubemx给我自动配置的引脚有三个不同。分别是PB11、PB12、PB13 。淘宝给的是PG11、PG13、PG14 。我改成淘宝给的这三个引脚,就可以正常通信了。虽然我看了原理图,这些引脚应该都是可以用的,不知道为什么只能用PG系列的。
页: [1]
查看完整版本: STM32CUBEMX为STM32F407ZG创建lwip,使用udp发送数据失败