Skip to content

Commit 9620b0f

Browse files
committed
STM32 - fix bug were sockets stop receiving data
The function _eth_arch_low_level_input() is meant to pass data into LWIP and to prepare the ethernet buffers to receive more data. If the LWIP heap is empty and the call to pbuf_alloc() in _eth_arch_low_level_input returns null, the ethernet receive buffers are not updated to receive data. Because of this the ethernet RX interrupt will not fire. Since the RX interrupt is the only thing that triggers a call to _eth_arch_low_level_input(), the receive buffers will never get cleared, and the device stops receiving data. To prevent this from happening, this patch ensures that the function _eth_arch_low_level_input() clears the receive buffers even if a new pbuf for the data couldn't be allocated. This issue can be reproduce by running the test "features-feature_lwip-tests-mbedmicro-net-udp_echo_parallel" and on the same machine running the below python script to flood the device with UDP broadcast packets: MY_IP = #ADD your local IP here from socket import * s = socket(AF_INET, SOCK_DGRAM) s.bind((MY_IP, 1234)) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) for _ in range(1000): s.sendto("test data", ('255.255.255.255', 1234)) print("Message sent")
1 parent f31ea01 commit 9620b0f

File tree

1 file changed

+11
-11
lines changed
  • features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_STM

1 file changed

+11
-11
lines changed

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_STM/stm32xx_emac.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,20 @@ static struct pbuf * _eth_arch_low_level_input(struct netif *netif)
305305
memcpy((uint8_t*)((uint8_t*)q->payload + payloadoffset), (uint8_t*)((uint8_t*)buffer + bufferoffset), byteslefttocopy);
306306
bufferoffset = bufferoffset + byteslefttocopy;
307307
}
308+
}
308309

309-
/* Release descriptors to DMA */
310-
/* Point to first descriptor */
311-
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
312-
/* Set Own bit in Rx descriptors: gives the buffers back to DMA */
313-
for (i = 0; i < EthHandle.RxFrameInfos.SegCount; i++) {
314-
dmarxdesc->Status |= ETH_DMARXDESC_OWN;
315-
dmarxdesc = (ETH_DMADescTypeDef*)(dmarxdesc->Buffer2NextDescAddr);
316-
}
317-
318-
/* Clear Segment_Count */
319-
EthHandle.RxFrameInfos.SegCount = 0;
310+
/* Release descriptors to DMA */
311+
/* Point to first descriptor */
312+
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
313+
/* Set Own bit in Rx descriptors: gives the buffers back to DMA */
314+
for (i = 0; i < EthHandle.RxFrameInfos.SegCount; i++) {
315+
dmarxdesc->Status |= ETH_DMARXDESC_OWN;
316+
dmarxdesc = (ETH_DMADescTypeDef*)(dmarxdesc->Buffer2NextDescAddr);
320317
}
321318

319+
/* Clear Segment_Count */
320+
EthHandle.RxFrameInfos.SegCount = 0;
321+
322322
/* When Rx Buffer unavailable flag is set: clear it and resume reception */
323323
if ((EthHandle.Instance->DMASR & ETH_DMASR_RBUS) != (uint32_t)RESET) {
324324
/* Clear RBUS ETHERNET DMA flag */

0 commit comments

Comments
 (0)