|
我用 CubeMX 生成了基础工程,板子上以太网通信在网线提前插好时运行正常。 如果开发板上电启动时没有插入网线,以太网功能失效;后续就算插上网线,网络也始终无法恢复。 我在 LWIP 初始化之后添加了下面这个函数:netif_set_link_callback(&gnetif, ethernetif_update_config); ethernetif_update_config 函数由 CubeMX 自动生成,位于 ethernetif.c 文件内,重新启动以太网自协商: 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); } 在插上网线后手动调用回调函数,执行 netif_set_link_up(&gnetif),以太网依旧无法正常工作。请教在这种场景下该如何让以太网恢复正常? |
有使用STM32芯片制作嵌入式PLC比较成熟的方案吗?
stm32mp157 通过codesys 运行PLC程序
请教专家,STM8L052的GPIO口做输入检测,为什么不能反应管脚实际电压变化?
STM32H563 RTC无法进行时间赋值
非对称PWM的问题
STM32H723 TIM1输出三相50%的占空比,TIM_CH3的输出上升沿略比TIM_CH1和TIM_CH2超前,这是哪里配置有问题吗
如何用STM32芯片设计出能输出5路可分别控制脉冲数目的方波?
U575+OV5640
STM32H7B0 CAN发送异常
救急,摄像头监控方案
微信公众号
手机版