0

I am trying to set up an http server on STM32H750B-DK (on STM32CubeIDE) with LwIP. When I program it without implementing FreeRTOS I call the function MX_LWIP_Process in while function in main:

 * Function given to help user to continue LwIP Initialization
 * Up to user to complete or change this function ...
 * Up to user to call this function in main.c in while (1) of main(void)
 *-----------------------------------------------------------------------
 * Read a received packet from the Ethernet buffers
 * Send it to the lwIP stack for handling
 * Handle timeouts if LWIP_TIMERS is set and without RTOS
 * Handle the llink status if LWIP_NETIF_LINK_CALLBACK is set and without RTOS
 */
void MX_LWIP_Process(void)
{
  ethernetif_input(&gnetif);
  sys_check_timeouts();
  Ethernet_Link_Periodic_Handle(&gnetif);
}

The IP address pings fine and the http server is set up. But when I enable FreeRTOS the declaration of this function does not happen:

#if !WITH_RTOS
/* Function defined in lwip.c to:
 *   - Read a received packet from the Ethernet buffers
 *   - Send it to the lwIP stack for handling
 *   - Handle timeouts if NO_SYS_NO_TIMERS not set
 */
void MX_LWIP_Process(void);

#endif /* WITH_RTOS */ Even if I define it outside the if function it doesn’t work. I guess this should work in another way when working with RTOS. I tried calling http_server_init in StartDefaultTask:

static void http_server(struct netconn *conn)
{
    struct netbuf *inbuf;
    err_t recv_err;
    char* buf;
    u16_t buflen;
    struct fs_file file;

    /* Read the data from the port, blocking if nothing yet there */
    recv_err = netconn_recv(conn, &inbuf);

    if (recv_err == ERR_OK)
    {
        if (netconn_err(conn) == ERR_OK)
        {
            /* Get the data pointer and length of the data inside a netbuf */
            netbuf_data(inbuf, (void**)&buf, &buflen);

            /* Check if request to get the index.html */
            if (strncmp((char const *)buf,"GET /index.html",15)==0)
            {
                fs_open(&file, "/index.html");
                netconn_write(conn, (const unsigned char*)(file.data), (size_t)file.len, NETCONN_NOCOPY);
                fs_close(&file);
            }
            else
            {
                /* Load Error page */
                fs_open(&file, "/404.html");
                netconn_write(conn, (const unsigned char*)(file.data), (size_t)file.len, NETCONN_NOCOPY);
                fs_close(&file);
            }
        }
    }
    /* Close the connection (server closes in HTTP) */
    netconn_close(conn);

    /* Delete the buffer (netconn_recv gives us ownership,
   so we have to make sure to deallocate the buffer) */
    netbuf_delete(inbuf);
}


static void http_thread(void *arg)
{ 
  struct netconn *conn, *newconn;
  err_t err, accept_err;
  
  /* Create a new TCP connection handle */
  conn = netconn_new(NETCONN_TCP);
  
  if (conn!= NULL)
  {
    /* Bind to port 80 (HTTP) with default IP address */
    err = netconn_bind(conn, IP_ADDR_ANY, 80);
    
    if (err == ERR_OK)
    {
      /* Put the connection into LISTEN state */
      netconn_listen(conn);
  
      while(1) 
      {
        /* accept any incoming connection */
        accept_err = netconn_accept(conn, &newconn);
        if(accept_err == ERR_OK)
        {
          /* serve connection */
          http_server(newconn);

          /* delete connection */
          netconn_delete(newconn);
        }
      }
    }
  }
}


void http_server_init()
{
  sys_thread_new("http_thread", http_thread, NULL, DEFAULT_THREAD_STACKSIZE, osPriorityNormal);
}

Still doesn’t work. Can anyone help me?

I tried defining the function MX_LWIP_Process outside the if function or otherwise, but I think there is a reason the definition of this function doesn't happen for a reason, but I couldn't get the same results as with this function in another way.

AK16
  • 1

0 Answers0