MII on MPC5748G

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

MII on MPC5748G

Jump to solution
3,022 Views
tiju
Contributor II

Hi,

I have a custom board made from the devkit MPC5748G. Instead of RMII, we use MII and its directly connected to another chip that uses RvMII.

Is there already some sample code available so that I can use the MII code to interact with the other chip.

Or can I reuse the ENET sample code by just changing the pin muxes and the code to

ethernet1_InitConfig0.miiMode = ENET_MII_MODE;

Any help is appreciated.

Thanks and Regards,

Tiju

Labels (3)
0 Kudos
Reply
1 Solution
2,367 Views
tiju
Contributor II

Ok, I've made up an ICMP packet and with reply which toggles the led.

Here is the code.

 

uint8_t my_ping_data[] = {
        0x18,0xdb,0xf2,0x3b,0xc0,0x59,0x11,0x22,0x33,0x44,0x55,0x66,0x08,0x00,0x45,0x00,
        0x00,0x3c,0x3a,0x2c,0x00,0x00,0x80,0x01,0x7d,0x2d,0xc0,0xa8,0x01,0x12,0xc0,0xa8,
        0x01,0x05,0x08,0x00,0xcd,0x8f,0x00,0x01,0x7f,0xcb,0x61,0x62,0x63,0x64,0x65,0x66,
        0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,
        0x77,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69
};

uint16_t length;

void build_ping(uint8_t *data)
{
#if 1
    uint8_t dst_mac[6]  = { 0x18, 0xdb, 0xf2, 0x3b, 0xc0, 0x59 };    /* MAC address of target */
    uint8_t dst_ip[4]   = { 0xc0, 0xa8, 0x01, 0x05 };                /* 192.168.1.5 IP of target */
#else
    uint8_t dst_mac[6]  = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };    /* MAC address of board */
    uint8_t dst_ip[4]   = { 0xc0, 0xa8, 0x01, 0x12 };                /* 192.168.1.18 IP of board */
#endif
    uint8_t src_mac[6]  = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };    /* MAC address of board */
    uint8_t src_ip[4]   = { 0xc0, 0xa8, 0x01, 0x12 };                /* 192.168.1.18 IP of board */

 

    /* MAC and IP addresses */
    copy_buff(&data[FRAME_ETH_DEST_MAC_OFFSET], dst_mac, 6);
    copy_buff(&data[FRAME_ETH_SRC_MAC_OFFSET], src_mac, 6);
    copy_buff(&data[FRAME_IP_DEST_OFFSET], dst_ip, 4);
    copy_buff(&data[FRAME_IP_SRC_OFFSET], src_ip, 4);

 

    /* Clear IP and ICMP checksums (to be filled in by the MAC) */
    data[FRAME_IP_CHECKSUM_OFFSET] = 0;
    data[FRAME_IP_CHECKSUM_OFFSET + 1] = 0;
    data[FRAME_ICMP_CHECKSUM_OFFSET] = 0;
    data[FRAME_ICMP_CHECKSUM_OFFSET + 1] = 0;

 

    /* Update ICMP type to represent Ping */
    data[FRAME_ICMP_TYPE_OFFSET] = FRAME_ICMP_TYPE_ECHO_REQUEST;

 

}

 

Add this to rx_callback

else if (buffList[0].data[FRAME_IP_PROTO_OFFSET] == FRAME_IP_PROTO_ICMP &&
                    buffList[0].data[FRAME_ICMP_TYPE_OFFSET] == FRAME_ICMP_TYPE_ECHO_REPLY){

 

                /* Toggle output value LED1 if we get ping reply*/
                SIUL2->GPDO[LED/4] = SIUL2->GPDO[LED/4] ^ (SIUL2_GPDO_PDO_4n_WIDTH << (SIUL2_GPDO_PDO_4n_SHIFT - (8 * (LED & 0x03))));
            }

 

In main add this:

    enet_buffer_t buff;

    buff.data = my_ping_data;
    buff.length = sizeof(my_ping_data);
    build_ping(buff.data);

 

  for (;;)
  {
    /* Send back an ICMP echo reply frame */
    ENET_DRV_SendFrame(INST_ETHERNET1, &buff, 1);
      /* Insert a small delay to make the blinking visible */
      delay(720000);

}

 

Thanks and Regards,

Tiju

