*更新:立方体具有状态和链接回调。还没有尝试过它们,但我希望这是最好的解决方案
我使用
在我的STM32F429ZI
上使用以太网外围LWIP中间件由Cubemx生成
。这个问题类似,但对于PC。
我发现很难理解产品规格中的以太网部分。我可以观看哪些寄存器来检查掉落的链接。
我还研究了 lwip 代码,以防万一明显的非注册观看方法。在主循环中,它将用MX_LWIP_Process
进行轮询网络接口。在阅读时,它知道是否有以下数据包:
void ethernetif_input(struct netif *netif)
{
err_t err;
struct pbuf *p;
/* move received packet into a new pbuf */
p = low_level_input(netif);
/* no packet could be read, silently ignore this */
if (p == NULL) return;
发送时,tcp_output()
功能非常麻烦。它对于无效的Netif,无效的local_ip和我可以观看的一般错误有错误,但没有直接告诉我链接下降的错误。
我最后的想法是,如果电缆被拔下,以太网标题已启用,则关闭。我要查看STM32F4 DK的硬件图,以查看是否可以观看。
是的,您可以使用回调。
您所需要的只是:
1-)启用lwip_netif_link_callback lwipopts.h文件中的定义。默认情况下,值可以为0。检查它。
2-)初始化" netif_set_link_callback(netif,ethernetif_update_config);"在void ethernetif_input(struct netif *netif)函数中。
3-)阅读phy寄存器并做任何意愿。
请参见我的示例,如果以太网电缆断开并重新连接,则系统将自身重置。
void ethernetif_input(struct netif *netif)
{
err_t err;
struct pbuf *p;
/* move received packet into a new pbuf */
p = low_level_input(netif);
uint32_t regvalue = 0;
netif_set_link_callback(netif, ethernetif_update_config); //added by Volkan
// Read PHY link status
if (HAL_ETH_ReadPHYRegister(&EthHandle, PHY_BSR, ®value) == HAL_OK)
{
if((regvalue & PHY_LINKED_STATUS)== (uint16_t)RESET)
{
// Link status = disconnected
if (netif_is_link_up(netif))
{
netif_set_down(netif);
printf("unpluggedrn");
netif_set_link_down(netif);
}
}
else
{
// Link status = connected
if (!netif_is_link_up(netif))
{
printf("pluggedrn");
NVIC_SystemReset();
}
}
}
/* no packet could be read, silently ignore this */
if (p == NULL) return;
/* entry point to the LwIP stack */
err = netif->input(p, netif);
if (err != ERR_OK)
{
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input errorn"));
pbuf_free(p);
p = NULL;
}
}
仅此而已。