MAC controller of STM32 network


The previous article mainly introduced the external interface of STM32《STM32 network circuit design》That is, area 1 in the figure below.

This article will focus on the MAC controller of STM32, that is, area 2 in the figure below.


01. MAC overview of stm32

The full name of STM32 MAC controller is mediaaccess control.

Modes supported by the MAC controller of stm32f207

  • IEEE 802.3 compliant mac

  • 10 / 100Mbps network

  • Full duplex and half duplex communication

  • MII interface and RMII interface with external phy

  • It supports the insertion or deletion of preamble and frame start data (SFD)

  • Supports IPv4 header checksum check

  • Support Ethernet wake-up

  • Payload check


In fact, when designing the MAC controller, St designed other functions, such as PTP (IEEE1588) precise time protocol and MMC network statistics. These functions are not commonly used, and I have not contacted them, so I won’t explain them any more.

For the above: it supports the insertion or deletion of preamble and frame start data (SFD).

Previous tweets《Ethernet data header》Preamble and frame start data (SFD) are not mentioned in. An Ethernet data structure is as follows:


Most network devices support the insertion or deletion of preamble and frame start data (SFD). Therefore, it can be said that this is the data packaged by the network hardware device in front of the Ethernet frame. Personally, I don’t think it belongs to the TCP / IP protocol cluster.

02. MAC address filtering

The MAC controller of STM32 supports MAC address filtering.

Destination address filtering:

  • Unicast filtering

  • Multicast filtering

  • Broadcast filtering

Note: Broadcast filtering will result in ARP broadcasts not being received. Please see《ARP protocol in TCP / IP protocol cluster》。

Source address filtering:

  • Unicast filtering

The MAC controller of STM32 also supports rule reversal. For example, only unicast filtering reception is allowed in the past. After reversal, only unicast is not received.

In the actual project development of STM32, you only need to call the library file of St

ETH_ InitStructure.ETH_ BroadcastFramesReception =ETH_ BroadcastFramesReception_ Enable;// Allow all broadcast frames to be received

For MAC address related information, what is broadcast and MAC address representation, please see the previous tweets《Ethernet data header》。

03. Payload inspection

The payload check is actually the IP protocol. The length must be greater than 46 bytes. If it is insufficient, fill in pad bytes. See for details《5000 words “liver” this IP protocol》。

When the number of bytes received from the application is less than 60 (DA + SA + LT + data), zero is appended to the transmission frame so that the data length is exactly 46 bytes to meet the requirements of IEEE802.3.


04. Checksum

First of all, it is clear that the MAC controller of STM32 cannot automatically verify all checksums in TCP / IP protocol. STM32 implements the checksum of IPv4, ICMP, TCP and UDP protocols.

When sending, STM32 will automatically calculate the checksum and insert it automatically.

When receiving, STM32 will automatically verify whether the checksum is correct.

The above functions can be turned on by the following operations:

Through in eth_ Set the IPCO bit in the maccr register to enable receive checksum offload.

By setting the CIC bit in the tdes1 register, checksum calculation and insertion are enabled during transmission.

However, in the actual code development, the operation register is not required. The library interface using ST is as follows

ETH_ InitStructure.ETH_ ChecksumOffload = ETH_ ChecksumOffload_ Enable;           // Enable frame checksum offload for IPv4 and TCP / UDP / ICMP

Click to view the album where this article is located,Stm32f207 network development

Recommended Today

C # regular implementation of UBB parsing class code

The parsed code can pass XHTML   one   Strict verification;It includes title, link, font, alignment, picture, reference, list and other functions  Ubb.ReadMe.htm UBB code description title [H1] title I [/ H1] Title I [H2] Title II [/ H2] Title II [H1] Title III [/ H1] Title III [H4] Title IV [/ H4] Title IV […]