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
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.
- 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));