Repository navigation
mcxe31b emac - #201
mcxe31b emac#201twcook86 wants to merge 11 commits into
Conversation
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.
|
There was a problem hiding this comment.
🟡 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
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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.
3b16b9e to
19f2ebf
Compare


nxp_mcxe_emac: standalone EMAC driver for NXP MCX E31B (also E327/E32B)
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