Skip to content

Fix STM32H7 multi-descriptor RX segment lengths - #1362

Open
kzorer wants to merge 1 commit into
FreeRTOS:mainfrom
kzorer:fix/stm32h7-rx-segment-length
Open

kzorer wants to merge 1 commit into
FreeRTOS:mainfrom
kzorer:fix/stm32h7-rx-segment-length

Conversation

@kzorer

@kzorer kzorer commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description

Fix the segment length passed by HAL_ETH_ReadData() to the RX link callback when an STM32H7 Ethernet frame spans multiple DMA descriptors.

The current implementation reads RDES3.PL for every descriptor. In the STM32H7 enhanced RX descriptor format, PL contains the total frame length on the last descriptor; it is not the length of each intermediate segment. Consequently, a frame that occupies more than one RX DMA buffer can be linked with incorrect segment lengths and reconstructed incorrectly.

This change:

  • uses heth->Init.RxBuffLen for every non-last descriptor;
  • reads the total frame length from PL only on the last descriptor; and
  • preserves the existing last-segment calculation by subtracting the accumulated length.

The change is limited to the STM32H7 HAL Ethernet receive path.

Test Steps

Hardware-in-the-loop validation was performed on an STM32H745ZI using FreeRTOS+TCP with D-cache enabled. The RX DMA buffer size was reduced to 256 bytes so ordinary Ethernet frames crossed multiple RX descriptors. A Windows UDP echo validator compared every returned payload byte with the transmitted data.

The following tests passed without reported payload corruption or timeout:

  • 100 packets at each payload size: 18, 32, 100, 200, 209-215, 220, 400, 465, 466, 469-472, 500, 700, 978, 982, 1000, 1234, 1400, and 1472 bytes;
  • 10,000 packets with a 1400-byte payload;
  • 10,000 packets with random payload sizes from 18 to 1472 bytes; and
  • 1,000 four-packet bursts, for a total of 4,000 packets.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

N/A

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

RDES3.PL contains the total frame length only on the last RX descriptor. Using it for intermediate descriptors produces invalid linked-buffer lengths for frames spanning more than one DMA buffer.

Use the configured RX buffer length for intermediate descriptors, and calculate the remaining frame length from PL only for the last descriptor.
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.

1 participant