国产芯片GD32与国产以太网芯片的坑

aebd754c2e0fa882d0c7dbd31c0ffcb8.png

由于有国产化要求,需要将以太网及主控芯片全部换成国产,参考例程是基于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,修改内容如下图所示
1a8d234f10e9d7c8a0416935b6ba1f7d.png

4,修改static void enet_default_init,修改内容如下图所示:
6023332f8f9c9983ba2e9953f80a437d.png

修改以上内容后,程序可以正确运行:
949f777fb68c750019e176802bd228f4.png

==========

往期回顾:

【蓝桥杯更新通知】

传输距离达到1500米的485电路

结构体与指针的关系

琢磨了一天的CAN协议

什么是Modbus协议?

============

作者:探索者515

平台:CSDN

链接:

e73e77bc353d13ecb10ade8f5c7758a3.png

a7bc36d27e5c52022c5660533c288c3a.png

18ef6deb9f23a88e589c0c451b7d3606.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值