Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,20 @@ An Example
----------

There is a good example in the STM32 Ethernet driver. The STM32 F7
Ethernet driver (``arch/arm/src/stm32f7/stm32_ethernet.c``) derives
Ethernet driver (formerly ``arch/arm/src/stm32f7/stm32_ethernet.c``) derived
directly from the STM32 F4 Ethernet driver
(``arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c``). These two Ethernet MAC peripherals
are nearly identical. Only changes that are a direct consequence of the
STM32 F7 D-Cache were required to make the driver work on the STM32 F7.
Those changes are summarized below.

.. note::

The F7 now uses the F4 driver, which sends and receives the IOBs of the
network in place (see :doc:`stm32_ports`): the RX and TX packet buffers
described below are gone. With the D-Cache, the driver pads the
descriptors, cleans the TX IOBs and invalidates the RX IOBs.

Reorganize DMA Data Structure
-----------------------------

Expand Down
35 changes: 34 additions & 1 deletion Documentation/guides/chip-specific/stm32_ports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,39 @@ that the chip Kconfig ``select``-s next to its timer IP-core selector. The
16-bit cases - TIM2 on STM32F10xx/STM32L15xx/STM32L0 and TIM5 on
STM32F10xx/STM32F30xx - simply leave them unset.

Ethernet drivers
================

The Ethernet MAC drivers of F1, F2, F4, F7
(``common/stm32/stm32_eth_m3m4_v1.c``) and H5, H7, N6
(``common/stm32/stm32_eth_v2.c``) are lower half drivers of the network upper
half (``include/nuttx/net/netdev_lowerhalf.h``, see
:ref:`Network Drivers <netdriver>`). New STM32 network drivers must use this
interface too.

The drivers send and receive the IOBs of the network in place. Each DMA
descriptor holds one IOB and a frame spans ``NSEGS`` descriptors, where
``NSEGS`` is ``CONFIG_NET_ETH_PKTSIZE + 4`` divided by ``CONFIG_IOB_BUFSIZE``,
rounded up. The frames are received in the interrupt work
(``NETDEV_RX_DIRECT``). When no IOB is free, the received frame is
dropped. ``CONFIG_STM32_ETH_NRXDESC`` and
``CONFIG_STM32_ETH_NTXDESC`` are the number of RX and TX frames. The build
fails if the IOB pool is too small for the rings. All STM32 Ethernet
configurations use:

- ``CONFIG_IOB_NBUFFERS=100``: the rings hold ``(NRXDESC + 1) * NSEGS +
NTXDESC`` IOBs, 76 with the default 8 RX and 4 TX frames of up to 1514
bytes, and the network keeps the others,
- ``CONFIG_IOB_THROTTLE=8``: the IOBs that the driver needs to refill the
RX ring for one frame. Without this reserve the TCP receive window takes
all free IOBs and received frames are dropped.

With the D-Cache (``CONFIG_ARMV7M_DCACHE`` or ``CONFIG_ARMV8M_DCACHE``),
also in the write-through mode, ``CONFIG_IOB_ALIGNMENT`` and
``CONFIG_IOB_BUFSIZE`` must be multiples of the D-Cache line size, for
example ``CONFIG_IOB_ALIGNMENT=32`` and ``CONFIG_IOB_BUFSIZE=224``: the RX
DMA corrupts other data in the D-Cache lines of its buffers.

Family peripheral inventory
===========================

Expand Down Expand Up @@ -540,7 +573,7 @@ CAN/FDCAN bxCAN arch/arm/src/stm32f7/stm32_can.c
DAC to be done not supported
DMA v2 style arch/arm/src/stm32f7/stm32_dma.c
DMA2D v1 arch/arm/src/stm32f7/stm32_dma2d.c
ETH to be done arch/arm/src/stm32f7/stm32_ethernet.c
ETH to be done arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c
EXTI to be done arch/arm/src/stm32f7/stm32_exti_gpio.c
FLASH to be done arch/arm/src/stm32f7/stm32_flash.c
FMC/FSMC to be done arch/arm/src/stm32f7/stm32_fmc.c
Expand Down
5 changes: 5 additions & 0 deletions Documentation/os/drivers/special/net/ethernet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Ethernet Device Drivers
Each Ethernet driver registers itself by calling
``netdev_register()``.

- ``include/nuttx/net/netdev_lowerhalf.h``. (Recommended for new
drivers, see :ref:`Network Drivers <netdriver>`)
A lower half driver registers itself by calling
``netdev_lower_register()``.

- **Examples**: ``drivers/net/dm90x0.c``,
``arch/drivers/arm/src/c5471/c5471_ethernet.c``,
``arch/z80/src/ez80/ez80_emac.c``, etc.
8 changes: 4 additions & 4 deletions arch/arm/src/common/stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ if(CONFIG_STM32_SPI AND CONFIG_STM32_HAVE_IP_SPI_V5)
list(APPEND SRCS stm32_spi_v5.c)
endif()

if(CONFIG_STM32_ETHMAC AND CONFIG_STM32_HAVE_IP_ETHMAC_M3M4_V1)
list(APPEND SRCS stm32_eth_m3m4_v1.c)
endif()

if(CONFIG_STM32_ETHMAC AND CONFIG_STM32_HAVE_IP_ETHMAC_V2)
list(APPEND SRCS stm32_eth_v2.c)
endif()
Expand Down Expand Up @@ -310,10 +314,6 @@ if(CONFIG_STM32_COMMON_LEGACY)
endif()
endif()

if(CONFIG_STM32_ETHMAC AND CONFIG_STM32_HAVE_IP_ETHMAC_M3M4_V1)
list(APPEND SRCS stm32_eth_m3m4_v1.c)
endif()

if(CONFIG_STM32_PWR AND CONFIG_STM32_HAVE_IP_PWR_M3M4_V1)
list(APPEND SRCS stm32_pwr_m3m4_v1.c stm32_exti_pwr_m3m4_v1.c)
endif()
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/common/stm32/Kconfig.periph
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ config STM32_ETHMAC
select NETDEVICES
select ARCH_HAVE_PHY
select STM32_PHY_HAVE_POLLED if !STM32_COMMON_LEGACY
select ARCH_HAVE_NETDEV_STATISTICS

# CORDIC peripherals

Expand Down
10 changes: 4 additions & 6 deletions arch/arm/src/common/stm32/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ ifeq ($(CONFIG_STM32_SPI)$(CONFIG_STM32_HAVE_IP_SPI_V5),yy)
CHIP_CSRCS += stm32_spi_v5.c
endif

ifeq ($(CONFIG_STM32_ETHMAC)$(CONFIG_STM32_HAVE_IP_ETHMAC_M3M4_V1),yy)
CHIP_CSRCS += stm32_eth_m3m4_v1.c
endif

ifeq ($(CONFIG_STM32_ETHMAC)$(CONFIG_STM32_HAVE_IP_ETHMAC_V2),yy)
CHIP_CSRCS += stm32_eth_v2.c
endif
Expand Down Expand Up @@ -332,12 +336,6 @@ endif
endif
endif

ifeq ($(CONFIG_STM32_ETHMAC),y)
ifeq ($(CONFIG_STM32_HAVE_IP_ETHMAC_M3M4_V1),y)
CHIP_CSRCS += stm32_eth_m3m4_v1.c
endif
endif

ifeq ($(CONFIG_STM32_PWR)$(CONFIG_STM32_HAVE_IP_PWR_M3M4_V1),yy)
CHIP_CSRCS += stm32_pwr_m3m4_v1.c stm32_exti_pwr_m3m4_v1.c
endif
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/common/stm32/hardware/stm32_eth_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
# define ETH_MACMIIAR_CR_100_150 (1 << ETH_MACMIIAR_CR_SHIFT) /* 001 100-150 MHz HCLK/62 */
# define ETH_MACMIIAR_CR_20_35 (2 << ETH_MACMIIAR_CR_SHIFT) /* 010 20-35 MHz HCLK/16 */
# define ETH_MACMIIAR_CR_35_60 (3 << ETH_MACMIIAR_CR_SHIFT) /* 011 35-60 MHz HCLK/26 */
# define ETH_MACMIIAR_CR_150_180 (4 << ETH_MACMIIAR_CR_SHIFT) /* 100 150-180 MHz HCLK/102 */
# define ETH_MACMIIAR_CR_150_216 (4 << ETH_MACMIIAR_CR_SHIFT) /* 100 150-216 MHz HCLK/102 */
#endif
#define ETH_MACMIIAR_MR_SHIFT (6) /* Bits 6-10: MII register */
#define ETH_MACMIIAR_MR_MASK (31 << ETH_MACMIIAR_MR_SHIFT)
Expand Down
Loading
Loading