View solution in original post

3 Replies
2,368 Views
tiju
Contributor II

Ok, I've made up an ICMP packet and with reply which toggles the led.

Here is the code.

 

uint8_t my_ping_data[] = {
        0x18,0xdb,0xf2,0x3b,0xc0,0x59,0x11,0x22,0x33,0x44,0x55,0x66,0x08,0x00,0x45,0x00,
        0x00,0x3c,0x3a,0x2c,0x00,0x00,0x80,0x01,0x7d,0x2d,0xc0,0xa8,0x01,0x12,0xc0,0xa8,
        0x01,0x05,0x08,0x00,0xcd,0x8f,0x00,0x01,0x7f,0xcb,0x61,0x62,0x63,0x64,0x65,0x66,
        0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,
        0x77,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69
};

uint16_t length;

void build_ping(uint8_t *data)
{
#if 1
    uint8_t dst_mac[6]  = { 0x18, 0xdb, 0xf2, 0x3b, 0xc0, 0x59 };    /* MAC address of target */
    uint8_t dst_ip[4]   = { 0xc0, 0xa8, 0x01, 0x05 };                /* 192.168.1.5 IP of target */
#else
    uint8_t dst_mac[6]  = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };    /* MAC address of board */
    uint8_t dst_ip[4]   = { 0xc0, 0xa8, 0x01, 0x12 };                /* 192.168.1.18 IP of board */
#endif
    uint8_t src_mac[6]  = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };    /* MAC address of board */
    uint8_t src_ip[4]   = { 0xc0, 0xa8, 0x01, 0x12 };                /* 192.168.1.18 IP of board */

 

    /* MAC and IP addresses */
    copy_buff(&data[FRAME_ETH_DEST_MAC_OFFSET], dst_mac, 6);
    copy_buff(&data[FRAME_ETH_SRC_MAC_OFFSET], src_mac, 6);
    copy_buff(&data[FRAME_IP_DEST_OFFSET], dst_ip, 4);
    copy_buff(&data[FRAME_IP_SRC_OFFSET], src_ip, 4);

 

    /* Clear IP and ICMP checksums (to be filled in by the MAC) */
    data[FRAME_IP_CHECKSUM_OFFSET] = 0;
    data[FRAME_IP_CHECKSUM_OFFSET + 1] = 0;
    data[FRAME_ICMP_CHECKSUM_OFFSET] = 0;
    data[FRAME_ICMP_CHECKSUM_OFFSET + 1] = 0;

 

    /* Update ICMP type to represent Ping */
    data[FRAME_ICMP_TYPE_OFFSET] = FRAME_ICMP_TYPE_ECHO_REQUEST;

 

}

 

Add this to rx_callback

else if (buffList[0].data[FRAME_IP_PROTO_OFFSET] == FRAME_IP_PROTO_ICMP &&
                    buffList[0].data[FRAME_ICMP_TYPE_OFFSET] == FRAME_ICMP_TYPE_ECHO_REPLY){

 

                /* Toggle output value LED1 if we get ping reply*/
                SIUL2->GPDO[LED/4] = SIUL2->GPDO[LED/4] ^ (SIUL2_GPDO_PDO_4n_WIDTH << (SIUL2_GPDO_PDO_4n_SHIFT - (8 * (LED & 0x03))));
            }

 

In main add this:

    enet_buffer_t buff;

    buff.data = my_ping_data;
    buff.length = sizeof(my_ping_data);
    build_ping(buff.data);

 

  for (;;)
  {
    /* Send back an ICMP echo reply frame */
    ENET_DRV_SendFrame(INST_ETHERNET1, &buff, 1);
      /* Insert a small delay to make the blinking visible */
      delay(720000);

}

 

Thanks and Regards,

Tiju

2,367 Views
veronicavelciu
NXP Employee
NXP Employee

Hello Tiju,

The sample code should work with the changes mentioned by you: updating the pins configuration and the miiMode field of the ENET driver configuration structure.

Please let me know if you have any issues.

Best regards,

Veronica

0 Kudos
Reply
2,367 Views
tiju
Contributor II

Hi Veronica,

Thanks for confirming.

Is there a sample transmit code (ICMP) for ENET available to test by enabling the loopback in the code available by default?

If not, how can we test the interface?

Thanks and Regards,

Tiju

0 Kudos
Reply