在hardware_init.c初始化EVK上所有的5个PHY,这段代码来自之前的netc_switch_cm33示例
status_tAPP_PHY_Init(void){status_t result = kStatus_Success;phy_config_t phy8211Config = { .autoNeg = true, //yangliang .speed = kPHY_Speed1000M, .duplex = kPHY_FullDuplex, .enableEEE = false, .ops = &phyrtl8211f_ops, };phy_config_t phy8201Config = { .autoNeg = true, //yangliang .speed = kPHY_Speed100M, .duplex = kPHY_FullDuplex, .enableEEE = false, .ops = &phyrtl8201_ops, };/* Reset all PHYs even some are not used in case unstable status has effect on other PHYs. *//* Reset PHY8201 for ETH4(EP), ETH0(Switch port0). Power on 150ms, reset 10ms, wait 150ms. *//* Reset PHY8211 for ETH1(Switch port1), ETH2(Switch port2), ETH3(Switch port3). Reset 10ms, wait 30ms. */ RGPIO_PinWrite(EXAMPLE_EP0_PORT_PHY_RESET_PIN, 0); RGPIO_PinWrite(EXAMPLE_SWT_PORT0_PHY_RESET_PIN, 0); RGPIO_PinWrite(EXAMPLE_SWT_PORT1_PHY_RESET_PIN, 0); RGPIO_PinWrite(EXAMPLE_SWT_PORT2_PHY_RESET_PIN, 0); RGPIO_PinWrite(EXAMPLE_SWT_PORT3_PHY_RESET_PIN, 0); SDK_DelayAtLeastUs(10000, CLOCK_GetFreq(kCLOCK_CpuClk)); RGPIO_PinWrite(EXAMPLE_EP0_PORT_PHY_RESET_PIN, 1); RGPIO_PinWrite(EXAMPLE_SWT_PORT0_PHY_RESET_PIN, 1); RGPIO_PinWrite(EXAMPLE_SWT_PORT1_PHY_RESET_PIN, 1); RGPIO_PinWrite(EXAMPLE_SWT_PORT2_PHY_RESET_PIN, 1); RGPIO_PinWrite(EXAMPLE_SWT_PORT3_PHY_RESET_PIN, 1); SDK_DelayAtLeastUs(150000, CLOCK_GetFreq(kCLOCK_CpuClk));#if 1/* Initialize PHY for EP. */ phy8201Config.resource = &s_phy_resource[EXAMPLE_EP0_PORT]; phy8201Config.phyAddr = BOARD_EP0_PHY_ADDR; result = APP_PHY_SetPort(EXAMPLE_EP0_PORT, &phy8201Config);if (result != kStatus_Success) {return result; } result = APP_Phy8201SetUp(&s_phy_handle[EXAMPLE_EP0_PORT]);if (result != kStatus_Success) {return result; }#endif/* Initialize PHY for switch port0. */ phy8201Config.resource = &s_phy_resource[EXAMPLE_SWT_PORT0]; phy8201Config.phyAddr = BOARD_SWT_PORT0_PHY_ADDR; result = APP_PHY_SetPort(EXAMPLE_SWT_PORT0, &phy8201Config);if (result != kStatus_Success) {return result; } result = APP_Phy8201SetUp(&s_phy_handle[EXAMPLE_SWT_PORT0]);if (result != kStatus_Success) {return result; }/* Initialize PHY for switch port1. */ phy8211Config.resource = &s_phy_resource[EXAMPLE_SWT_PORT1]; phy8211Config.phyAddr = BOARD_SWT_PORT1_PHY_ADDR; result = APP_PHY_SetPort(EXAMPLE_SWT_PORT1, &phy8211Config);if (result != kStatus_Success) {return result; }if (((1U << 2) & EXAMPLE_SWT_USED_PORT_BITMAP) != 0U) {/* Initialize PHY for switch port2. */ phy8211Config.resource = &s_phy_resource[EXAMPLE_SWT_PORT2]; phy8211Config.phyAddr = BOARD_SWT_PORT2_PHY_ADDR; result = APP_PHY_SetPort(EXAMPLE_SWT_PORT2, &phy8211Config);if (result != kStatus_Success) {return result; } }if (((1U << 3) & EXAMPLE_SWT_USED_PORT_BITMAP) != 0U) {/* Initialize PHY for switch port3. */ phy8211Config.resource = &s_phy_resource[EXAMPLE_SWT_PORT3]; phy8211Config.phyAddr = BOARD_SWT_PORT3_PHY_ADDR; result = APP_PHY_SetPort(EXAMPLE_SWT_PORT3, &phy8211Config);if (result != kStatus_Success) {return result; } }return result;}
需要注意的是,把自协商打开了:
