Using STM32Duino on Nucleo F429ZI:

#include <LwIP.h>
#include <STM32Ethernet.h>
#include <EthernetUdp.h>

IPAddress remoteIP;
unsigned int remotePort;

EthernetUDP Udp;
uint8_t packetBuffer[UDP_TX_PACKET_MAX_SIZE];

void setup() 
  IPAddress localIP = /***/;
  IPAddress netmask = /***/;
  IPAddress dns = /***/;
  IPAddress gateway = /***/;

  Ethernet.begin(localIP, netmask, dns, gateway);
  uint8_t *mac = Ethernet.macAddress();

  int port = 8888;

void loop() 

void processUDPMessage(void)
  while (int size = Udp.parsePacket())
    if (size > 0) parsePacket(size);

void parsePacket(int size)
  remoteIP = Udp.remoteIP();
  remotePort = Udp.remotePort();

  Udp.read(packetBuffer, size);
  Serial.println((char *) packetBuffer);  

If I received at least 4 packets at the same time, one of them is not received. Each packet is less than 50 byte long.

Is there anything I could do to improve the reliability of my code?

  • are you sure it is STM32duino by Roger Clark and not STM32 by STM? does STM32Duino support F4 and STM32Ethernet? the experts are here stm32duino.com – Juraj Feb 17 '20 at 14:36
  • The STM32 Core is by STM, the STM32duino STM32Ethernet library is by "Various" and STM32duino LwIP is by Adam Dunkels. – Mark Feb 17 '20 at 14:51
  • UDP is, by definition, unreliable. If you want more reliability then use TCP. – Majenko Feb 17 '20 at 15:55
  • @Majenko, sorry I don't agree. This is a problem in my code, not in the UDP protocol. I use it since 10 years and I never missed a packet. Here I miss packets every time they are sent. It's a different thing :) – Mark Feb 18 '20 at 6:55
  • @Mark My point is: that UDP is not a reliable protocol ("reliable" has a specific meaning in networking). That means that the protocol that you design with it must be tolerant of dropped packets. Yes, there may well be problems with your code or with the IP stack in use, but if you designed your protocol properly then it shouldn't care that you lost some packets. – Majenko Feb 18 '20 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.