Skip to main content
Jessy J
Associate III
May 27, 2018
Question

how to g

  • May 27, 2018
  • 25 replies
  • 3651 views

..

    This topic has been closed for replies.

    25 replies

    Jessy J
    Jessy JAuthor
    Associate III
    May 28, 2018
    Posted on May 28, 2018 at 14:45

    I got error sayin Passing argument 1 of 'fs_open' from incompatible pointer type 

    Jessy J
    Jessy JAuthor
    Associate III
    May 28, 2018
    Posted on May 28, 2018 at 14:46

    and info saying '' expected 'struct fs_file*' but argument is of type 'struct fs_file**' 

    what does this mean please ? 

    Tesla DeLorean
    Guru
    May 28, 2018
    Posted on May 28, 2018 at 14:56

    It means it wants a pointer, and you provided a pointer to a pointer, ie the address of a pointer rather the address of a structure

    If a function wants ptr, don't use &ptr

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Jessy J
    Jessy JAuthor
    Associate III
    May 28, 2018
    Posted on May 28, 2018 at 15:01

     so what I wrote is correct ? 

    struct fs_file *file;

    recv_err = fs_open ( fichier, '/ STM32F4xx_files / ST.gif'); 

    but I have the same warning sayin file may be used uninitialized in this function

    Like

    Show 0 Likes

    https://community.st.com/0D70X000006SwhsSAC

    https://community.st.com/0D70X000006SwhsSAC

    Tesla DeLorean
    Guru
    May 28, 2018
    Posted on May 28, 2018 at 15:38

    fichier != file, and the file pointer needs to actually point to some physical memory

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Jessy J
    Jessy JAuthor
    Associate III
    May 28, 2018
    Posted on May 28, 2018 at 15:47

    I meant file and not fichier 

    struct fs_file *file;

    recv_err = fs_open ( fichier, '/ STM32F4xx_files / ST.gif'); 

    is it correct ?? how can I correct it please !!? 

    Tesla DeLorean
    Guru
    May 28, 2018
    Posted on May 28, 2018 at 16:06

    The compiler is usually right, so if it is complaining something is wrong. Showing me two lines that haven't been cut-n-pasted from the failing code correctly doesn't help me diagnose the issue.

    The 'file' pointer ultimately needs to point at some memory that describes some 'struct fs_file'

    struct fs_file foofile;

    struct fs_file *file = &foofile;

    recv_err = fs_open ( file, '/STM32F4xx_files/ST.gif');
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Jessy J
    Jessy JAuthor
    Associate III
    May 28, 2018
    Posted on May 28, 2018 at 16:30

    here all the code for the http server based on netconn

    /**

    * @brief serve tcp connection

    * @param conn: pointer on connection structure

    * @retval None

    */

    void http_server_serve(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.

    We assume the request (the part we care about) is in one netbuf */

    recv_err = netconn_recv(conn, &inbuf);

    if (recv_err == ERR_OK)

    {

    if (netconn_err(conn) == ERR_OK)

    {

    netbuf_data(inbuf, (void**)&buf, &buflen);

    /* Is this an HTTP GET command? (only check the first 5 chars, since

    there are other formats for GET, and we're keeping it very simple )*/

    if ((buflen >=5) && (strncmp(buf, 'GET /', 5) == 0))

    {

    /* Check if request to get ST.gif */

    if (strncmp((char const *)buf,'GET /STM32F4xx_files/ST.gif',27)==0)

    {

    recv_err = fs_open(file,'/STM32F4xx_files/ST.gif');

    netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);

    fs_close(file);

    }

    /* Check if request to get stm32.jpeg */

    else if (strncmp((char const *)buf,'GET /STM32F4xx_files/stm32.jpg',30)==0)

    {

    recv_err = fs_open(file,'/STM32F4xx_files/stm32.jpg');

    netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);

    fs_close(file);

    }

    else if (strncmp((char const *)buf,'GET /STM32F4xx_files/logo.jpg', 29) == 0)

    {

    /* Check if request to get ST logo.jpg */

    recv_err = fs_open(file,'/STM32F4xx_files/logo.jpg');

    netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);

    fs_close(file);

    }

    else if(strncmp(buf, 'GET /STM32F4xxTASKS.html', 24) == 0)

    {

    /* Load dynamic page */

    DynWebPage(conn);

    }

    else if((strncmp(buf, 'GET /STM32F4xx.html', 19) == 0)||(strncmp(buf, 'GET / ', 6) == 0))

    {

    /* Load STM32F4x7 page */

    recv_err = fs_open(file,'/STM32F4xx.html');

    netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);

    fs_close(file);

    }

    else

    {

    /* Load Error page */

    recv_err = 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);

    }

    /**

    * @brief http server thread

    * @param arg: pointer on argument(not used here)

    * @retval None

    */

    static void http_server_netconn_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, NULL, 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_serve(newconn);

    /* delete connection */

    netconn_delete(newconn);

    }

    }

    }

    }

    }

    /**

    * @brief Initialize the HTTP server (start its thread)

    * @param none

    * @retval None

    */

    void http_server_netconn_init(void)

    {

    sys_thread_new('HTTP', http_server_netconn_thread, NULL, DEFAULT_THREAD_STACKSIZE, osPriorityAboveNormal);

    }
    Tesla DeLorean
    Guru
    May 29, 2018
    Posted on May 29, 2018 at 14:44

    Per examples, you're supposed to be passing a pointer to a pointer so that fs_open can fill that pointer with a 'handle' to it's own structure.

    recv_err = fs_open(&file,'/STM32F4xx_files/ST.gif');

    See STM32Cube_FW_F7_V1.9.0\Projects\STM32746G-Discovery\Applications\LwIP\LwIP_HTTP_Server_Netconn_RTOS\Src\httpserver-netconn.c (or equivalent)

    /**

      * @brief serve tcp connection

      * @param conn: pointer on connection structure

      * @retval None

      */

    static void http_server_serve(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.

       We assume the request (the part we care about) is in one netbuf */

      recv_err = netconn_recv(conn, &inbuf);

      if (recv_err == ERR_OK)

      {

        if (netconn_err(conn) == ERR_OK)

        {

          netbuf_data(inbuf, (void**)&buf, &buflen);

          /* Is this an HTTP GET command? (only check the first 5 chars, since

          there are other formats for GET, and we're keeping it very simple )*/

          if ((buflen >=5) && (strncmp(buf, 'GET /', 5) == 0))

          {

            /* Check if request to get ST.gif */

            if (strncmp((char const *)buf,'GET /STM32F7xx_files/ST.gif',27)==0)

            {

              fs_open(&file, '/STM32F7xx_files/ST.gif');

              netconn_write(conn, (const unsigned char*)(file.data), (size_t)file.len, NETCONN_NOCOPY);

              fs_close(&file);

            }

            /* Check if request to get stm32.jpeg */

            else if (strncmp((char const *)buf,'GET /STM32F7xx_files/stm32.jpg',30)==0)

            {

              fs_open(&file, '/STM32F7xx_files/stm32.jpg');

              netconn_write(conn, (const unsigned char*)(file.data), (size_t)file.len, NETCONN_NOCOPY);

              fs_close(&file);

            }

    ...

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..