mirror of https://github.com/ARMmbed/mbed-os.git
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")
pull/4536/head
parent
f31ea01237
commit
9620b0fc7f
|
|
@ -305,6 +305,7 @@ static struct pbuf * _eth_arch_low_level_input(struct netif *netif)
|
||||||
memcpy((uint8_t*)((uint8_t*)q->payload + payloadoffset), (uint8_t*)((uint8_t*)buffer + bufferoffset), byteslefttocopy);
|
memcpy((uint8_t*)((uint8_t*)q->payload + payloadoffset), (uint8_t*)((uint8_t*)buffer + bufferoffset), byteslefttocopy);
|
||||||
bufferoffset = bufferoffset + byteslefttocopy;
|
bufferoffset = bufferoffset + byteslefttocopy;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Release descriptors to DMA */
|
/* Release descriptors to DMA */
|
||||||
/* Point to first descriptor */
|
/* Point to first descriptor */
|
||||||
|
|
@ -317,7 +318,6 @@ static struct pbuf * _eth_arch_low_level_input(struct netif *netif)
|
||||||
|
|
||||||
/* Clear Segment_Count */
|
/* Clear Segment_Count */
|
||||||
EthHandle.RxFrameInfos.SegCount = 0;
|
EthHandle.RxFrameInfos.SegCount = 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* When Rx Buffer unavailable flag is set: clear it and resume reception */
|
/* When Rx Buffer unavailable flag is set: clear it and resume reception */
|
||||||
if ((EthHandle.Instance->DMASR & ETH_DMASR_RBUS) != (uint32_t)RESET) {
|
if ((EthHandle.Instance->DMASR & ETH_DMASR_RBUS) != (uint32_t)RESET) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue