本帖最后由 muyichuan2012 于 2024-3-25 14:31 编辑
SC0073 AT32F407/437 EMAC接不同PHY配置方法
示例目的
演示AT32F407/437 EMAC接不同PHY配置方法使用方法。
EMAC支持MII和RMII模式,可根据代码里面配置进行选择,同时PHY开发板上要对应选择RMII或者MII。另外部分型号的PHY仅支持RMII或者MII,需要根据PHY的文档进行选择。另外PHY的原理图请参考Ethernet SUB BOARD对应的原理图。
支持型号列表:
AT32F407 系列
AT32F437 系列
主要使用外设列表:
主要使用外设
EMAC
支持PHY列表:
PHY
DM9162
DP83848C
LAN8720A
AR8032
IP101GR
RTL8201F
YT8512
IP175LL
IP179N
KSZ8041TL
1 快速使用方法
1.1 硬件资源
1) Ethernet Main Board开发板(AT32F407/AT32F437)
2) Ethernet Sub board (DM9162,DP83848C,LAN8720A,…)
3) 将Main Board 和 Sub board 连接
4) 选择对应的MII或者RMII模式
5) 选择对应的时钟来源(建议直接使用晶振给PHY供时钟,使用PLL通过MCO输出的时钟可能达不到PHY的要求)
注意1:LAN8720A仅支持RMII模式
注意2:DP83848在RMII模式下,建议直接给PHY给50MHz晶振,不建议使用PLL输出50MHz给PHY
1.2 软件资源
SourceCode包含两个demo:
at32f407_emac_phy_demo (AT32F407对应EMAC Demo)
工程路径:utilities\emac_phy_demo
at32f437_emac_phy_demo (AT32F437对应EMAC Demo)
工程路径:utilities\emac_phy_demo
1.3 示例使用
软件使用:
打开对应的emac_phy_demo工程, project\at_start_f4xx\examples\emac\emac_phy_demo
在at32_emac.h 中选择对应的PHY和对应的模式,通过选择不同的宏
- /* Select PHY MII or RMII Mode */
- /* #define MII_MODE */
- #define RMII_MODE
- /* DM9162 Support RMII and MII */
- #define DM9162
- /* DP83848 Support RMII and MII */
- /* #define DP83848 */
- /* LAN8720 Support just only support RMII */
- /* #define LAN8720 */
- /* RTL8201F Support RMII and MII */
- /* #define RTL8201F */
- /* AR8032 Support RMII */
- /* #define AR8032 */
- /* YT8512 Support RMII and MII */
- /* #define YT8512 */
- /* IP101GR Support RMII and MII */
- /* #define IP101GR */
- /* Support RMII */
- /* #define IP179N */
- /* Support MII */
- /* #define IP175LLF */
- /* KSZ8041TL Support RMII and MII */
- /* #define KSZ8041TL */
编译通过之后下载到MAIN BOARD
网线连接之后,通过PC可以ping 192.168.81.37,测试是否有正常连接。
调用ethernetif_set_link函数对网络连接状态进行相应的LWIP处理。
- #if (LINK_DETECTION > 0)
- /* link detection process every 500 ms */
- if (localtime - link_timer >= 500)
- {
- link_timer = localtime;
- ethernetif_set_link(&netif);
- }
- #endif
- void ethernetif_set_link(void const *argument)
- {
- uint16_t regvalue = 0;
- struct netif *netif = (struct netif *)argument;
- /* read phy_bsr*/
- regvalue = link_update();
- /* check whether the netif link down and the phy link is up */
- if(!netif_is_link_up(netif) && (regvalue))
- {
- /* network cable is connected */
- netif_set_link_up(netif);
- }
- else if(netif_is_link_up(netif) && (!regvalue))
- {
- /* network cable is dis-connected */
- netif_set_link_down(netif);
- }
- }
|