title: How to receive data over Ethernet using LWIP, UDP
body: <p>I'm trying to send data to and from my computer and an <a href="https://www.st.com/en/microcontrollers-microprocessors/stm32h745-755.html" rel="nofollow noreferrer">STM32H745</a> over Ethernet using <a href="https://en.wikipedia.org/wiki/LwIP" rel="nofollow noreferrer">LwIP</a> and UDP. I have successfully configured the card and right now I can send data from the card to a Python script running on the computer. However, I don't understand how udp_recv works <a href="https://www.nongnu.org/lwip/2_0_x/group__udp__raw.html" rel="nofollow noreferrer">&lt;udp,lwip&gt;</a> or how to receive data with UDP on LwIP in general, and I can't find examples that do just that. Where is the data being received? Should I even use udp_recv?</p>
  <p>In the main loop I run MX_LWIP_Process, which runs ethernetif_input which somehow handles the received data, but I don't understand where it puts it.</p>
  <p>Below is the main code, just for reference.</p>
  <pre><code>const char* message = &quot;a&quot;;
  
  HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1); // orange
  
  ip_addr_t PC_IPADDR;
  IP_ADDR4(&amp;PC_IPADDR, 192, 168, 1, 200);
  
  u16_t port = 8000;
  
  struct udp_pcb* my_udp = udp_new();
  
  struct pbuf* udp_buffer = NULL;
  
  /* Infinite loop */
  for (;; )
  {
      MX_LWIP_Process();
      HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1); // orange
      HAL_Delay(1000);
  
      udp_buffer = pbuf_alloc(PBUF_TRANSPORT, strlen(message), PBUF_RAM);
      if (udp_buffer != NULL)
      {
          memcpy(udp_buffer-&gt;payload, message, strlen(message));
          udp_sendto(my_udp, udp_buffer,&amp;PC_IPADDR, port);
          pbuf_free(udp_buffer);
      }
  
      //udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
  }
  </code></pre>