Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

uIP : Can't print a webpage

Posted by Benjamin on April 8, 2012
Hi everybody,

I'm new on this forum and I will start with a big thanks to the FreeRTOS team, you really do a great job with this system!

I'm trying to get the uIP stack working with my STM32F103 linked with an ENC28J60 and I'm encountering some issues.
I started with the example provided and replaced the receive and send packet functions by the ones that I have for the ENC28J60.

When I ping the IP address I get a pong but if it type the IP address in my browser, nothing append. The page is loading indefinitely. What could be wrong?

I've already used this configuration (STM32F103+ENC28J60) with an other project and it works fine but was not satisfied with the stack, that's why I would like to use the uIP stack.

there is my main function :

int main( void ){

struct uip_eth_addr mac = { {0x42,0x45,0x4E,0x45,0x4C,0x21} };

enc28j60Init(mac.addr);

enc28j60PhyWrite(PHLCON,0x7a4);
enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz

uip_init();
uip_arp_init();

xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );

vTaskStartScheduler();

return 0;
}


and the uIP task :

void vuIP_TASK( void *pvParameters )
{

httpd_init();

while(1)
{
/* Let the network device driver read an entire IP packet
into the uip_buf. If it returns > 0, there is a packet in the
uip_buf buffer. */
uip_len = enc28j60PacketReceive(UIP_BUFSIZE, uip_buf);

if(uip_len > 0)
{
/* A packet is present in the packet buffer. We call the
appropriate ARP functions depending on what kind of packet we
have received. If the packet is an IP packet, we should call
uip_input() as well. */
if(BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
uip_arp_out();
enc28j60PacketSend(uip_len,uip_buf);
}
}
else if(BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
enc28j60PacketSend(uip_len,uip_buf);
}
}
}

vTaskDelay( uipSHORT_DELAY );

}
}


thanks

RE: uIP : Can't print a webpage

Posted by Benjamin on April 8, 2012
just a note, my router sees the system with the good MAC and IP addresses

RE: uIP : Can't print a webpage

Posted by Dave on April 9, 2012
I don't know anything about the ENC28J60, but it sounds like you have a network connection because ping is working and that the http request is getting through because the page is loading, it just doesn't finish loading. I would suggest first taking a capture of the network traffic using wireshark to see how far the HTTP request gets, and from there you will have to follow the packets through the network stack using the debugger to find the place where it goes wrong.

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
Thanks for your help

that's what I've got with wireshark :

No.     Time        Source                Destination           Protocol Length Info
2 0.022900 Apple_1e:3a:4b Broadcast ARP 42 Who has 192.168.1.188? Tell 192.168.1.100

Frame 2: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
Ethernet II, Src: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Address Resolution Protocol (request)

No. Time Source Destination Protocol Length Info
3 0.025169 42:45:4e:45:4c:21 Apple_1e:3a:4b ARP 60 192.168.1.188 is at 42:45:4e:45:4c:21

Frame 3: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21), Dst: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b)
Address Resolution Protocol (reply)

No. Time Source Destination Protocol Length Info
4 0.025224 192.168.1.100 192.168.1.188 TCP 78 54241 > http [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=8 TSval=313730621 TSecr=0 SACK_PERM=1

Frame 4: 78 bytes on wire (624 bits), 78 bytes captured (624 bits)
Ethernet II, Src: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b), Dst: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21)
Internet Protocol Version 4, Src: 192.168.1.100 (192.168.1.100), Dst: 192.168.1.188 (192.168.1.188)
Transmission Control Protocol, Src Port: 54241 (54241), Dst Port: http (80), Seq: 0, Len: 0

No. Time Source Destination Protocol Length Info
5 0.027400 192.168.1.188 192.168.1.100 TCP 60 http > 54241 [SYN, ACK] Seq=0 Ack=1 Win=32768 Len=0 MSS=1994

Frame 5: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21), Dst: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b)
Internet Protocol Version 4, Src: 192.168.1.188 (192.168.1.188), Dst: 192.168.1.100 (192.168.1.100)
Transmission Control Protocol, Src Port: http (80), Dst Port: 54241 (54241), Seq: 0, Ack: 1, Len: 0

No. Time Source Destination Protocol Length Info
6 0.027462 192.168.1.100 192.168.1.188 TCP 54 54241 > http [ACK] Seq=1 Ack=1 Win=65535 Len=0

Frame 6: 54 bytes on wire (432 bits), 54 bytes captured (432 bits)
Ethernet II, Src: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b), Dst: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21)
Internet Protocol Version 4, Src: 192.168.1.100 (192.168.1.100), Dst: 192.168.1.188 (192.168.1.188)
Transmission Control Protocol, Src Port: 54241 (54241), Dst Port: http (80), Seq: 1, Ack: 1, Len: 0

