Hello,
I try to implement very simple function, let's name it connect_and_get_ip(void);
For now I have following code:
struct netif fsl_netif0; ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw; void connect_and_get_ip(void) { // Setup IP Config for DHCP ... IP4_ADDR(&fsl_netif0_ipaddr, 0,0,0,0); IP4_ADDR(&fsl_netif0_netmask, 0,0,0,0); IP4_ADDR(&fsl_netif0_gw, 0,0,0,0); /* Add a network interface to the list of lwIP netifs. */ netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input); /* Set the network interface as the default network interface. */ netif_set_default(&fsl_netif0); /* obtain the IP address, default gateway and subnet mask by using DHCP*/ dhcp_start(&fsl_netif0); printf("got IP Address!"); // Make it active ... netif_set_up(&fsl_netif0); printf("%s : Interface is up : %d\n", __FUNCTION__, fsl_netif0.dhcp->state); printf("%s : IP %s\n", __FUNCTION__, ipaddr_ntoa(&fsl_netif0.ip_addr)); printf("%s : NM %s\n", __FUNCTION__, ipaddr_ntoa(&fsl_netif0.netmask)); printf("%s : GW %s\n", __FUNCTION__, ipaddr_ntoa(&fsl_netif0.gw)); } int main(void) { /* Disable the mpu */ MPU_Type *base = MPU; base->CESR &= ~MPU_CESR_VLD_MASK; /* Init board hardware. */ BOARD_InitPins(); BOARD_BootClockRUN(); BOARD_InitDebugConsole(); connect_and_get_ip(); prox_agent_init(); for(;;) { //not important } }
Unfortunately I get "PHY Link down, please check the cable connection." on console. It happens during executing netif_add(...) function.
What am I doing wrong. I just simply want to connect to serwer and get IP.
Thank you.
Paweł Żydziak
Hello,
This message is received once PHY is initialized and cable detection is performed. In ethernetif.c file you can find the low_level_init function in which a while loop is waiting until activity on the PHY is received, if no activity is received a "timeout error" will be shown.
Be sure that cable is connected correctly and also that you are initializing Ethernet/PHY pins in the MCU.
I also didn't see any call to lwip_init(); before netif_add function is being called.
Hope this helps!
Regards,
Isaac
Could you provide me tutorial how to " initializing Ethernet/PHY pins in the MCU". Im pretty new in that stuff.
Best,
Paweł
Hello,
Which board are you using?
You can refer to any lwIP example that is located at board folder. For example, I am using lwip_httpsrv_bm_frdmk64f example located at <SDK_2_0_FRDM-K64F>/boards/frdmk64f/demo_apps/lwip/lwip_httpsrv
In FRDM-K64F, PTB0 and PTB1 pins are used as RMII0_MDC and RMII0_MDIO respectively, so they are configured in BOARD_InitPins as follows:
/* Affects PORTB_PCR1 register */
PORT_SetPinMux(PORTB, 1u, kPORT_MuxAlt4);
configENET.openDrainEnable = kPORT_OpenDrainEnable;
configENET.mux = kPORT_MuxAlt4;
configENET.pullSelect = kPORT_PullUp;
/* Ungate the port clock */
CLOCK_EnableClock(kCLOCK_PortA);
/* Affects PORTB_PCR0 register */
PORT_SetPinConfig(PORTB, 0u, &configENET);
And PTA12, PTA13, PTA14, PTA5, PTA15, PTA16 and PTA17 are also connected to PHY:
/* Affects PORTA_PCR13 register */
PORT_SetPinMux(PORTA, 13u, kPORT_MuxAlt4);
/* Affects PORTA_PCR12 register */
PORT_SetPinMux(PORTA, 12u, kPORT_MuxAlt4);
/* Affects PORTA_PCR14 register */
PORT_SetPinMux(PORTA, 14u, kPORT_MuxAlt4);
/* Affects PORTA_PCR5 register */
PORT_SetPinMux(PORTA, 5u, kPORT_MuxAlt4);
/* Affects PORTA_PCR16 register */
PORT_SetPinMux(PORTA, 16u, kPORT_MuxAlt4);
/* Affects PORTA_PCR17 register */
PORT_SetPinMux(PORTA, 17u, kPORT_MuxAlt4);
/* Affects PORTA_PCR15 register */
PORT_SetPinMux(PORTA, 15u, kPORT_MuxAlt4);
You can check FRDM-K64F's schematic for more details.
Also, after BOARD_InitPins, BOARD_BootClockRUN and BOARD_InitDebugConsole function, lwip_init function is being called:
MPU_Type *base = MPU;
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Disable MPU. */
base->CESR &= ~MPU_CESR_VLD_MASK;
lwip_init();
I hope this helps!
Regards,
Isaac