Microchip® Advanced Software Framework

Quickstart guide for GMAC driver.

This is the quickstart guide for the Ethernet MAC, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic use case

In the basic use case, the GMAC driver are configured for:

  • PHY component KSZ8061RNB is used
  • GMAC uses RMII mode
  • The number of receive buffer is 16
  • The number of transfer buffer is 8
  • MAC address is set to 00-04-25-1c-a0-02
  • IP address is set to 192.168.0.2
  • Gateway is set to 192.168.0.1
  • Network mask is 255.255.255.0
  • PHY operation max retry count is 1000000
  • GMAC is configured to not support copy all frame and support broadcast
  • The data will be read from the ethernet

Setup steps

Prerequisites

  1. System Clock Management (sysclock)
  2. Power Management Controller (pmc)
  3. PHY component (KSZ8061RNB)

Example code

Content of conf_eth.h

* #define GMAC_RX_BUFFERS 16
* #define GMAC_TX_BUFFERS 8
* #define MAC_PHY_RETRY_MAX 1000000
* #define ETHERNET_CONF_ETHADDR0 0x00
* #define ETHERNET_CONF_ETHADDR0 0x00
* #define ETHERNET_CONF_ETHADDR1 0x04
* #define ETHERNET_CONF_ETHADDR2 0x25
* #define ETHERNET_CONF_ETHADDR3 0x1C
* #define ETHERNET_CONF_ETHADDR4 0xA0
* #define ETHERNET_CONF_ETHADDR5 0x02
* #define ETHERNET_CONF_IPADDR0 192
* #define ETHERNET_CONF_IPADDR1 168
* #define ETHERNET_CONF_IPADDR2 0
* #define ETHERNET_CONF_IPADDR3 2
* #define ETHERNET_CONF_GATEWAY_ADDR0 192
* #define ETHERNET_CONF_GATEWAY_ADDR1 168
* #define ETHERNET_CONF_GATEWAY_ADDR2 0
* #define ETHERNET_CONF_GATEWAY_ADDR3 1
* #define ETHERNET_CONF_NET_MASK0 255
* #define ETHERNET_CONF_NET_MASK1 255
* #define ETHERNET_CONF_NET_MASK2 255
* #define ETHERNET_CONF_NET_MASK3 0
* #define ETH_PHY_MODE ETH_PHY_MODE
*

A specific gmac device and the receive data buffer must be defined; another ul_frm_size should be defined to trace the actual size of the data received.

* static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
*
* uint32_t ul_frm_size;
*

Add to application C-file:

* void gmac_init(void)
* {
*
*
*
* gmac_option.uc_copy_all_frame = 0;
* gmac_option.uc_no_boardcast = 0;
* memcpy(gmac_option.uc_mac_addr, gs_uc_mac_address, sizeof(gs_uc_mac_address));
* gs_gmac_dev.p_hw = GMAC;
*
* gmac_dev_init(GMAC, &gs_gmac_dev, &gmac_option);
*
* NVIC_EnableIRQ(GMAC_IRQn);
*
* ethernet_phy_init(GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz());
*
* ethernet_phy_auto_negotiate(GMAC, BOARD_GMAC_PHY_ADDR);
*
* ethernet_phy_set_link(GMAC, BOARD_GMAC_PHY_ADDR, 1);
*

Workflow

  1. Ensure that conf_eth.h is present and contains the following configuration symbol. This configuration file is used by the driver and should not be included by the user.
    • * #define GMAC_RX_BUFFERS 16
      * #define GMAC_TX_BUFFERS 8
      * #define MAC_PHY_RETRY_MAX 1000000
      * #define ETHERNET_CONF_ETHADDR0 0x00
      * #define ETHERNET_CONF_ETHADDR0 0x00
      * #define ETHERNET_CONF_ETHADDR1 0x04
      * #define ETHERNET_CONF_ETHADDR2 0x25
      * #define ETHERNET_CONF_ETHADDR3 0x1C
      * #define ETHERNET_CONF_ETHADDR4 0xA0
      * #define ETHERNET_CONF_ETHADDR5 0x02
      * #define ETHERNET_CONF_IPADDR0 192
      * #define ETHERNET_CONF_IPADDR1 168
      * #define ETHERNET_CONF_IPADDR2 0
      * #define ETHERNET_CONF_IPADDR3 2
      * #define ETHERNET_CONF_GATEWAY_ADDR0 192
      * #define ETHERNET_CONF_GATEWAY_ADDR1 168
      * #define ETHERNET_CONF_GATEWAY_ADDR2 0
      * #define ETHERNET_CONF_GATEWAY_ADDR3 1
      * #define ETHERNET_CONF_NET_MASK0 255
      * #define ETHERNET_CONF_NET_MASK1 255
      * #define ETHERNET_CONF_NET_MASK2 255
      * #define ETHERNET_CONF_NET_MASK3 0
      * #define ETH_PHY_MODE GMAC_PHY_MII
      *
  2. Enable the system clock:
  3. Enable PIO configurations for GMAC:
  4. Enable PMC clock for GMAC:
  5. Set the GMAC options; it's set to copy all frame and support broadcast:
  6. Initialize GMAC device with the filled option:
  7. Enable the interrupt service for GMAC:
    • * NVIC_EnableIRQ(GMAC_IRQn);
      *
  8. Initialize the PHY component:

The link will be established based on auto negotiation.

Establish the ethernet link; the network can be worked from now on:

Usage steps

Example code

Add to, e.g., main loop in application C-file:

* gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size));
*

Workflow

  1. Start reading the data from the ethernet:
    • gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size));