Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

DAVE™ Forum Discussions

Not applicable
I wish to ask wich type of API is used in WEBSERVER001_Example1 or WEBSERVER001_Example2 from lwIP Stack.
Conform lwIP documentation there are some types of API wich can be used: Raw API or Netconn API
I wish to send some data over a network/Internet using TCP sockets, but I don't know wich type of API should I use.

Thank You.
0 Likes
18 Replies
Not applicable
I've started to make a project using lwIP Stack, but when I want to add a function in Main.c which is used by the stack, the editor doesn't recognize that function and I can't use it.

I wrote my_tcp_pcb=new_tcp(); in main file after the initialization of the stack, but when i want to "Open Declaration" I get an error: "Could not find symbol 'tcp_new' in index". If I search manually after tcp_new() I can see that the function is located in MyProject/Dave/Generated/src/ETH004/01_lwIP_Stack/src/include/lwip/tcp.h

Another observation is for initializing the stack, in manual is used: LwIP_Init() but in DAVE is used this function: lwIPStack_init() which can be seen in the WEBSERVER001_Example1 (I used this example as reference).

What could be wrong in my project? Do I have to include another directive(s) in Main.c?

Thank You.
0 Likes
oreste
Employee
Employee
dorinjj wrote:
I've started to make a project using lwIP Stack, but when I want to add a function in Main.c which is used by the stack, the editor doesn't recognize that function and I can't use it.

I wrote my_tcp_pcb=new_tcp(); in main file after the initialization of the stack, but when i want to "Open Declaration" I get an error: "Could not find symbol 'tcp_new' in index". If I search manually after tcp_new() I can see that the function is located in MyProject/Dave/Generated/src/ETH004/01_lwIP_Stack/src/include/lwip/tcp.h

Another observation is for initializing the stack, in manual is used: LwIP_Init() but in DAVE is used this function: lwIPStack_init() which can be seen in the WEBSERVER001_Example1 (I used this example as reference).

What could be wrong in my project? Do I have to include another directive(s) in Main.c?

Thank You.


Hi dorinjj ,
The present lwip app (ETH004) is not using a RTOS but just an internal scheduler so as written in lwip documentation you shall use only Raw_API. http://lwip.wikia.com/wiki/Raw/native_API

tcp_new is correct (I guess new_tcp is a typo).
I can find the definition of tcp_new using the contextual menu without problem. If you have still problem I suggest to rebuild the index (On project right click, index-> rebuld), sometime Eclipse forgets it after the first code generation.
I have no problem to compile the project and use tcp_new(); in the main.c including the same .h files as in the webserver demo. (I guess you problem was related to wrong function name new_tcp)

lwIPStack_init is used to initialize not only the lwip stack but also the webserver. I can agree it is unhappy function name :o. So to initialize just the lwip stack LwIP_Init() is ok.

Best Regards
Oreste
0 Likes
Not applicable
Now is working, the mistake was mine because I used the function with a wrong name 🙂 and the
I suggest to rebuild the index (On project right click, index-> rebuld)
was helpfully.
0 Likes
Not applicable
What are the diferences between WEBSERVER001_Example1 and WEBSERVER001_Example2?
0 Likes
oreste
Employee
Employee
dorinjj wrote:
What are the diferences between WEBSERVER001_Example1 and WEBSERVER001_Example2?

The first one just shows how to set up webserver that fetchs html files from a SD card. The page is static.
The second example is litte more complex. In the web page there is a button and when the user press it, a callback function is executed (defined in main.c). This function is calling api of I/O app to toggle a led. (In other word it is a server side scripting based on C)
0 Likes
Not applicable
When I use lwip_init() I think that I have to configure manualy and another things like IP, MAC within the Stack or to "add a network interface", "register the default network interface". It is that true?
I observed that if I use only lwIPStack() into an "empty" project then it is possible to ping the XMC Board from my PC, but if I use lwip_init() and tcp_tmr() which is called by a software timer (SYSTM001) on every TCP_TMR_INTERVAL the ping wil doesn't work.
What are the necessary steps for making the application to respond on ping?
Thank You.
0 Likes
Not applicable
When I want to create a PCB using tcp_new() function, why do I have to use something like this: struct tcp_pcb my_tcp_pcb = *tcp_new();
The declaration of this function is: struct tcp_pcb *tcp_new(void) and I think that I should be allowed to create the PCB in this way: tcp_pcb my_tcp_pcb = *tcp_new(); (without struct).

I know that I have to use Raw API, another question is if can I use the Socket API (Sockets Interfaces)?
0 Likes
oreste
Employee
Employee
When I use lwip_init() I think that I have to configure manualy and another things like IP, MAC within the Stack or to "add a network interface", "register the default network interface". It is that true?
I observed that if I use only lwIPStack() into an "empty" project then it is possible to ping the XMC Board from my PC, but if I use lwip_init() and tcp_tmr() which is called by a software timer (SYSTM001) on every TCP_TMR_INTERVAL the ping wil doesn't work.
What are the necessary steps for making the application to respond on ping?
Thank You.



You are right.
If you look in the lwip
I used ETH004 some time ago and in those example all the configuration you see in lwIPStack() where in the main function and lwip_init was called.
Later it was decide to push al these in the lwIPStack to make it easier to be used.
So I have to correct myself lwIPStack is better in your case becasue it is easier.
0 Likes
oreste
Employee
Employee
dorinjj wrote:
When I want to create a PCB using tcp_new() function, why do I have to use something like this: struct tcp_pcb my_tcp_pcb = *tcp_new();
The declaration of this function is: struct tcp_pcb *tcp_new(void) and I think that I should be allowed to create the PCB in this way: tcp_pcb my_tcp_pcb = *tcp_new(); (without struct).

