cancel
Showing results for 
Search instead for 
Did you mean: 

stm32:[cubeMX] freeRTOS lwip dhcp IPaddress

sycinfinity
Associate
Posted on February 19, 2016 at 09:27

Hi everyone. 

I need your's help. 

I use stm32cubemx for init all pins and functions.

and I wonder use FreeRTOS, and LWIP driver. 

My purpose is create LWIP threads, and do TCP/IP communication to my virtual box's ubuntu system. (TCP, UDP echo server and client.)

So, I make IAR project from cubeMX. First time, I didn't use LWIP_DHCP option. at cubeMX's lwip_configuration. Set IP address manually, and my TCP and UDP echo server and client were done very well. 

ex) Ubuntu(TCP server) <-> board(TCP client)

Ubuntu(TCP client) <-> board(TCP server)

Ubuntu(UDP server) <-> board(UDP client)

Ubuntu(UDP client) <-> board(UDP server)

Next, I USE DHCP option. but, it didn't work. 

So I found why didn't work it. 

First I looked my iptime  router's setting window. (192.168.1.1) (DHPC server) . But didn't find my board's MAC addr, and IP addr at 'inside network table.' So I look router's system log. And found my board's ip addr. 

I don't know why It didn't exist at 'inside network table'. But i knew board' ip addr. 

Anyway, I get my board's ip addr. so do TCP and UDP. but, when i use it server i work good. but, client didn't work.

ex) Ubuntu(TCP server) <-> board(TCP client) --> not work.

Ubuntu(TCP client) <-> board(TCP server) --> work.

Ubuntu(UDP server) <-> board(UDP client) --> not work.

Ubuntu(UDP client) <-> board(UDP server) --> work.

So, i look my source. 

And found where my ip addr's saved. 

at my main(), freeRTOS's kernel start, and in my defaultTask , it call MX_LWIP_Init();, and in this function, 

/******************************************************************/

void MX_LWIP_Init(void)

  tcpip_init( NULL, NULL );

 

  ipaddr.addr = 0;

  netmask.addr = 0;

  gw.addr = 0;

  

  /* add the network interface */

  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

 

  /*  Registers the default network interface */

  netif_set_default(&gnetif);

  if (netif_is_link_up(&gnetif))

  {

    /* When the netif is fully configured this function must be called */

    netif_set_up(&gnetif);

  }

  else

  {

    /* When the netif link is down this function must be called */

       netif_set_down(&gnetif);

  }  

dhcp_start(&gnetif);

}

/******************************************************************/

'gnetif' is definedd netif.

So, go to inside of gnetif, and found my DHCP's client addr are saved at here.

gnetif.dhcp->offered_ip_addr.addr;

gnetif.dhcp->offered_gw_addr.addr;

gnetif.dhcp->offered_sn_mask.addr;

So, I add this source at my defaultTask where called MX_LWIP_Init(); 

like this.  

/************************************************************************/

void StartDefaultTask(void const * argument)

{

  /* init code for LWIP */

  MX_LWIP_Init();

  

  gnetif.ip_addr.addr = gnetif.dhcp->offered_ip_addr.addr;

  gnetif.gw.addr = gnetif.dhcp->offered_gw_addr.addr;

  gnetif.netmask.addr = gnetif.dhcp->offered_sn_mask.addr;

  

  ~~~~~~~~

/************************************************************************/

finally, my source are work well. 

But, I don't convince my solution is right solution. 

Is it right solution??? eles, Do I mistake when use dhcp configure?? 

I confused . because, at menual, just I check DHCP option, I could work my source easy.

plz anyone tell me why my source can't work. or, tell me exist other right solution?

thank you.

#freertos #stm32 #lwip #dhcp
0 REPLIES 0