Ethernet frame transmission

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ethernet frame transmission

2,323 Views
trilokjt
Contributor III

Hi, Everyone

 

I'm trying to transmit frame on Ethernet, I made internal loop back, but i'm unable to transmit the frame. I  tested both interrupt and polling. None of them worked. I'm attaching file please have a look at it and tell me whats the problem is?

Processor : MK60N512

Here is the BIT test code

uint8_tPerformBIT_EthernetTest(void)

{

LDD_ETH_TBufferDesc BufferDescListPtr[2];
uint8*  BufferListPtr[2];
uint8 tx_buf[120],rx_buf[120];
uint8_t dummy[100],  Status = 0;
int i;
uint8_t temp[] = {"\n\r\v 3. Testing Ethernet.."};
uint8_t ErrorMsg[] = {"\n\n\r\t Ethernet Test Failed"};
uint32 *reg_ptr1,reg_value1;
BufferDescListPtr[0].DataPtr = tx_buf;
BufferDescListPtr[0].Size = 100;
BufferListPtr[0] = rx_buf;

 

  TxStr(temp);

 

 

 

tx_buf[0]=0xff;  // broad cast frame address = ff:ff:ff:ff:ff:ff
tx_buf[1]=0xff;
tx_buf[2]=0xff;
tx_buf[3]=0xff;
tx_buf[4]=0xff;
tx_buf[5]=0xff;

 

 

tx_buf[6]=0x00;
tx_buf[7]=0x01;
tx_buf[8]=0x02;
tx_buf[9]=0x03;
tx_buf[10]=0x04;
tx_buf[11]=0x05;
for (i=12;i<100;i++) tx_buf[i]=0x55;     // fill data area with 0x55

  for (i=12;i<100;i++)  rx_buf[i]=0xaa;     // fill data area with 0xaa

Status=1;

ENET_PDD_EnableInternalLoopback(ENET_BASE_PTR, PDD_ENABLE);

 

ETH1_ReceiveFrame(eth_handler,  BufferListPtr,  1);

eth_rx_set =0;

ETH1_SendFrame(eth_handler, BufferDescListPtr, 1);

   eth_tx_set = 0;

 

 

 

for (i=0;i<100;i++)
{
Delay(1000);
  if(eth_tx_set)
break;
}

 

 

for (i=0;i<100;i++)
{
Delay(1000);
   if(eth_rx_set)
break;
}
if (eth_tx_set && eth_rx_set )
{
Status=0;
  for(i=12;i<90;i++)  // compare recived data

        {

                if (tx_buf[i] != rx_buf[i])
              {
                  Status=0;

                   break;

              }
             

        }

 

}
else
{
Status = 1;
TxStr(ErrorMsg);
}
return Status;

Original Attachment has been moved to: ETH.c.zip

Original Attachment has been moved to: ENET_PDD.h.zip

Labels (1)
0 Kudos
6 Replies

1,132 Views
trilokjt
Contributor III

I'm using Keil and PEx is there any provision to add Lwip to it? I tried 2nd Option as you said but I failed. Is there any document to getting started with 2nd option? I don't want do in KDS because I already wrote body of Project in keil. So

Thank you

Trilok

0 Kudos

1,132 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Trilok

  You can download examples in Keil, search Kinetis Expert in the web, after that log in and select the option "Build an SDK". See the picture below

kinetis expert.png

Select the board that you are using and name the configuration

kinetis expert3.png

Write a Package name SDK version 1.3 and then choose Keil MDK in Supported toolchain, with the host that you are working. Be sure to mark the FreeRTOS option.

kinetis expert2.png

Click Build SDK Package and select "software vault" to see the download process. I recommended to you, take a look lwip examples.

Hope it helps

Mario

0 Kudos

1,132 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Trilok

It seems to me you are sending Raw Ethernet frames, unfortunately we don’t have examples, but if you want to take a look to the KQRUG, it shows an initialization code example for ENET Module.

http://www.nxp.com/files/32bit/doc/quick_ref_guide/KQRUG.pdf

However, due to complexity of the Ethernet protocol, I recommend you to use a Multi Layered Software Architecture and a TCP/IP stack. The OSI model and the TCP/IP model are the most popular multilayer communication models.

The next image shows you the layers the TCP communication model.

ethernet.png

According to the image above, when sending an Ethernet packet the data is generated in the application layer, then Transport Layer protocol header (TCP in this case) is concatenated to the payload, this header contains tracking transmitted data segments, ACK received, unacknowledged data and connection ports, then another header for the Network layer is added including Time to live, source IP and destination IP address. At the end the MCU creates the Ethernet Header containing preamble, source and destination MAC address, and with all that information calculates the Checksum and send the packet.

When receiving data the MCU checks the FCS, then IP header is decoupled and destination IP is compared to evaluate if it belongs to this device, if it doesn´t then the entire frame is ignored. After this the network layer header (TCP in this case) is decoupled and the connection port is checked, the last layer decouples the application header if it exists and gets the payload.

If you try to send Ethernet data without TCP/IP stack, you have to create all the headers each layer one by one manually and it might be complicated.

On the other hand a TCP/IP stack will create all the headers like TCP, IP and you only have to provide the data, and when you are receiving data, a TCP/IP stack will process the headers and give you the payload without all the headers. This is why it is strongly recommended to use a TCP/IP stack, as it makes all that process, and the user can only focus in the application.

NXP provides different tools with TCP/IP Stacks:

-MQX4.2 with RTCS

-KSDK2.0 with lwIP

           

RTCS TCP/IP Stack in MQX 4.2

RTCS provides a rich assortment of TCP/IP networking application protocols and uses the NXP MQX RTOS drivers for Ethernet and serial connectivity.

For stating with MQX go to www.nxp.com/mqx

Once you install MQX you will find different examples using RTCS, you can follow the next path: C:\Freescale\Freescale_MQX_4_2\rtcs\examples

Note: RTCS is no longer supported in SDK2.0

Lightweight TCP/IP (lwIP) Stack in Kinetis SDK

NXP provides a software development kit for Kinetis MCUs that includes system startup, peripheral drivers, USB and connectivity stacks, middleware, and real-time operating system (RTOS) kernels. The Kinetis SDK also includes getting started and API documentation along with usage examples and demo applications

For starting with KSDK follow this link https://community.freescale.com/docs/DOC-329662

The TCP/IP stack provided in KSDK is Lightweight IP (lwIP), it also provides several protocols and you could check next path for examples using lwIP:

C:\Freescale\SDK_2.0\boards\K60D100M\demo_apps\lwIP

If you are getting stated with this TCP/IP stack. The next document is a guide on how to reproduce this example as a standalone project.

https://community.freescale.com/docs/DOC-252874

As a side comment, please note that the K60DN512 is the first silicon version of K60 and it is no longer manufactured. For new designs it is strongly recommended to use a second version like K60D100M,

Let me know if you have any question.

Regards,

Mario

1,132 Views
norbertoj
Contributor III

Hi Mario,

I have a similar problem. I need to create two communications (UDP and TCP/IP). I am sending commands with parameters in TCP/IP and UDP, and I need to receive commands in TCP/IP. The problem is that I need and interrupt of flag that tell me that there is a message to process. I'm working with tasks. So, I don't know how to do it in MQX and RTCS. I saw that there is the tcp.h, ip.h and udp.h, but I didn't find how to add Data to the datagram. :smileysad:

0 Kudos

1,132 Views
trilokjt
Contributor III

Hi Mario

Thank you so much for info

I'm using Processor expert Generated code in my project. I'm doubt about whether it has proper TCP/IP Stack or Not. And I doing project on Keil IDE.

0 Kudos

1,132 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi

There are 3 important point to be clear

-PEx Processor Expert

-TCP/IP stack

-IDE

PEx is a development system to create, configure, software components that generate source code, for ENET, it can provide initialization examples, and creates a simple driver, but this option is the same problem, you have to create the headers manually, PE doesn´t provides  a TCP/IP stack.

Unfortunately we don´t have a solution with this features, PEx + TCP/IP stack + KEIL.

Other options could be

  1. KDS + PEx + RTCs you can check the next document https://community.freescale.com/docs/DOC-106170
  2. KEIL + KSDK 2.0 + lwIP, without PEx
  3. Add to your project (manually) the lwIP stack, and you can read the next document, and use as a reference to PEx, the process in the document is created in KDS. https://community.freescale.com/docs/DOC-252874

Best Regards

Mario

0 Kudos