cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP Server. Webpage in SD

mllona
Associate II
Posted on December 13, 2013 at 19:35

Hi Everyone,

I have a STM32F4Discovery board and I have implemented on it an http server using the lwip v1.41 stack. I also have implemented a micro-SD with SDIO and FATFS, and USB FS as a mass storage device. All of this is working fine together.

My question is if I can store the webpages in the SD card in binary format instead of using the fsdata.c inside the microcontroller flash. If so, how can I do that? Is there any example?

Thanks

#stm32f4discovery #ethernet #sdio
7 REPLIES 7
Posted on December 13, 2013 at 19:50

My question is if I can store the webpages in the SD card in binary format instead of using the fsdata.c inside the microcontroller flash. If so, how can I do that? Is there any example?

 

I didn't do it with the DISCO board, but yes it's possible, I modified httpserver-socket.c to direct ''GET /SDCARD/'' access to the FAT FS implementation and served the data from there to demonstrate functionality. The data could come completely from the card if you so chose.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mllona
Associate II
Posted on December 16, 2013 at 12:45

Thanks for your answer clive.

Could you please teel me how did you modify the sockets.c file, or if you have a post explaining it because i couldn't find it.

Thanks

mllona
Associate II
Posted on December 18, 2013 at 14:55

I've tried to modify the fs_open, fs_close, fs_read ... functions from the fs.c file to point to the similar ones from the ff.c file (fat fs), to read files from sd, but no luck. No data is sent to the browser.

I think I know what I have to do but I don't know how.

Any help?

Posted on December 18, 2013 at 20:59

Yeah, I'm not sure that approach addresses how the data is presented to the socket, and definitely falls over if the file size exceeds the available RAM.

STM32F217VGT6\Code\STM32F2x7_ETH_LwIP_V1.0.2\Project\FreeRTOS\httpserver_socket\src\httpserver-socket.c

http_server_serve()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 20, 2013 at 17:07

...
else if(strncmp((char *)recv_buffer, ''GET /SDCARD/'', 12) == 0)
{
FRESULT res;
FIL fil;
int i;
i = 12; // Find end of name
while(recv_buffer[i] && (recv_buffer[i] != ' ') && (recv_buffer[i] != '
') && (recv_buffer[i] != '
'))
i++;
recv_buffer[i] = 0; // Terminate with NUL
#ifdef SERIAL_DEBUG
puts(&recv_buffer[12]);
#endif
res = f_open(&fil, (void*)&recv_buffer[12], FA_READ);
if (res != FR_OK)
{
/* Load 404 page */
file = fs_open(''/html'');
write(conn, (const unsigned char*)(file->data), (size_t)file->len);
if(file) fs_close(file);
}
else
{
UINT BytesRead;
i = sprintf((void*)recv_buffer, // Generate a server side header
''HTTP/1.0 200 OK

''
''Server: lwIP/1.3.1 (http://savannah.nongnu.org/projects/lwip + sourcer32@gmail.com)

''
''Content-Length: %d

''
''Content-Type: text/plain

''
''

'', fil.fsize);
write(conn, (const unsigned char*)(recv_buffer), (size_t)i); // Send HTTP Header
#ifdef SERIAL_DEBUG
printf(recv_buffer);
#endif
while(1) // Transfer file packets until gone
{
res = f_read(&fil, recv_buffer, sizeof(recv_buffer), &BytesRead);
if ((res == FR_OK) && (BytesRead))
write(conn, (const unsigned char*)(recv_buffer), (size_t)BytesRead);
else
break;
}
res = f_close(&fil);
}
}
else if((strncmp((char *)recv_buffer, ''GET /STM32F2x7.html'', 19) == 0)||(strncmp((char *)recv_buffer, ''GET / '', 6) == 0))
{
/* Load STM32F2x7 page */
file = fs_open(''/STM32F2x7.html'');
write(conn, (const unsigned char*)(file->data), (size_t)file->len);
if(file) fs_close(file);
}
...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mllona
Associate II
Posted on December 23, 2013 at 20:27

Thanks for your help, clive1.

I could not make it work yet because I'm not using an RTOS but a standalone mode. In this mode, the ethernet system provides very poor functionality.

I will try to use the lwip socket in this mode. And if it still doesn't work I will modify my whole application to use it under an rtos.

Martin

Pm77
Associate II
Posted on October 12, 2014 at 20:19

Here is my example working from SD card..

Find complete project in attachment

Enjoy it..

Pankaj

________________

Attachments :

Http_Server_SDCard.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzhA&d=%2Fa%2F0X0000000bRw%2FWiVPWXSXsb57a7330NEdIgIHDLrdzFPxNALGSGrFv_w&asPdf=false