Repository navigation
Derive the STM32 Ethernet default MAC from the unique device ID - #202
Merged
Merged
Conversation
|
Contributor
There was a problem hiding this comment.
🟢 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:11prefix. - 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
dgarske
force-pushed
the
stm32_eth_mac
branch
from
December 1, 2026 18:19
0af6bd7 to
c2b475b
Compare
mattia-moffa
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
stm32_eth_init()(BFAR 0x08FFF800).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.