cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746 Webserver files loaded from SD card

Hoang Phuc
Associate II
Posted on May 21, 2017 at 13:36

Hello, 

I want to create a webserver application, and I want my html file modified seperately. So I think that saving my web files (including .html, .css and .js files) into SD card I a good solution, So whenever I want to modify my website, I just need to edit web files and put them into SD card.

I read a lot about lwIP and FatFs package but I still dont know how to figure it out.

Can any one expert on this field give me an example project like that? any IDE project is OK. Or I just need to be guided to configure the STM32cubeMX, and create a simple webserver saved on SD card.

Thank you very much

#fatfs #sd-card #web-server #lwip
13 REPLIES 13
Haithem Rahmani
ST Employee
Posted on May 24, 2017 at 16:39

Hi Hoang,

the STM32Cube provides a http server application based on the LwIP API.Have a look at the project:

Projects\STM32756G_EVAL\Applications\LwIP\LwIP_HTTP_Server_Socket_RTOS

the LwIP comes with a builtin http server, the server is expecting the html pages in the file 'fsdata_custom.c' when the lwip config flag HTTPD_USE_CUSTOM_FSDATA is defined.

for the aforementioned project, the actual html pages and data are under 'Projects\STM32746G-Discovery\Applications\LwIP\LwIP_HTTP_Server_Netconn_RTOS\Fs'

you can use any binary dump tool,

https://kent.dl.sourceforge.net/project/bin2header/current/bin2header_0.0.1_portable-win32.zip

for example, to generate your own  'fsdata_custom.c' from your webpages.

Could you please try and let us know whether it suits your needs?

regards

Haithem.

Posted on May 24, 2017 at 17:49

Hi Haithem, thanks for replying me, that's very helpful, I will try this example.

But I have two question:

Is there any way that I can send my web directly to the client, without converting it into the fsdata_custom file?

I read about TFTP, can I use this interface to do some thing like on-the-air update for my web server?. For example I just need to modified my web files (including css,js or cgi files) on my PC and send them to the kit via TFTP interface(with or without converting to fsdata file is all OK), after that the web server will display with the new updates.

If any of my questions is possible, could you show me a brief guide to do it?

Many thanks no matter if you could or couldn't help me this

andrea formentin
Associate II
Posted on May 30, 2017 at 14:35

Hi Hoang

I'm working on a small project that show logs file using lwip. It's possible to read custtom pages/files from sdcard by using

LWIP_HTTPD_CUSTOM_FILES

LWIP_HTTPD_DYNAMIC_FILE_READ

variables. Then you need to implements 3 custom methods :

int fs_open_custom(struct fs_file *file, const char *name);

void  fs_close_custom(struct fs_file *file);

int fs_read_custom(struct fs_file *file, char *buffer, int count);

I'm still working on it, but this is the starting point if you want to use lwip+sd card without using freertos

Andrea

Posted on June 01, 2017 at 09:02

Thank andrea,

That's very helpful. I will try your suggestion.

Have a good day

Posted on June 05, 2017 at 19:44

here is my starting code:

//open custom file

int fs_open_custom(struct fs_file *file, const char *name) {

    //open log file

    if(strncmp_url(name,'/log_file.txt',13)>0)

    {

        file->data = 'buffer_open_custom';    

        file->len = 1000;

        file->index = 0;

        file->pextension = NULL;

        file->is_custom_file = 1;

    

    //0 if unable to open

    return 1;

    }

}

//read file and fill 'buffer' step by step by 'count' bytes amount

int fs_read_custom(struct fs_file *file, char *buffer, int count)  {

    

    int read = 0;    

    if (file->index < file->len)

    {

        read = 100;

        file->is_custom_file = 1;

        buffer = 'buffer_read_custom';

    }

    else

    {

        //end reached

        read = FS_READ_EOF;

    }

    return read;

}

void  fs_close_custom(struct fs_file *file){

    //close file

    //f_close(&fileOpen);

}

fs_open_custom works ok and the first part of the page is correctly loaded, then fs_read_custom is called 10 times before return FS_READ_EOF but only the first call appends to the buffer 'buffer_read_custom' string, next calls append only part of 'fsdata_custom.c' file. Any idea about this behavior? This is only a proof of concept example. I just need to test this code works correctly

LMI2
Lead
Posted on June 05, 2017 at 22:18

Is it so that there is no example project or code for the SD card in the 746 Discovery? Even though there SD drive included. Probably many of us could one, me included.

Posted on June 05, 2017 at 22:24

read/write from to the sd card is quite simple. My problem is to stream huge custom log files stored on usb to port 80 by using lwip. I need to solve issue with buffer of fs_read_custom method...

Posted on June 06, 2017 at 02:37

STM32Cube_FW_F7_V1.7.0/Projects/STM32746G-Discovery/Examples/BSP

and

STM32Cube_FW_F7_V1.7.0/Projects/STM32746G-Discovery/Applications/Display/LTDC_PicturesFromSDCard

both contain example code for SD

Posted on June 06, 2017 at 09:07

thank you but my problem is on lwip side, not sd side. I need to show custom page/log file using lwip webserver...