FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
5943 Discussions

DE2_UDP example for download here free (feedbacks are wellcomed)

Altera_Forum
Honored Contributor II
5,178 Views

Hi all. 

My goal is to get about 3Mbytes/sec data transfer rate from my DE2 board to PC. 

Here in this example I get about 1.2 Mbytes/sec.  

I'll accept comments about, how to speed up this, as well as suggests to improve the code, and some feedback from people that have interest in this theme. Could be in this thread or private. 

You can download the full project from: 

http://www.btxsistemas.com.ar/net2.zip 

 

I've used Quartus II 7.2 full suite. And the Wireshark software (http://www.wireshark.org/) like a net sniffer, but also, I've included in the main project folder, a UDP reciever to test the comunication between the DE2 board and the PC, if you wont to download the wireshark. 

Don't forget to specify your IP address and your MAC address in the NIOS hello_word "C" code to get it work properly. 

The main project is a modification of the DE2_NET demostration code that comes with the DE2 board. 

 

Have fun, and I'll be waiting for some comments.
0 Kudos
94 Replies
Altera_Forum
Honored Contributor II
298 Views

 

--- Quote Start ---  

Hi,  

I was success to make it transfer a character from DE2 board to PC, and I got correct a character on PC side. But when I transferred the character back from PC to DE2 board, I could not make it correctly. I always got the same data for different character data. Could anyone please help me with my code 

Here is my files 

 

/* * network.h * */ # ifndef NETWORK_H_# define NETWORK_H_ /* Assign IP: 192.168.1.44 IP Address for the DE2 */# define Src_IP1 0xC0# define Src_IP2 0xA8# define Src_IP3 0x01# define Src_IP4 0x2C /* Assign IP: 192.168.1.30 IP Address for the PC */# define Dest_IP1 0xC0# define Dest_IP2 0xA8# define Dest_IP3 0x01# define Dest_IP4 0x1E /* DE2 MAC Address */# define Src_MAC1 0x01# define Src_MAC2 0x60# define Src_MAC3 0x6E# define Src_MAC4 0x11# define Src_MAC5 0x02# define Src_MAC6 0x0F /* PC MAC Address */# define Dest_MAC1 0x00# define Dest_MAC2 0x16# define Dest_MAC3 0xD4# define Dest_MAC4 0xBB# define Dest_MAC5 0xCA# define Dest_MAC6 0x91 # define payload 1 /* Send and receive one character */ /* Total Packet Length * Frame Header, IP Header, UDP Header, Payload * */# define Packet_Len (payload + 0x2B) # define UDP_Len (payload + 8)# define UDP_Len_H ((UDP_Len & 0xFF00)>>8)# define UDP_Len_L (UDP_Len & 0x00FF) # define IP_Len (payload + 8 + 20)# define IP_Len_H ((IP_Len & 0xFF00)>>8)# define IP_Len_L (IP_Len & 0x00FF) # define IP_Csum1 (0x0000C511 + (Src_IP1<<8)+Src_IP2+(Src_IP3<<8)+Src_IP4+(Dest_IP1<<8)+Dest_IP2+(Dest_IP3<<8)+(Dest_IP4)+(IP_Len_H<<8) + IP_Len_L)# define IP_Csum2 ((IP_Csum1&0x0000FFFF)+(IP_Csum1>>16))# define IP_Csum3 (0x0000FFFF - IP_Csum2)# define IP_Csum4 ((IP_Csum3 & 0xFF00)>>8)# define IP_Csum5 ((IP_Csum3 & 0x00FF)) # endif /* NETWORK_H_ */  

 

/* * main.c * */# include "basic_io.h"# include "network.h"# include "LCD.h"# include "DM9000A.C"# include "DM9000A.H"# include <string.h># include <ctype.h> unsigned char PC_MAC_ADDR = { 0x00, 0x16, 0xD4, 0xBB, 0xCA, 0x91 }; unsigned char DE2_MAC_ADDR = { 0x01, 0x60, 0x6E, 0x11, 0x02, 0x0F }; unsigned int receive_status, receive_len, i, packet_num; unsigned char receive_buffer; # define UDP_PACKET_PAYLOAD_OFFSET 42 unsigned char ARP_Packet = { /* Ethernet MAC header 14 bytes, * first 6 bytes for Destination MAC address * second 6 bytes for SOURCE MAC address * last 2 bytes for Ethernet types (ARP = 0806) */ Dest_MAC1, Dest_MAC2, Dest_MAC3, Dest_MAC4, Dest_MAC5, Dest_MAC6, Src_MAC1, Src_MAC2, Src_MAC3, Src_MAC4, Src_MAC5, Src_MAC6, 0x08, 0x06, /* ARP Header, * */ 0x00, 0x01, // Hardware Ethernet 0x0001 0x08, 0x00, // Protocol IP 0x0800 0x06, // Hardware size 6 0x04, // Protocol size 4 0x00, 0x02, // Reply Src_MAC1, Src_MAC2, Src_MAC3, Src_MAC4, Src_MAC5, Src_MAC6, Src_IP1, Src_IP2, Src_IP3, Src_IP4, Dest_MAC1, Dest_MAC2, Dest_MAC3, Dest_MAC4, Dest_MAC5, Dest_MAC6, Dest_IP1, Dest_IP2, Dest_IP3, Dest_IP4 }; unsigned char UDP_Packet = { /* Ethernet MAC header 14 bytes, * first 6 bytes for Destination MAC address * second 6 bytes for SOURCE MAC address * last 2 bytes for Ethernet types (IP = 0800) */ Dest_MAC1, Dest_MAC2, Dest_MAC3, Dest_MAC4, Dest_MAC5, Dest_MAC6, Src_MAC1, Src_MAC2, Src_MAC3, Src_MAC4, Src_MAC5, Src_MAC6, 0x08, 0x00, /* IP Header, 20 bytes * 4 bits for version * 4 bits for header length * 8 bits for type of service * 16 bits for total length of packet * 16 bits for identification * 3 bits for flag, 13 bits for fragment offset * 8 bits for time to live * 8 bit for protocol * 16 bit for header checksum * 32 bits for source IP * 32 bits for destination IP */ 0x45, 0x00, IP_Len_H, IP_Len_L, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, // UDP Type IP_Csum4, IP_Csum5, Src_IP1, Src_IP2, Src_IP3, Src_IP4, Dest_IP1, Dest_IP2, Dest_IP3, Dest_IP4, 0x04, 0x00, 0x04, 0x00, // Port 1024 UDP_Len_H, UDP_Len_L, 0x00, 0x00, /* UDP data, * Data take one byte. */ 0x41 // Character A }; void ethernet_interrupt_handler() { int i = 0; unsigned char mac_addr; receive_status = ReceivePacket(receive_buffer, &receive_len); if (receive_status == DMFE_SUCCESS) { /* Display the whole packet receive */ printf("\n\nReceive Packet Length = %d", receive_len); for(i = 0; i < receive_len;i++) { if (i%8==0) printf("\n"); printf("0x%.2X,", receive_buffer); } printf("\n"); /* Get the source address from the packet */ for(i = 6 ; i < 12; i++) { mac_addr = receive_buffer; } /* Compare the mac address to the PC MAC address */ if (memcmp(mac_addr, PC_MAC_ADDR, 6) == 0) { if (receive_len >= 14) { // A real Ethernet packet if (receive_buffer == 8 && receive_buffer == 6){ // An ARP Packet TransmitPacket(ARP_Packet, sizeof(ARP_Packet)); /* Clear the DM9000A ISR: PRS, PTS, ROS, ROOS 4 bits, by RW/C1 */ iow(ISR, 0x3F); /* Re-enable DM9000A interrupts */ iow(IMR, INTR_set); //DM9000_init(SRC_MAC_ADDR); } else { if (receive_buffer == 8 && receive_buffer == 0 && receive_len >= 34) { // An IP packet if (receive_buffer == 0x11) { // A UDP packet if (receive_len >= UDP_PACKET_PAYLOAD_OFFSET) { char request = (receive_buffer + UDP_PACKET_PAYLOAD_OFFSET); printf("Receive message: %c\n",request); } } else { printf("Received non-UDP packet\n"); } } else { printf("Received non-IP packet\n"); } } } else { printf("Malformed Ethernet packet\n"); } } } else { printf("Error receiving packet\n"); } /* Clear the DM9000A ISR: PRS, PTS, ROS, ROOS 4 bits, by RW/C1 */ iow(ISR, 0x3F); /* Re-enable DM9000A interrupts */ iow(IMR, INTR_set); //DM9000_init(SRC_MAC_ADDR); } int main() { LCD_Init(); LCD_Show_Text("TEAM-SYNTHESIS"); LCD_Line2(); LCD_Show_Text("Ethernet Testing"); printf("Network Transfer: Team-Synthesis (c) 2011.\n"); DM9000_init(); // Initialize the DM9000A. alt_irq_register( DM9000A_IRQ, NULL, (void*)ethernet_interrupt_handler ); while (1) { TransmitPacket(UDP_Packet,sizeof(UDP_Packet)); usleep(500000); } return 0; }  

 

Here is my receiving data (always the same for different character data) 

 

Receive Packet Length = 64 

0x01,0x60,0x6E,0x11,0x02,0x0F,0x00,0x16, 

0xD4,0xBB,0xCA,0x91,0x08,0x00,0x45,0x00, 

0x00,0x2D,0x10,0xC7,0x00,0x00,0x80,0x11, 

0xA6,0x5E,0xC0,0xA8,0x01,0x1E,0xC0,0xA8, 

0x01,0x2C,0x04,0x00,0x04,0x00,0x00,0x19, 

0x88,0xAE,0x2F,0x31,0x39,0x32,0x2E,0x31, 

0x36,0x38,0x2E,0x31,0x2E,0x34,0x34,0x20, 

0x3A,0x20,0x54,0x00,0x2A,0x58,0x79,0x24, 

Receive message: / 

--- Quote End ---  

 

 

 

 

 

I have compiled above code and check with de2 board char A is transmitting to PC but there is a error massege display "Error receiving packet" i have tried lot of ways but couldnt find any way to get receiving data from PC. Can anyone help me to receive UDP data from PC thankyou.
0 Kudos
Altera_Forum
Honored Contributor II
298 Views

 

--- Quote Start ---  

I have compiled above code and check with de2 board char A is transmitting to PC but there is a error massege display "Error receiving packet" i have tried lot of ways but couldnt find any way to get receiving data from PC. Can anyone help me to receive UDP data from PC thankyou. 

--- Quote End ---  

 

 

Okay, I don't have a DE2 anymore but the first thing you're probably going to want to do is figure out what exactly that response you're getting is. I can tell you this much so far: 

 

 

 

 

0x01,0x60,0x6e,0x11,0x02,0x0f 

 

de2 mac address 

 

 

0x00,0x16,0xd4,0xbb,0xca,0x91 

 

pc mac address 

 

 

0x08,0x00 

 

protocol ip 0x0800 

 

 

0x45,0x00 

 

??? 

 

 

0x00,0x2d 

 

ip_len_h? 

 

 

0x10,0xc7 

ip_len_l? 

 

 

0x00,0x00 

??? 

 

 

0x80, 0x11 

udp type 

 

 

0xa6,0x5e 

???  

 

 

0xc0,0xa8,0x01,0x1e 

pc ip 

 

 

0xc0,0xa8,0x01,0x2c,  

de2 ip 

 

 

0x04,0x00,0x04,0x00,  

port 1024 

 

 

0x00,0x19,  

udp_len_h? 

 

 

0x88,0xae,  

udp_len_l? 

 

 

0x2f,  

??? 

 

 

0x31,0x39,0x32,0x2e,0x31,0x36,0x38,0x2e 0x31,0x2e,0x34,0x34  

de2 ip in ascii 

 

 

