1. 程式人生 > >LWIP network interface 網卡 初始化 以 STM32 為例子 後面會有 用 2G 或者4G 模塊 用 PPP撥號的 形式 虛擬出網卡 所以先以 這個為 前提

LWIP network interface 網卡 初始化 以 STM32 為例子 後面會有 用 2G 或者4G 模塊 用 PPP撥號的 形式 虛擬出網卡 所以先以 這個為 前提

lan 函數 網卡 描述 ane details 我們 err img

LWIP network interface 網卡 初始化 以 STM32 為例子 後面會有 用 2G 或者4G 模塊 用 PPP撥號的 形式 虛擬出網卡 所以先以 這個為 前提

LWIP 有 一個 結構體 是 描述 物理 接口 的 即 netif Struct, 大神朱工 對這個 有個 詳細的 解釋 :http://blog.csdn.net/zhzht19861011/article/details/6690534

LWIP 官網 對 這個 結構體 也有 詳細 的 描述 :http://www.nongnu.org/lwip/2_0_x/structnetif.html

技術分享

我 使用 的 代碼 是 ST 官方 提供 的 演示例程 , 可以在 這裏下載到 STM32F407 + DP83848

工程 打開路徑 : C:\Users\admin\Desktop\STM32F4x7_ETH_LwIP_V1.1.0\Project\FreeRTOS\udptcp_echo_server_netconn\MDK-ARM

看看 ST 是怎麽 定義 一個 網卡 變量 並 初始化的

首先看 定義 的 地方 :

技術分享

然後 看看 對 這個變量 怎麽 初始化 的 。。

/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
struct ip_addr *netmask, struct ip_addr *gw,
void *state, err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif))

Adds your network interface to the netif_list. Allocate a struct
netif and pass a pointer to this structure as the first argument.
Give pointers to cleared ip_addr structures when using DHCP,
or fill them with sane numbers otherwise. The state pointer may be NULL.

The init function pointer must point to a initialization function for
your ethernet netif interface. The following code illustrates it‘s use.*/
netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

使用 了 netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input); 這個 函數 對 這個 網卡 進行 了 初始化 。

這個 函數 是 LWIP 提供的 函數 ,我們 看一下 官方 的 解釋 :http://www.nongnu.org/lwip/2_0_x/group__netif.html#gade5498543e74067f28cc6bef0209e3be

技術分享

第一步 : 我 們 需要 先 定義 一個 netif Struct 類型 的變量

LWIP network interface 網卡 初始化 以 STM32 為例子 後面會有 用 2G 或者4G 模塊 用 PPP撥號的 形式 虛擬出網卡 所以先以 這個為 前提