I am working with the UDP protocol setting. I am able to receive UDP packets correctly until the Sn_RX_RD pointer reaches the end of the 2K RX buffer (I’m using the default 2K, and using Socket 0). Here is the pseudocode of what I am doing:
rx_len = getSn_RX_RSR() // get packet, returns when non-zero rx_len
rx_ptr = getSn_RX_RD() // get Rx pointer
buffer = readData(rx_ptr) // read data at pointer address
rx_ptr += rx_len // calculate new pointer
if (rx_ptr > 0x07ff) // check for wrap-around
setSn_RX_RD() // update pointer
setRECV() // notify receive complete
It works up until the next packet that arrives after the wrap-around. When that packet arrives, the getSn_RX_RSR() function returns 0x07ff and “gets stuck” at 0x07ff. So the W5500 reports that a packet is continuously arriving with length 0x07ff.
Any hints on how to handle the wrap-around logic – or perhaps it is something else I’ve missed?