Skip to content

mcxe31b emac - #201

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

twcook86 wants to merge 14 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

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 →

stm32h563-freertos-https

  • FLASH: .text +8 B (+0.0%, 284,884 B / 2,064,384 B, total: 14% used)

stm32h563-full

  • FLASH: .text +8 B (+0.0%, 357,988 B / 2,064,384 B, total: 17% used)

stm32h563-https

  • FLASH: .text +8 B (+0.0%, 281,964 B / 2,064,384 B, total: 14% 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

@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, src/test/unit/unit.c, src/test/unit/unit_tests_proto.c
Coverage: 2 of 8 in-scope changed file(s) opened by the reviewer; not opened: src/port/nxp_mcxe_emac/config.h, src/port/nxp_mcxe_emac/nxp_mcxe_emac.c, src/port/nxp_mcxe_enet/config.h, src/port/nxp_mcxe_enet/nxp_mcxe_enet.h, src/port/nxp_mcxe_enet/nxp_mcxe_enet_board.h, src/port/nxp_mcxe_enet/nxp_mcxe_enet_regs.h

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved

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

A full TX ring can cause a 5 ms busy-wait per send inside wolfIP_poll(), delaying receive processing, timers, and other interfaces instead of immediately returning -WOLFIP_EAGAIN as required.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread src/port/nxp_mcxe_emac/nxp_mcxe_emac.c Resolved
- nxp_mcxe_emac_stop() disables the interrupts, the MAC and its DMA, so a
  caller can stop it before a clock change; init uses it to stop a running
  MAC first.
- Remove tx_wait_cycles from the stats: send() never waited, and the
  nxp_mcxe_enet_stats layout it mirrored no longer has it.
- Reset and restart the MAC and DMA after a fatal bus error, including
  one raised while the restart runs; the restart is kept out of line so
  poll() and send() stay small. After a failed re-init or restart,
  poll() and send() drop traffic until init succeeds.
- After an MDIO timeout, later transfers fail at once until re-init.
- Read the core and CSR clocks live for timeouts, the MDIO divider and
  the stats; us_to_cycles() scales milliseconds and the remainder
  separately so long delays do not overflow.
- Keep the PHY address once the LAN8741 is identified.
- Document the init return codes and blocking time, that only a LAN8741
  is supported, link changes, bus error restarts, and the 1518-byte
  (VLAN-tagged) frame limit.
- CI: Cortex-M7 compile of the driver and wolfIP core (polled, IRQ with
  stats, IRQ without OSF), checking the interrupt handler symbol and
  that both include the port's config.h.

Tested on the FRDM-MCXE31B: speed test unchanged.
-I. came first, so wolfip.c included the top-level config.h instead of
src/port/nxp_mcxe_enet/config.h. Put the port directory first, as the
wolfBoot test-app does, and check that wolfip.c and the driver both
include the port's config.h.
- grep -q exits at the first match, which can end nm with SIGPIPE and,
  with pipefail, fail the check for a handler that is there. Use
  grep -c, which reads all of its input.
- nxp_mcxe_enet: drop the stale TX timeout reference in send().
- Set DEMCR.TRCENA before the DWT unlock: the DWT ignores writes, the
  unlock too, until it is set, and the cycle counter then never starts.
- init() stops the interface before its argument and cache checks, so a
  call that fails with -1 or -5 also leaves it stopped, as documented.
- Stop the build when the descriptor counts are not 2 to 1024 or the
  DMA burst length is not 1, 2, 4, 8, 16 or 32.

Tested on the FRDM-MCXE31B: speed test unchanged.
Replace the driver's copy of the clause-22 register map and of the PHY
reset and auto-negotiation start with nxp_phy.h and nxp_phy_init(),
through MDIO accessors as in nxp_mcxe_enet. The LAN8741 ID check and
the special control/status register stay in the driver. Its reset and
auto-negotiation waits are bounded to about 1 s each, so init() without
link now blocks for up to about 7 s.

Tested on the FRDM-MCXE31B: link up, DHCP, speed test unchanged, and a
second init.
eth_poll() copied each frame from the buffer address in the receive
descriptor. Copy from the driver's rx_buf[] for that descriptor
instead, and check the length against the buffer size; the descriptor
snapshot no longer reads the buffer field.
A completely full transmit ring moves the tail pointer onto the oldest
pending descriptor, which the DMA reads as an empty ring, and transmit
stalls. eth_send now refuses a frame when the next descriptor is still
owned. README: the timestamp clock stays at /2 at both link speeds.

@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): .github/workflows/mcxe247.yml, .github/workflows/mcxe31b.yml, src/port/nxp_mcxe_emac/README.md
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: src/port/nxp_mcxe_emac/nxp_mcxe_emac.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: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review December 5, 2026 05:46

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

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.

🔵 Needs a closer look

The review is incomplete because one or more reviewers received a runtime budget-stop instruction.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

- emac_reset(): say why MAC_Configuration is written between setting
  SWR and waiting for it, as the NXP SDK does in RMII mode
- The rx_errors stat also counts frames too long for the wolfIP buffer
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