cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP sendto() is not sending the data in the buffer passed to it

ttatakis
Associate III

I have a H745 Nucleo board running LwIP. I have implemented a simple udp echo server. I receive all of the data for the udp messages being sent to the board but the data I am sending back never makes it out on the wire (verified with Wireshark). I have stepped all the way down to HAL_ETH_Transmit() and everything looks fine at that point. The correct number of bytes get transmitted, just the wrong data (mostly zeros).

I'm assuming this is a memory/cache/dma configuration issue but I can not seem to locate the problem. I've tried doubling the task stack size but that did not help. I've also been through numerous HowTo's including this one: https://community.st.com/s/article/How-to-create-project-for-STM32H7-with-Ethernet-and-LwIP-stack-working

Any help is appreciated. My entire project is attached, including the ioc for CubeMX. All the relevant code is in main.c: functions myudpInit() and mydupEcho().

3 REPLIES 3
TDK
Guru

Disable data cache and try it. If that solves it, you are likely not handling cache appropriately. Clean before sending, invalidate before reading. Buffers must be cache aligned.

If you feel a post has answered your question, please click "Accept as Solution".

> invalidate before reading

Invalidating before reading is too late. It has to be invalidated before starting the reception - therefore before passing it to DMA. The reason is cache eviction, which can happen at any time.

https://community.st.com/s/question/0D53W00000oXSzySAG/different-cache-behavior-between-stm32h7-and-stm32f7

https://community.st.com/s/question/0D50X0000C9hGoz/weird-cache-writeback-behavior-for-stm32f7508

embedko
Associate

Hi. I faced the same problem.
The problem is that the send buffer is located in cached memory. When using the lwip_send socket API, the transfer data buffer is stored as a reference by netbuf_ref. Then this buffer will be sent by DMA
Ways to solve the problem:

  1. clean DCache for send buffer before call lwip_send
  2. configure MPU region with Write-Through policy for send buffer
  3. define LWIP_NETIF_TX_SINGLE_PBUF 1 in lwipopts.h to force copy tx data to buffer from LwIP heap