HTTP File Server using SD Card for STM32F407VET6.
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed
Fork of Arch_Max_SD_HTTP_Server by
HTTP File Server using SD Card
This is a fork of a program first published by Ivan Georgiev.
- See https://os.mbed.com/users/hudakz/code/STM32F407VET6_Hello/ for more info about the Ethernet interface.
- See https://os.mbed.com/users/hudakz/code/STM32F407VET6_SDCard/ for more details on the SD Card slot.
Diff: main.cpp
- Revision:
- 3:aaf055cd9d06
- Parent:
- 1:8150297e8849
- Child:
- 4:4ddfbdaafbac
--- a/main.cpp Thu Nov 19 06:04:52 2015 +0000 +++ b/main.cpp Mon Jun 04 21:46:29 2018 +0000 @@ -11,7 +11,7 @@ #define PORT 80 Serial pc (USBTX,USBRX); // tx, rx -SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCK, SD_CS, "wfs"); // the pinout on the mbed +SDFileSystem sd(PC_3, PC_2, PB_10, PC_0, "wfs"); // mosi, miso, sck, cs char sMethod[7]; char sURL[250]; @@ -240,26 +240,22 @@ void parseHTTPRequest(char* buffer) { - char spacePos; - char *tmpBuffer; - spacePos = strcspn(buffer, " ") + 1; //position of first space character - snprintf(sMethod, spacePos,"%s", buffer); + char space1Pos, space2Pos, newlinePos; + char* tmpBuffer; + space1Pos = strcspn(buffer, " "); //position of first space character + snprintf(sMethod, space1Pos + 1, "%s", buffer); - //get Protocol - tmpBuffer=&(buffer[spacePos]); //move pointer to buffer (delete Method) - spacePos = strcspn(tmpBuffer, "\r\n") + 1; - tmpBuffer[spacePos]='\0'; //set end of string ...cut - sprintf(sProtocol, "%s", strrchr(tmpBuffer,' ')); //get string after last (space ) - printf("\r\nsProtocol:%s", tmpBuffer); - buffer = &(sProtocol[1]); //cut first character (space) - sprintf(sProtocol, "%s", buffer); + tmpBuffer = buffer + space1Pos + 1; + space2Pos = strcspn(tmpBuffer, " "); //position of second space character + snprintf(sURL, space2Pos + 1, "%s", tmpBuffer); - //get URL - snprintf(sURL,strlen(tmpBuffer)-strlen(sProtocol),"%s\r\n", tmpBuffer); //URL is between Method and Protocol + tmpBuffer = buffer + space1Pos + 1 + space2Pos + 1; + newlinePos = strcspn(tmpBuffer, "\r\n"); //position of newline + carriage return + snprintf(sProtocol, newlinePos + 1, "%s", tmpBuffer); - printf("\nParse Method:%s",sMethod); - printf("\nParse URL:%s",sURL); - printf("\nParse PROTOCOL:%s",sProtocol); + printf("\nParse Method:%s", sMethod); + printf("\nParse URL:%s", sURL); + printf("\nParse Protocol:%s", sProtocol); printf("\n\r\n"); } @@ -304,6 +300,15 @@ ledTick.attach(&ledTickfunc,0.5); //ledTick.detach(); + + printf("\r\n"); + printf("Mounting file system...\r\n"); + + int err = sd.mount(); + printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n")); + if (err) + return err; + //setup ethernet interface eth.init(); //Use DHCP // eth.init(IP,MASK,GATEWAY); //IP,mask,Gateway