I know that I have to use Raw API, another question is if can I use the Socket API (Sockets Interfaces)?


1) struct it is required due to C language specification. tcp_pcb it is a struct and not a type defined using typedef.http://en.wikipedia.org/wiki/Typedef#Simplifying_a_declaration For this you can blame the lwip developer ;).

2) As stated here http://lwip.wikia.com/wiki/Porting_For_Bare_Metal netcoon and socket interface are not available without operating system; so you can't :(.
Our developer are working on lwip + operating system but I can't commit any date for this.
0 Likes
Not applicable
This means that I can't establish a "socket connection" between the XMC Board and another device using Raw API?

At begining I wish to send with XMC Board some simple data over network and checking on my PC with a Network Protocol Analyzer software if received data will be the same. I will try this using the rules from "lwIP Session Establishment (Local lwIP client / remote server)" table.

Thank You.
0 Likes
oreste
Employee
Employee
dorinjj wrote:
This means that I can't establish a "socket connection" between the XMC Board and another device using Raw API?

At begining I wish to send with XMC Board some simple data over network and checking on my PC with a Network Protocol Analyzer software if received data will be the same. I will try this using the rules from "lwIP Session Establishment (Local lwIP client / remote server)" table.

Thank You.


If your problem it is just send simple data I suggest UDP protocol (simpler to be used).
I have already used UDP in one of past example based on this http://www.ultimaserial.com/avr_lwip_udp.html (use only raw api).

For tcp I have never tried it but you can look at this http://www.ultimaserial.com/avr_lwip_tcp.html example.
0 Likes
Not applicable
Thank You for examples, these are usefull and based on the example with Raw API I have succed in sending UDP packets, but I think that something is missing there. 🙂
I can't figure out how to read UDP packets and I tried a lot of hours for making the application to read UDP packets.
Could You explain how can I read UDP packets?
I know that I have to use udp_recv function, but I'm not sure how to use it and when I tried the code similar like in the example, the microcontroller has blocked.

void udp_recv(struct udp_pcb * pcb,
void (* recv)(void * arg, struct udp_pcb * upcb,
struct pbuf * p,
struct ip_addr * addr,
u16_t port),
void * recv_arg)
0 Likes
Not applicable
dorinjj wrote:
Thank You for examples, these are usefull and based on the example with Raw API I have succed in sending UDP packets, but I think that something is missing there. 🙂
I can't figure out how to read UDP packets and I tried a lot of hours for making the application to read UDP packets.
Could You explain how can I read UDP packets?
I know that I have to use udp_recv function, but I'm not sure how to use it and when I tried the code similar like in the example, the microcontroller has blocked.

void udp_recv(struct udp_pcb * pcb,
void (* recv)(void * arg, struct udp_pcb * upcb,
struct pbuf * p,
struct ip_addr * addr,
u16_t port),
void * recv_arg)


Do You think that udp_recv should be called by the Interrupt Service Routine of the Ethernet module?
0 Likes
Not applicable
Finally I have succed in making an udp echo broadcaster application based on that example and with very few modifications. 😄
0 Likes
oreste
Employee
Employee
dorinjj wrote:
Finally I have succed in making an udp echo broadcaster application based on that example and with very few modifications. 😄


Hi,
I am just back from vacation.
I prepared a udp demo project before leaving ofr my vacation but it was not put on the update site due to a technical problem.:(

This is implementing a simple udp echo server. (It send back received udp packet on a different port).
Probably you don't need it but just in case :confused:.

Project name is ETH004_Example and it should be available since tomorrow morning.
You can download it by pressing Install Dave apps/Example Library in the help menu.

Regards
Oreste
0 Likes
Not applicable
Do you know how could I to extract data from my pbuf when it will arrive? I tried something in my receive function, but is not working:

/*
udp_data[30]; //used to store incoming data
//my receive function
//...
memcpy(udp_data, p->payload, p->len); //version 1
memcpy(udp_data, p->payload, sizeof(p->payload)); //version 2
//...
*/

Design and Implementation of the lwIP TCP/IP Stack; page 9 (pdf)
-len: "contains the length of the data contents of the pbuf"
-payload: "points to the start of the data in the pbuf"
0 Likes
oreste
Employee
Employee
dorinjj wrote:
Do you know how could I to extract data from my pbuf when it will arrive? I tried something in my receive function, but is not working:

/*
udp_data[30]; //used to store incoming data
//my receive function
//...
memcpy(udp_data, p->payload, p->len); //version 1
memcpy(udp_data, p->payload, sizeof(p->payload)); //version 2
//...
*/

Design and Implementation of the lwIP TCP/IP Stack; page 9 (pdf)
-len: "contains the length of the data contents of the pbuf"
-payload: "points to the start of the data in the pbuf"



Hi
the correct function should be:
/*** Copy (part of) the contents of a packet buffer* to an application supplied buffer.** @param buf the pbuf from which to copy data* @param dataptr the application supplied buffer* @param len length of data to copy (dataptr must be big enough). No more * than buf->tot_len will be copied, irrespective of len
* @param offset offset into the packet buffer from where to begin copying len bytes* @return the number of bytes copied, or 0 on failure*/
u16_t
pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset);

I don't tried it but from the code, it should be the correct one. (It support chined pbuf)

Regards
Oreste
0 Likes
Not applicable
n=pbuf_copy_partial(p, udp_data, p->len, 0);

Yes, it seems to work. Thank You. 🙂
0 Likes