Skip to main content
Visitor II
May 10, 2021
Solved

I'd like to make TCP/IP communication with DHCP on freeRTOS.

  • May 10, 2021
  • 1 reply
  • 1279 views

Hi everyone.

I would like to know how to use DHCP and check if DHCP is working what I expected.

Please, confirm my process for using TCP/IP communication with DHCP on freeRTOS.

First, I make CubeMX configuration.

0693W00000ANo3VQAT.jpgLike this, I make DHCP_Module enable.

And then, I put TCP/IP echo server C code on RTOS.

0693W00000ANo4OQAT.jpgBelow I attach the TCP/IP echo server thread C code.

/* USER CODE END Header_tcp_echo_server */
void tcp_echo_server(void const * argument)
{
 /* USER CODE BEGIN tcp_echo_server */
	struct netconn *conn, *newconn;
		err_t err, accept_err;
		struct netbuf *buf;
		void *data;
		u16_t len;
		LWIP_UNUSED_ARG(argument);
 
		/* Create a new connection identifier. */
		conn = netconn_new(NETCONN_TCP);
		if (conn!=NULL)
		{
			/* Bind connection to well known port number 7. */
			err = netconn_bind(conn, NULL, 7);
 
		 if (err == ERR_OK)
		 {
		 	/* Tell connection to go into listening mode. */
		 	netconn_listen(conn);
		 	/* Infinite loop */
		 	for(;;)
		 	{
		 		/* Grab new TCP connection. */
	 	 		accept_err = netconn_accept(conn, &newconn);
	 	 		/* Process the new connection. */
	 	 		if (accept_err == ERR_OK)
	 	 		{
	 	 			while (netconn_recv(newconn, &buf) == ERR_OK)
	 	 			{
	 	 				do
	 	 				{
	 	 					netbuf_data(buf, &data, &len);
	 	 					netconn_write(newconn, data, len, NETCONN_COPY);
	 	 				}
	 	 				while (netbuf_next(buf) >= 0);
	 	 				netbuf_delete(buf);
	 	 			}
	 	 	 /* Close connection and discard connection identifier. */
	 	 	 netconn_close(newconn);
	 	 	 netconn_delete(newconn);
	 	 		}
		 	}
		 }
		 else
		 {
		 	netconn_delete(newconn);
		 }
		}
 /* USER CODE END tcp_echo_server */
}

Also, I double-check that there is 'DHCP start' code.

0693W00000ANo45QAD.jpg In 'MX_LWIP_Init()' function, I could find the dhcp_start function.

So,,,.,.,., I think I did all the progress that I can do....

However, I can not connect any DHCP server program, even Window's DHCP mode.

Of course, I use IP Router device.

Is there anybody who using TCP/IP communication with DHCP on freeRTOS??

Or Is there any example??

Or My process is right??

Please help me to get out from this puzzle :(

    This topic has been closed for replies.
    Best answer by Walid ZRELLI

    Hello @EHa.1​ ,

    Unfortunately, we do not have an example DHCP developed in our CubeFW.  But LwIP provides a DHCP test under Middlewares\Third_Party\LwIP\testunit\dhcp that might help you.

    BeST Regards,

    Walid

    1 reply

    Visitor II
    May 28, 2021

    Hello @EHa.1​ ,

    Unfortunately, we do not have an example DHCP developed in our CubeFW.  But LwIP provides a DHCP test under Middlewares\Third_Party\LwIP\testunit\dhcp that might help you.

    BeST Regards,

    Walid