No. Time Source Destination Protocol Length Info
7 0.027507 192.168.1.100 192.168.1.188 HTTP 371 GET / HTTP/1.1

Frame 7: 371 bytes on wire (2968 bits), 371 bytes captured (2968 bits)
Ethernet II, Src: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b), Dst: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21)
Internet Protocol Version 4, Src: 192.168.1.100 (192.168.1.100), Dst: 192.168.1.188 (192.168.1.188)
Transmission Control Protocol, Src Port: 54241 (54241), Dst Port: http (80), Seq: 1, Ack: 1, Len: 317
Hypertext Transfer Protocol

No. Time Source Destination Protocol Length Info
8 0.034701 192.168.1.188 192.168.1.100 HTTP 417 GET /\000HTTP/1.1 Continuation or non-HTTP traffic

Frame 8: 417 bytes on wire (3336 bits), 417 bytes captured (3336 bits)
Ethernet II, Src: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21), Dst: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b)
Internet Protocol Version 4, Src: 192.168.1.188 (192.168.1.188), Dst: 192.168.1.100 (192.168.1.100)
Transmission Control Protocol, Src Port: http (80), Dst Port: 54241 (54241), Seq: 1, Ack: 318, Len: 363
Hypertext Transfer Protocol
Hypertext Transfer Protocol

No. Time Source Destination Protocol Length Info
9 0.401366 192.168.1.100 192.168.1.188 HTTP 371 [TCP Retransmission] GET / HTTP/1.1

Frame 9: 371 bytes on wire (2968 bits), 371 bytes captured (2968 bits)
Ethernet II, Src: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b), Dst: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21)
Internet Protocol Version 4, Src: 192.168.1.100 (192.168.1.100), Dst: 192.168.1.188 (192.168.1.188)
Transmission Control Protocol, Src Port: 54241 (54241), Dst Port: http (80), Seq: 1, Ack: 1, Len: 317
Hypertext Transfer Protocol

No. Time Source Destination Protocol Length Info
10 0.405694 192.168.1.188 192.168.1.100 TCP 60 http > 54241 [ACK] Seq=1 Ack=318 Win=32768 Len=0

Frame 10: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 42:45:4e:45:4c:21 (42:45:4e:45:4c:21), Dst: Apple_1e:3a:4b (c8:2a:14:1e:3a:4b)
Internet Protocol Version 4, Src: 192.168.1.188 (192.168.1.188), Dst: 192.168.1.100 (192.168.1.100)
Transmission Control Protocol, Src Port: http (80), Dst Port: 54241 (54241), Seq: 1, Ack: 318, Len: 0


Do you have any idea of what could be wrong?

RE: uIP : Can't print a webpage

Posted by Dave on April 9, 2012
Unfortunately the formatting is all mess up. Could you post a screen capture image instead?

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
no problem!


RE: uIP : Can't print a webpage

Posted by Dave on April 9, 2012
I'm not sure how much I can tell from that. But it looks like the GET request is duplicated in packet 6, but only 0.33 seconds after the first. Do you send each packet twice? That is done sometimes in uIP to speed it up when the link partner is implementing delayed acknowledgments. Otherwise, try putting a break point on the reply in packet 5 and follow the processing of the packet through the stack to see what happens.

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
“Do you send each packet twice?”

No, I don't do anything, I think...

Do you think that it's normal that the packet 5 start with "GET /\000HTTP/1.1 Continuation..." ? It should be something like "HTTP/1.1 200 OK...". It's sending the packet it just receive instead of the HTTP response + header + page content.

Another thing is strange, I tried to force some content after the GET from the client with this :

char page[] = "

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
hummm, I think that there was a bug with the post. I try agin

“Do you send each packet twice?”

No, I don't do anything, I think...

Do you think that it's normal that the packet 5 start with "GET /\000HTTP/1.1 Continuation..." ? It should be something like "HTTP/1.1 200 OK...". It's sending the packet it just receive instead of the HTTP response + header + page content.

Another thing is strange, I tried to force some content after the GET from the client with this :

char page[] = "

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
well, it doesn' want me to post my H-T-T-P 200 OK so I will put some hyphens


char page[] = "

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
“Do you send each packet twice?”

No, I don't do anything, I think...

Do you think that it's normal that the packet 5 start with "GET /\000HTTP/1.1 Continuation..." ? It should be something like "HTTP/1.1 200 OK...". It's sending the packet it just receive instead of the HTTP response + header + page content.

Another thing is strange, I tried to force some content after the GET from the client with this :

char page[] = HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHello World\r\n\r\n;
memcpy(uip_buf+54,page,strlen(page));


but after that, the uip_buffer remains the same as previously.

Where the page should be loaded in the uip_buffer? Because I tried to use the debugger but I have some difficulties to know if it's doing the right things or not (it's the first time I used uIP and I don't know it very well)

can someone remove the previous posts?

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
(I removed the double quotes around the HTTP... just for the post, it's not a mistake in my code)

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
Sorry for the number of posts.

I finally figured out what is the problem but don't know how to solve it.

When I try to load a page, httpd_appcall is called and the content of the page is loaded then pointed by uip_sappdata (I checked with the debugger that the page is loaded correctly). Then, the the function exits and returns in uip_process and a few lines later, uip_sappdata is copied in uip_appdata but at any time uip_appdata is copied into uip_buf so that's why the page is not send.

I don't know why the buffer is not filled and I don't know too if I have to do that manually.

An idea?

RE: uIP : Can't print a webpage

Posted by Dave on April 9, 2012
uip_buf is the buffer that eventually gets transmitted. Depending on your Ethernet driver, uip_buf is often just a pointer into an Ethernet DMA buffer so no copying of data is actually performed. uip_appdata is normally a pointer to a location within uip_buf so writing to uip_appdata writes data directly into uip_buf so I would not expect to see data copied from uip_appdata into uip_buf explicitly. Are you sure uip_appdata is not already pointing to the correct location in uip_buf?

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
Thanks for this clarification.

When I monitor the address of uip_appdata, it points 54 bytes after the start of uip_buf for incoming data (e.g, uip_appdata contains something like GET / HTTP/1.1...) but points somewhere outside uip_buf for outgoing data (but it contains the web page to print).

I don't know if it's normal, what do you think?

Thanks again for your help

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
if fact, it doesn't point 'elsewhere' but points uip_sappdata

RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
so, waiting for a 'pretty' solution I added this before uip_arp_out() :

if(uip_appdata != (uint8_t*)uip_buf+54) {
strcpy(uip_buf+54,uip_appdata);
}


and all it's working! That's great!

Just some things that I want to fix but it's not a big deal :
- When I access to the main page by typing the IP address, the page is printed correctly but it's loading indefinitely (the blue ring in firefox is turning, turning, turning,...)
- When I access to the file list, I can open everything except bg.png image
- I really don't know why but I can't use fsdata.c as is. It gives me an error per struct declaration : array type has incomplete element type. To fix that I had to rename the file to fsdata.cpp and add this at the top of the file :
#include "fsdata.h"

typedef struct fsdata_file fsdata_file;

So I modified the script that generating the file from the html pages to include this changes. I'm using GCC (yagarto more precisely) under Eclipse to compile my project

So if you have any clues about that I'll be happy to hear them.

Thanks again for the help you brought to me, I was on this problem for days.

RE: uIP : Can't print a webpage

Posted by Richard on April 9, 2012
“so, waiting for a 'pretty' solution I added this before uip_arp_out() :


Very curious. I have used uIP many times, and never had to do that. Where did you get the uIP code from? If it was the FreeRTOS distribution, which directory was it in?

“ - When I access to the main page by typing the IP address, the page is printed correctly but it's loading indefinitely (the blue ring in firefox is turning, turning, turning,...)”


Pass.

“- When I access to the file list, I can open everything except bg.png image ”


The makefsdata script can misbehave for binaries (such as images) if you are using windows. If this is the case then I have a windows .exe file that does the same thing, but correctly.


“- I really don't know why but I can't use fsdata.c as is. It gives me an error per struct declaration : array type has incomplete element type. To fix that I had to rename the file to fsdata.cpp and add this at the top of the file :”


fsdata.c should not be compiled, but included as if it was a header file. In fact, it is included as if it were a header file in some of the standard uIP web server code. I have no idea why it was given a .c file extension.

Even the, you will often see warnings (not errors) about the types being incomplete because makefsdata does not populate the complete C structure. It is valid C code, but bad practice. I think you can manually add a zero to the end of each structure to remove the warnings (from memory).

Regards.


RE: uIP : Can't print a webpage

Posted by Benjamin on April 9, 2012
Thanks for these precisions.

Actually, I spent so much time to manage to compile the project that I don't know where the files are coming exactly. From the FreeRTOS distribution for sure. If you want to analyze my project, you can download it there.

“The makefsdata script can misbehave for binaries (such as images) if you are using windows. If this is the case then I have a windows .exe file that does the same thing, but correctly./quote]
I'm using a Mac
When I analyze the traffic with wireshark I got this 'Continuation or non-HTTP traffic (PNG)[Malformed Packet]'.

I tried to add a little jpeg file so I put it in the fs directory, modifiy the files cgi script, launched makefsdata and reprogram my ┬ÁC but the new file doesn't appear in the list. Is there something else to do? ”

RE: uIP : Can't print a webpage

Posted by Benjamin on April 10, 2012
Hi,

A restarted a new project from scratch using the files in the FreeTCPIP directory and pick the missing files in the STM32F107 demo project. After some tweaks all is working perfectly, as expected.

I just have a last question, is it possible to send data that are larger than the buffer size by using chunks?


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS