Sorry, you need to enable JavaScript to visit this website.

Ethernet driver (Bare-Metal Application)

Unsolved
27 posts / 0 new
sysseon's picture
sysseon
Junior(0)
Ethernet driver (Bare-Metal Application)

Hi,

I'm starting to work with the Zedboard and I'm very lost. I want to establish an Ethernet connection between the board and a PC, running in the Zedboard a bare-metal application.

I've tried to make work the example of the Xilinx driver emacps (which don't seems very simple to me...), but I don't see any result. I'm running the example on the Zedboard and Wireshark in the PC. As long as I know, I should receive some frames from the board, but I don't see anything (after power up the board I see a lot of frames, but they aren't sent from mi application).

Maybe I'm wrong about what the example shoud do. I just want to learn the simplest way to send and receive frames and see it works...

Any help?

Thank you (and sorry for my English...).

fleogefyr's picture
fleogefyr
Junior(0)
Where can I find the example code?

Hi Sysseon,
I'm new to Zed, and can't find "the example of xilinx driver emacps". Actually I have worked on this driver without any example for a few days, so if you could help me with getting the example I will be appreciated very much.
Thank you in advance.

Gayathri's picture
Gayathri
Junior(0)
Example code

Once the SDK is open, create an application project with peripheral test.

Open the .mss file from the board support package folder.
In that there would be a list of peripheral drivers. An d from there you can get the documentation and the example for the emacps.

I hope this is what you wanted..

yaro's picture
yaro
Junior(1)
Example missunderstood

Hey sysseon,
you missunderstood the example. The example does not send anything to the PC, it makes a selftest useing the loopback function of the PHY.
I got Ethernet to work with PC, so if someone needs an example, just send me a personal message (like that I get an email notification)

jt_plusn's picture
jt_plusn
Junior(0)
Ethernet Example to Host PC

Yaro,

I would very much like to see that example. I have a custom design running on the Pl side of Zedboard. I would like to send LTE baseband data from the Host via Ethernet. This example will help with that past of the code.

Thanks

JT

yaro123's picture
yaro123
Junior(1)
Hello JT,

Hello JT,

you can download the design here:
https://dl.dropboxusercontent.com/u/"replace with no bot number"/ethernet.7z

No bot number is 15987625

I use Zedboard revision C, but it should work with d, too.

The program sends a frame (from PS) over gigabit Ethernet and then waits for one. As soon as it receives a frame, it is printed on the standard output.
You can test it by receiving the frame with wiresharc. I have written a test program to send something to the Zedboard, so if you need that, I can give that to you, too.

The main difference to the example project is that the Phy is no longer in loopback mode.
Makeing the region of the BD-list uncacheable is verry important. If you do not know how that is done, read this:
http://www.silica.com/fileadmin/02_Products/Productdetails/Xilinx/Zynq_M...

The program is not well documented, so if you do not understand something, feel free to ask.

Harsesis's picture
Harsesis
Junior(0)
Hello yaro123,

Hello yaro123,

thank you for sharing your project with us. It would be perfect if you could also share the test program for sending data to the Zedboard too.

yaro123's picture
yaro123
Junior(1)
Hello Harsesis,

Hello Harsesis,

I do not have a small workong programm that sends just one message at the moment.
But my test program was basically taken from here:
http://www.winpcap.org/docs/docs_412/html/group__wpcap__tut8.html

If you want to use raw Ethernet with Windows, just install winpcap and read the tutorial (it's not difficult).
For debugging reasons I also recommend you to use wireshark https://www.wireshark.org/
It's a nice and verry easy to use tool for network debugging (by the way, it uses winpcap, too)

Harsesis's picture
Harsesis
Junior(0)
Hi yaro123,

Hi yaro123,

thank you for the hints, I already used wireshark for debugging, but I had problems generating the correct packages. I will try again with the sources you gave me. Thank you!

yaro123's picture
yaro123
Junior(1)
For setting up the header you

For setting up the header you can use this function:

[code]
#define MAC_ADDR_SIZE 6

void setFrameHeader(uint8_t *frame, uint8_t *sourceAddr, uint8_t *destAddr, uint16_t etherType)
{
int i;

/* Destination address */
for (i = 0; i < MAC_ADDR_SIZE; i++) {
*frame++ = *destAddr++;
}

/* Source address */
for (i = 0; i < MAC_ADDR_SIZE; i++) {
*frame++ = *sourceAddr++;
}

*frame++ = (etherType & 0xff00) >> 8;
*frame++ = etherType & 0x00ff;
}

[\code]

joker007's picture
joker007
Junior(0)
Can't see the "sent" frame on Wireshark

hello yaro123,
I'm using your code albeit with 100 mbps configuration.
I'm able to receive the frame and see it on UART, but I am not able to see the sent frame on Wireshark.
Where do you think the issue might be?
I'm using Avnet Smart Vision Development Kit.

shivendra's picture
shivendra
Junior(0)
Require example

hey can u please give me that example my email id is there below..
it would be of great help to me

shivendraj8@gmail.com

Oggo's picture
Oggo
Junior(0)
Ethernet project

Dear Yaroslav,

I would appreciate it if you send me your Zedboard ethernet project as I cant access dropbox where I am

cheerful_dirge@hotmail.com

Thanks Maged

I want the ethernet example

Hey yaro,

You said you got ethernet to work with your pc.
Will you please be kind to share it with me.

Regards,
Manthan

raseshjd's picture
raseshjd
Junior(0)
Ethernet Example

I want to use ethernet coomunication with PC, Please provide Example that will be useful.

Thanks in advance

Rasesh Dave
ITER-India
raseshjd@gmail.com

Muhammad Aslam's picture
Muhammad Aslam
Junior(0)
Need code related to ethernet

can you send that example to me at aslam.bsee1420@gmail.com. Thanks

devilbehra's picture
devilbehra
Junior(0)
please help

Hi,
could you please send me the example. i would be highly grateful. my email id is devilbehra@gmail.com
thanks in advance

hockeyman1972's picture
hockeyman1972
Junior(11)
lwIP echo server example

Guys,
  If you are looking for a simple example application that uses a TCP/IP protocol stack, you can just generate the echo server example Application in the SDK.  That should give you some working code that you can step through with the symbolic debugger to see exactly how the code is structured and how you can set up the low level Ethernet interface.
 
Ron

josevi's picture
josevi
Junior(0)
I'm going to jump in here and

I'm going to jump in here and support yaro123 when he says that making the RxBDs and the Rx Buffers uncacheable is super important. I can't figure out how to download yaro123's program, though he posted a few snippets of it for me earlier. Here is how I was able to get the Rx Buffers out of cached memory while still not breaking the Xilinx IEEE1588PTP example (which sends and receives Ethernet packets):

#define RX_BUF_ADDRESS 0x1FF00000
#define RxBufMem (unsigned char **) RX_BUF_ADDRESS
typedef struct packet {
u8 data[XEMACPS_RX_BUF_SIZE];
} Packet;
Packet *packets;

int main(void)
{
Xil_SetTlbAttributes(RX_BUF_ADDRESS, 0xc02);
packets = (Packet*)RX_BUF_ADDRESS;

josevi's picture
josevi
Junior(0)
Heh... I get it, "replace

Heh... I get it, "replace with no bot number"...
Now I just feel silly for not understanding it the first time I looked at it.

msinger's picture
msinger
Junior(0)
repost

Could you possibly repost the example?

Thanks

yaro123's picture
yaro123
Junior(1)
The example is stil up

The example is stil up

you can download the design here:
https://dl.dropboxusercontent.com/u/ "replace with no bot number" /ethernet.7z

No bot number is 15987625

You just have to replace "replace with no bot number" with 15987625

Dropbox does not allow more than 20GB download a day, so if some bots just click on that link, they would get over the limit and I nobody elese would be able to download anything from my dropbox. Thats why there is this mysterious "no bot number" and not just a simple link.

By the way, the example is for raw ethernet. Most people do not need this! If you just want to communicate over Ethernet, use the lwIP stack. There is an example project in the SDK called "lwIP Echo Server". It is much easier!

auahmed's picture
auahmed
Junior(0)
still interested getting yaro123's example

dropobox says "File not found. Sorry, that file doesn’t live here anymore. It might have been moved or made private." Can you please repost or email me at austin.ashraf@gmail.com? Thanks a lot.

jschaefer's picture
jschaefer
Junior(0)
XEmacPs_BdRingCheck 'fails'

Hi,
thank you very much for the example!

At the moment, I still cannot log any ethernet frame from the board at the connected PC (running Wireshark).

I've checked the TX ringbuffer just before transmitting with 'XEmacPs_BdRingCheck' and it reports an internal data structure error.
I cannot identify any problem though :-/

Any ideas what I should be looking for?

Thank you very much.

josevi's picture
josevi
Junior(0)
Hello!

Hello!
Try setting the destination MAC address to the broadcast address (the all F's address).

If your Tx isn't working, here is what mine looks like:
int XEmacPs_PtpTxPacket(XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf, int PacketLen){
int Status;
XEmacPs_Bd *BdPtr;
XEmacPs_BdRing *TxRingPtr;
Xil_ExceptionDisable();
while((XEmacPs_ReadReg(InstancePtr->EmacPsInstance->Config.BaseAddress,
XEMACPS_TXSR_OFFSET)) & 0x08);

TxRingPtr = &(XEmacPs_GetTxRing(InstancePtr->EmacPsInstance));
Status = XEmacPs_BdRingAlloc(TxRingPtr, 1, &BdPtr);
if (Status != XST_SUCCESS) {
Xil_ExceptionEnable();
return XST_FAILURE;}
//Fill the BD entries for the Tx1!!1`
XEmacPs_BdSetAddressTx (BdPtr, PacketBuf);
XEmacPs_BdSetLength(BdPtr, PacketLen);
XEmacPs_BdClearTxUsed(BdPtr);
XEmacPs_BdSetLast(BdPtr);
dmb();
dsb();
Status = XEmacPs_BdRingToHw(TxRingPtr, 1, BdPtr);
if (Status != XST_SUCCESS) {
Xil_ExceptionEnable();
return XST_FAILURE;}
dmb();
dsb();
//Start the Tx
XEmacPs_Transmit(InstancePtr->EmacPsInstance);
Xil_ExceptionEnable();
return XST_SUCCESS;

Although it sounds like your problem is not with the actual transmitting, but with the TxBD ring. Here is how I initialized the TxBD ring (this is abridged):
void XEmacPs_InitializeEmacPsDma (XEmacPs_Ieee1588 *InstancePntr){
int Status;
XEmacPs_BdRing *TxRingPtr;
XEmacPs_Bd BdTemplate;
TxRingPtr = &XEmacPs_GetTxRing(InstancePntr->EmacPsInstance);
XEmacPs_BdClear(&BdTemplate);

//Set the Used Bit.
XEmacPs_BdSetStatus(&BdTemplate, XEMACPS_TXBUF_USED_MASK);

//Create 32 BDs for Tx path.
Status = XEmacPs_BdRingCreate (TxRingPtr,(u32)TX_BD_START_ADDRESS,(u32)TX_BD_START_ADDRESS, XEMACPS_IEEE1588_BD_ALIGNMENT, XEMACPS_IEEE1588_NO_OF_TX_DESCS);
if (Status != XST_SUCCESS) {return;}

//Clone the 32 BDs with BdTemplate. This will clear all the BDs and set the Used bit in all of them.
Status = XEmacPs_BdRingClone (TxRingPtr, &BdTemplate, XEMACPS_SEND);
if (Status != XST_SUCCESS) {return;}

Finally, the only other problem that I can think of that you might be having, is that you are caching the ?xBD rings. But that shouldn't even actually affect Tx'ing. Either way, make sure you uncache your Buffer Descriptors. There are numerous ways to do this, here is how I did it:
#define RX_BUF_ADDRESS 0x1FF00000
#define RxBufMem (unsigned char **) RX_BUF_ADDRESS
typedef struct packet { u8 data[XEMACPS_RX_BUF_SIZE];} Packet;
Packet *packets;
/* main starts */
Xil_SetTlbAttributes(RX_BUF_ADDRESS, 0xc02);
packets = (Packet*)RX_BUF_ADDRESS;

sulemanzp's picture
sulemanzp
Junior(0)
No more packets after two.

I tried your ethernet_selbst code. when i place ethernet_test function in a while loop, it only send two time and then no more packets. it stuck in a while (!FramesTx) loop.

babuji's picture
babuji
Junior(0)
Communication between the ZedBoard and Pc via Ethernet

Hii every one,here i like to transfer the data from the ZedBoard to my Pc via Ethernet.Here my application is i want to transfer packets from My Board to PC using Ethernet port not by serial port.So please help me regarding this issue.