Ethernet Communication

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

Ethernet Communication

Jump to solution
3,489 Views
Govind89
Contributor II

I am new to i.MX RT1170 development and using the EVKBMIMXRT1170 board. I'm working with the built-in example code evkbmimxrt1170_enet_txrx_transfer_cm7 for Ethernet functionality, but I'm finding it difficult to understand how it works.

I would like to request a simpler, bare-metal code example that focuses just on basic Ethernet operations:

  • Ethernet configuration

  • Ethernet initialization

  • Ethernet frame transmission

  • Ethernet frame reception

I need this in API-style simple code without RTOS, using MCUXpresso IDE. Please provide guidance and the simplest base code for Ethernet functionality on my EVKBMIMXRT1170 development board.
i.MX-RT1170 MCUXpresso-IDE 

Tags (2)
0 Kudos
Reply
1 Solution
3,381 Views
mayliu1
NXP Employee
NXP Employee

Hi @Govind89 ,

 

I suggest you can check the example in SDK import Wizard.

mayliu1_0-1746098335143.png

Best Regards

MayLiu

View solution in original post

0 Kudos
Reply
5 Replies
3,460 Views
mayliu1
NXP Employee
NXP Employee

Hi @Govind89 ,

 

Thank you so much for your interest in our products and for using our community.

I think the project you imported is already without FREERTOS, if you want more Ethernet demo, you can check by import  SDK example. 

mayliu1_0-1745898661549.png

If you want know more about the SDK API. you can refer to the document "MCUXpresso SDK API Reference Manual"

https://mcuxpresso.nxp.com/api_doc/dev/329/index.html

Wish it helps you.
If you still have question about it, please kindly let me know.

Wish you a nice day!

Best Regards
MayLiu

0 Kudos
Reply
3,452 Views
Govind89
Contributor II
helle @mayliu1
Thanks for replay

Based on the example, I tried, but I am unable to receive and transmit the frame.

I modified the code to create a simpler version. using evkbmimxrt1170_enet_txrx_transfer_cm7 example code please guide me what will be need to change. i am attech project file.



#include "fsl_debug_console.h"

#include "fsl_silicon_id.h"

#include "fsl_enet.h"

#include "fsl_phy.h"

#include "board.h"



#include "fsl_phyrtl8201.h"



#include "fsl_enet.h"

#include "board.h"



#define EXAMPLE_ENET ENET

#define EXAMPLE_CLOCK_FREQ CLOCK_GetRootClockFreq(kCLOCK_Root_Bus)

#define ENET_RXBD_NUM 4

#define ENET_TXBD_NUM 4

#define ENET_RXBUFF_SIZE ENET_FRAME_MAX_FRAMELEN

#define ENET_TXBUFF_SIZE ENET_FRAME_MAX_FRAMELEN

#define ENET_DATA_LENGTH 1000



/* Buffer descriptors */

AT_NONCACHEABLE_SECTION_ALIGN(enet_rx_bd_struct_t g_rxBuffDescrip[ENET_RXBD_NUM], ENET_BUFF_ALIGNMENT);

AT_NONCACHEABLE_SECTION_ALIGN(enet_tx_bd_struct_t g_txBuffDescrip[ENET_TXBD_NUM], ENET_BUFF_ALIGNMENT);



/* Data buffers */

SDK_ALIGN(uint8_t g_rxDataBuff[ENET_RXBD_NUM][ENET_RXBUFF_SIZE], ENET_BUFF_ALIGNMENT);

SDK_ALIGN(uint8_t g_txDataBuff[ENET_TXBD_NUM][ENET_TXBUFF_SIZE], ENET_BUFF_ALIGNMENT);



/* MAC address */

uint8_t g_macAddr[6] =

{ 0x02, 0x12, 0x13, 0x14, 0x15, 0x16 };



/* ENET handle */

static enet_handle_t g_handle;



static void BuildTestFrame(uint8_t *frame)

{

/* Destination MAC (broadcast) */

for (int i = 0; i < 6; i++)

{

frame[i] = 0xFF;

}



/* Source MAC */

memcpy(&frame[6], g_macAddr, 6);



/* EtherType/Length */

frame[12] = 0x08; // IPv4

frame[13] = 0x00;



/* Simple payload */

for (int i = 14; i < ENET_DATA_LENGTH; i++)

{

frame[i] = i % 256;

}

}



void InitEthernet(void)

{

enet_config_t config;



/* Prepare buffer configuration */

enet_buffer_config_t buffConfig =

{

ENET_RXBD_NUM,

ENET_TXBD_NUM,

ENET_RXBUFF_SIZE,

ENET_TXBUFF_SIZE, g_rxBuffDescrip, g_txBuffDescrip, &g_rxDataBuff[0][0], &g_txDataBuff[0][0],

true,

true,

NULL };



/* Get default ENET configuration */

ENET_GetDefaultConfig(&config);

config.miiMode = kENET_RmiiMode;

config.miiSpeed = kENET_MiiSpeed100M;

config.miiDuplex = kENET_MiiFullDuplex;



/* Initialize ENET */

ENET_Init(EXAMPLE_ENET, &g_handle, &config, &buffConfig, g_macAddr, EXAMPLE_CLOCK_FREQ);

ENET_ActiveRead(EXAMPLE_ENET);

}



int main(void)

{

uint8_t txFrame[ENET_DATA_LENGTH];

uint8_t rxBuffer[ENET_RXBUFF_SIZE];



/* Initialize hardware */

BOARD_InitHardware();



/* Initialize Ethernet */

InitEthernet();



/* Build test frame */

BuildTestFrame(txFrame);



while (1)

{

uint32_t frameLength = 0;



/* Check for received frames */

if (ENET_GetRxFrameSize(&g_handle, &frameLength, 0) == kStatus_Success)

{

if (frameLength > 0)

{

/* Read the frame */

if (ENET_ReadFrame(EXAMPLE_ENET, &g_handle, rxBuffer, frameLength, 0, NULL) == kStatus_Success)

{

/* Process received frame here */

}

}

}



/* Send test frame */

status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *data, uint32_t length, uint8_t ringId,

bool tsFlag, void *context);



ENET_SendFrame(EXAMPLE_ENET, &g_handle, txFrame, ENET_DATA_LENGTH, 0, false, NULL);



/* Small delay */

for (volatile int i = 0; i < 1000000; i++);

}

}











in that i am getting also error undefined reference to `PHY_LinkStatusChange'
0 Kudos
Reply
3,425 Views
mayliu1
NXP Employee
NXP Employee

Hi @Govind89 ,

 

Thanks for your updated information.

I don't recommend modifying the NXP SDK demo code ,because it may introduce additional issues.

Since the NXP SDK demo is already well-optimized , and it was rigorously tested to ensure proper functionality, I suggest you refer to the example code as it is(when the demo runs ok, then you can modify the code you want to test).

Additionally, I suggest you check  the README file for this demo to confirm your development environment is correctly configured.

mayliu1_0-1745985202094.png

Wish it helps you.
If you still have question about it, please kindly let me know.

Wish you a nice day!

Best Regards
MayLiu

0 Kudos
Reply
3,412 Views
Govind89
Contributor II
Thank you for your response. Additionally, I would like to inquire about communication between two RT boards using Ethernet. Both boards have 1 Gbps and 100 Mbps ports available. Could you please advise which example I should follow for this setup?
0 Kudos
Reply
3,382 Views
mayliu1
NXP Employee
NXP Employee

Hi @Govind89 ,

 

I suggest you can check the example in SDK import Wizard.

mayliu1_0-1746098335143.png

Best Regards

MayLiu

0 Kudos
Reply