Skip to content

Derive the STM32 Ethernet default MAC from the unique device ID - #202

Merged
mattia-moffa merged 1 commit into
wolfSSL:masterfrom
dgarske:stm32_eth_mac
Dec 1, 2026
Merged

mattia-moffa merged 1 commit into
wolfSSL:masterfrom
dgarske:stm32_eth_mac

Conversation

@dgarske

@dgarske dgarske commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

stm32_eth_init(ll, NULL) gave every board of a family the same MAC: 02:11:AA:BB:22:33 for the H5 and C5, 02:11:22:33:44:55 for the H7. Every STM32 example in the tree passes NULL, so two boards of one family on a LAN share an address.

Symptom

A NUCLEO-H563ZI and a NUCLEO-C5A3ZG on the same switch both used 02:11:AA:BB:22:33. The DHCP server leased them the same IP, and the switch delivered unicast to whichever board had sent last, so each board lost its DHCP offers and TCP replies intermittently while broadcasts kept arriving. On the H563 this read as a dead receive path: the MAC counted transmitted frames and no unicast received.

Fix

stm32_eth_generate_mac() keeps the locally administered 02:11 prefix and fills the last four bytes from an FNV-1a hash of the 96-bit unique device ID (0x08FFF800 on the H5 and C5, 0x1FF1E800 on the H7), so two boards on one LAN are very unlikely to collide. Under TZEN=1 the H5 reads it from the Non-Secure application, which wolfBoot allows by marking 0x08FFF000-0x08FFFFFF Non-Secure in the SAU. A caller that passes its own MAC is unaffected.

On the H5 and C5 the unique-ID area cannot be read through the instruction cache: with ICACHE enabled the load takes a precise bus fault. wolfBoot leaves ICACHE on at handoff on the C5. The ID is therefore copied with ICACHE disabled, only if it was enabled and after any invalidation in progress (BUSYF) has finished, and ICACHE is restored before the copy is hashed.

The N6 keeps its fixed address: its unique ID is in BSEC rather than in flash, and that path is not tested here.

Hardware / test status

Validated on the LAN where the collision occurred, each board launched by wolfBoot with ICACHE enabled:

  • NUCLEO-C5A3ZG: its own MAC and DHCP lease, and the wolfBoot network update scenarios pass (update, tampered image refused, update, downgrade refused). Without the ICACHE handling the board faults in stm32_eth_init() (BFAR 0x08FFF800).
  • NUCLEO-H563ZI (TZEN=1, Non-Secure application, ICACHE enabled from the Non-Secure side): its own MAC and DHCP lease and an FDO onboarding over the link, with ICACHE still enabled afterwards; the same image without the ICACHE handling faults at 0x08FFF800. Also run with ICACHE disabled.

The H563, H753, N6 and C5A3 ports build cleanly with arm-none-eabi-gcc and -Werror. The H7 path is build-tested only.

Scope

The H7 address is the one for the Ethernet-equipped H72x-H75x parts; the H7A3/B0/B3, whose unique ID sits at 0x08FFF800, have no Ethernet MAC. The N6 can follow once its BSEC read is tested.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 03:15
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

stm32h563-echo

  • FLASH: .text +156 B (+0.4%, 39,916 B / 2,064,384 B, total: 2% used)

stm32h563-freertos-echo

  • FLASH: .text +152 B (+0.2%, 79,360 B / 2,064,384 B, total: 4% used)

stm32h563-freertos-https

  • FLASH: .text +1,160 B (+0.4%, 284,452 B / 2,064,384 B, total: 14% used)

stm32h563-full

  • FLASH: .text +2,032 B (+0.6%, 356,188 B / 2,064,384 B, total: 17% used)

stm32h563-https

  • FLASH: .text +1,160 B (+0.4%, 281,532 B / 2,064,384 B, total: 14% used)

stm32h563-tzen-ssh

  • FLASH: .text +2,032 B (+0.6%, 320,956 B / 654,336 B, total: 49% 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.

🟢 Approval recommended

There are no active review issues blocking the STM32 default MAC-address change.

No open issues 🎉

What changed in this PR

This PR replaces shared default MAC addresses in the STM32 Ethernet driver with device-derived addresses, reducing address collisions when multiple boards share a LAN.

Changes:

  • Derives H5, C5, and Ethernet-equipped H7 default MACs from an FNV-1a hash of the 96-bit device ID, retaining the locally administered 02:11 prefix.
  • Preserves caller-supplied MAC addresses and the N6’s fixed default address.
File Description
src/​port/​stm32/​stm32_eth.c Adds family-specific UID addresses and hash-based default MAC generation.

Review effort: Balanced

@mattia-moffa
mattia-moffa merged commit d5c7f01 into wolfSSL:master Dec 1, 2026
65 of 67 checks passed
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