cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer
Observer
9,790 Views
Registered: ‎07-07-2009

UDP communcation

Hi, all, I am using spartan 3e and test the ethernet communication with echo example, but I can not ping the FPGA after the example running. I am using a Hub to connect the FPGA and Pc, does it cause the issue?

 

Any one has the expericence on UDP communication between FPGA and PC? I am new to FPGA-based.

 

Best Regards,

Roy

0 Kudos
10 Replies
Highlighted
Observer
Observer
9,772 Views
Registered: ‎07-07-2009

Re: UDP communcation

I changed a bit from Echo example, and used waveshark to check the communication step by step,  FPGA send the broadcast to the PC with Gratuitous ARP when code goes to netif_set_up(netif);  (so, means the IP interface is up?) .  But the waveshark can not catch anything for the following UDP communication, as well, ping can not work.

 

I used a HUB to connect the FPGA and PC, normal cables are used.

 

#include "xparameters.h"

#include "lwip/tcp.h"

#include "lwip/udp.h"

#include "lwip/memp.h"

#include "lwip/mem.h"

#include "netif/etharp.h"

#include "lwip/sys.h"

#include "lwip/netif.h"

#include "stdio.h"

 

#include "lwip/err.h"

int main(void)

{

err_t err;

xil_printf(
"Start");

struct netif *netif, server_netif;

struct ip_addr ipaddr, pc_ipaddr, netmask, gw;

/* the mac address of the board*/

 unsigned char mac_ethernet_address[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };

 

struct pbuf*p; unsigned char buffer[10] = "111111";

netif = &server_netif;

/* initliaze IP addresses to be used */

IP4_ADDR(&ipaddr, 192, 168, 1, 100);

IP4_ADDR(&pc_ipaddr, 192, 168, 1, 13);

IP4_ADDR(&netmask, 255, 255, 255, 0);

IP4_ADDR(&gw, 192, 168, 1, 1);

lwip_init();

udp_init();

 

/* Add network interface to the netif_list, and set it as default */

 if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, XPAR_ETHERNET_MAC_BASEADDR)) {

xil_printf("Error adding N/W interface\n\r");

return -1;

}

netif_set_default(netif);

/* specify that the network if is up */

netif_set_up(netif);

/* start the UDP server */

//------------------------

 struct udp_pcb *pcb;

unsigned port = (u16_t)8080;

unsigned pc_port = (u16_t)8080;

 

/* create new UDP PCB structure */

pcb = udp_new();

err = udp_bind(pcb, &ipaddr, port);

if(err !=ERR_OK)

{

xil_printf(
"\n\r Unable to bind"); return;

}

p = pbuf_alloc(PBUF_TRANSPORT,4096,PBUF_RAM);

p->payload = buffer;

 

err = udp_sendto(pcb, p, &pc_ipaddr, pc_port);

if(err !=ERR_OK)

{

xil_printf(
"\n\r Unable to send"); return;

}

 

while (1)

{

xemacif_input(netif);

// transfer_data();

}

return 0;

}

0 Kudos
Highlighted
Contributor
Contributor
9,758 Views
Registered: ‎05-17-2009

Re: UDP communcation

i think there is something wrong with the way u are trying to use the udp_send function. the better thing ot do is that in the files with the xapp1026 u should try and alter the udp transmission eprformance test instead of the echo server. that is much easier.

 

 

in the zip file go to the 10.1 folder, then in the s3an folder, next in the raw folder, then go to apps folder. there u will find a number of applications. what u need for ur udp transmission is the utxper.c file. apart from this file add the main.c platform.c platform.h file.

 

 

also u must enable lwip in the software platorm settings and in the compiler options indlude the -llwip4 library.

 

if u want to send or receive data using tcp or udp, u can find performance test measuring files in the apps folder i have mentioned above.

use them they are much easier to alter.

 

good luck

0 Kudos
Highlighted
Observer
Observer
9,701 Views
Registered: ‎07-07-2009

Re: UDP communcation

Thank you for your reply, which really helps.

 

The example you mentioned works, but just for the first time after I turn the power on in FPGA, I can catch the UDP pakeage with wireshark in the remote PC, then if stop the program and run it again,  just ARP cought.

 

I guess the problem is caused by the sendbuffer? or something else? any suggestions.

0 Kudos
Highlighted
Contributor
Contributor
9,683 Views
Registered: ‎05-17-2009

Re: UDP communcation

you probably need to use a software(you can find one from the internet)  that has an open port for UDP. open the UDP port in what ever software that you use witthe correct listening port and remote IP address.
0 Kudos
Highlighted
Observer
Observer
9,606 Views
Registered: ‎07-07-2009

Re: UDP communcation

Hi, Thanks the information from this forum, now, I can send the data from FPGA to MATLAB/SIMULINK precisely.

 

But, got some issues with receiving.

 

I tested with the example from xapp1026/10.1/raw/s3an/apps/src/urxperf.c (i am using 3E500 starter board).

 

Seems, it just can receive serveral packages (look like 16 bits), does it because the IO limit, I generated linker script with DDR_SDRAM_MPMC_BASEADDR.

 

Best Regards,

Roy from the UK

0 Kudos
Highlighted
Contributor
Contributor
9,600 Views
Registered: ‎05-17-2009

Re: UDP communcation

hi

i am sorry i didnt quite follow what you mean by 16 bits.

 

any how u can send any data that you give a pointer to in the udp send or udp write function

 

 

 

0 Kudos
Highlighted
Observer
Observer
9,597 Views
Registered: ‎07-07-2009

Re: UDP communcation

sorry, 16bytes. I tested with this example,  and put a print("*") in the callback function, which printed out a "*" when a package received, but just printed out serveral times, then no response anymore?

 

one more question, how could I check the content I received, p?

 

Thank you for your replay...

 

Best Regards,

Roy

 

0 Kudos
Highlighted
Observer
Observer
9,587 Views
Registered: ‎07-07-2009

Re: UDP communcation

hI, the communicatioin between FPGA and Simulink now works, sending and receiveing. I tested with the example from app1026....

 

But, could I fulfill the data exchange between FPGA and simulink in 1ms with RAW mode?  now I am testing it, seems the receive and sending can not work together, but they can work well if test seperately.

 

Seems I am colsing my objective now step by step.

 

Best Regards,

Roy   

0 Kudos
Highlighted
Contributor
Contributor
9,551 Views
Registered: ‎05-17-2009

Re: UDP communcation

hi

you need to understand how the raw mode works.

 it is controlled by interrupts.

 

when a pakcet is received, an interrupt is genrated and the program then executes the call back function specifed with udp_recv

on the other hand , when sending packets data through TCP , a interrupt is genrated when an acknowledgment to a previously sent data is received.

 

so my point is you can opearte them simultanously if they dont interfere with each other. one way to do that is to put the udp send function at the end inside the receive call back function

 

hope it helps

 

Message Edited by ahs23 on 09-16-2009 02:10 AM
0 Kudos
Highlighted
Observer
Observer
3,059 Views
Registered: ‎07-07-2009

Re: UDP communcation

1ms is a bit difficult, I change to 20ms, it works ok, but,,,after serveral packets, the send error happens:  *Error on udp_send: -1.  it looks like out ot memory?

 

not sure what the problem exactly comes from?

 

Best Regards,

Roy

0 Kudos