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
- System Clock Management (sysclock)
- Power Management Controller (pmc)
- 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.
*
* 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;
* gs_gmac_dev.
p_hw = GMAC;
*
*
* NVIC_EnableIRQ(GMAC_IRQn);
*
*
*
*
Workflow
- 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
*
- Enable the system clock:
- Enable PIO configurations for GMAC:
- Enable PMC clock for GMAC:
- Set the GMAC options; it's set to copy all frame and support broadcast:
* gmac_option.uc_copy_all_frame = 0;
* gmac_option.uc_no_boardcast = 0;
* gs_gmac_dev.
p_hw = GMAC;
*
- Initialize GMAC device with the filled option:
- Enable the interrupt service for GMAC:
* NVIC_EnableIRQ(GMAC_IRQn);
*
- 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
- 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));