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
Posted on June 06, 2017 at 12:08

that's why my reply is to mich.lei and not you

Tomas Spacil
Associate II
Posted on August 30, 2017 at 14:06

Hello.

I have some new experience on this topic.

I implemented 3 custom methods like this:

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

{

    FRESULT fres;

    char buffer[100];

    sprintf((char *)buffer, 'www%s', name);

    fres = f_open(&Msc.File[0], &buffer[0], FA_OPEN_EXISTING | FA_READ);

    if(fres != FR_OK)

    {

        return 0;

    }

    file->data = NULL;

    file->len = f_size(&Msc.File[0]);

    file->index = 0;

    file->pextension = NULL;

    return 1;

}

void fs_close_custom(struct fs_file *file)

{

    f_close(&Msc.File[0]);

}

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

{

    uint16_t DLen = 0;

    if(f_eof(&Msc.File[0]))

    {

        return(FS_READ_EOF);

    }

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

    {

        f_read(&Msc.File[0], buffer, count, (void *)&DLen);

        return(DLen);

    }

    else

    {

        DLen = FS_READ_EOF;

    }

    return(DLen);

}

I built a project with HAL and cubeMX with automatic configuration of middlewares like LWIP, USB MSC and Fatfs.

It works quete well. Sometimes it happens that styles are not included in pages. I have separete file style.css.

It works fine when I put styles directly into the pages. Maybe, there is some error occur during multiple file calling.

It seems like some data are lost during calling and styles are not presented correctly.

But the bigger problem is in 'shtml' files. Pages with this suffix are displayed for too long. It takes 20 - 30 sec.

When I only change the suffix from 'shtml' to 'html' it works OK but SSI tags are ignored which can be expected.

When I use a method of fsdata.c file 'shtml' pages are displayed correcly without any issues.

Do you have any opinions about 'shtml' files (SSI) behaviour in conjuction with Fatfs and fs_custom methods?

Thank you for your advice.

Tom.

Mark Shoe
Senior
Posted on February 24, 2018 at 16:53

Hi Thomas, Thanks for you custom functions, they do work however i see sometimes more than one file are opened by the browser at the same time. You used &Msc.File[0]  for fs_file. The should be something other than 0 there. The TM code uses &fil[file->id] but my fs_file has no id field. 

This way with multiple files the reader does not know which file to read. How to seperate the files?

Mark Shoe
Senior
Posted on March 15, 2018 at 09:49

Did someone managed to run a http server from the SD card? Please share your lwip.c