|
我用 STM32CubeMX 生成了工程,板子上的以太网通信在网线预先插好的情况下可以正常工作。 但存在一个问题:只有在开机时网线已经接好,以太网才能正常工作。如果板子上电时没有插网线,以太网就无法正常工作,即便之后再插上网线也始终无法恢复。 为了解决这个问题,我在 LWIP 初始化完成后添加了如下函数: netif_set_link_callback(&gnetif, ethernetif_update_config); 其中 void ethernetif_update_config( struct netif *netif) { __IO uint32_t tickstart = 0; uint32_t regvalue = 0; if (netif_is_link_up(netif)) { / Restart the auto-negotiation / if (heth.Init.AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE) { / Enable Auto-Negotiation / HAL_ETH_WritePHYRegister(&heth, PHY_BCR, PHY_AUTONEGOTIATION); / Get tick / tickstart = HAL_GetTick(); / Wait until the auto-negotiation will be completed / do { HAL_ETH_ReadPHYRegister(&heth, PHY_BSR, ®value); / Check for the Timeout ( 1s ) / if ((HAL_GetTick() - tickstart ) > 1000) { / In case of timeout / goto error; } } while (((regvalue & PHY_AUTONEGO_COMPLETE) != PHY_AUTONEGO_COMPLETE)); / Read the result of the auto-negotiation / HAL_ETH_ReadPHYRegister(&heth, PHY_SR, ®value); / Configure the MAC with the Duplex Mode fixed by the auto-negotiation process / if ((regvalue & PHY_DUPLEX_STATUS) != (uint32_t)RESET) { / Set Ethernet duplex mode to Full-duplex following the auto-negotiation / heth.Init.DuplexMode = ETH_MODE_FULLDUPLEX; } else { / Set Ethernet duplex mode to Half-duplex following the auto-negotiation / heth.Init.DuplexMode = ETH_MODE_HALFDUPLEX; } / Configure the MAC with the speed fixed by the auto-negotiation process / if (regvalue & PHY_SPEED_STATUS) { / Set Ethernet speed to 10M following the auto-negotiation / heth.Init.Speed = ETH_SPEED_10M; } else { / Set Ethernet speed to 100M following the auto-negotiation / heth.Init.Speed = ETH_SPEED_100M; } } else / AutoNegotiation Disable / { error : / Check parameters / assert_param(IS_ETH_SPEED(heth.Init.Speed)); assert_param(IS_ETH_DUPLEX_MODE(heth.Init.DuplexMode)); / Set MAC Speed and Duplex Mode to PHY / HAL_ETH_WritePHYRegister(&heth, PHY_BCR, ((uint16_t)(heth.Init.DuplexMode >> 3) | (uint16_t)(heth.Init.Speed >> 1))); } / ETHERNET MAC Re-Configuration / HAL_ETH_ConfigMAC(&heth, (ETH_MACInitTypeDef *) NULL); / Restart MAC interface / HAL_ETH_Start(&heth); } else { / Stop MAC interface / HAL_ETH_Stop(&heth); } ethernetif_notify_conn_changed(netif); } 我在插上网线后通过调用 |
什么是 GPIO 事件?如何将事件绑定到外设
STM32F407xx 是否可以输出 50MHz 时钟供给 RMII 以太网 PHY
求仅使用 HAL ETH、不依赖 LwIP 收发原始以太网帧的示例
STM32H573ZI 全速 USB
即使网络已连接时lwip 的 netconn 结构体 state 仍保持 NETCONN_NONE
stm32f746g-disco开发板的串口通讯连接方式
关于使用FMC功能中的NAND FLASH上的R/B引脚
STM32串口发送数据,USART_FLAG_TC无法置位
STM32L433VCT6 LCD复用引脚如何分配?(同一个引脚同一个复用功能里还有三类引脚)
如何用c#使用ST25R3911DISCOComm.dll来读取和写入NDEF区的数据,需要相关例程,感谢各位大佬拯救一下我啊!????
微信公众号
手机版