由于有国产化要求,需要将以太网及主控芯片全部换成国产,参考例程是基于GD32F450的,在移植过程中遇到一些容易忽略的地方,导致程序卡在gd32fxx_enet.c中enet_phy_config的位置。
将GD32F450上的代码全部移植到GD32F470平台后,一直卡在卡在gd32fxx_enet.c中enet_phy_config,经过排查发现GD32的官方库文件也需要修改,分别为gd32f4xx_enet.h和gd32f4xx_enet.c。
需要修改的地方如下:
1,如下添加宏定义:
#ifndef _PHY_H_
#define DP83848 0
#define LAN8700 1
#define SR8201F 2
#define PHY_TYPE SR8201F
#define PHY_ADDRESS ((uint16_t)0x3U) /*!< phy address determined by the hardware */
2,在头文件88行位置添加如下内容:
#if(PHY_TYPE == LAN8700)
#define PHY_SR 31U /*!< tranceiver status register */
#define PHY_SPEED_STATUS ((uint16_t)0x0004) /*!< configured information of speed: 10Mbit/s */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0010) /*!< configured information of duplex: full-duplex */
#elif(PHY_TYPE == DP83848)
#define PHY_SR 16U /*!< tranceiver status register */
#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< configured information of speed: 10Mbit/s */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< configured information of duplex: full-duplex */
#elif(PHY_TYPE == SR8201F)
#define PHY_SR PHY_REG_BCR /*!< tranceiver status register */
#define PHY_SPEED_STATUS ((uint16_t)0x2000) /*!< configured information of speed: 10Mbit/s */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0100) /*!< configured information of duplex: full-duplex */
#endif /* PHY_TYPE */
3,修改函数ErrStatus enet_init,修改内容如下图所示
4,修改static void enet_default_init,修改内容如下图所示:
修改以上内容后,程序可以正确运行:
==========
往期回顾:
============
作者:探索者515
平台:CSDN
链接: