cancel
Showing results for 
Search instead for 
Did you mean: 

STM3210C-EVAL and STM32F107_ETH_LwIP_V1.0.0 webserver example problem (AN3102)

pedro23
Senior
Posted on July 25, 2012 at 15:24

Hi, i'm having a problem with this example, when i compile with any kind of optimization (low, medium or high) the code, web server hangs trying to read files, while if i do the same stuff using no optimizations (None), it works perfectly.

Telnet has exactly the same problem, probably all TCP examples... any hint?

Tried to find it on internet with no luck

Using IAR 5.41, AN3102 and STM3210C-EVAL. Using RMII but not important i think 🙂

#an3102-stm3210c-iar-optimization
9 REPLIES 9
frankmeyer9
Associate II
Posted on July 25, 2012 at 16:26

This is almost certainly a problem of the application, i.e. the webserver example source.

It is usually caused by declaring variables as volatile too sparsely. When optimizing, the compiler throws out everything not visibly referenced, as seen by the compiler.

This issue is not uncommon. Either you debug the examples to fix that omissions, or use it as-is.

pedro23
Senior
Posted on July 25, 2012 at 17:30

Thanks for replying. Well, it is just the example downloaded from ST web, so i supposed that it worked perfectlly :), since it is a training/example program :), i will try what you said

BTW, it happens with all TCP servers, not sure about UDP  🙂
pedro23
Senior
Posted on July 25, 2012 at 17:34

I didnt tell what happened exactly, just the first package of TCP was sent, the rest was not, so if you had to sent 8k, only the first 15xx were sent. Working in debug all works, probably some variable definition as you said, but not easy to see with tons of .c files :9

frankmeyer9
Associate II
Posted on July 25, 2012 at 19:20

I didnt tell what happened exactly, just the first package of TCP was sent, the rest was not, so if you had to sent 8k, only the first 15xx were sent. Working in debug all works, probably some variable definition as you said, but not easy to see with tons of .c files :9

Please don't understand my comment as suggestion to debug this project. I have not seen it, but by the topic, it is supposed to be rather big. It would be a tremendous task to find all bugs...

Such examples are mostly just what the name says - examples.

Development stops after some basic tests, and there is no guaranty whatsoever.

But if you need use this code for any serious project, I would start to look at variables that cross module boundaries, i.e. accessed from different source files. And by definition, everything touched inside an interrupt handler should be declared volatile.

pedro23
Senior
Posted on July 26, 2012 at 10:48

I have been checking the example and changing optimization level for all files, i have identified the file with the problem, it is the tcp_in.c file.

Other thing that i found is that you might change code in file httpd.c from


for
(i = 0; i < 40; i++)

{

if
(((
char
*)data + 4)[i] == 
' '
||

((
char
*)data + 4)[i] == 
'
'
||

((
char
*)data + 4)[i] == 
'
'
)

{

((
char
*)data + 4)[i] = 0;

}

}


i = 0;

j = 0;


do

{

//fname[i] = ((char *)data + 4)[j];

fname[i]=data[j+4];

j++;

i++;

} 
while
(fname[i - 1] != 0 && i < 40);

to code

1.
for
(i=0;i<40 && data[i+4]!=
' '
&& data[i+4]!=
'
'
&& data[i+4]!=
'
'
;i++)
2.
fname[i]=data[i+4];
3.
fname[i]=0;

It doesn't work fine with IAR optimizations (it gets strange values in fname variable). I'm close to fix it, some news soon!
pedro23
Senior
Posted on July 26, 2012 at 11:00

fm, as you said, it was a volatile variable, found it

For IAR you just need to change seqno and ackno in file tcp_in.c from 

static u32_t seqno,ackno;

to

volatile static u32_t seqno,ackno;

Thanks for help

frankmeyer9
Associate II
Posted on July 26, 2012 at 15:02

Good if you found the bug - or, at least, found one bug ...

It might be possible that this code survived from very old ages, when the 'volatile' keyword was virtually unknown. There is a lot of networking example code around, that obvioulsy

stems from 30 or 40 year old unix systems, and compiles well in K&R mode.

And if you look closer at most of this examples, you notice 3 things they often miss:

 - error checking

 - exception raising

 - optimization

That is not unusual for example code, just cut down expectations.

pedro23
Senior
Posted on July 26, 2012 at 17:00

Well, lwIP is a well known TCP/IP library used for embedded system, the problem was on it, and it was version 1.3.1 if i'm not wrong that is dated just 2.5 years ago :).

I will probably use it as base for an important project, anyways i dont need everything, just udp/icmp/ip/dhcp, but I didnt find anything better with all these features without paying money 🙂

frankmeyer9
Associate II
Posted on July 26, 2012 at 19:57

The hardware layer is of course new.

For higher level TCP/IP stack routines, it is common to to use freely available open source code as a starting point. One does not need to reinvent the wheel, when there are abundant examples available.

I bet a lot of the high level code does not origin from ST.

And, as mentioned, most (TCP/IP - based) networking code dates back to unix.

As a side note: when Microsoft overslept the rise of the internet in the mid-nineties, they copied an unix IP stack and socket API to Windows, including a whole part of the folder structure.

I had to work on this under NT 4.0 ...

I will probably use it as base for an important project, anyways i dont need everything, just udp/icmp/ip/dhcp, but I didnt find anything better with all these features without paying money 🙂

 

 

This is certainly ok, I would do that too.

Open Source is not necessarily worse than Closed-Source software you pay for. But I would test all the code as if it was new.