STM32 NI: fix linked-RX handling and robustness issues#1317
STM32 NI: fix linked-RX handling and robustness issues#1317HTRamsey wants to merge 2 commits intoFreeRTOS:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extracts critical STM32 network interface fixes from PR #1309, focusing on correctness and stability improvements for linked-RX message handling, fragmented frame processing, and general robustness.
Changes:
- Reworked linked RX message and fragmented frame handling with overflow protection and proper buffer management
- Replaced direct HAL structure member access with HAL getter APIs (HAL_ETH_GetState, HAL_ETH_GetError, HAL_ETH_GetDMAError, HAL_ETH_GetMACError, HAL_ETH_GetTxBuffersNumber) for better encapsulation
- Added missing packet filtering function eConsiderPacketForProcessing to handle protocol-level filtering when ipconfigETHERNET_DRIVER_FILTERS_PACKETS is enabled
- Added vForceRefreshPhyLinkStatus helper and PHY link refresh on initialization complete
- Added safety guard for ETH IRQ handler to check Instance != NULL before calling HAL_ETH_IRQHandler
- Improved cache coherency handling in RX allocation and link callbacks with proper cache line alignment
- Fixed RX descriptor index calculation to use previous index (ulPrevIdx) instead of current
- Removed obsolete ETH HAL workarounds for bugs that are fixed in current HAL versions
- Updated STM32 H7 and H5 ETH HAL extended driver files from upstream ST repositories (formatting changes only)
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| source/portable/NetworkInterface/STM32/NetworkInterface.c | Main network interface implementation with critical fixes for RX handling, HAL API usage, IRQ safety, and packet filtering |
| source/portable/NetworkInterface/STM32/Drivers/H7/stm32h7xx_hal_eth_ex.h | Updated H7 HAL extended header with formatting standardization from upstream ST |
| source/portable/NetworkInterface/STM32/Drivers/H7/stm32h7xx_hal_eth_ex.c | Updated H7 HAL extended source with formatting standardization from upstream ST |
| source/portable/NetworkInterface/STM32/Drivers/H5/stm32h5xx_hal_eth_ex.h | Updated H5 HAL extended header with formatting standardization from upstream ST |
| source/portable/NetworkInterface/STM32/Drivers/H5/stm32h5xx_hal_eth_ex.c | Updated H5 HAL extended source with formatting standardization from upstream ST |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC)); | ||
| } | ||
|
|
||
| return HAL_OK;; |
There was a problem hiding this comment.
The extra semicolon after HAL_OK will cause a syntax error. This appears to be present in the upstream STMicroelectronics HAL source that was imported. Remove the extra semicolon.
| return HAL_OK;; | |
| return HAL_OK; |
| pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC)); | ||
| } | ||
|
|
||
| return HAL_OK;; |
There was a problem hiding this comment.
The extra semicolon after HAL_OK will cause a syntax error. This appears to be present in the upstream STMicroelectronics HAL source that was imported. Remove the extra semicolon.
| return HAL_OK;; | |
| return HAL_OK; |
becff5b to
da1fd52
Compare
Consolidate the critical STM32 network-interface fixes into one change set for focused review. - Rework Rx link callback flow for linked RX messages and fragmented frame handling - Remove obsolete ETH HAL workarounds now covered by current ST HAL drivers - Add missing packet-filter hook integration and PHY link refresh helper - Use HAL getter APIs for state/error reporting instead of direct handle access - Add safety guards around ETH IRQ and RX allocation/cache maintenance paths Also refresh STM32 ETH HAL sources to current upstream ST driver versions used by this branch.
da1fd52 to
490635a
Compare
|
@htibosch This has just fixes & HAL version updates now so should be easier to review |
|
Thank you very much, @HTRamsey. |
|
I had difficulties getting it to run on my STM32H755: it would start up, contact DHCP, send out logging on UDP, but there seems to be a problem on the reception side.
and I changed these two functions to allow all packets: With these changes, all of my integration tests passed, like ARP, DHCP4, RA, ND, iperf3, NTP, DNS, ICMP/ping, TCP, UDP, HTTP/GET, all done both IPv4 and IPv6 (when available). Now I will look at your list of proposed changes. |
|
When - pxTxPart = pxTxPart->pxNextBuffer;
+ #if ipconfigIS_ENABLED( ipconfigUSE_LINKED_RX_MESSAGES )
+ pxTxPart = pxTxPart->pxNextBuffer;
+ #else
+ pxTxPart = NULL;
+ #endif
}And I must admit that iperf will run faster without the linked-RX feature, both on IPv4 and IPv6 :-) |
|
I'll make some updates & do some more testing and get back to you |
- Fix BroadcastFilter polarity (ENABLE blocks broadcasts, use DISABLE) - Add volatile to ISR/task shared variables (xSwitchRequired, xDropCurrentRxFrame) - NULL-terminate pxNextBuffer in linked-RX chain - Move prvValidateFrame (DMA error check) after HAL_ETH_ReadData where descriptor state is finalized - Init MAC filters/ARP offload before HAL_ETH_Start_IT - Flush TX metadata, semaphore, and HAL bookkeeping in prvRecoverFromCriticalError - Remove racy TX semaphore resync from prvReleaseTxPacket - Fix RxLinkCallback drop handler: don't clear xDropCurrentRxFrame prematurely, release start descriptor on multi-buffer overflow - Release TX buffer in TxFreeCallback on invalid uxDescCount - Remove premature RxAllocateCallback cache invalidation - Replace broken eConsiderPacketForProcessing with prvPassesPacketFilter covering IPv4/IPv6 checks the stack skips (fragmentation, loopback, version, broadcast source, multicast source, unspecified address) - Gate ipconfigETHERNET_DRIVER_FILTERS_PACKETS to H5/H7 with required checksum offload and frame-type filtering prerequisites - Fix uint8_t shift UB in MAC address helpers (cast to uint32_t) - Fix uint32_t to uintptr_t for register address arithmetic - Remove dead uxMACEntryIndex clamping, add slot reclaim on remove - Restore compatibility defines (ETH_IP_PAYLOAD_UNKNOWN/UDP/TCP/IGMP)
Summary
This PR extracts the critical STM32 network-interface fixes from the broader work in #1309, so review can focus on correctness and stability first.
It specifically addresses the linked-RX/fragment handling concerns raised in review and keeps follow-on feature work out of scope.
Included changes
Out of scope (follow-up PRs)