Professional Documents
Culture Documents
STM32 Ethernet Summary
STM32 Ethernet Summary
Application layer
Session Layer
IP Network Layer
(MAC) Ethernet
between network entities:
RMII
interface
Select
Media External
Access Control PHY
MAC 802.3 MII
MDC
MDIO
Physical Layer Interface
TX _CLK 7
TXD[3:0]
• MII = 18 pins TX_ER
TX_EN
• 8 data pins
STM324x7
RX _CLK
802.3 MAC
• 6 control pins RXD[3:0]
External
RX_ER
• 2 Clock signals RX_DV
PHY
PHY_CLK
Selected in SYSCFG_PMC
• RMII = 10 pins TXD[1:0]
TX_EN
• 4 data
STM324x7
RXD[1:0]
802.3 MAC
• 3 control RX_ER
External
• 1 for the clock CRS_DV
PHY
MDC
• 2 for PHY configuration MDIO
• RX_ER(optional on switches) REF_CLK
PHY_CLK
Ethernet Interface Block Diagram (1/4) 8
MII 15 pins
MII+MDC
Ethernet = 18 pins
MAC 10/100
MDC/MDIO 2 pins
XTAL
HCLK
25MHz OSC PLL
25MHz MCO XT1
25MHz PHY
STM32F107/2x7/4x7
Ethernet Interface Block Diagram (2/4)
• One 50Mhz external oscillator 9
• This 50Mhz output clock is provided to the MAC & the PHY
• RMII interface
• 7 pins for the communication between the MAC & PHY
• 2 pins for the MDC (PHY control)
• 1 pin for the 50Mhz clock input
Ethernet
RMII 7 pins
RMII+MDC
MAC 10/100
1 pin +clock
50MHz = 10 pins
MDC/MDIO 2 pins
XTAL
25MHz OSC HCLK
PLL
STM32F107/2x7/4x7 XT1/XT2
OSC
50MHz 50MHz PHY
Ethernet Interface Block Diagram (3/4) 10
Ethernet
RMII 7 pins
RMII+MDC
MAC 10/100
1 pin +clock
50MHz = 10 pins
MDC/MDIO 2 pins
HCLK
OSC PLL
50MHz STM32F107/F4x7 XT1/XT2
50MHz PHY
Ethernet Interface Block Diagram (4/4)
• One 25Mhz external crystal (internal oscillator) 11
• RMII interface
• 7 pins for the communication between the MAC & PHY
• 2 pins for the MDC (PHY control)
• 1 pin for the 50Mhz clock input
Ethernet
RMII
MAC 10/100
50MHz Clk
MDC/MDIO
XTAL
25MHz OSC PLL
HCLK
Clk_out 50MHz
25MHz
XT1 25MHz PLL
STM32F107/2x7/4x7
PHY
PHY Registers 12
• So when you change from PHY to another, the user have to update
this value depending on the used external PHY.
• In file “stm32f7xx_hal_conf.h”
MAC
Media Access Control 18
• Operation modes and PHY support
• 10/100Mbps data rate
MAC 802.3
• Full-duplex and half-duplex operations
• MII and RMII interface to external PHY MAC Control
Registers
• Offload processing
• Preamble and start-of-frame data (SFD) Offload PTP
insertion or deletion Processing IEEE1588
• Checksum checking of IPv4 header and
TCP, UDP, or ICMP payload PMT MMC
• Calculates and inserts IPv4 header and TCP,
UDP, or ICMP payload checksums
• Low power mode
• Remote wakeup packet and AMD Magic
Packet™ detection
• Processing control
• MAC address filtering
• IEEE 802.3-2002 standard
• IEEE 1588-2008/PTPv2 support
• Supports network statistics with RMON/MIB
counters (RFC2819/RFC2665)
MAC 802.3 Operation : the frame format 19
Start of Frame
Destination
Checksum
MAC Address
TCP-IP
Source Stack data
MAC Address
Offload features
Ethernet datagram management overview
20
Automatic CRC and pad generation 21
When the number of bytes received from the application falls below 60
(DA+SA+LT+Data),zeros are appended to the transmitting frame to make
the data length exactly 46 bytes to meet the minimum data field
requirement of IEEE 802.3.
2KB
MAC 802.3 External
RX FIFO PHY
DP@TDES0= 0
DC@TDES0=0
DA SA LT Data Preamble&SFD DA SA LT Data Pad CRC
<46bytes 46bytes
Checksum Offload 22
Transmit:
Receive:
ETH_MACCR
Implement in code(1/2) 24
• Accuracy is
09:10
09:00 09:01
09:00
09:00
Grand
09:05
09:00 09:30
09:00
Master
Clock
09:00
26
Precision Time Protocol (IEEE1588) : How it works 27
Comparing the transmission of messages
27
Precision Time Protocol (IEEE1588) : How it works 28
Master Clock
8 Slave Clock
t1 10 Computation done PTP
by the slave
9
11
A = t2 - t1 = Delay + Offset
10 t1 A 12 B = t4 - t3 = Delay - Offset
11 Delay = (A + B)/2
t2 13 Offset = (A - B)/2
12
t4 14
13 This allow the Master
t3 B 15 and the slave to be
14 synchronized with a
t4
16 sub-µsecond precision
15
17
Propagation delay
16
Clocks Offset
28
Precision Time Protocol : Time stamping 29
The DMA returns the time The DMA returns the time
DMA stamp to the Application in the DMA stamp to the Application in the
RX descriptor TX descriptor
MAC The MAC captures the time MAC The MAC captures the time
stamp as soon as the frame stamp when the Tx Frame’s
PTP reception is complete PTP SFD is output on the MII
IEEE1588 IEEE1588
• PTP Objective
• Synchronize all nodes in a local network area (LAN)
with very high accuracy (<1us) by use of HW time
stamping Master Synchronization Master
Time Ref Time Ref
• PTP protocol define synchronization messages
between nodes and routers.
Path1 Path2 Path1 Path2
delay1 delay2 delay1 delay2
• STM32F7 MAC features
PTP SYNC
• MAC is compliant with PTPv2 (IEEE1588-2008)
messages Slave1 Slave2 Slave1 Slave2
Time1 Time2 Time Ref Time Ref
• Accurate timing reference is based on hardware
counter
• 64 internal bits (32 bits for second and 32 bits for
nanosecond counter)
• Counter accuracy on HCLK is down to ~ 5 ns (@
200MHz)
• Export timing reference through output pulse-per-
second (PPS) signal
30
Low-power modes 31
Mode Description
Run Active.
Sleep Active. Peripheral interrupts cause the device to exit Sleep mode.
The Ethernet peripheral is able to detect frames while the system is in the Stop
Stop
mode, provided that the EXTI line 19 is enabled.
Standby Powered-down. The peripheral must be reinitialized after exiting Standby mode.
Power Management 32
Power
Off
MAC Rx
MII PHY Network
• Wake-up
Down Off
• Wake-up is controlled by the network
• Wake-up packets are
• AMD Magic packet
• User defined
• Wakeup frame detection is an event that
can wakeup the system from STOP mode
Ethernet Block Diagram 33
• The MAC core has two FIFOs, of 2KB each one, with a configurable
threshold.
• Two modes for popping data towards the MAC, for frames transmission &
for frames reception:
Dedicated DMA
2KB
AHB Master
Media
BusMatrix
RX FIFO
Interface
DMA
2KB MAC 802.3
TX FIFO
Ethernet Block Diagram : FIFO
35
• Two modes for popping data towards the MAC, for frames
transmission:
• Threshold mode: as soon as the threshold level is reached.
• Store-and-Forward mode: a complete frame is stored into the FIFO.
DATA DATA
• Two modes for popping data towards the DMA, for frames reception:
• Cut-through mode: as soon as the threshold level is reached.
Cut-through mode
Threshold DATA
DATA DATA
DATA DATA
Ethernet Block Diagram : FIFO 37
• Transmission
• TSF: Transmit store and forward
• TTC: Transmit threshold control
• ST: Start/stop transmission
• Reception
• RSF: Receive store and forward
• RTC: Receive threshold control
• SR: Start/stop receive
ETH_DMAOMR
DMA Controller 38
2KB
AHB Master
Media
AHB Bus
BusMatrix
RX FIFO
Interface
Basic address of
receive descriptor
ETH_DMARDLAR
Receive
descriptor
DMA Controller: Descriptors Structure (2/2) 41
Chain mode Ring mode
• Each descriptor points to one buffer. • Each descriptor can point to a maximum of
two buffers.
• Each descriptor include the next
descriptor address. • Configurable descriptor skip length
• hold the status of the transmitted or • The last descriptor point back to the first
received packet. entry.
=1 =0
TCH@TDES0
Single frame/ Multiple descriptors Chain mode
43
Bit28: First Segment : 1
Bit29: Last Segment : 0
Control / Status
First Buffer DMA
Buffers Count
Start of Frame
Buffer1 Address
Next Desc Address
… Bit28: First Segment : 0 First Buffer
Control / Status
TX FIFO
Last Buffer
Buffers Count
DMA
Buffer1 Address
Next Desc Address
Control / Status
First Buffer DMA Start of Frame
Buffers Count
Buffer1 Address
… DMA First Buffer
Buffer2 Address
SRAM
DMA Descriptor Init 45
low_level_init
HAL_ETH_DMATxDescListInit
HAL_ETH_DMARxDescListInit
ethernetif.c
46
Ethernet over STM32 Family
MCU Core Ethernet controller is compliant with the following standards
47
Demo ST Provide 48
MII or RMII
HAL_ETH_Init, call from low_level_init
selection
Polling Mode
(Standalone)
Interrupt Mode
(RTOS)
Polling Rx Mode 51
if (err != ERR_OK)
{
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input
error\n"));
pbuf_free(p);
p = NULL;
}
}
Interrupt Rx Mode 52
Packet received
for( ;; )
{
if (osSemaphoreWait( s_xSemaphore,
TIME_WAITING_FOR_INPUT)==osOK)
{
do
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
{
{
p = low_level_input( netif );
osSemaphoreRelease(s_xSemaphore);
if (p != NULL)
}
{
if (netif->input( p, netif) != ERR_OK )
{
pbuf_free(p);
Release }
semaphore }
}while(p!=NULL);
}
}
}
Transmission Flow
53
Reception Flow
54
Thanks