【LwIP学习营】【第一周】移植中遇到phy芯片不一致及其解...

发布于 2018-05-17 16:24:51
    本帖最后由 碧水渊 于 2018-5-17 16:52 编辑


RTT+LWIP学习第一周

目标开发板:单片机STM32F407IGT6,PHY芯片DP83848源码版本 :RT-Thread官方源码3.0.3
源码的bsp中包含stm32f40x的rtt,通过env建立MDK工程,重新选择了目标芯片以后。遇到了第一个问题:bsp中的phy芯片是LAN9720和我的phy芯片不一致。解决办法:硬件原理图如下所示phy原理图.png由于是phy芯片不一致,修改phy芯片相关的操作。即修改stm32f4xx_eth.c中的函数static voidphy_monitor_thread_entry(void *parameter)。
第一步:定义phy芯片DP83848的地址和用到的寄存器#define DP83848_PHY_ADDRESS 0x01/* PHY registers */#define PHY_MICR 0x11 /* MII Interrupt Control Register */#define PHY_MICR_INT_EN ((uint16_t)0x0002) /* PHY Enable interrupts */#define PHY_MICR_INT_OE ((uint16_t)0x0001) /* PHY Enable output interrupt events */#define PHY_MISR 0x12 /* MII Interrupt Status and Misc. Control Register */#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /* Enable Interrupt on change of link status */#define PHY_LINK_STATUS ((uint16_t)0x2000) /* PHY link status interrupt mask */#define PHY_PHYSTS 0x01 /* PHY Status Register*/#define PHY_PHYSTS_AUTONEG_COMPLETE ((uint16_t)0x0010) /* 自动协商完成 */#define PHY_PHYSTS_DUPLEX_STATUS ((uint16_t)0x0004) /* 全双工,半双工,状态标识*/#define PHY_PHYSTS_SPEED_STATUS ((uint16_t)0x0002) /* 10Mb/s和100Mb/s速度状态标识 */#define PHY_PHYSTS_LINK_STATUS ((uint16_t)0x0001) /* 建立有效连接状态标识 */

第二步:初始化phy芯片DP83848/* Read MICRregister */tmpreg =ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_MICR);
/* Enable output interrupt events to signalvia the INT pin */tmpreg |= (uint32_t)PHY_MICR_INT_EN |PHY_MICR_INT_OE;if(!(ETH_WritePHYRegister(DP83848_PHY_ADDRESS, PHY_MICR, tmpreg))){ /* Return ERROR in case of writetimeout */ STM32_ETH_PRINTF("phy writetimeout\r\n");}
/* Read MISR register */tmpreg =ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_MISR);
/* Enable Interrupt on change of linkstatus */tmpreg |= (uint32_t)PHY_MISR_LINK_INT_EN;if(!(ETH_WritePHYRegister(DP83848_PHY_ADDRESS, PHY_MISR, tmpreg))){ /* Return ERROR in case of writetimeout */ STM32_ETH_PRINTF("phy writetimeout\r\n");}/* Return SUCCESS */STM32_ETH_PRINTF("phy init\r\n");第三步:修改读取phy芯片DP83848的link status的函数uint16_t status =ETH_ReadPHYRegister(DP83848_PHY_ADDRESS, PHY_PHYSTS);STM32_ETH_PRINTF("DP83848PHYSTS:0x%04X\r\n", status);phy_speed_new = 0;if(status &(PHY_PHYSTS_AUTONEG_COMPLETE |PHY_PHYSTS_LINK_STATUS)) //link status changed { phy_speed_new = PHY_LINK_MASK; if((status & 0x03) == 1) { phy_speed_new |= PHY_100M_MASK; }
if(status & 0x04) { phy_speed_new |= PHY_DUPLEX_MASK; }}第4步,编译完成,下载到开发板。通过网线把开发板连接到路由器上。在finsh窗口中输入list_if()命令。listif.png查看IP地址为192.168.1.100在电脑的cmd窗口中就可以ping通开发板。pcping.png

查看更多

关注者
0
被浏览
2.8k
2 个回答
aozima
aozima 2018-05-17
拒绝白嫖,拒绝键盘侠!
写得很好,很有实用参考价值。
Cold
Cold 2019-04-26
#define PHY_PHYSTS 0x01 /* PHY Status Register*/

这个地方写错了,查看DP83848手册 地址应为为0x10

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友