首先看一下注釋(這個是靠譜的):
/** Whether the network interface is 'up'. This is
* a software flag used to control whether this network
* interface is enabled and processes traffic.
* It must be set by the startup code before this netif can be used
* (also for dhcp/autoip).
*/
#define NETIF_FLAG_UP 0x01U
/** If set, the netif has broadcast capability.
* Set by the netif driver in its init function. */
#define NETIF_FLAG_BROADCAST 0x02U
/** If set, the interface has an active link
* (set by the network interface driver).
* Either set by the netif driver in its init function (if the link
* is up at that time) or at a later point once the link comes up
* (if link detection is supported by the hardware). */
#define NETIF_FLAG_LINK_UP 0x04U
那麼下面這兩個註釋是否正確呢?
if (netif_is_link_up(&gnetif))
{
/* When the netif is fully configured this function must be called */
netif_set_up(&gnetif);
}
else
{
/* When the netif link is down this function must be called */
netif_set_down(&gnetif);
}
先不談DHCP的問題。
先談自動協商,DP83848的自動協商成功必須在有網線插上的情況下進行。
所以這個問題很複雜,很可能STM32前幾年給出的模板程序纔是靠譜的程序。