AnsweredAssumed Answered

Connect and DHCP IP

Question asked by Paweł Żydziak on Jul 20, 2016
Latest reply on Aug 3, 2016 by isaacavila


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

Outcomes