Skip to content

STM32 NI: fix linked-RX handling and robustness issues#1317

Open
HTRamsey wants to merge 2 commits intoFreeRTOS:mainfrom
HTRamsey:fix/stm32-network-interface-important-fixes
Open

STM32 NI: fix linked-RX handling and robustness issues#1317
HTRamsey wants to merge 2 commits intoFreeRTOS:mainfrom
HTRamsey:fix/stm32-network-interface-important-fixes

Conversation

@HTRamsey
Copy link
Copy Markdown
Contributor

@HTRamsey HTRamsey commented Feb 25, 2026

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

  • Rework HAL_ETH_RxLinkCallback handling for linked RX messages and fragmented frames
  • Remove obsolete ETH HAL workaround/warning code now superseded by current HAL
  • Remove outdated RX buffer length assert tied to legacy assumptions
  • Add missing packet filtering hook path and PHY link refresh helper
  • Use HAL getter APIs for state/error reporting where available
  • Add safety guards for ETH IRQ and RX allocation/cache handling paths
  • Refresh STM32 ETH HAL sources from upstream ST repos used by this tree

Out of scope (follow-up PRs)

  • Additional HAL feature enablement
  • Multiple NIC compatibility support

Copilot AI review requested due to automatic review settings February 25, 2026 06:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return HAL_OK;;
return HAL_OK;

Copilot uses AI. Check for mistakes.
pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
}

return HAL_OK;;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return HAL_OK;;
return HAL_OK;

Copilot uses AI. Check for mistakes.
@HTRamsey HTRamsey force-pushed the fix/stm32-network-interface-important-fixes branch from becff5b to da1fd52 Compare February 25, 2026 08:29
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.
@HTRamsey HTRamsey force-pushed the fix/stm32-network-interface-important-fixes branch from da1fd52 to 490635a Compare February 25, 2026 10:03
@HTRamsey
Copy link
Copy Markdown
Contributor Author

@htibosch This has just fixes & HAL version updates now so should be easier to review

@htibosch
Copy link
Copy Markdown
Contributor

Thank you very much, @HTRamsey.
I will test it on my NUCLEO-H755ZI-Q and report back.

@htibosch
Copy link
Copy Markdown
Contributor

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.
As a temporary fix I made it promiscuous:

xFilterConfig.ReceiveAllMode = ENABLE; // DISABLE;
xFilterConfig.PassAllMulticast = ENABLE; // DISABLE;
xFilterConfig.PromiscuousMode = ENABLE; // DISABLE;

and I changed these two functions to allow all packets:

static BaseType_t prvAcceptPacket( EMACData_t * pxEMACData,
                                   const NetworkBufferDescriptor_t * const pxDescriptor,
                                   uint16_t usLength )
{
    return pdTRUE;
}

static eFrameProcessingResult_t eConsiderPacketForProcessing( const uint8_t * const pucEthernetBuffer )
{
    return eProcessBuffer;
}

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.

@htibosch
Copy link
Copy Markdown
Contributor

When ipconfigUSE_LINKED_RX_MESSAGES is not enabled, the compiler gives an error. It can be solved safely with the following change:

-        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 :-)

@HTRamsey
Copy link
Copy Markdown
Contributor Author

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)
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.

3 participants