2023-10-13
基本介绍
1.CH32V307 使用的是某宝的开发板 (注意配置为 FLASH-224K + RAM-96K),与官网的开发板以太网部分没区别
2.FreeRTOS 用的是官方DEMO的例子
3.LwIP 用的 2.2.0rc
4.使用 MounRiver Studio 集成开发平台
移植过程复杂,直接贴源码
...............................................................................................
链接:https://pan.baidu.com/s/1uxyRt1_FMINprVJBKyIWxg
提取码:5th0
...............................................................................................
注意此函数被修改,主要添加 case ,优先dhcp_reboot(原因:DHCP服务器为软路由的时候,插拔网线,每次IP都会改变,从而使DHCP 分配的IP耗尽)
void
dhcp_network_changed_link_up(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
if (!dhcp) {
return;
}
switch (dhcp->state) {
case DHCP_STATE_REBINDING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_BOUND:
case DHCP_STATE_SELECTING:
case DHCP_STATE_REBOOTING:
case DHCP_STATE_CHECKING:
dhcp->tries = 0;
dhcp_reboot(netif);
break;
case DHCP_STATE_OFF:
/* stay off */
break;
default:
LWIP_ASSERT("invalid dhcp->state", dhcp->state <= DHCP_STATE_BACKING_OFF);
/* INIT/REQUESTING/CHECKING/BACKING_OFF restart with new 'rid' because the
state changes, SELECTING: continue with current 'rid' as we stay in the
same state */
/* ensure we start with short timeouts, even if already discovering */
dhcp->tries = 0;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_network_changed_link_up: dhcp->state=%d\n",dhcp->state));
dhcp_discover(netif);
break;
}
}
功能
1.调试信息串口输出 PA9
2. 支持 网口(每次接收与发送的时候会闪灯)
3. 支持 DHCP 带网线插拔 (主要是这个函数 netif_set_link_callback(&gnetif, ethernetif_update_config);)
4. 开了DHCP调试信息,不用的话在 “lwipopts.h” 中可以注释掉
#define LWIP_DEBUG
#define DBG_TYPES_ON 0xff
//#define ETHARP_DEBUG LWIP_DBG_OFF
//#define NETIF_DEBUG LWIP_DBG_ON
//#define PBUF_DEBUG LWIP_DBG_OFF
//#define API_LIB_DEBUG LWIP_DBG_OFF
//#define API_MSG_DEBUG LWIP_DBG_OFF
//#define SOCKETS_DEBUG LWIP_DBG_OFF
//#define ICMP_DEBUG LWIP_DBG_OFF
//#define IGMP_DEBUG LWIP_DBG_OFF
//#define INET_DEBUG LWIP_DBG_OFF
//#define IP_DEBUG LWIP_DBG_OFF
//#define IP_REASS_DEBUG LWIP_DBG_OFF
//#define RAW_DEBUG LWIP_DBG_OFF
//#define MEM_DEBUG LWIP_DBG_OFF
//#define MEMP_DEBUG LWIP_DBG_OFF
//#define SYS_DEBUG LWIP_DBG_OFF
//#define TCP_DEBUG LWIP_DBG_OFF
//#define TCP_INPUT_DEBUG LWIP_DBG_OFF
//#define TCP_FR_DEBUG LWIP_DBG_OFF
//#define TCP_RTO_DEBUG LWIP_DBG_OFF
//#define TCP_CWND_DEBUG LWIP_DBG_OFF
//#define TCP_WND_DEBUG LWIP_DBG_OFF
//#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
//#define TCP_RST_DEBUG LWIP_DBG_OFF
//#define TCP_QLEN_DEBUG LWIP_DBG_OFF
//#define UDP_DEBUG LWIP_DBG_OFF
//#define TCPIP_DEBUG LWIP_DBG_OFF
//#define PPP_DEBUG LWIP_DBG_OFF
//#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_ON
参考资料 STM32Cube生成LwIP的源码