Skip to content

mcxe31b emac - #201

Open
twcook86 wants to merge 11 commits into
wolfSSL:masterfrom
twcook86:mcxe31b_emac
Open

twcook86 wants to merge 11 commits into
wolfSSL:masterfrom
twcook86:mcxe31b_emac

Conversation

@twcook86

@twcook86 twcook86 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

nxp_mcxe_emac: standalone EMAC driver for NXP MCX E31B (also E327/E32B)

Depends on #196 (MCXE247 nxp_mcxe_enet driver). This branch is built on
top of it. Review only the last 4 commits; the rest drop out once #196
merges. The new driver only adds files under src/port/nxp_mcxe_emac/; the
wolfBoot test build uses #196's build-time WOLFIP_POLL_BUDGET.

Note: Goes with wolfBoot PR #1001

Tested on the FRDM-MCXE31B with the wolfBoot test-app:
TCP 88-90 Mbit/s receive and 86 Mbit/s send
UDP 95.7 Mbit/s each way

Replace the fsl_enet based port with a register-level ENET, LAN8741 and
eDMA driver that builds without the vendor SDK.

- NXP_MCXE_ENET_IRQ: polled (0) or interrupt driven (1). The receive
  interrupt lets poll() return at once on an empty ring; send() sleeps in
  wfi when the transmit ring is full.
- NXP_MCXE_ENET_EDMA: copy frames between the rings and wolfIP buffers
  with an eDMA channel, memcpy for short frames or on error.
- NXP_MCXE_ENET_STATS: frame and DWT cycle counters for throughput
  profiling, read with nxp_mcxe_enet_stats_get().
- A full transmit ring waits for the oldest frame instead of failing,
  since wolfIP does not retry a dropped ACK.
- config.h: RXBUF_SIZE and TXBUF_SIZE can be overridden by the build.
wolfIP_poll() takes up to 128 frames from each device per call. On a slow
CPU under a line-rate UDP flood the socket buffer fills after a few
datagrams, and the rest of the batch is processed only to be dropped before
the application can read. A smaller budget lets the application drain the
socket between batches.
eth_poll() released an errored frame (FIFO overrun, CRC error) and returned
0, which wolfIP takes as an empty ring, so poll_devices() stopped and left
the rest of the ring for the next poll. Under a line-rate flood while the
CPU was also transmitting, the MAC refilled each freed descriptor with
another overrun fragment and the ring stayed full: in a UDP bidir test 71k
polls returned 4k good frames and 93% of received frames overflowed the
FIFO. Release errored frames and look at the next descriptor, returning on
a good frame, an empty ring, or after one pass over the ring.