0x20,0x3a,0x20,0x54,0x00,0x2a,0x58,0x79,0x24 

??? 

 

 

 

 

does this make sense? should any of these be changed or would you know what some of those question marks should be?
0 Kudos
Altera_Forum
Honored Contributor II
298 Views

TO_BE_DONE

0 Kudos
Altera_Forum
Honored Contributor II
298 Views

TO_BE_DONE

0 Kudos
Altera_Forum
Honored Contributor II
298 Views

I compiled this code to DE2 its successfully sends data DE2 to PC but when we send data PC to Board it didn't receive data it receives one or two packets and then stops need a big help its urgently thankyou

0 Kudos
Altera_Forum
Honored Contributor II
298 Views

I also have this problem i need to big help if any one have UDP Receiving code mail me thankyou tharangasliit@gmail.com

0 Kudos
Altera_Forum
Honored Contributor II
298 Views

 

--- Quote Start ---  

Hi all. 

My goal is to get about 3Mbytes/sec data transfer rate from my DE2 board to PC. 

Here in this example I get about 1.2 Mbytes/sec.  

I'll accept comments about, how to speed up this, as well as suggests to improve the code, and some feedback from people that have interest in this theme. Could be in this thread or private. 

You can download the full project from: 

http://www.btxsistemas.com.ar/net2.zip 

 

I've used Quartus II 7.2 full suite. And the Wireshark software (http://www.wireshark.org/) like a net sniffer, but also, I've included in the main project folder, a UDP reciever to test the comunication between the DE2 board and the PC, if you wont to download the wireshark. 

Don't forget to specify your IP address and your MAC address in the NIOS hello_word "C" code to get it work properly. 

The main project is a modification of the DE2_NET demostration code that comes with the DE2 board. 

 

Have fun, and I'll be waiting for some comments. 

--- Quote End ---  

 

 

 

 

Dear Sir, 

 

For my finale year project i am streaming audio data via UDP using DE2-70 board. i have successfully finished transmitting part but for the receiving part i have failed i've spend more that one month to do it but still iam stuck with this i need big help sir if you have source code for receiving part email me thankyou  

 

tharangasliit@gmail.com
0 Kudos
Altera_Forum
Honored Contributor II
298 Views

Use Signaltap to check what is happening between the MAC and the DMA on the receive path. The big problem with UDP streams is that they are unreliable. If your software is too slow to receive the UDP packets then it will miss some. If it stops completely to receive any data it probably means that your software crashes, and you should use a debugger to see what it is doing.

0 Kudos
Altera_Forum
Honored Contributor II
298 Views

 

--- Quote Start ---  

hi, I modified your project for DE2-70 Board, but since nothing come in and out on the board, I could not make the connection between the board and my PC. 

Please help me (Urgent) 

 

Here I attached my project. 

 

http://cid-70829448936b989b.office.live.com/embedicon.aspx/Public/NET^_PART.zip 

 

http://cid-70829448936b989b.office.live.com/self.aspx/public/net%5e_part.zip 

--- Quote End ---  

 

 

 

Dear thangdc01_02, 

some time ago you were working on a connection between PC and DE2_70 board via UDP. I´m now working on a similar project and because I´m new to this, it would be big help if you could send me your code to that project (if it still exists) because it´s not online anymore... 

 

you would save me a lot of time and i would really appreciate it! :) 

thx! 

 

greetz 

bob
0 Kudos
Altera_Forum
Honored Contributor II
298 Views

Hi all, 

 

I have a part in my project to send and receive data using Ethernet  

I am working on DE2_115 

Could you help me in this, about which topics I should read and from where I should to start 

 

Tanks in advance
0 Kudos
Altera_Forum
Honored Contributor II
298 Views

Hi, I'm trying to have a simple example to the DE1-SoC board. I need to transfer data from the FPGA to the PC throught ethernet. In your zip I didn't found the qsys file, could you send me this file? I want to do the porting to the DE1-SoC board. Thank you. My email is gianlucavicidomini@gmail.com

0 Kudos
Reply