This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to read SD card file via http server

Hi everyone,

I am currently working on TIRTOS to set up httpServer and store server content on the SD card following Todd Mullanix's presentation (http://processors.wiki.ti.com/index.php/TI-RTOS_HTTP_Example).

I have my webpage which is converted into "default.h" file and is inculded in my project in the Project Explorer CCS. I can visit the webpage. In my case, I also have a ".txt" file stored in SD card which I would like to download by using "href".  I am aware that this can be done by storing the ".html" file and ".txt" file both into the SD card (same directory) as described in Todd's presentation. Is there any solution to achieve this that the "default.h" file and ".txt" file are in different directories ?

Thanks in advance!

Bin

  • Bin,

    Have you tried placing the files in different directories?  What happens when you do that?

    Can you try to debug this by putting a break point into efs_fopen()?  What is the file name that you see when it's called when you try to access the file from the browser?  (you could also add a print statement into efs_fopen() to check this).

    The efs_stdio.c file was provided only for the purpose of the demo.  I suspect that you may have to do some work to modify that file to handle the directory structure you are trying to make.

    Steve

  • Hi Steve,

    Thanks for your reply. Yes, I did try to place files in different directories. And I think the "efs_studio.c" is working fine because I just got the updated file from Todd and it was working fine in my project. I am sorry I did not explain this very clearly in last post. Now, I will make this a bit clearer with images.

    I tried Todd's presentation and placed two files in the SD card. One is "index.html" the other one is "RTOS.txt" as shown in figure 1. The html code in "index.html" is below.


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <title>TI</title>
        </head>
        <body>
            <p>
                 Click here to download file from SD card:<a href="/RTOS.txt">Download</a>
            </p>           
        </body>
    </html>

                                                                  Figure 1

    I typed the IP address and clicked the hyperlink in my webpage as shown in Figure 2. I can download the "RTOS.txt" file from SD card.

                                                                Figure 2

    Now, I deleted the "index.html" file from SD card and use "binsrc.ext" to convert the "index.html" to "default.h" file and included it into my project. I also deleted "efs_stdio.c" from the project as shown in Figure 3.

          

                                                              Figure 3

    However, when I loaded page and clicked the hyperlink it was shown as in Figure 4 and Figure 5.

                                                                Figure 4

                                                             Figure 5

    I also tried to include the "efs_stdio.c" file. But when I tried to load the page, the M3 core paused and I had got the messages in Console as shown in Figure 6.

                                                                      Figure 6.

    I am thinking that the "default.h" file and "RTOS.txt" file are now in different directories. But my html code in the "default.h" file is still "Click here to download file from SD card:<a href="/RTOS.txt">Download</a>", so I am wondering how can I point to the directory to SD card to download the "RTOS.txt" file in this case?

    Hope this explaination is better than last time and I am looking forward for your reply.

    Many Thanks,

    Bin

  • Bin,

    Bin Li1 said:
    Now, I deleted the "index.html" file from SD card and use "binsrc.ext" to convert the "index.html" to "default.h" file and included it into my project. I also deleted "efs_stdio.c" from the project as shown in Figure 3.

    I think what's happening here is that there is a mix up of file locations.  Since you have removed the efs_stdio.c file from your project, the call to efs_createfile() is now calling the default NDK version, which is a RAM disk.

    Then when you click the link that references "/RTOS.txt", it is looking in the RAM file system for that file, but since it's not there it gives you the 404 error you see.

    Bin Li1 said:
    I also tried to include the "efs_stdio.c" file. But when I tried to load the page, the M3 core paused and I had got the messages in Console as shown in Figure 6.

    I think we need to better understand this, first using ROV:

    1. Can you open ROV when this happens (tools ->RTOS Object Viewer)?
    2. And check the Task module?
    3. Do you see any Task stack overflows?
    4. Which Task corresponds to the one shown in the error message?  (i.e. dchild, handle == 0x20010938 in your screen shot

    If it's just a simple matter of a Task overflow, then you will need to increase the offending Task's stack size.

    If not, then you need to use those register dumps to trace back to the instruction in your program that caused the exception.

    Please follow the steps on this wiki page to do that and let me know what the results are.

    Then, if you are able to resolve that exception, can you please add a print to the efs_open() and efs_filecheck() functions (the ones that are in efs_stdio.c) and print out the filename and path that it's trying to access/open?  I want to see what the full path of RTOS.txt is at these two points of the program.

    Steve

  • Hi Steve,

    I followed your suggestions on monitoring the ROV when the pause occured, it is shown in Figure 1. I do not think there is any task overflow.

                                                                        Figure 1

    Then, I followed the wiki page about the register dumps. I changed those three register values but it was still not working as shown in Figure 2 and Figure 3. What I had done was only to change the value of the three registers, not sure if that is the correct way ? Figure 2 is the scree shot before changing and Figure 3 is the screenshot after changing.

                                                                Figure 2

                                                               Figure 3

    To you last suggestion, could you please advise a bit more on how can I do that? I can find those two functions in my "efs_stdio.c" in the project. But can you advise what is the syntax I need to add in (maybe "system_printf") and where ? And do I need to see the results from console? I also attached the "efs_stdio.c" file. If you can help me add a print in, that will be great for me to check tomorrow.

    6505.2642.efs_stdio.c

    Many Thanks,

    Bin

  • Hi Bin,

    Which version of BIOS are you using?

    Bin Li1 said:
    Then, I followed the wiki page about the register dumps. I changed those three register values but it was still not working as shown in Figure 2 and Figure 3. What I had done was only to change the value of the three registers, not sure if that is the correct way ?

    Based on your screen shots, it looks like you did everything correctly.  I was hoping that following those steps would cause the stack trace to show up in CCS.

    I think at this point it would be most helpful if you could zip up your entire built project and attach it to this thread (you can create an archive file of your project through right click -> export in CCS).

    Steve

  • Hi Steve,

    I think the BIOS version I am using is v6.35.

    I attached the zip file of my project and the .txt file in my sd card. You can unzip the file and copy the RTOS.txt into the sd card for trying.

    I am looking forward to hearing from you !

    Bin

    0675.httpServer.rar

    7215.RTOS.txt

  • Hi Bin,

    I was able to download and build your project, and I could reproduce the problem. But this is as far as I was able to get today, I will have to continue on Monday.

    Steve

  • Hi Steve,

    Thanks for your help. I am looking forward to your changes.

    Regards,

    Bin

  • Hi Bin,

    I am still working on the issue and will update you as soon as I can.  Thanks for your patience.

    Steve

  • Bin,

    I was able to resolve the problem.

    The first thing I noticed when reproducing the problem (and putting the register dump values printed out into the registers as described in the BIOS FAQ page) was that the PC was pointing right at the beginning of the INDEX[] array.  The index array is data, and it was trying to execute it as code.  This is because the support for RAM disk files was removed with the new efs_stdio.c, and this caused the program to try to execute that HTML data as a CGI function.

    So, to get this to work, you need both the original efs.c APIs (to create/access files in RAM) as well as the updated efs_stdio.c (to create/access files on the SD card).

    I did this by updating efs_stdio.c to contain the original functions from efs.c, too.  I only renamed the original functions with "RAM" appended to their names (e.g. efs_getfilesizeRAM()).  Then, in all of the functions that are called by the NDK HTTP server module, I check if the file name argument that's passed has the extension ".html" and if it does, then I assume that this file should be created/accessed in RAM.  All other files are processed on the SD card (such as your RTOS.txt).  (of course the other exception is .cgi files, and those are processed as normal).

    I've attached the example to this thread for you to use.  Please note that this is just something that I created to help you and was not thoroughly tested.  But it should get you past the problem you were having.  Again, the example will create/access all *.html files in RAM - so if you want to put them anywhere else, you will have to update the file to handle that yourself.

    The example has the original 'index.h' built into the project, and will create
    this file in RAM when opened in a browser by typing "<IP address>/index.html".  Note also that I had to change the creation call to use the "RAM" in empty.c:

        efs_createfileRAM("index.html", INDEX_SIZE, (UINT8 *)INDEX);

    Similarly, you can access a file (such as RTOS.txt) on the SD card by typing
    "<IP address>/RTOS.txt".

    Lastly, the CGI remains unchanged - "<IP address>/getTime.cgi"

    You can diff efs_stdio.c with the original one to see what's changed.

    Steve

    8203.httpServer_htmlRam_and_SDfiles.zip

  • Hi Steve,

    Thanks very much for your kind help. The new project is working absolutely fine in my project. I will play around with this new project and may seek for more help if any other problems occur. By the way, after building the project there is an optimiation advice "Current optimization/debug settings:--opt_level=4 --opt_for_speed=5 -g". This message turned up after I optimized the speed and level. I am wondering if this will affact my futher work and how can I solve this advice.

    Many Thanks Again,

    Bin

  • Hi Steve,

    I have been working on this new version for the whole day. It is working fine to get access to the SD card now, but I am not able to add any images to my webpage. The two attached projects are the ones which I am working on today. One of them, I can add my company's logo into the webpage by using previous function "efs_createfile", but cannot get access to the SD card. To the other one, I can sucessfully get access to the SD card buy using your modification function "efs_createfileRAM", but cannot add any logo into the webpage. Are there any solutions to acheive both of these two applications? Apart from that, I am also interested in adding jquery code to optimize my webpage, is that possible to achieve that as well? If yes, can you advise?

    Many Thanks,

    Bin

    8004.httpSrvOctUpd_2013_10_16.rar

    4237.httpSrvOctUpd_2013_10_16_RAM.rar