UDP bidir at 80 MHz: board rx 2.9 -> 19.1 Mbit/s.
The checksums added one 16-bit word at a time, byte swapping each, and
transport_checksum was a quarter of the CPU time on a Cortex-M4 at line
rate. csum_add() adds 32-bit words in host byte order into a 64-bit sum,
four per iteration, through memcpy so the buffer need not be aligned.
csum_fold() folds to 16 bits once and swaps back to network order (the
one's complement sum is byte order independent, RFC 1071 2(B)). The
transport, ICMP, IP header and multicast checksums all use them.

MCX E247 at 80 MHz: udp-rx 43.4 -> 56.0, udp-tx 41.7 -> 49.6, tcp-rx
27.0 -> 29.2, tcp-tx 25.6 -> 28.7 Mbit/s. Matches a byte-wise RFC 1071
reference for every length 0-1600 at four alignments; unit, multicast,
asan, ubsan and ipv6 unit tests pass.
A timed-out eDMA copy returned while the channel could still be pending
or running, and its buffers then changed hands (the receive descriptor
back to the MAC, the transmit buffer to the MAC). edma_stop() now keeps
a channel that has not started from starting (clears START) and
cancels a running one with CR.CX, then waits until it is idle. If it
does not become idle, the eDMA is not used again and all copies use
memcpy.

tx_wait() slept in wfi until the transmit interrupt. DWT_CYCCNT stops
while the core sleeps, so a transmitter that never raised the interrupt
would never time out. It now polls the descriptor within the 5 ms
limit, and the transmit interrupt, which only woke that wfi, is no
longer enabled.

Tested on the FRDM-MCXE247: the wolfBoot test-app speed suite passes
at unchanged rates, and with the copy timeout forced to 20 cycles all
411124 copies were cancelled and redone by the CPU with no errors.
Copilot AI balanced review requested due to automatic review settings November 24, 2026 06:17
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

amd-zynq7000

  • OCM: .text +160 B (+0.1%, 234,680 B / 262,144 B, total: 90% used)

linux-x64-libwolfip

  • Code: .eh_frame +64 B, .eh_frame_hdr +16 B, .text -173 B (-0.1%, 165,289 B)

lpc54s018

  • FLASH: .text +128 B (+0.2%, 68,732 B / 16,777,216 B, total: 0% used)

stm32h563-echo

  • FLASH: .text +100 B (+0.3%, 39,860 B / 2,064,384 B, total: 2% used)

stm32h563-freertos-echo

  • FLASH: .text +96 B (+0.1%, 79,304 B / 2,064,384 B, total: 4% used)

stm32h563-freertos-https

  • FLASH: .text +1,176 B (+0.4%, 283,316 B / 2,064,384 B, total: 14% used)

stm32h563-full

  • FLASH: .text +1,176 B (+0.3%, 354,180 B / 2,064,384 B, total: 17% used)

stm32h563-https

  • FLASH: .text +1,176 B (+0.4%, 280,396 B / 2,064,384 B, total: 14% used)

stm32h563-tzen-ssh

  • FLASH: .text +1,184 B (+0.4%, 319,012 B / 654,336 B, total: 49% used)

stm32h563-wolfhal-nucleo

  • FLASH: .text +100 B (+0.2%, 40,492 B / 2,097,152 B, total: 2% used)

stm32n6

  • SRAM: .text +72 B (+0.1%, 129,856 B / 524,288 B, total: 25% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Oversized packet-socket frames can permanently block TX queues, and descriptor-ring tails at the DTCM boundary can be programmed with untranslated DMA addresses.

2 open issues
What changed in this PR

Adds an SDK-independent EMAC port for NXP MCX E31B, with documented E327/E32B Cortex-M7_0 support, for wolfIP’s wolfBoot test-app integration. The branch builds on the MCXE247 ENET work in #196.

Changes:

  • Adds EMAC initialization, DMA descriptor rings, polling or receive interrupts, and optional statistics.
  • Documents board wiring, clock setup, DTCM placement, and configuration options.
  • Includes the stacked ENET driver changes, configurable polling budget, and shared checksum optimizations.
File Description
src/​wolfip.c Makes the polling budget configurable and consolidates checksum calculations.
src/​port/​nxp_mcxe_enet/​README.md Documents standalone ENET operation and memory requirements.
src/​port/​nxp_mcxe_enet/​nxp_mcxe_enet.h Adds interrupt, eDMA, statistics, and configuration APIs.
src/​port/​nxp_mcxe_enet/​nxp_mcxe_enet.c Replaces SDK calls with direct ENET, PHY, and eDMA control.
src/​port/​nxp_mcxe_enet/​nxp_mcxe_enet_regs.h Defines registers for the standalone ENET driver.
src/​port/​nxp_mcxe_enet/​config.h Allows socket-buffer size overrides.
src/​port/​nxp_mcxe_emac/​README.md Documents supported hardware, integration, and tuning.
src/​port/​nxp_mcxe_emac/​nxp_mcxe_emac.h Defines the EMAC public API and build options.
src/​port/​nxp_mcxe_emac/​nxp_mcxe_emac.c Implements EMAC initialization, DMA transfers, interrupts, and statistics.
src/​port/​nxp_mcxe_emac/​nxp_mcxe_emac_regs.h Defines EMAC and platform-control registers.
src/​port/​nxp_mcxe_emac/​config.h Supplies networking defaults for the new port.

Review effort: Balanced

Comment thread src/port/nxp_mcxe_emac/config.h Resolved
Comment thread src/port/nxp_mcxe_emac/nxp_mcxe_emac.c Resolved
@twcook86 twcook86 self-assigned this Nov 24, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #201

Scan targets checked: wolfip-src, wolfip-bugs
Not reviewed (no scan target covers them): src/port/nxp_mcxe_emac/README.md, src/port/nxp_mcxe_enet/README.md
Coverage: 6 of 9 in-scope changed file(s) opened by the reviewer; not opened: src/port/nxp_mcxe_emac/config.h, src/port/nxp_mcxe_enet/config.h, src/port/nxp_mcxe_enet/nxp_mcxe_enet.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

eth_send() rejects frames over 1518 bytes, but LINK_MTU was 1536, so
wolfIP accepted 1519-1536 byte packet-socket frames that the driver
then refused forever, blocking the socket's transmit queue. Set
LINK_MTU to 1518 and check it against ENET_MAX_FRAME_LEN at build
time; the socket buffer defaults stay at 1536 bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants